use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy240Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy240Vizmap() throws Exception {
Properties props = loadVizmapProps("v240_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(4, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Sample2", "SimpleBioMoleculeEditor" });
// Test visual styles (defaults, mappings and dependencies)
// -----
VisualStyle def = getVisualStyleByTitle(styles, DEFAULT_STYLE_NAME);
assertEquals(new Color(204, 204, 254), def.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(new Color(0, 0, 255), def.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(0, 0, 255), def.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(254, 0, 0), def.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(new Color(255, 153, 153), def.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(254, 254, 0), def.getDefaultValue(NODE_SELECTED_PAINT));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) def.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) def.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal1RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.5, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(new Color(0, 0, 255), nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(0.0, nColorMp.getPoint(1).getValue(), 0.0);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().equalValue);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(2.1, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(0, 255, 102), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(0, 0, 0), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(0, 255, 102), nColorMp.getPoint(2).getRange().lesserValue);
ContinuousMapping<Double, NodeShape> nShapeMp = (ContinuousMapping<Double, NodeShape>) def.getVisualMappingFunction(NODE_SHAPE);
assertEquals("gal1RGexp", nShapeMp.getMappingColumnName());
assertEquals(Number.class, nShapeMp.getMappingColumnType());
assertEquals(3, nShapeMp.getPointCount());
assertEquals(-1.0, nShapeMp.getPoint(0).getValue(), 0.0);
assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(0).getRange().equalValue);
assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(0).getRange().greaterValue);
assertEquals(NodeShapeVisualProperty.PARALLELOGRAM, nShapeMp.getPoint(0).getRange().lesserValue);
assertEquals(0.0, nShapeMp.getPoint(1).getValue(), 0.0);
assertEquals(NodeShapeVisualProperty.DIAMOND, nShapeMp.getPoint(1).getRange().equalValue);
assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(1).getRange().greaterValue);
assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(1).getRange().lesserValue);
assertEquals(1.0, nShapeMp.getPoint(2).getValue(), 0.0);
assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(2).getRange().equalValue);
assertEquals(NodeShapeVisualProperty.HEXAGON, nShapeMp.getPoint(2).getRange().greaterValue);
assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(2).getRange().lesserValue);
ContinuousMapping<Double, Double> nSizeMp = (ContinuousMapping<Double, Double>) def.getVisualMappingFunction(NODE_SIZE);
assertEquals("gal1RGexp", nSizeMp.getMappingColumnName());
assertEquals(Number.class, nSizeMp.getMappingColumnType());
assertEquals(2, nSizeMp.getPointCount());
assertEquals(0.0, nSizeMp.getPoint(0).getValue(), 0.0);
assertEquals(50, nSizeMp.getPoint(0).getRange().equalValue.intValue());
assertEquals(50, nSizeMp.getPoint(0).getRange().greaterValue.intValue());
assertEquals(20, nSizeMp.getPoint(0).getRange().lesserValue.intValue());
assertEquals(1.0, nSizeMp.getPoint(1).getValue(), 0.0);
assertEquals(100, nSizeMp.getPoint(1).getRange().equalValue.intValue());
assertEquals(100, nSizeMp.getPoint(1).getRange().greaterValue.intValue());
assertEquals(100, nSizeMp.getPoint(1).getRange().lesserValue.intValue());
// -----
VisualStyle bio = getVisualStyleByTitle(styles, "SimpleBioMoleculeEditor");
assertEquals(new Color(204, 204, 255), bio.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(new Color(0, 0, 0), bio.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), bio.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(Font.decode("Monospaced-PLAIN-12"), bio.getDefaultValue(EDGE_LABEL_FONT_FACE));
// defaultEdgeLineType=DASHED_2 (split "DASHED" + "2")
assertEquals(LineTypeVisualProperty.EQUAL_DASH, bio.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(2, bio.getDefaultValue(EDGE_WIDTH).intValue());
// defaultEdgeSourceArrow=WHITE_T (can't test EDGE_SOURCE_ARROW_UNSELECTED_PAINT; it's Ding Lexicon's property)
assertEquals(ArrowShapeVisualProperty.T, bio.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
// defaultEdgeTargetArrow=BLACK_ARROW
assertEquals(ArrowShapeVisualProperty.ARROW, bio.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals(new Color(255, 255, 255), bio.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), bio.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(35, bio.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(28, bio.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(42, bio.getDefaultValue(NODE_SIZE).intValue());
// defaultNodeLineType=LINE_1
assertEquals(LineTypeVisualProperty.SOLID, bio.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals(1, bio.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(NodeShapeVisualProperty.RECTANGLE, bio.getDefaultValue(NODE_SHAPE));
nLabelMp = (PassthroughMapping<String, String>) bio.getVisualMappingFunction(NODE_LABEL);
assertEquals("canonicalName", nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
DiscreteMapping<String, NodeShape> nShape = (DiscreteMapping<String, NodeShape>) bio.getVisualMappingFunction(NODE_SHAPE);
assertEquals("NODE_TYPE", nShape.getMappingColumnName());
assertEquals(String.class, nShape.getMappingColumnType());
assertEquals(NodeShapeVisualProperty.ELLIPSE, nShape.getMapValue("biochemicalReaction"));
assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, nShape.getMapValue("catalyst"));
assertEquals(NodeShapeVisualProperty.RECTANGLE, nShape.getMapValue("protein"));
assertEquals(NodeShapeVisualProperty.DIAMOND, nShape.getMapValue("smallMolecule"));
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy283Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy283Vizmap() throws Exception {
Properties props = loadVizmapProps("v283_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(6, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Solid", "Universe", "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;", /*Testing special chars*/
"Nested Network Style" });
// Test visual styles (defaults, mappings and dependencies)
// -----
VisualStyle sample1 = getVisualStyleByTitle(styles, "Sample1");
assertEquals(new Color(255, 255, 204), sample1.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 1), sample1.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(Font.decode("Default-PLAIN-10"), sample1.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(10, sample1.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 10, 0), sample1.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(120, sample1.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals("", sample1.getDefaultValue(EDGE_LABEL));
assertEquals(LineTypeVisualProperty.SOLID, sample1.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(1, sample1.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(180, sample1.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, sample1.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.CIRCLE, sample1.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", sample1.getDefaultValue(EDGE_TOOLTIP));
assertEquals(new Color(10, 20, 0), sample1.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(242, sample1.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals(new Color(204, 204, 255), sample1.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 1), sample1.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(Font.decode("Dialog-BOLD-12"), sample1.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(12, sample1.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals("node", sample1.getDefaultValue(NODE_LABEL));
assertEquals(new Color(0, 0, 255), sample1.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(220, sample1.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(30, sample1.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(70, sample1.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(40, sample1.getDefaultValue(NODE_SIZE).intValue());
assertEquals(LineTypeVisualProperty.LONG_DASH, sample1.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals(0, sample1.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(250, sample1.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(NodeShapeVisualProperty.ELLIPSE, sample1.getDefaultValue(NODE_SHAPE));
assertEquals(true, sample1.getDefaultValue(NODE_NESTED_NETWORK_IMAGE_VISIBLE));
assertEquals("My test...", sample1.getDefaultValue(NODE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(EDGE_LABEL);
assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
DiscreteMapping<String, Paint> eColorMp1 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp1.getMappingColumnName());
assertEquals(String.class, eColorMp1.getMappingColumnType());
assertEquals(new Color(255, 0, 51), eColorMp1.getMapValue("pd"));
assertEquals(new Color(0, 204, 0), eColorMp1.getMapValue("pp"));
DiscreteMapping<String, Paint> eColorMp2 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp2.getMappingColumnName());
assertEquals(String.class, eColorMp2.getMappingColumnType());
assertEquals(new Color(255, 0, 51), eColorMp2.getMapValue("pd"));
assertEquals(new Color(0, 204, 0), eColorMp2.getMapValue("pp"));
DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) sample1.getVisualMappingFunction(EDGE_LINE_TYPE);
assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
VisualPropertyDependency<?> dep1 = getDependency(sample1, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
// -----
VisualStyle galFiltered = getVisualStyleByTitle(styles, "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;");
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) galFiltered.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.0249776914715767, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(0.20517408847808838, nColorMp.getPoint(1).getValue(), 0.0001);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(2.5, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(0, 0, 204), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().lesserValue);
VisualPropertyDependency<?> dep2 = getDependency(galFiltered, NODE_SIZE_LOCKED_DEPENDENCY);
assertTrue(dep2.isDependencyEnabled());
// -----
VisualStyle nested = getVisualStyleByTitle(styles, "Nested Network Style");
DiscreteMapping<Boolean, Paint> nLabelColorMp = (DiscreteMapping<Boolean, Paint>) nested.getVisualMappingFunction(NODE_LABEL_COLOR);
assertEquals("has_nested_network", nLabelColorMp.getMappingColumnName());
assertEquals(Boolean.class, nLabelColorMp.getMappingColumnType());
assertEquals(new Color(0, 102, 204), nLabelColorMp.getMapValue(true));
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class AbstractXGMMLWriterTest method init.
@Before
public void init() {
netViewTestSupport = new NetworkViewTestSupport();
netMgr = mock(CyNetworkManager.class);
netFactory = netViewTestSupport.getNetworkFactory();
rootNetMgr = netViewTestSupport.getRootNetworkFactory();
vmMgr = mock(VisualMappingManager.class);
VisualStyle style = mock(VisualStyle.class);
when(style.getTitle()).thenReturn("default");
when(vmMgr.getDefaultVisualStyle()).thenReturn(style);
when(vmMgr.getVisualStyle(any(CyNetworkView.class))).thenReturn(style);
renderingEngineMgr = mock(RenderingEngineManager.class);
when(renderingEngineMgr.getDefaultVisualLexicon()).thenReturn(new BasicVisualLexicon(new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property")));
unrecogVisPropMgr = mock(UnrecognizedVisualPropertyManager.class);
tm = mock(TaskMonitor.class);
grMgr = mock(CyGroupManager.class);
grFactory = grTestSupport.getGroupFactory();
serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyNetworkManager.class)).thenReturn(netMgr);
when(serviceRegistrar.getService(CyNetworkFactory.class)).thenReturn(netFactory);
when(serviceRegistrar.getService(CyRootNetworkManager.class)).thenReturn(rootNetMgr);
when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(renderingEngineMgr);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
when(serviceRegistrar.getService(CyGroupManager.class)).thenReturn(grMgr);
when(serviceRegistrar.getService(CyGroupFactory.class)).thenReturn(grFactory);
groupUtil = new GroupUtil(serviceRegistrar);
createBaseNetwork();
out = new ByteArrayOutputStream();
xpathFactory = XPathFactory.newInstance();
doc = null;
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class AddNestedNetworkTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
final CyNode node = nodeView.getModel();
setNestedNetwork(node, nestedNetwork.getSelectedValue());
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final VisualStyle style = vmMgr.getVisualStyle(netView);
style.apply(netView.getModel().getRow(node), nodeView);
netView.updateView();
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class AddNodeTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
final CyNetwork net = view.getModel();
final CyNode n = net.addNode();
// set the name attribute for the new node
final String nodeName = "Node " + new_node_index;
new_node_index++;
final CyRow nodeRow = net.getRow(n);
nodeRow.set(CyNetwork.NAME, nodeName);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.flushPayloadEvents();
View<CyNode> nv = view.getNodeView(n);
nv.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, xformPt.getX());
nv.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, xformPt.getY());
// Apply visual style
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
VisualStyle vs = vmMgr.getVisualStyle(view);
vs.apply(net.getRow(n), nv);
view.updateView();
}
Aggregations