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 underlyingCustomGraphicLayer
not the type of the resultingCyCustomGraphics2
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 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). Ifcy_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, RANDOMcy_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. 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.
-
-
Field Summary
Fields Modifier and Type Field Description static String
GROUP
Optional property key that tells Cytoscape under which group it should add the editor created by this factory (seecreateEditor(CyCustomGraphics2)
).
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JComponent
createEditor(CyCustomGraphics2<T> customGraphics)
Creates a UI component that configures the givenCyCustomGraphics2
.String
getDisplayName()
Return theCyCustomGraphics2
name which is will be displayed to the user.Icon
getIcon(int width, int height)
String
getId()
Return the prefix to identify this Custom Graphics factory.CyCustomGraphics2<T>
getInstance(String input)
Get a new instance of aCyCustomGraphics2
.CyCustomGraphics2<T>
getInstance(Map<String,Object> properties)
Get a new instance of aCyCustomGraphics2
with the passed properties.CyCustomGraphics2<T>
getInstance(CyCustomGraphics2<T> customGraphics)
Get a new instance of aCyCustomGraphics2
that is a clone of the passed argument.Class<? extends CyCustomGraphics2<T>>
getSupportedClass()
-
-
-
Field Detail
-
GROUP
static final String GROUP
Optional property key that tells Cytoscape under which group it should add the editor created by this factory (seecreateEditor(CyCustomGraphics2)
).- See Also:
- Constant Field Values
-
-
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 theCyCustomGraphics2
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 aCyCustomGraphics2
. The string argument may be used by some implementations to create the initialCyCustomGraphics2
objects. This is the method that will be used to take a String passthrough mapping and create the correctCyCustomGraphics2
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
-
getInstance
CyCustomGraphics2<T> getInstance(CyCustomGraphics2<T> customGraphics)
Get a new instance of aCyCustomGraphics2
that is a clone of the passed argument.- Parameters:
customGraphics
- another Custom Graphics- Returns:
- the new instance
-
getInstance
CyCustomGraphics2<T> getInstance(Map<String,Object> properties)
Get a new instance of aCyCustomGraphics2
with the passed properties. The properties object should contain the same keys that are returned by the correspondingCyCustomGraphics2.getProperties()
implementation.- Parameters:
properties
- optional properties to initialize the new custom graphics.- 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 givenCyCustomGraphics2
.- Parameters:
customGraphics
- theCyCustomGraphics2
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.
-
-