Skip to content

Commit 4baf524

Browse files
committed
Refs #255: It's now possible to set node charts for a single dataset. Also, the Radial Heat Map accepts more than 3 colours and colour points--when NES, it uses ColorBrewer 9-class RdBu scheme by default.
1 parent 3f8c2ca commit 4baf524

File tree

10 files changed

+216
-139
lines changed

10 files changed

+216
-139
lines changed
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
11
package org.baderlab.csplugins.enrichmentmap.style;
22

33
import java.awt.Color;
4-
import java.util.ArrayList;
4+
import java.util.Arrays;
55
import java.util.Collections;
6-
import java.util.HashMap;
76
import java.util.List;
8-
import java.util.Map;
97

108
public enum ColorScheme {
119

1210
// 3-color ColorBrewer schemes (color-blind safe and print friendly):
1311
// Diverging
14-
RD_BU("RdBu", "ColorBrewer 3-class RdBu (Diverging, Colorblind Safe)", new Color(103, 169, 207), new Color(247, 247, 247), new Color(239, 138, 98)),
15-
BR_BG("BrBG", "ColorBrewer 3-class BrBG (Diverging, Colorblind Safe)", new Color(90, 180, 172), new Color(245, 245, 245), new Color(216, 179, 101)),
16-
PI_YG("PiYG", "ColorBrewer 3-class PiYG (Diverging, Colorblind Safe)", new Color(161, 215, 106), new Color(247, 247, 247), new Color(233, 163, 201)),
17-
PU_OR("PuOr", "ColorBrewer 3-class PuOr (Diverging, Colorblind Safe)", new Color(153, 142, 195), new Color(247, 247, 247), new Color(241, 163, 64)),
18-
RD_YL_BU("RdYlBu", "ColorBrewer 3-class RdYlBu (Diverging, Colorblind Safe)", new Color(145, 191, 219), new Color(255, 255, 191), new Color(252, 141, 89)),
12+
RD_BU_9("RdBu-9", "ColorBrewer 9-class RdBu (Diverging, Colorblind Safe)",
13+
new Color[] {
14+
new Color(178, 24, 43), new Color(178, 24, 43), new Color(214, 96, 77), new Color(244, 165, 130),
15+
new Color(253, 219, 199), new Color(247, 247, 247), new Color(209, 229, 240),
16+
new Color(146, 197, 222), new Color(67, 147, 195), new Color(33, 102, 172), new Color(33, 102, 172),
17+
18+
},
19+
new Double[] {
20+
4.0, 1.4, 1.0, 0.5, 0.49999, 0.0, -0.49999, -0.5, -1.0, -1.4, -4.0
21+
}
22+
),
23+
24+
RD_BU_3("RdBu-3", "ColorBrewer 3-class RdBu (Diverging, Colorblind Safe)",
25+
new Color(103, 169, 207), new Color(247, 247, 247), new Color(239, 138, 98)),
26+
27+
BR_BG_3("BrBG-3", "ColorBrewer 3-class BrBG (Diverging, Colorblind Safe)",
28+
new Color(90, 180, 172), new Color(245, 245, 245), new Color(216, 179, 101)),
29+
30+
PI_YG_3("PiYG-3", "ColorBrewer 3-class PiYG (Diverging, Colorblind Safe)",
31+
new Color(161, 215, 106), new Color(247, 247, 247), new Color(233, 163, 201)),
32+
33+
PU_OR_3("PuOr-3", "ColorBrewer 3-class PuOr (Diverging, Colorblind Safe)",
34+
new Color(153, 142, 195), new Color(247, 247, 247), new Color(241, 163, 64)),
35+
36+
RD_YL_BU_3("RdYlBu-3", "ColorBrewer 3-class RdYlBu (Diverging, Colorblind Safe)",
37+
new Color(145, 191, 219), new Color(255, 255, 191), new Color(252, 141, 89)),
1938
;
2039

2140
private final String name;
2241
private final String description;
23-
private final Color up, zero, down;
42+
private final Color[] colors;
43+
private final Double[] points;
2444

25-
private static Map<String, ColorScheme>cMap;
26-
27-
ColorScheme(final String name, final String description, final Color down, final Color zero, final Color up) {
45+
ColorScheme(String name, String description, Color down, Color zero, Color up) {
46+
this.name = name;
47+
this.description = description;
48+
this.colors = new Color[] { up, zero, down };
49+
this.points = null;
50+
}
51+
52+
ColorScheme(String name, String description, Color[] colors, Double[] points) {
2853
this.name = name;
2954
this.description = description;
30-
this.up = up;
31-
this.down = down;
32-
this.zero = zero;
33-
addGradient(this);
55+
this.colors = colors;
56+
this.points = points;
3457
}
3558

3659
public String getName() {
@@ -42,37 +65,14 @@ public String getDescription() {
4265
}
4366

4467
public List<Color> getColors() {
45-
final List<Color> retColors = new ArrayList<>();
46-
retColors.add(up);
47-
if (zero != null) retColors.add(zero);
48-
retColors.add(down);
49-
50-
return retColors;
51-
}
52-
53-
public static boolean contains(final String name) {
54-
return name != null && cMap.containsKey(normalize(name));
55-
}
56-
57-
public static ColorScheme getGradient(final String name) {
58-
return cMap.get(normalize(name));
59-
}
60-
61-
public static List<Color> getColors(String name) {
62-
name = normalize(name);
63-
64-
if (name != null && cMap.containsKey(name))
65-
return cMap.get(name).getColors();
66-
67-
return Collections.emptyList();
68-
}
69-
70-
private void addGradient(final ColorScheme cg) {
71-
if (cMap == null) cMap = new HashMap<>();
72-
cMap.put(normalize(cg.name()), cg);
68+
return Arrays.asList(colors);
7369
}
7470

75-
private static String normalize(final String name) {
76-
return name != null ? name.toUpperCase().replaceAll("[-_]", "") : null;
71+
/**
72+
* Can be used to create more complex gradients, with fixed range points,
73+
* such as the ones created by Continuous Mappings.
74+
*/
75+
public List<Double> getPoints() {
76+
return points != null ? Arrays.asList(points) : Collections.emptyList();
7777
}
7878
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
466466
.collect(Collectors.toList());
467467

468468
if (dataSets.size() == 1) {
469-
// Only 1 Data Set? Use node colour instead of charts...
469+
// Only 1 Data Set? Set a continuous mapping for node colour...
470470
EMDataSet ds = (EMDataSet) dataSets.iterator().next();
471471

472472
// Create boundary conditions

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/AbstractChart.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public abstract class AbstractChart<T extends CustomGraphicLayer>
4646
implements CyCustomGraphics2<T>, MappableVisualPropertyValue {
4747

4848
public static final String COLORS = "cy_colors";
49+
public static final String COLOR_POINTS = "em_colorPoints";
4950
public static final String ORIENTATION = "cy_orientation";
5051
public static final String ROTATION = "cy_rotation";
5152
public static final String DATA_COLUMNS = "cy_dataColumns";
@@ -454,9 +455,11 @@ protected List<String> getItemLabels(final CyNetwork network, final CyIdentifiab
454455
}
455456

456457
protected List<Color> getColors(final Map<String, List<Double>> data) {
457-
List<Color> colors = getList(COLORS, Color.class);
458-
459-
return colors;
458+
return getList(COLORS, Color.class);
459+
}
460+
461+
protected List<Double> getColorPoints(final Map<String, List<Double>> data) {
462+
return getList(COLOR_POINTS, Double.class);
460463
}
461464

462465
@SuppressWarnings("unchecked")
@@ -558,6 +561,7 @@ public Class<?> getSettingType(final String key) {
558561
if (key.equalsIgnoreCase(BORDER_WIDTH)) return Float.class;
559562
if (key.equalsIgnoreCase(BORDER_COLOR)) return Color.class;
560563
if (key.equalsIgnoreCase(COLORS)) return List.class;
564+
if (key.equalsIgnoreCase(COLOR_POINTS)) return List.class;
561565
if (key.equalsIgnoreCase(ORIENTATION)) return Orientation.class;
562566
if (key.equalsIgnoreCase(ROTATION)) return Rotation.class;
563567

@@ -570,6 +574,7 @@ public Class<?> getSettingElementType(final String key) {
570574
if (key.equalsIgnoreCase(ITEM_LABELS)) return String.class;
571575
if (key.equalsIgnoreCase(RANGE)) return Double.class;
572576
if (key.equalsIgnoreCase(COLORS)) return Color.class;
577+
if (key.equalsIgnoreCase(COLOR_POINTS)) return Double.class;
573578

574579
return Object.class;
575580
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/AbstractChartLayer.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class AbstractChartLayer<T extends Dataset> implements Cy2DGraph
4848
protected final boolean showRangeAxis;
4949
protected final LabelPosition domainLabelPosition;
5050
protected final List<Color> colors;
51+
protected final List<Double> colorPoints;
5152
protected final float borderWidth;
5253
protected final Color borderColor;
5354
protected Color labelColor = Color.DARK_GRAY;
@@ -66,23 +67,26 @@ public abstract class AbstractChartLayer<T extends Dataset> implements Cy2DGraph
6667

6768
// ==[ CONSTRUCTORS ]===============================================================================================
6869

69-
protected AbstractChartLayer(final Map<String, List<Double>> data,
70-
final List<String> itemLabels,
71-
final List<String> domainLabels,
72-
final List<String> rangeLabels,
73-
final boolean showItemLabels,
74-
final boolean showDomainAxis,
75-
final boolean showRangeAxis,
76-
final float itemFontSize,
77-
final LabelPosition domainLabelPosition,
78-
final List<Color> colors,
79-
final float axisWidth,
80-
final Color axisColor,
81-
final float axisFontSize,
82-
final float borderWidth,
83-
final Color borderColor,
84-
final List<Double> range,
85-
final Rectangle2D bounds) {
70+
protected AbstractChartLayer(
71+
final Map<String, List<Double>> data,
72+
final List<String> itemLabels,
73+
final List<String> domainLabels,
74+
final List<String> rangeLabels,
75+
final boolean showItemLabels,
76+
final boolean showDomainAxis,
77+
final boolean showRangeAxis,
78+
final float itemFontSize,
79+
final LabelPosition domainLabelPosition,
80+
final List<Color> colors,
81+
final List<Double> colorPoints,
82+
final float axisWidth,
83+
final Color axisColor,
84+
final float axisFontSize,
85+
final float borderWidth,
86+
final Color borderColor,
87+
final List<Double> range,
88+
final Rectangle2D bounds
89+
) {
8690
this.data = data;
8791
this.itemLabels = itemLabels;
8892
this.domainLabels = domainLabels;
@@ -93,6 +97,7 @@ protected AbstractChartLayer(final Map<String, List<Double>> data,
9397
this.itemFontSize = itemFontSize;
9498
this.domainLabelPosition = domainLabelPosition;
9599
this.colors = colors;
100+
this.colorPoints = colorPoints;
96101
this.axisWidth = axisWidth;
97102
this.axisColor = axisColor;
98103
this.axisFontSize = axisFontSize;

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/radialheatmap/RadialHeatMapChart.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public List<RadialHeatMapLayer> getLayers(final CyNetworkView networkView, final
6464
final Map<String, List<Double>> data = getData(network, model);
6565

6666
final List<Color> colors = getColors(data);
67+
final List<Double> colorPoints = getColorPoints(data);
6768
final double size = 32;
6869
final Rectangle2D bounds = new Rectangle2D.Double(-size / 2, -size / 2, size, size);
6970
final boolean showLabels = get(SHOW_ITEM_LABELS, Boolean.class, false);
@@ -74,8 +75,8 @@ public List<RadialHeatMapLayer> getLayers(final CyNetworkView networkView, final
7475
final boolean global = get(GLOBAL_RANGE, Boolean.class, true);
7576
final List<Double> range = global ? getList(RANGE, Double.class) : null;
7677

77-
final RadialHeatMapLayer layer = new RadialHeatMapLayer(data, labels, showLabels, itemFontSize, colors, borderWidth,
78-
borderColor, startAngle, rotation, range, bounds);
78+
final RadialHeatMapLayer layer = new RadialHeatMapLayer(data, labels, showLabels, itemFontSize, colors,
79+
colorPoints, borderWidth, borderColor, startAngle, rotation, range, bounds);
7980

8081
return Collections.singletonList(layer);
8182
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/radialheatmap/RadialHeatMapChartFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public Class<? extends CyCustomGraphics2<RadialHeatMapLayer>> getSupportedClass(
4545

4646
@Override
4747
public String getDisplayName() {
48-
return "Heat Pie (by EnrichmentMap)";
48+
return "Radial Heat Map (by EnrichmentMap)";
4949
}
5050

5151
@Override

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/radialheatmap/RadialHeatMapLayer.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public RadialHeatMapLayer(
3636
final boolean showLabels,
3737
final float itemFontSize,
3838
final List<Color> colors,
39+
final List<Double> colorPoints,
3940
final float borderWidth,
4041
final Color borderColor,
4142
final double startAngle,
@@ -44,10 +45,10 @@ public RadialHeatMapLayer(
4445
final Rectangle2D bounds
4546
) {
4647
super(data, itemLabels, null, null, showLabels, false, false, itemFontSize, LabelPosition.STANDARD, colors,
47-
0.0f, TRANSPARENT_COLOR, 0.0f, borderWidth, borderColor, range, bounds);
48-
this.startAngle = startAngle;
49-
this.rotation = rotation;
50-
this.labels = new HashMap<>();
48+
colorPoints, 0.0f, TRANSPARENT_COLOR, 0.0f, borderWidth, borderColor, range, bounds);
49+
this.startAngle = startAngle;
50+
this.rotation = rotation;
51+
this.labels = new HashMap<>();
5152

5253
// Range cannot be null
5354
if (this.range == null)
@@ -128,13 +129,15 @@ protected JFreeChart createChart(final PieDataset dataset) {
128129
Color lowerColor = Color.RED;
129130
Color nanColor = DEFAULT_ITEM_BG_COLOR;
130131

131-
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
132-
final int colorsSize = colors != null ? colors.size() : 0;
133-
134-
if (colorsSize > 0) upperColor = colors.get(0);
135-
if (colorsSize > 1) zeroColor = colors.get(1);
136-
if (colorsSize > 2) lowerColor = colors.get(2);
137-
if (colorsSize > 3) nanColor = colors.get(3);
132+
if (colorPoints.isEmpty() || colorPoints.size() != colors.size()) {
133+
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
134+
final int colorsSize = colors != null ? colors.size() : 0;
135+
136+
if (colorsSize > 0) upperColor = colors.get(0);
137+
if (colorsSize > 1) zeroColor = colors.get(1);
138+
if (colorsSize > 2) lowerColor = colors.get(2);
139+
if (colorsSize > 3) nanColor = colors.get(3);
140+
}
138141
}
139142

140143
final List<?> keys = dataset.getKeys();
@@ -145,10 +148,14 @@ protected JFreeChart createChart(final PieDataset dataset) {
145148
Double v = values.size() > i ? values.get(i) : null;
146149
final Color c;
147150

148-
if (v == null)
151+
if (v == null) {
149152
c = nanColor;
150-
else
151-
c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
153+
} else {
154+
if (colorPoints.isEmpty() || colorPoints.size() != colors.size())
155+
c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
156+
else
157+
c = ColorUtil.getColor(v, colors, colorPoints);
158+
}
152159

153160
plot.setSectionPaint(k, c);
154161
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);

0 commit comments

Comments
 (0)