Search in sources :

Example 41 with VisualStyle

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;
}
Also used : RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) Vizmap(org.cytoscape.io.internal.util.vizmap.model.Vizmap) CyNetwork(org.cytoscape.model.CyNetwork) Network(org.cytoscape.io.internal.util.vizmap.model.Network) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge)

Example 42 with VisualStyle

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);
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) CyTable(org.cytoscape.model.CyTable) TaskIterator(org.cytoscape.work.TaskIterator) VisualProperty(org.cytoscape.view.model.VisualProperty) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 43 with VisualStyle

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;
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) Color(java.awt.Color) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) Paint(java.awt.Paint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 44 with VisualStyle

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;
}
Also used : VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 45 with VisualStyle

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());
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VisualStyle (org.cytoscape.view.vizmap.VisualStyle)100 CyNetworkView (org.cytoscape.view.model.CyNetworkView)42 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)37 CyNetwork (org.cytoscape.model.CyNetwork)35 CyNode (org.cytoscape.model.CyNode)30 CyEdge (org.cytoscape.model.CyEdge)24 CyEventHelper (org.cytoscape.event.CyEventHelper)14 HashSet (java.util.HashSet)13 VisualProperty (org.cytoscape.view.model.VisualProperty)12 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)12 Paint (java.awt.Paint)11 HashMap (java.util.HashMap)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)11 Color (java.awt.Color)10 ArrayList (java.util.ArrayList)10 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)9 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)9 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)9 View (org.cytoscape.view.model.View)8