Example #1
0
  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();
  }
Example #2
0
  @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);
      }
    }
  }