15
15
import javax .swing .UIManager ;
16
16
17
17
import org .baderlab .csplugins .enrichmentmap .model .EMDataSet ;
18
+ import org .baderlab .csplugins .enrichmentmap .style .ChartData ;
18
19
import org .baderlab .csplugins .enrichmentmap .style .ChartOptions ;
19
20
import org .baderlab .csplugins .enrichmentmap .style .ColorScheme ;
20
21
import org .baderlab .csplugins .enrichmentmap .style .ColumnDescriptor ;
@@ -133,6 +134,21 @@ else if (row.isSet(column.getName()))
133
134
return range ;
134
135
}
135
136
137
+ public static List <Color > getChartColors (ChartOptions options ) {
138
+ ColorScheme colorScheme = options != null ? options .getColorScheme () : null ;
139
+ List <Color > colors = colorScheme != null ? colorScheme .getColors () : null ;
140
+ ChartData data = options != null ? options .getData () : null ;
141
+
142
+ // Swap UP and ZERO colors if q or p-value (it should not have negative values!)
143
+ if ((data == ChartData .FDR_VALUE || data == ChartData .P_VALUE ) && colors .size () == 3 )
144
+ colors = Arrays .asList (new Color [] { colors .get (1 ), colors .get (0 ), colors .get (1 ) });
145
+
146
+ if (colors == null || colors .size () < 3 ) // UP, ZERO, DOWN:
147
+ colors = Arrays .asList (new Color [] { Color .LIGHT_GRAY , Color .WHITE , Color .DARK_GRAY });
148
+
149
+ return colors ;
150
+ }
151
+
136
152
public static JFreeChart createRadialHeatMapLegend (List <EMDataSet > dataSets , ChartOptions options ) {
137
153
// All the slices must have the same size
138
154
final DefaultPieDataset pieDataset = new DefaultPieDataset ();
@@ -169,19 +185,17 @@ public static JFreeChart createRadialHeatMapLegend(List<EMDataSet> dataSets, Cha
169
185
plot .setLabelShadowPaint (TRANSPARENT_COLOR );
170
186
plot .setToolTipGenerator (new StandardPieToolTipGenerator ("{0}" ));
171
187
172
- ColorScheme colorScheme = options != null ? options .getColorScheme () : null ;
173
- List <Color > colors = colorScheme != null ? colorScheme .getColors () : null ;
174
-
175
- if (colors == null || colors .size () < 3 ) // UP, ZERO, DOWN:
176
- colors = Arrays .asList (new Color [] { Color .LIGHT_GRAY , Color .WHITE , Color .DARK_GRAY });
188
+ List <Color > colors = getChartColors (options );
177
189
178
190
int total = dataSets .size ();
179
- int v = total / -2 ;
191
+ int lowerBound = options .getData () == ChartData .NES_VALUE ? -total : 0 ;
192
+ int upperBound = lowerBound + (2 * total );
193
+ int v = lowerBound / 2 ;
180
194
181
195
for (EMDataSet ds : dataSets ) {
182
196
plot .setSectionPaint (
183
197
ds .getName (),
184
- ColorUtil .getColor (v , - total , total , colors .get (2 ), colors .get (1 ), colors .get (0 ))
198
+ ColorUtil .getColor (v , lowerBound , upperBound , colors .get (2 ), colors .get (1 ), colors .get (0 ))
185
199
);
186
200
v ++;
187
201
}
@@ -231,18 +245,16 @@ public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOpti
231
245
final NumberAxis rangeAxis = (NumberAxis ) plot .getRangeAxis ();
232
246
rangeAxis .setVisible (false );
233
247
234
- ColorScheme colorScheme = options != null ? options .getColorScheme () : null ;
235
- List <Color > colors = colorScheme != null ? colorScheme .getColors () : null ;
236
-
237
- if (colors == null || colors .size () < 3 ) // UP, ZERO, DOWN:
238
- colors = Arrays .asList (new Color [] { Color .LIGHT_GRAY , Color .WHITE , Color .DARK_GRAY });
248
+ List <Color > colors = getChartColors (options );
239
249
240
250
List <Color > itemColors = new ArrayList <>();
241
251
int total = dataSets .size ();
242
- int v = total / 2 ;
252
+ int lowerBound = options .getData () == ChartData .NES_VALUE ? -total : 0 ;
253
+ int upperBound = lowerBound + (2 * total );
254
+ int v = lowerBound / 2 ;
243
255
244
256
for (int i = 0 ; i < total ; i ++)
245
- itemColors .add (ColorUtil .getColor (v --, - total , total , colors .get (2 ), colors .get (1 ), colors .get (0 )));
257
+ itemColors .add (ColorUtil .getColor (v ++, lowerBound , upperBound , colors .get (2 ), colors .get (1 ), colors .get (0 )));
246
258
247
259
final BarRenderer renderer = new BarRenderer () {
248
260
@ Override
@@ -264,7 +276,9 @@ public Paint getItemPaint(int row, int column) {
264
276
public static JFreeChart createHeatStripsLegend (List <EMDataSet > dataSets , ChartOptions options ) {
265
277
final DefaultCategoryDataset dataset = new DefaultCategoryDataset ();
266
278
int total = dataSets .size ();
267
- int v = total / -2 ;
279
+ int lowerBound = options .getData () == ChartData .NES_VALUE ? -total : 0 ;
280
+ int upperBound = lowerBound + (2 * total );
281
+ int v = lowerBound / 2 ;
268
282
269
283
for (int i = 0 ; i < total ; i ++) {
270
284
if (v == 0.0 ) v = 1 ; // Just to make sure there is always a bar for each data set name
@@ -313,18 +327,13 @@ public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartO
313
327
final NumberAxis rangeAxis = (NumberAxis ) plot .getRangeAxis ();
314
328
rangeAxis .setVisible (false );
315
329
316
- ColorScheme colorScheme = options != null ? options .getColorScheme () : null ;
317
- List <Color > colors = colorScheme != null ? colorScheme .getColors () : null ;
318
-
319
- if (colors == null || colors .size () < 3 ) // UP, ZERO, DOWN:
320
- colors = Arrays .asList (new Color [] { Color .LIGHT_GRAY , Color .WHITE , Color .DARK_GRAY });
321
-
330
+ List <Color > colors = getChartColors (options );
322
331
List <Color > itemColors = new ArrayList <>();
323
332
324
333
for (int i = 0 ; i < total ; i ++) {
325
334
Number n = dataset .getValue (options .getData ().toString (), dataSets .get (i ).getName ());
326
335
itemColors .add (
327
- ColorUtil .getColor (n .doubleValue (), - total , total , colors .get (2 ), colors .get (1 ), colors .get (0 )));
336
+ ColorUtil .getColor (n .doubleValue (), lowerBound , upperBound , colors .get (2 ), colors .get (1 ), colors .get (0 )));
328
337
}
329
338
330
339
final BarRenderer renderer = new BarRenderer () {
0 commit comments