Search in sources :

Example 1 with ColorBrewer

use of org.jcolorbrewer.ColorBrewer in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method createEdgeColorMapping.

private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
    String prefix = options.getAttributePrefix();
    String col = Columns.EDGE_DATASET.with(prefix, null);
    DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(col, String.class, vp);
    // Silence events fired by this mapping, or it will fire too many VisualMappingFunctionChangedEvents,
    // which can be captured by VisualStyle later and cause unnecessary view updates,
    // even though this mapping has not been set to a style yet
    // (unfortunately that's just how Cytoscape's event payloads work).
    eventHelper.silenceEventSource(dm);
    try {
        dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
        //			dm.putMapValue(Columns.EDGE_DATASET_VALUE_SIG, Colors.SIG_EDGE_COLOR);
        List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
        final ColorBrewer colorBrewer;
        // Try colorblind and/or print friendly colours first
        if (// Try a colorblind safe color scheme first
        dataSets.size() <= 4)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
            colorBrewer = ColorBrewer.Paired;
        else if (// Same--more than 5, it adds a RED that can be confused with the edge selection color
        dataSets.size() <= 5)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
            colorBrewer = ColorBrewer.Paired;
        else
            // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
            colorBrewer = ColorBrewer.Set3;
        Color[] colors = colorBrewer.getColorPalette(dataSets.size());
        // Do not use the filtered data sets here, because we don't want edge colours changing when filtering
        for (int i = 0; i < dataSets.size(); i++) {
            EMDataSet ds = dataSets.get(i);
            Color color = colors[i];
            dm.putMapValue(ds.getName(), color);
            ds.setColor(color);
        }
    } finally {
        eventHelper.unsilenceEventSource(dm);
    }
    return dm;
}
Also used : ColorBrewer(org.jcolorbrewer.ColorBrewer) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) Paint(java.awt.Paint) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)

Aggregations

Color (java.awt.Color)1 Paint (java.awt.Paint)1 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)1 ContinuousMappingPoint (org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1 ColorBrewer (org.jcolorbrewer.ColorBrewer)1