Skip to content

Commit 64286f3

Browse files
committed
Fixes #323, wrong edge colors in Legend.
1 parent 9f2acc8 commit 64286f3

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/EMStyleBuilder.java

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
package org.baderlab.csplugins.enrichmentmap.style;
22

3-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY;
4-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE;
5-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT;
6-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY;
7-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT;
8-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH;
9-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT;
10-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT;
11-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY;
12-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH;
13-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR;
14-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL;
15-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY;
16-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE;
17-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE;
18-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP;
19-
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY;
3+
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.*;
204
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND;
215
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE;
226
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE;
@@ -272,6 +256,20 @@ private void setEdgePaint(VisualStyle vs, EMStyleOptions options) {
272256
vs.addVisualMappingFunction(edgeStrokePaint);
273257
}
274258

259+
260+
public static Color[] getColorPalette(int datasetCount) {
261+
final ColorBrewer colorBrewer;
262+
// Try colorblind and/or print friendly colours first
263+
if (datasetCount <= 4) // Try a colorblind safe color scheme first
264+
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
265+
else if (datasetCount <= 5) // Same--more than 5, it adds a RED that can be confused with the edge selection color
266+
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
267+
else
268+
colorBrewer = ColorBrewer.Set3; // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
269+
270+
return colorBrewer.getColorPalette(datasetCount);
271+
}
272+
275273
private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
276274
int dataSetCount = options.getEnrichmentMap().getDataSetCount();
277275
boolean distinctEdges = options.getEnrichmentMap().getParams().getCreateDistinctEdges();
@@ -292,17 +290,7 @@ private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions opt
292290
List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
293291

294292
// if (dataSetCount > 1 && distinctEdges) {
295-
final ColorBrewer colorBrewer;
296-
297-
// Try colorblind and/or print friendly colours first
298-
if (dataSets.size() <= 4) // Try a colorblind safe color scheme first
299-
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
300-
else if (dataSets.size() <= 5) // Same--more than 5, it adds a RED that can be confused with the edge selection color
301-
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
302-
else
303-
colorBrewer = ColorBrewer.Set3; // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
304-
305-
Color[] colors = colorBrewer.getColorPalette(dataSets.size());
293+
Color[] colors = getColorPalette(dataSets.size());
306294

307295
// Do not use the filtered data sets here, because we don't want edge colours changing when filtering
308296
for (int i = 0; i < dataSets.size(); i++) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/legend/LegendPanel.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,15 @@ public Map<Object,Paint> getEdgeColors() {
530530
VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
531531

532532
final Collator collator = Collator.getInstance();
533-
Map<Object,Paint> dmMap = new TreeMap<>((Object o1, Object o2) -> {
534-
if (Columns.EDGE_DATASET_VALUE_SIG.equals(o1)) return 1;
535-
if (Columns.EDGE_DATASET_VALUE_SIG.equals(o2)) return -1;
533+
Map<Object,Paint> dmMap = new TreeMap<>((o1, o2) -> {
534+
boolean sig1 = Columns.EDGE_DATASET_VALUE_SIG.equals(o1);
535+
boolean sig2 = Columns.EDGE_DATASET_VALUE_SIG.equals(o2);
536+
if(sig1 && sig2)
537+
return 0;
538+
if(sig1)
539+
return 1;
540+
if(sig2)
541+
return -1;
536542
return collator.compare("" + o1, "" + o2);
537543
});
538544

@@ -545,6 +551,7 @@ public Map<Object,Paint> getEdgeColors() {
545551

546552
dmMap.putAll(dm.getAll());
547553
dmMap.remove(Columns.EDGE_DATASET_VALUE_COMPOUND);
554+
dmMap.remove(Columns.EDGE_INTERACTION_VALUE_OVERLAP);
548555

549556
// Special case of 1 dataset with distinct edges and maybe signature genesets as well
550557
if (map.getDataSetCount() == 1) {
@@ -557,17 +564,20 @@ public Map<Object,Paint> getEdgeColors() {
557564
dmMap.put(Columns.EDGE_DATASET_VALUE_SIG, p2);
558565
}
559566

560-
if (!map.hasSignatureDataSets())
567+
if (!map.hasSignatureDataSets()) {
561568
dmMap.remove(Columns.EDGE_DATASET_VALUE_SIG);
562-
563-
if (dmMap.size() > 0) {
564-
569+
dmMap.remove(Columns.EDGE_INTERACTION_VALUE_SIG);
565570
}
566571
}
567572
}
568573

569574
if (dmMap.isEmpty()) {
570-
dmMap.put(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
575+
Color[] colors = EMStyleBuilder.getColorPalette(map.getDataSetCount());
576+
if(colors != null && colors.length > 0) {
577+
dmMap.put(Columns.EDGE_DATASET_VALUE_COMPOUND, colors[0]);
578+
} else {
579+
dmMap.put(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
580+
}
571581
if (map.hasSignatureDataSets()) {
572582
dmMap.put(Columns.EDGE_DATASET_VALUE_SIG, Colors.SIG_EDGE_COLOR);
573583
}

0 commit comments

Comments
 (0)