/** * By passing a list of key-value pairs for each Visual Property, update network view. * * <p>The body should have the following JSON: * * <pre> * [ * { * "visualProperty": "Visual Property Name, like NETWORK_BACKGROUND_PAINT", * "value": "Serialized form of value, like 'red.'" * }, * ... * {} * ] * </pre> * * Note that this API directly set the value to the view objects, and once Visual Style applied, * those values are overridden by the Visual Style. * * @summary Update single network view value, such as background color or zoom level. * @param networkId Network SUID * @param viewId Network view SUID */ @PUT @Path("/{viewId}/network") @Consumes(MediaType.APPLICATION_JSON) public Response updateNetworkView( @PathParam("networkId") Long networkId, @PathParam("viewId") Long viewId, final InputStream is) { final CyNetworkView networkView = getView(networkId, viewId); final ObjectMapper objMapper = new ObjectMapper(); try { // This should be an JSON array. final JsonNode rootNode = objMapper.readValue(is, JsonNode.class); styleMapper.updateView(networkView, rootNode, getLexicon()); } catch (Exception e) { throw getError( "Could not parse the input JSON for updating view because: " + e.getMessage(), e, Response.Status.INTERNAL_SERVER_ERROR); } // Repaint networkView.updateView(); return Response.ok().build(); }
private void display() { CyServiceRegistrarImpl register = new CyServiceRegistrarImpl(bc); CyNetworkViewManager viewManager = register.getService(CyNetworkViewManager.class); CyNetworkViewFactory viewFactory = register.getService(CyNetworkViewFactory.class); CyNetworkView networkView = viewFactory.createNetworkView(network); viewManager.addNetworkView(networkView); VisualMappingFunctionFactory passthroughFactory = register.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)"); VisualMappingFunctionFactory continuousFactory = register.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)"); VisualMappingManager vmManager = register.getService(VisualMappingManager.class); VisualStyleFactory vsFactory = register.getService(VisualStyleFactory.class); VisualStyle vs = vsFactory.createVisualStyle( network.getDefaultNetworkTable().getRow(network.getSUID()).get("name", String.class)); PassthroughMapping pMapping = (PassthroughMapping) passthroughFactory.createVisualMappingFunction( "name", String.class, BasicVisualLexicon.NODE_LABEL); vs.addVisualMappingFunction(pMapping); vs.apply(networkView); ContinuousMapping mapping = (ContinuousMapping) continuousFactory.createVisualMappingFunction( "score", Double.class, BasicVisualLexicon.NODE_FILL_COLOR); Double val1 = getMinimum(network.getDefaultNodeTable().getColumn("score")); BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.GREEN, Color.GREEN); Double val3 = getMaximum(network.getDefaultNodeTable().getColumn("score")); BoundaryRangeValues<Paint> brv3 = new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED); Double val2 = (val1 + val3 + val1 + val1) / 4; BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.YELLOW, Color.YELLOW, Color.YELLOW); mapping.addPoint(val1, brv1); mapping.addPoint(val2, brv2); mapping.addPoint(val3, brv3); vs.addVisualMappingFunction(mapping); vs.apply(networkView); vmManager.addVisualStyle(vs); vmManager.setVisualStyle(vs, networkView); networkView.updateView(); }
/** * By passing list of key-value pair for each Visual Property, update node view. * * <p>The body should have the following JSON: * * <pre> * [ * { * "SUID": SUID of node, * "view": [ * { * "visualProperty": "Visual Property Name, like NODE_FILL_COLOR", * "value": "Serialized form of value, like 'red.'" * }, * ... * {} * ] * }, * ... * {} * ] * </pre> * * Note that this API directly set the value to the view objects, and once Visual Style applied, * those values are overridden by the Visual Style. * * @summary Update node/edge view objects at once * @param networkId Network SUID * @param viewId Network view SUID * @param objectType Type of objects ("nodes" or "edges") */ @PUT @Path("/{viewId}/{objectType}") @Consumes(MediaType.APPLICATION_JSON) public Response updateViews( @PathParam("networkId") Long networkId, @PathParam("viewId") Long viewId, @PathParam("objectType") String objectType, final InputStream is) { final CyNetworkView networkView = getView(networkId, viewId); final ObjectMapper objMapper = new ObjectMapper(); try { // This should be an JSON array. final JsonNode rootNode = objMapper.readValue(is, JsonNode.class); for (JsonNode entry : rootNode) { final Long objectId = entry.get(CyIdentifiable.SUID).asLong(); final JsonNode viewNode = entry.get("view"); if (objectId == null || viewNode == null) { continue; } View<? extends CyIdentifiable> view = null; if (objectType.equals("nodes")) { view = networkView.getNodeView(networkView.getModel().getNode(objectId)); } else if (objectType.equals("edges")) { view = networkView.getEdgeView(networkView.getModel().getEdge(objectId)); } else if (objectType.equals("network")) { view = networkView; } else { throw getError( "Method not supported.", new IllegalStateException(), Response.Status.INTERNAL_SERVER_ERROR); } if (view == null) { throw getError( "Could not find view.", new IllegalArgumentException(), Response.Status.NOT_FOUND); } styleMapper.updateView(view, viewNode, getLexicon()); } // Repaint networkView.updateView(); } catch (Exception e) { throw getError( "Could not parse the input JSON for updating view because: " + e.getMessage(), e, Response.Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); }
public void redo() { ; final CyNetworkView view = viewFactory.createNetworkView(network); networkViewManager.addNetworkView(view); for (final View<CyNode> nodeView : view.getNodeViews()) nodesAndLocations.get(nodeView.getModel()).restoreLocations(nodeView); view.setVisualProperty(NETWORK_CENTER_X_LOCATION, networkCenterX); view.setVisualProperty(NETWORK_CENTER_Y_LOCATION, networkCenterY); view.setVisualProperty(NETWORK_CENTER_Z_LOCATION, networkCenterZ); view.setVisualProperty(NETWORK_SCALE_FACTOR, networkScaleFactor); eventHelper.flushPayloadEvents(); view.updateView(); }
private final void clearAll( final CyNetworkView netView, final View<? extends CyIdentifiable> nodeView) { boolean needToUpdateView = false; final VisualStyle style = vmm.getCurrentVisualStyle(); for (VisualProperty<?> vp : vpSet) { final boolean lock = nodeView.isDirectlyLocked(vp); if (lock) { nodeView.clearValueLock(vp); needToUpdateView = true; } } if (needToUpdateView) { style.apply(netView); netView.updateView(); } }
/** * Apply bypass * * @param netView * @param graphObjectView * @param vp */ private final void applBypassValue( final CyNetworkView netView, final View<? extends CyIdentifiable> graphObjectView, VisualProperty<?> vp) { final ValueEditor<Object> editor = (ValueEditor<Object>) editorManager.getValueEditor(vp.getRange().getType()); final Object bypassValue = editor.showEditor(null, graphObjectView.getVisualProperty(vp)); // Set lock for the vp graphObjectView.setLockedValue(vp, bypassValue); // Apply the new value only for the given view // TODO don't do this, because it overwrites some bypassed values with default ones!!! Calling // setLockedValue should be enough // final CyRow row = netView.getModel().getRow(graphObjectView.getModel()); // vmm.getCurrentVisualStyle().apply(row, graphObjectView); // Redraw the view netView.updateView(); }
@SuppressWarnings("unchecked") @Override protected void doLayout(TaskMonitor taskMonitor) { if (!context.m_cancel && networkView != null && dynView != null) { taskMonitor.setTitle("Compute Dynamic Kamada Kawai Force Layout"); taskMonitor.setStatusMessage("Running energy minimization..."); taskMonitor.setProgress(0); // int size = (int) (4*50*Math.sqrt(nodesToLayOut.size())); int size = (int) (dynView.getCurrentVisualStyle().getDefaultValue(BasicVisualLexicon.NODE_SIZE) * Math.sqrt(nodesToLayOut.size())); // int size =(int) // dynView.getCurrentVisualStyle().getDefaultValue(BasicVisualLexicon.NETWORK_HEIGHT).floatValue(); snap = new DynNetworkSnapshotImpl<T>(dynView, context.m_attribute_name); kklayout = new KKLayout<T>(snap, new Dimension(4 * size, 4 * size)); List<Double> events = context.m_event_list; // Full KK evaluation to initialize the network at time t=0 kklayout.setAdjustForGravity(true); kklayout.setExchangeVertices(context.m_exchange_nodes); kklayout.setAutoscaling(context.m_autoscale); kklayout.setMaxIterations(1000); // Compute incremental KK. The number of iterations is proportional to the time to the next // event. double t0, t1; for (int t = 0; t < events.size() - 1; t++) { t0 = events.get(Math.max(0, t - context.m_past_events)); t1 = events.get(Math.min(events.size() - 1, t + 1 + context.m_future_events)); snap.setInterval((DynInterval<T>) new DynIntervalDouble(t0, t1), t, 1000, 1000); if (!context.m_attribute_name.equals("none")) kklayout.setDistance(new DijkstraShortestPath<T>(snap, snap.getWeightMap(), 100)); else kklayout.setDistance(new UnweightedShortestPath<T>(snap)); kklayout.initialize(); kklayout.run(); updateGraph((DynInterval<T>) new DynIntervalDouble(events.get(t), events.get(t + 1))); kklayout.setMaxIterations( (int) (context.m_iteration_rate * (events.get(t + 1) - events.get(t)))); if (t % 10 == 0) taskMonitor.setProgress(((double) t) / (double) events.size()); taskMonitor.setStatusMessage("Running energy minimization... " + t + "/" + events.size()); } // Finalize layout layout.finalize(); taskMonitor.setProgress(1); // Set the current network view initializePositions(size); layout.initNodePositions(timeInterval); view.fitContent(); view.updateView(); } }