Interface CyCustomGraphics2Factory<T extends CustomGraphicLayer>


  • public interface CyCustomGraphics2Factory<T extends CustomGraphicLayer>

    Factory to create CyCustomGraphics2 objects. CyCustomGraphics2Factory objects are registered as OSGi services and will be used by Renderers to create the actual custom graphics implementations. Note that the type parameter T of CyCustomGraphics2Factory is the type of the underlying CustomGraphicLayer not the type of the resulting CyCustomGraphics2 object this factory creates.

    The pattern is to register CyCustomGraphics2Factory implementations as OSGi services in your CyActivator class.

     CyCustomGraphics2Factory myCustomGraphics2Factory = new MyCustomGraphics2Factory();
     registerService(bundleContext, myCustomGraphics2Factory, CyCustomGraphics2Factory.class, new Properties());
     

    Charts

    Cytoscape provides some predefined custom graphics factories for creating charts. These factories can be retreived as OSGi services by using their IDs.

    Bar Chartorg.cytoscape.BarChart
    Box Chartorg.cytoscape.BoxChart
    Heat Map Chartorg.cytoscape.HeatMapChart
    Line Chartorg.cytoscape.LineChart
    Pie Chartorg.cytoscape.PieChart
    Ring Chartorg.cytoscape.RingChart
    Linear Gradientorg.cytoscape.LinearGradient
    Radial Gradientorg.cytoscape.RadialGradient

    To retrieve a reference to a predefined chart factory you must use an OSGi service listener. For example:

     public class CustomChartListener {
            private static final String FACTORY_ID = "org.cytoscape.PieChart";
            private CyCustomGraphics2Factory<?> factory;
            
            public void addCustomGraphicsFactory(CyCustomGraphics2Factory<?> factory, Map<Object,Object> serviceProps) {
                    if(FACTORY_ID.equals(factory.getId())) {
                            this.factory = factory;
                    }
            }
            
            public void removeCustomGraphicsFactory(CyCustomGraphics2Factory<?> factory, Map<Object,Object> serviceProps) {
                    this.factory = null;
            }
            
            public CyCustomGraphics2Factory<?> getFactory() {
                    return factory;
            }
     }
     

    Register the listener in your CyActivator class.

       CustomChartListener customChartListener = new CustomChartListener();
       registerServiceListener(context, customChartListener, "addCustomGraphicsFactory", "removeCustomGraphicsFactory", CyCustomGraphics2Factory.class);
     

    Use the factory to create an instance of CyCustomGraphics2 for your charts. The data and appearance of the charts are controlled by a Map of properties that are passed to the getInstance() method.

     CyCustomGraphics2Factory<?> customGraphicsFactory = customChartListener.getFactory();
     CyColumnIdentifierFactory columnIdFactory; // Get OSGi service
     
     CyColumnIdentifier columnId = columnIdFactory.createColumnIdentifier(chartColumn);
     Map<String,Object> chartProps = new HashMap<String,Object>();
     chartProps.put("cy_dataColumns", Arrays.asList(columnId)); 
     chartProps.put("cy_colorScheme", "CONTRASTING");
                    
     CyCustomGraphics2<?> customGraphics = customGraphicsFactory.getInstance(chartProps);
    
     // Set the custom graphics on the visual style
     VisualStyle visualStyle = visualMappingManager.getCurrentVisualStyle();
     CyApplicationManager appManager; // Get OSGi service
     RenderingEngine engine = appManager.getCurrentRenderingEngine();
     VisualLexicon lexicon = engine.getVisualLexicon();
     VisualProperty<CyCustomGraphics> visualProperty = lexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
     
     if (visualProperty != null)
         visualStyle.setDefaultValue(visualProperty, customGraphics);
     

    Chart Properties

    All built-in properties start with the "cy_" prefix. If you are writing an App that provides additional properties please specify your own prefix in order to prevent name collisions.

    All Charts

    Property NameTypeDescription
    cy_dataColumnsList<CyColumnIdentifier>Names of data columns from the default node table. Columns of type List become separate groups (or data series) in the chart (for example a ring chart will have a separate ring for each group). The column type must be numerical.
    cy_valuesList<Double>Specific values to use for each segment of the chart. If cy_dataColumns is specified, this property does not need to be set.
    cy_colorsList<java.awt.Color>List of specific colors to use with each data column (if the column contains single numbers) or value. The color list should have one entry for every corresponding entry in the cy_dataColumns property list, if the list contains only columns of simple numerical types (no List types). If cy_dataColumns contains List-typed columns, it must contain as many colors as elements in the list values.
    cy_colorSchemeStringName of a predefined color scheme. Use this property instead of cy_colors to have the colors chosen automatically. Values: CONTRASTING, MODULATED, RAINBOW, RANDOM
    cy_itemLabelsList<String>Labels to use for each segment of the chart (for example each slice of a pie chart.) The label list should have one entry for every corresponding entry in the cy_dataColumns property list.
    cy_itemLabelsColumnCyColumnIdentifierName of a data column to use for value labels. The column should be of type List, each element in the list will be used as a label.
    cy_showItemLabelsBooleanSet to true to show value labels
    cy_borderWidthFloatBorder width
    cy_borderColorjava.awt.ColorBorder color

    Bar/Box/Line/Heat Charts

    Property NameTypeDescription
    cy_orientationStringValues: HORIZONTAL, VERTICAL
    cy_domainLabelsColumnCyColumnIdentifierName of a data column to use for domain labels. The column should be of type List.
    cy_rangeLabelsColumnCyColumnIdentifierName of a data column to use for range labels. The column should be of type List.
    cy_domainLabelPositionStringValues: STANDARD, DOWN_45, DOWN_90, UP_45, UP_90
    cy_globalRangeBooleanIf true, all charts' range (min and max bounds) will be automatically set to the network-wide range.
    cy_rangeList<Double>Allows the global range to be set manually. Must be a list with exactly two elements. Specifies the lower (first element) and upper bound for the range axis. The property cy_range must be set to true.
    cy_showDomainAxisBooleanSet to true to show the domain axis.
    cy_showRangeAxisBooleanSet to true to show the range axis.
    cy_axisWidthFloatAxis stroke width.
    cy_axisColorjava.awt.ColorAxis line color.

    Bar Charts

    Property NameTypeDescription
    cy_typeStringValues: GROUPED, STACKED, HEAT_STRIPS, UP_DOWN
    cy_separationDoubleSeparation between bars. Value must be between 0.0 and 0.5

    Line Charts

    Property NameTypeDescription
    cy_lineWidthFloatLine width

    Pie Charts

    Property NameTypeDescription
    cy_startAngleDoubleStart angle for the first pie section.

    Ring Charts

    Property NameTypeDescription
    cy_startAngleDoubleStart angle for the first section.
    cy_holeSizeDoubleWidth of the hole in the center of the ring.

    Gradients

    Property NameTypeDescription
    cy_gradientFractionsList<Float>Numbers ranging from 0.0 to 1.0 specifying the distribution of colors along the gradient. See javadocs for java.awt.MultipleGradientPaint for more detail.
    cy_gradientColorsList<java.awt.Color>List of colors corresponding to each fraction value.

    Linear Gradient

    Property NameTypeDescription
    cy_angleDoubleSlope (rotation) of the gradient, in degrees.

    Radial Gradient

    Property NameTypeDescription
    cy_centerjava.awt.geom.Point2DCenter of the gradient. Each coordinate must be between 0.0 and 1.0.



    Module: presentation-api

    To use this in your app, include the following dependency in your POM:

    <dependency>
        <groupId>org.cytoscape</groupId>
        <artifactId>presentation-api</artifactId>
    </dependency>

    Cytoscape Backwards Compatibility (SPI Interface): We expect that this interface will be implemented. Therefore to maintain backwards compatibility this interface will only be modified for major version updates.
    • Method Detail

      • getId

        String getId()
        Return the prefix to identify this Custom Graphics factory. This is used by the passthrough mapping logic to figure out if a given String value should be mapped to this factory.
        Returns:
        the prefix for this CyCustomGraphics2Factory
      • getDisplayName

        String getDisplayName()
        Return the CyCustomGraphics2 name which is will be displayed to the user.
        Returns:
        display name as String.
      • getIcon

        Icon getIcon​(int width,
                     int height)
        Parameters:
        width -
        height -
        Returns:
        an optional icon that represents a custom graphics type.
      • getInstance

        CyCustomGraphics2<T> getInstance​(String input)
        Get a new instance of a CyCustomGraphics2. The string argument may be used by some implementations to create the initial CyCustomGraphics2 objects. This is the method that will be used to take a String passthrough mapping and create the correct CyCustomGraphics2 instance. Note that the prefix defined above will get removed from the string before this method is called.
        Parameters:
        input - a possible input string that may be used to create the instance. Not all implementations will use this.
        Returns:
        the new instance
      • getSupportedClass

        Class<? extends CyCustomGraphics2<T>> getSupportedClass()
        Returns:
        the class that this factory creates. This is used by the deserialization mechanism to find the factory method that can deserialize a given string.
      • createEditor

        JComponent createEditor​(CyCustomGraphics2<T> customGraphics)
        Creates a UI component that configures the given CyCustomGraphics2.
        Parameters:
        customGraphics - the CyCustomGraphics2 to be configured.
        Returns:
        a UI panel that configures the given CyCustomGraphics2 or null if the factory does not want to provide a visual editor.