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(); }
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(); } }
@SuppressWarnings({"rawtypes", "unchecked"}) private final void parseMappings( JsonNode mappings, VisualStyle style, VisualLexicon lexicon, MappingFactoryManager factoryManager) { for (final JsonNode mapping : mappings) { final String type = mapping.get(MAPPING_TYPE).textValue(); final String column = mapping.get(MAPPING_COLUMN).textValue(); final String colType = mapping.get(MAPPING_COLUMN_TYPE).textValue(); final String vpName = mapping.get(MAPPING_VP).textValue(); final VisualProperty vp = getVisualProperty(vpName, lexicon); final Class<?> columnType = MapperUtil.getColumnClass(colType); if (vp == null || columnType == null) { continue; } VisualMappingFunction newMapping = null; if (type.equals(MAPPING_DISCRETE)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(DiscreteMapping.class); newMapping = parseDiscrete(column, columnType, vp, factory, mapping.get(MAPPING_DISCRETE_MAP)); } else if (type.equals(MAPPING_CONTINUOUS)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(ContinuousMapping.class); newMapping = parseContinuous(column, columnType, vp, factory, mapping); } else if (type.equals(MAPPING_PASSTHROUGH)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(PassthroughMapping.class); newMapping = parsePassthrough(column, columnType, vp, factory); } if (newMapping != null) { if (style.getVisualMappingFunction(vp) != null) { style.removeVisualMappingFunction(vp); } style.addVisualMappingFunction(newMapping); } } }
private void checkNetwork(final CyNetwork network) { checkNodeEdgeCount(network, 331, 362, 0, 0); // Non-default columns should not be immutable assertCy2CustomColumnsAreMutable(network); // View test Collection<CyNetworkView> views = viewManager.getNetworkViews(network); assertEquals(1, views.size()); final CyNetworkView view = views.iterator().next(); assertEquals(331, view.getNodeViews().size()); assertEquals(362, view.getEdgeViews().size()); // Check updated view final VisualStyle style = vmm.getVisualStyle(view); style.apply(view); checkView(view); }
@SuppressWarnings({"rawtypes", "unchecked"}) private final void parseDefaults( final JsonNode defaults, final VisualStyle style, final VisualLexicon lexicon) { for (final JsonNode vpNode : defaults) { String vpName = vpNode.get(MAPPING_VP).textValue(); final VisualProperty vp = getVisualProperty(vpName, lexicon); final JsonNode value = vpNode.get("value"); if (vp == null || value == null) { continue; } Object parsedValue = null; if (value.isTextual()) { parsedValue = vp.parseSerializableString(value.asText()); } else { parsedValue = vp.parseSerializableString(value.toString()); } style.setDefaultValue(vp, parsedValue); } }
public void updateDependencies(final VisualStyle style, final JsonNode rootNode) { final Set<VisualPropertyDependency<?>> deps = style.getAllVisualPropertyDependencies(); final Map<String, VisualPropertyDependency<?>> names = new HashMap<>(); for (final VisualPropertyDependency<?> dep : deps) { names.put(dep.getIdString(), dep); } for (final JsonNode depNode : rootNode) { String depId = depNode.get(VisualStyleMapper.VP_DEPENDENCY).textValue(); final VisualPropertyDependency<?> dep = names.get(depId); if (dep == null) { continue; } final JsonNode enabled = depNode.get("enabled"); if (enabled == null) { continue; } boolean value = enabled.asBoolean(); dep.setDependency(value); } }
public void updateStyleName( final VisualStyle style, final VisualLexicon lexicon, final JsonNode rootNode) { final String newTitle = rootNode.get(TITLE).textValue(); style.setTitle(newTitle); }
@SuppressWarnings("unchecked") private void checkCurrentVisualStyle(final VisualStyle style) { assertNotNull(style); assertEquals("Sample3", style.getTitle()); Collection<VisualMappingFunction<?, ?>> mappings = style.getAllVisualMappingFunctions(); assertEquals(6, mappings.size()); // Test defaults NodeShape defaultShape = style.getDefaultValue(NODE_SHAPE); Paint nodeColor = style.getDefaultValue(NODE_FILL_COLOR); Integer fontSize = style.getDefaultValue(NODE_LABEL_FONT_SIZE); Integer transparency = style.getDefaultValue(NODE_TRANSPARENCY); Double w = style.getDefaultValue(NODE_WIDTH); Double h = style.getDefaultValue(NODE_HEIGHT); Paint edgeLabelColor = style.getDefaultValue(EDGE_LABEL_COLOR); assertEquals(new Color(255, 255, 204), edgeLabelColor); assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, defaultShape); assertEquals(Color.WHITE, nodeColor); assertEquals(Integer.valueOf(16), fontSize); assertEquals(Integer.valueOf(180), transparency); assertEquals(Double.valueOf(80), w); assertEquals(Double.valueOf(30), h); // Check each mapping VisualMappingFunction<?, String> nodeLabelMapping = style.getVisualMappingFunction(NODE_LABEL); VisualMappingFunction<?, String> edgeLabelMapping = style.getVisualMappingFunction(EDGE_LABEL); assertTrue(nodeLabelMapping instanceof PassthroughMapping); assertTrue(edgeLabelMapping instanceof PassthroughMapping); assertEquals(CyNetwork.NAME, nodeLabelMapping.getMappingColumnName()); assertEquals(CyEdge.INTERACTION, edgeLabelMapping.getMappingColumnName()); assertEquals(String.class, nodeLabelMapping.getMappingColumnType()); assertEquals(String.class, edgeLabelMapping.getMappingColumnType()); // Node Color mapping VisualMappingFunction<?, Paint> nodeColorMapping = style.getVisualMappingFunction(NODE_FILL_COLOR); assertTrue(nodeColorMapping instanceof ContinuousMapping); assertEquals("gal4RGexp", nodeColorMapping.getMappingColumnName()); assertEquals(Number.class, nodeColorMapping.getMappingColumnType()); // Edge Color mapping VisualMappingFunction<?, Paint> edgeColorMapping = style.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT); assertTrue(edgeColorMapping instanceof DiscreteMapping); assertEquals(CyEdge.INTERACTION, edgeColorMapping.getMappingColumnName()); assertEquals(String.class, edgeColorMapping.getMappingColumnType()); DiscreteMapping<String, Paint> disc1 = (DiscreteMapping<String, Paint>) edgeColorMapping; assertEquals(Color.WHITE, disc1.getMapValue("pp")); assertEquals(new Color(102, 255, 255), disc1.getMapValue("pd")); assertEquals(null, disc1.getMapValue("this is an invalid value")); // Numbers as Tooltip VisualMappingFunction<?, String> nodeTooltipMapping = style.getVisualMappingFunction(NODE_TOOLTIP); assertTrue(nodeTooltipMapping instanceof PassthroughMapping); assertEquals("gal4RGexp", nodeTooltipMapping.getMappingColumnName()); // Cy2 doesn't write the "controllerType" property for PassThroughMappings, // so it's always created as String (it shouldn't cause any issues) assertEquals(String.class, nodeTooltipMapping.getMappingColumnType()); VisualMappingFunction<?, LineType> edgeLineStyleMapping = style.getVisualMappingFunction(EDGE_LINE_TYPE); assertTrue(edgeLineStyleMapping instanceof DiscreteMapping); assertEquals(CyEdge.INTERACTION, edgeLineStyleMapping.getMappingColumnName()); assertEquals(String.class, edgeLineStyleMapping.getMappingColumnType()); DiscreteMapping<String, LineType> disc2 = (DiscreteMapping<String, LineType>) edgeLineStyleMapping; assertEquals(LineTypeVisualProperty.SOLID, disc2.getMapValue("pp")); assertEquals(LineTypeVisualProperty.LONG_DASH, disc2.getMapValue("pd")); assertEquals(null, disc2.getMapValue("this is an invalid value")); }