Search in sources :

Example 46 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateNodeChartPanel.

private void updateNodeChartPanel(Collection<EMDataSet> dataSets, EnrichmentMap map) {
    JPanel p = getNodeChartPanel();
    chartLegendPanel.removeAll();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    NetworkViewRenderer renderer = applicationManager.getCurrentNetworkViewRenderer();
    if (renderer == null)
        renderer = applicationManager.getDefaultNetworkViewRenderer();
    VisualLexicon lexicon = renderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
    VisualProperty<?> vp = lexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
    Object cg = vp != null ? style.getDefaultValue(vp) : null;
    ChartType chartType = options.getChartOptions() != null ? options.getChartOptions().getType() : null;
    if (chartType != null && cg instanceof CyCustomGraphics2 && dataSets != null && dataSets.size() > 1) {
        ChartPanel chart = createChartPanel(dataSets);
        if (chart != null) {
            JLabel titleLabel = new JLabel("" + options.getChartOptions().getData());
            titleLabel.setHorizontalAlignment(JLabel.CENTER);
            makeSmall(titleLabel);
            chartLegendPanel.add(chart, BorderLayout.CENTER);
            chartLegendPanel.add(titleLabel, BorderLayout.SOUTH);
        }
        p.setVisible(true);
    } else {
        p.setVisible(false);
    }
    p.revalidate();
}
Also used : JPanel(javax.swing.JPanel) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) ChartPanel(org.jfree.chart.ChartPanel) JLabel(javax.swing.JLabel) ChartType(org.baderlab.csplugins.enrichmentmap.style.ChartType) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 47 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateEdgeColorPanel.

private void updateEdgeColorPanel(EnrichmentMap map) {
    JPanel p = getEdgeColorPanel();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    JComponent[][] entries = null;
    if (map != null) {
        Dimension iconSize = new Dimension(LEGEND_ICON_SIZE, LEGEND_ICON_SIZE / 2);
        if (map.getParams().getCreateDistinctEdges()) {
            VisualMappingFunction<?, Paint> mf = style.getVisualMappingFunction(BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
            if (mf instanceof DiscreteMapping) {
                DiscreteMapping<?, Paint> dm = (DiscreteMapping<?, Paint>) mf;
                final Collator collator = Collator.getInstance();
                Map<Object, Paint> dmMap = new TreeMap<>((Object o1, Object o2) -> {
                    return collator.compare("" + o1, "" + o2);
                });
                dmMap.putAll(dm.getAll());
                dmMap.remove(Columns.EDGE_DATASET_VALUE_COMPOUND);
                if (!map.hasSignatureDataSets())
                    dmMap.remove(Columns.EDGE_DATASET_VALUE_SIG);
                if (dmMap.size() > 0) {
                    entries = new JComponent[dmMap.size()][2];
                    int i = 0;
                    for (Entry<?, Paint> e : dmMap.entrySet()) {
                        Color color = null;
                        if (e.getValue() instanceof Color)
                            color = (Color) e.getValue();
                        JLabel iconLabel = createColorLabel(color, iconSize);
                        JLabel descLabel = new JLabel("" + e.getKey());
                        if (Columns.EDGE_DATASET_VALUE_SIG.equals(e.getKey()))
                            descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                        entries[i++] = new JComponent[] { iconLabel, descLabel };
                    }
                }
            }
        }
        if (entries == null) {
            int rows = map.hasSignatureDataSets() ? 2 : 1;
            entries = new JComponent[rows][2];
            {
                JLabel iconLabel = createColorLabel(Colors.COMPOUND_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_COMPOUND);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[0] = new JComponent[] { iconLabel, descLabel };
            }
            if (rows == 2) {
                JLabel iconLabel = createColorLabel(Colors.SIG_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_SIG);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[1] = new JComponent[] { iconLabel, descLabel };
            }
        }
    }
    updateStyleLegendPanel(entries, p);
}
Also used : JPanel(javax.swing.JPanel) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Paint(java.awt.Paint) TreeMap(java.util.TreeMap) Paint(java.awt.Paint) Collator(java.text.Collator) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 48 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateNodeShapePanel.

private void updateNodeShapePanel(EnrichmentMap map) {
    JPanel p = getNodeShapePanel();
    p.removeAll();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    nodeShapeIcon1.setVisible(style != null);
    nodeShapeDesc1.setVisible(style != null);
    nodeShapeIcon2.setVisible(style != null && map.hasSignatureDataSets());
    nodeShapeDesc2.setVisible(style != null && map.hasSignatureDataSets());
    if (style != null) {
        NodeShape shape = EMStyleBuilder.getGeneSetNodeShape(style);
        nodeShapeIcon1.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
        if (map.hasSignatureDataSets()) {
            shape = EMStyleBuilder.getSignatureNodeShape(style);
            nodeShapeIcon2.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
        }
    }
    p.revalidate();
}
Also used : JPanel(javax.swing.JPanel) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 49 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeColors.

private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
    String prefix = options.getAttributePrefix();
    List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
    ds -> ds instanceof EMDataSet).collect(Collectors.toList());
    if (dataSets.size() == 1) {
        // Only 1 Data Set? Use node colour instead of charts...
        EMDataSet ds = (EMDataSet) dataSets.iterator().next();
        // Create boundary conditions
        BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        // Continuous Mapping - set node colour based on the sign of the ES score of the dataset
        ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(cm);
        try {
            // Set the attribute point values associated with the boundary values
            cm.addPoint(-1.0, bv3a);
            cm.addPoint(-0.995, bv3b);
            cm.addPoint(-0.95, bv3c);
            cm.addPoint(-0.9, bv3d);
            cm.addPoint(0.0, bv3e);
            cm.addPoint(0.9, bv3f);
            cm.addPoint(0.95, bv3g);
            cm.addPoint(0.995, bv3h);
            cm.addPoint(1.0, bv3i);
        } finally {
            eventHelper.unsilenceEventSource(cm);
        }
        vs.addVisualMappingFunction(cm);
        // Then we need to use bypass to colour the hub nodes (signature genesets)
        List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
        CyNetworkView netView = options.getNetworkView();
        CyNetwork net = netView.getModel();
        for (EMSignatureDataSet sds : signatureDataSets) {
            for (Long suid : sds.getNodeSuids()) {
                CyNode node = net.getNode(suid);
                if (node != null) {
                    View<CyNode> nv = netView.getNodeView(node);
                    if (nv != null)
                        nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
                }
            }
        }
    } else {
        // 2 or more Data Sets? Use simple node colours and charts...
        // Add mapping function for node fill color
        DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 50 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class ApplyEMStyleTask method applyVisualStyle.

private void applyVisualStyle() {
    CyNetworkView view = options.getNetworkView();
    VisualStyle vs = getVisualStyle(options.getEnrichmentMap());
    if (updateChartOnly)
        styleBuilderProvider.get().updateNodeChart(vs, options, chart);
    else
        styleBuilderProvider.get().updateProperties(vs, options, chart);
    if (!vs.equals(visualMappingManager.getVisualStyle(view)))
        visualMappingManager.setVisualStyle(vs, view);
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

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