use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualStyleSerializer method createVizmap.
/**
* This method creates a serializable Vizmap object based on the provided collection of visual styles.
* @param styles The collection of VisualStyles that you wish to convert into a serializable object.
* @return A Vizmap object that contains a representation of the collection of visual styles.
*/
public Vizmap createVizmap(final Collection<VisualStyle> styles) {
final Vizmap vizmap = new Vizmap();
final RenderingEngineManager renderingEngineManager = serviceRegistrar.getService(RenderingEngineManager.class);
lexicon = renderingEngineManager.getDefaultVisualLexicon();
if (styles != null) {
for (VisualStyle style : styles) {
org.cytoscape.io.internal.util.vizmap.model.VisualStyle vsModel = new org.cytoscape.io.internal.util.vizmap.model.VisualStyle();
vizmap.getVisualStyle().add(vsModel);
vsModel.setName(style.getTitle());
vsModel.setNetwork(new Network());
vsModel.setNode(new Node());
vsModel.setEdge(new Edge());
createVizmapProperties(style, BasicVisualLexicon.NETWORK, vsModel.getNetwork().getVisualProperty());
createVizmapProperties(style, BasicVisualLexicon.NODE, vsModel.getNode().getVisualProperty());
createVizmapProperties(style, BasicVisualLexicon.EDGE, vsModel.getEdge().getVisualProperty());
// Create Dependencies
createDependencies(style, vsModel);
}
}
return vizmap;
}
use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class NetworkColorDialog method actionPerformed.
/**
* DOCUMENT ME!
*
* @param e DOCUMENT ME!
*/
public void actionPerformed(ActionEvent e) {
// Are we the source of the event?
String command = e.getActionCommand();
if (command.equals("done")) {
animating = false;
this.setVisible(false);
} else if (command.equals("up")) {
shiftList(-1);
} else if (command.equals("down")) {
shiftList(1);
} else if (command.equals("vizmap")) {
String attribute = (String) attributeSelector.getSelectedValue();
MapTask task = new MapTask(attribute, "-heatMap", false);
taskManager.execute(new TaskIterator(task));
} else if (command.equals("animate")) {
if (animating) {
animating = false;
animateButton.setText("Animate Vizmap");
return;
}
// Get the selected attributes
Object[] attributeArray = attributeSelector.getSelectedValues();
if (attributeArray.length < 2) {
// Really nothing to animate if we only have one map
MapTask task = new MapTask((String) attributeArray[0], "-heatMap", false);
taskManager.execute(new TaskIterator(task));
return;
}
if (currentAttribute == null) {
// Build the necessary vizmap entries
styles = new VisualStyle[attributeArray.length];
for (int i = 0; i < attributeArray.length; i++) {
styles[i] = createNewStyle((String) attributeArray[i], "-" + (String) attributeArray[i], false, false);
}
}
// Change the animate button
animateButton.setText("Stop animation");
animating = true;
// Set up the animation task
Animate a = new Animate(styles, attributeArray);
a.start();
} else if (command.equals("heatstrip")) {
// Get the selected attributes
Object[] attributeArray = attributeSelector.getSelectedValues();
// We need to use enhancedgraphics for this.
// 1) create a heatstrip command
// 2) Write it into a column for every node
// 3) Add a passthrough mapper for custom graphics
String heatstrip = "heatstripchart: separation=\"1\" attributelist=\"";
for (Object attr : attributeArray) heatstrip += attr.toString() + ",";
// strip off the extra comma
heatstrip = heatstrip.substring(0, heatstrip.length() - 1);
String colorSpec = getColorSpec();
heatstrip += "\" colorlist=\"" + colorSpec + "\" position=south showlabels=false size=30x60\"";
CyNetwork net = clusterManager.getNetwork();
String columnName = "clusterMaker-heatStrip";
CyTable nodeTable = net.getDefaultNodeTable();
if (nodeTable.getColumn(columnName) == null)
nodeTable.createColumn(columnName, String.class, false);
for (CyNode node : net.getNodeList()) {
nodeTable.getRow(node.getSUID()).set(columnName, heatstrip);
}
VisualStyle style = ViewUtils.getCurrentVisualStyle(clusterManager);
if (!style.getTitle().endsWith("-heatStrip"))
style = ViewUtils.copyStyle(clusterManager, style, "-heatStrip");
// Get the default lexicon (CUSTOMGRAPHICS aren't in the basic lexicon)
VisualLexicon currentLexicon = ((RenderingEngineManager) clusterManager.getService(RenderingEngineManager.class)).getDefaultVisualLexicon();
VisualProperty customGraphicsVP = currentLexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
if (customGraphicsVP == null)
System.err.println("couldn't get NODE CUSTOM GRAPHICS");
// Get a function factory
VisualMappingFunctionFactory vmff = clusterManager.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
PassthroughMapping map = (PassthroughMapping) vmff.createVisualMappingFunction(columnName, String.class, customGraphicsVP);
style.addVisualMappingFunction(map);
// TODO: Do we want to mess with the CUSTOMGRAPHICS_POSITION?
ViewUtils.setVisualStyle(clusterManager, clusterManager.getNetworkView(), style);
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class NetworkColorDialog method createNewStyle.
private VisualStyle createNewStyle(String attribute, String suffix, boolean update, boolean edge) {
boolean newStyle = false;
// Get our current vizmap
VisualMappingManager vmm = clusterManager.getService(VisualMappingManager.class);
VisualStyle style = ViewUtils.getCurrentVisualStyle(clusterManager);
// Get our colors
Color missingColor = colorExtractor.getMissing();
// Get the type of "attribute"
CyNetwork network = clusterManager.getNetwork();
VisualProperty<Paint> property;
CyColumn column;
if (edge) {
column = network.getDefaultEdgeTable().getColumn(attribute);
property = BasicVisualLexicon.EDGE_PAINT;
} else {
column = network.getDefaultNodeTable().getColumn(attribute);
property = BasicVisualLexicon.NODE_FILL_COLOR;
}
if (column == null)
return null;
Class type = column.getType();
if (!style.getTitle().endsWith(suffix)) {
style = ViewUtils.copyStyle(clusterManager, style, suffix);
newStyle = true;
}
// Get a function factory
VisualMappingFunctionFactory vmff = clusterManager.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
ContinuousMapping colorMapping = (ContinuousMapping) vmff.createVisualMappingFunction(attribute, type, property);
double minStep = minValue / 5.0;
for (int i = 0; i < 5; i++) {
Color color = colorExtractor.getColor(minValue - (minStep * i));
// System.out.println("Value: "+(minValue-(minStep*i))+" Color: "+color.toString());
colorMapping.addPoint(minValue - (minStep * i), new BoundaryRangeValues<Paint>(color, color, color));
}
{
Color color = colorExtractor.getColor(0.0f);
colorMapping.addPoint(0.0f, new BoundaryRangeValues<Paint>(color, color, color));
}
double maxStep = maxValue / 5.0;
for (int i = 1; i <= 5; i++) {
Color color = colorExtractor.getColor(maxStep * i);
// System.out.println("Value: "+(maxStep*i)+" Color: "+color.toString());
colorMapping.addPoint(maxStep * i, new BoundaryRangeValues<Paint>(color, color, color));
}
style.addVisualMappingFunction(colorMapping);
if (update) {
ViewUtils.setVisualStyle(clusterManager, clusterManager.getNetworkView(), style);
}
return style;
}
use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class NewNetworkView method styleNewView.
private VisualStyle styleNewView(VisualStyle style, String clusterAttribute) {
VisualStyle newStyle = ViewUtils.copyStyle(manager, style, "--clustered");
VisualMappingFunctionFactory vmff = manager.getService(VisualMappingFunctionFactory.class);
DiscreteMapping edgeWidth = (DiscreteMapping) vmff.createVisualMappingFunction(clusterAttribute, Integer.class, BasicVisualLexicon.EDGE_WIDTH);
edgeWidth.putMapValue(new Integer(0), new Double(1));
edgeWidth.putMapValue(new Integer(1), new Double(5));
DiscreteMapping edgeTrans = (DiscreteMapping) vmff.createVisualMappingFunction(clusterAttribute, Integer.class, BasicVisualLexicon.EDGE_TRANSPARENCY);
edgeTrans.putMapValue(new Integer(0), new Integer(50));
edgeTrans.putMapValue(new Integer(1), new Integer(255));
newStyle.addVisualMappingFunction(edgeWidth);
newStyle.addVisualMappingFunction(edgeTrans);
return newStyle;
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-api by cytoscape.
the class CySessionTest method testSetVisualStyles.
@Test
public void testSetVisualStyles() {
VisualStyle v1 = mock(VisualStyle.class);
Set<VisualStyle> set = new HashSet<VisualStyle>();
set.add(v1);
session = new CySession.Builder().visualStyles(set).build();
assertNotNull(session);
assertNotNull(session.getVisualStyles());
assertEquals(set, session.getVisualStyles());
}
Aggregations