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 retrieved as OSGi services by using their IDs.
Bar Chart | org.cytoscape.BarChart |
Box Chart | org.cytoscape.BoxChart |
Heat Map Chart | org.cytoscape.HeatMapChart |
Line Chart | org.cytoscape.LineChart |
Pie Chart | org.cytoscape.PieChart |
Ring Chart | org.cytoscape.RingChart |
Linear Gradient | org.cytoscape.LinearGradient |
Radial Gradient | org.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 Name | Type | Description |
---|
cy_dataColumns | List<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_values | List<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_colors | List<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_colorScheme | String | Name of a predefined color scheme. Use this property instead of cy_colors to have the colors chosen automatically. Values: CONTRASTING, MODULATED, RAINBOW, RANDOM |
cy_itemLabels | List<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_itemLabelsColumn | CyColumnIdentifier | Name 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_showItemLabels | Boolean | Set to true to show value labels |
cy_borderWidth | Float | Border width |
cy_borderColor | java.awt.Color | Border color |
Bar/Box/Line/Heat Charts
Property Name | Type | Description |
---|
cy_orientation | String | Values: HORIZONTAL, VERTICAL |
cy_domainLabelsColumn | CyColumnIdentifier | Name of a data column to use for domain labels. The column should be of type List. |
cy_rangeLabelsColumn | CyColumnIdentifier | Name of a data column to use for range labels. The column should be of type List. |
cy_domainLabelPosition | String | Values: STANDARD, DOWN_45, DOWN_90, UP_45, UP_90 |
cy_globalRange | Boolean | If true, all charts' range (min and max bounds) will be automatically set to the network-wide range. |
cy_range | List<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_showDomainAxis | Boolean | Set to true to show the domain axis. |
cy_showRangeAxis | Boolean | Set to true to show the range axis. |
cy_axisWidth | Float | Axis stroke width. |
cy_axisColor | java.awt.Color | Axis line color. |
Bar Charts
Property Name | Type | Description |
---|
cy_type | String | Values: GROUPED, STACKED, HEAT_STRIPS, UP_DOWN |
cy_separation | Double | Separation between bars. Value must be between 0.0 and 0.5 |
Line Charts
Property Name | Type | Description |
---|
cy_lineWidth | Float | Line width |
Pie Charts
Property Name | Type | Description |
---|
cy_startAngle | Double | Start angle for the first pie section. |
Ring Charts
Property Name | Type | Description |
---|
cy_startAngle | Double | Start angle for the first section. |
cy_holeSize | Double | Width of the hole in the center of the ring. |
Gradients
Property Name | Type | Description |
---|
cy_gradientFractions | List<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_gradientColors | List<java.awt.Color> | List of colors corresponding to each fraction value. |
Linear Gradient
Property Name | Type | Description |
---|
cy_angle | Double | Slope (rotation) of the gradient, in degrees. |
Radial Gradient
Property Name | Type | Description |
---|
cy_center | java.awt.geom.Point2D | Center of the gradient. Each coordinate must be between 0.0 and 1.0. |