56
56
import java .awt .Paint ;
57
57
import java .text .Collator ;
58
58
import java .util .Collection ;
59
+ import java .util .LinkedHashMap ;
59
60
import java .util .List ;
60
61
import java .util .Map ;
61
62
import java .util .Map .Entry ;
@@ -122,6 +123,7 @@ public class LegendPanel extends JPanel implements LegendContent {
122
123
123
124
private final Border DEF_LEGEND_BORDER = BorderFactory .createLineBorder (UIManager .getColor ("Separator.foreground" ));
124
125
private final Color DEF_LEGEND_BG = Color .WHITE ;
126
+ private final Dimension COLOR_ICON_SIZE = new Dimension (LEGEND_ICON_SIZE , LEGEND_ICON_SIZE / 2 );
125
127
126
128
@ Inject private CyApplicationManager applicationManager ;
127
129
@ Inject private VisualMappingManager visualMappingManager ;
@@ -144,6 +146,7 @@ public class LegendPanel extends JPanel implements LegendContent {
144
146
private final JPanel chartLegendPanel = new JPanel (new BorderLayout ());
145
147
146
148
private JPanel edgeColorPanel ;
149
+ private JPanel dataSetColorPanel ;
147
150
148
151
private EMStyleOptions options ;
149
152
@@ -168,6 +171,7 @@ public LegendPanel() {
168
171
equalizeSize (nodeShapeDesc1 , nodeShapeDesc2 );
169
172
}
170
173
174
+ @ Override
171
175
public EMStyleOptions getOptions () {
172
176
return options ;
173
177
}
@@ -232,6 +236,7 @@ void update(EMStyleOptions options, Collection<EMDataSet> filteredDataSets) {
232
236
nodeChartPanel = null ;
233
237
edgeLegendPanel = null ;
234
238
edgeColorPanel = null ;
239
+ dataSetColorPanel = null ;
235
240
236
241
nodeColorLegend = null ;
237
242
chartPosLegend = null ;
@@ -244,6 +249,7 @@ void update(EMStyleOptions options, Collection<EMDataSet> filteredDataSets) {
244
249
updateNodeShapePanel ();
245
250
updateNodeChartPanel (filteredDataSets );
246
251
updateNodeChartColorPanel (filteredDataSets );
252
+ updateNodeDataSetColorPanel ();
247
253
updateEdgeColorPanel ();
248
254
249
255
JPanel panel = new JPanel ();
@@ -272,7 +278,9 @@ private void updateNodeColorPanel(Collection<EMDataSet> dataSets) {
272
278
JPanel p = getNodeColorPanel ();
273
279
p .removeAll ();
274
280
275
- if (dataSets != null && dataSets .size () == 1 ) {
281
+ ChartData data = options .getChartOptions ().getData ();
282
+
283
+ if (dataSets != null && dataSets .size () == 1 && data == ChartData .NONE ) {
276
284
EMDataSet ds = dataSets .iterator ().next ();
277
285
278
286
nodeColorLegend = new ColorLegendPanel (
@@ -306,7 +314,7 @@ private void updateNodeChartColorPanel(Collection<EMDataSet> dataSets) {
306
314
ChartOptions chartOptions = options .getChartOptions ();
307
315
ChartData data = chartOptions .getData ();
308
316
309
- if (data != ChartData .NONE ) {
317
+ if (data != ChartData .NONE && data != ChartData . DATA_SET ) {
310
318
AbstractColumnDescriptor columnDescriptor = data .getColumnDescriptor ();
311
319
List <CyColumnIdentifier > columns = ChartUtil .getSortedColumnIdentifiers (options .getAttributePrefix (),
312
320
dataSets , columnDescriptor , columnIdFactory );
@@ -393,7 +401,7 @@ private void updateNodeShapePanel() {
393
401
p .revalidate ();
394
402
}
395
403
396
- private void updateNodeChartPanel (Collection <EMDataSet > dataSets ) {
404
+ private void updateNodeChartPanel (Collection <EMDataSet > filteredDataSets ) {
397
405
JPanel p = getNodeChartPanel ();
398
406
chartLegendPanel .removeAll ();
399
407
@@ -409,8 +417,8 @@ private void updateNodeChartPanel(Collection<EMDataSet> dataSets) {
409
417
Object cg = vp != null ? style .getDefaultValue (vp ) : null ;
410
418
ChartType chartType = options .getChartOptions () != null ? options .getChartOptions ().getType () : null ;
411
419
412
- if (chartType != null && cg instanceof CyCustomGraphics2 && dataSets != null ) {
413
- ChartPanel chart = createChartPanel (dataSets );
420
+ if (chartType != null && cg instanceof CyCustomGraphics2 && filteredDataSets != null ) {
421
+ ChartPanel chart = createChartPanel (filteredDataSets );
414
422
415
423
if (chart != null ) {
416
424
JLabel titleLabel = new JLabel (getChartLabel ());
@@ -429,11 +437,14 @@ private void updateNodeChartPanel(Collection<EMDataSet> dataSets) {
429
437
p .revalidate ();
430
438
}
431
439
432
- private ChartPanel createChartPanel (Collection <EMDataSet > dataSets ) {
433
- List <EMDataSet > sortedDataSets = ChartUtil .sortDataSets (dataSets );
440
+ private ChartPanel createChartPanel (Collection <EMDataSet > filteredDataSet ) {
441
+ List <EMDataSet > sortedDataSets = ChartUtil .sortDataSets (filteredDataSet );
434
442
ChartType chartType = options .getChartOptions () != null ? options .getChartOptions ().getType () : null ;
435
443
436
444
switch (chartType ) {
445
+ case DATASET_PIE :
446
+ chart = ChartUtil .createRadialHeatMapLegend (options .getEnrichmentMap ().getDataSetList (), options .getChartOptions ());
447
+ break ;
437
448
case RADIAL_HEAT_MAP :
438
449
chart = ChartUtil .createRadialHeatMapLegend (sortedDataSets , options .getChartOptions ());
439
450
break ;
@@ -460,31 +471,57 @@ private ChartPanel createChartPanel(Collection<EMDataSet> dataSets) {
460
471
461
472
private void updateEdgeColorPanel () {
462
473
JPanel p = getEdgeColorPanel ();
463
- Dimension iconSize = new Dimension (LEGEND_ICON_SIZE , LEGEND_ICON_SIZE / 2 );
464
-
465
474
Map <Object , Paint > dmMap = getEdgeColors ();
466
475
467
476
JComponent [][] entries = new JComponent [dmMap .size ()][2 ];
468
477
469
478
int i = 0 ;
470
479
for (Entry <?, Paint > e : dmMap .entrySet ()) {
471
- Color color = null ;
472
- if (e .getValue () instanceof Color )
473
- color = (Color ) e .getValue ();
480
+ Color color = e .getValue () instanceof Color ? (Color )e .getValue (): null ;
474
481
475
- JLabel iconLabel = createColorLabel (color , iconSize );
482
+ JLabel iconLabel = createColorLabel (color , COLOR_ICON_SIZE );
476
483
JLabel descLabel = new JLabel ("" + e .getKey ());
477
484
478
485
if (Columns .EDGE_DATASET_VALUE_SIG .equals (e .getKey ()))
479
486
descLabel .setFont (descLabel .getFont ().deriveFont (Font .ITALIC ));
480
487
481
- entries [i ++] = new JComponent []{ iconLabel , descLabel };
488
+ entries [i ++] = new JComponent [] { iconLabel , descLabel };
482
489
}
483
490
484
491
updateStyleLegendPanel (entries , p );
485
492
}
486
493
487
494
495
+ private void updateNodeDataSetColorPanel () {
496
+ JPanel p = getNodeDataSetColorPanel ();
497
+
498
+ ChartData data = options .getChartOptions ().getData ();
499
+
500
+ if (data == ChartData .DATA_SET ) {
501
+ Map <Object ,Paint > colorMap = getDataSetColors ();
502
+
503
+ JComponent [][] entries = new JComponent [colorMap .size ()][2 ];
504
+
505
+ int i = 0 ;
506
+ for (Entry <?, Paint > e : colorMap .entrySet ()) {
507
+ Color color = e .getValue () instanceof Color ? (Color )e .getValue (): null ;
508
+
509
+ JLabel iconLabel = createColorLabel (color , COLOR_ICON_SIZE );
510
+ JLabel descLabel = new JLabel ("" + e .getKey ());
511
+
512
+ entries [i ++] = new JComponent [] {iconLabel , descLabel };
513
+ }
514
+
515
+ updateStyleLegendPanel (entries , p );
516
+
517
+ p .setVisible (true );
518
+ } else {
519
+ p .setVisible (false );
520
+ }
521
+ p .revalidate ();
522
+ }
523
+
524
+
488
525
@ Override
489
526
public Map <Object ,Paint > getEdgeColors () {
490
527
EnrichmentMap map = options .getEnrichmentMap ();
@@ -540,6 +577,16 @@ public Map<Object,Paint> getEdgeColors() {
540
577
}
541
578
542
579
580
+ @ Override
581
+ public Map <Object ,Paint > getDataSetColors () {
582
+ Map <Object ,Paint > colorMap = new LinkedHashMap <>();
583
+ for (EMDataSet dataset : options .getEnrichmentMap ().getDataSetList ()) {
584
+ colorMap .put (dataset .getName (), dataset .getColor ());
585
+ }
586
+ return colorMap ;
587
+ }
588
+
589
+
543
590
BasicCollapsiblePanel getNodeLegendPanel () {
544
591
if (nodeLegendPanel == null ) {
545
592
nodeLegendPanel = new BasicCollapsiblePanel ("Nodes (Gene Sets)" );
@@ -551,16 +598,18 @@ BasicCollapsiblePanel getNodeLegendPanel() {
551
598
layout .setAutoCreateGaps (true );
552
599
553
600
layout .setHorizontalGroup (layout .createParallelGroup (Alignment .CENTER , true )
554
- .addComponent (getNodeColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
555
- .addComponent (getNodeShapePanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
556
- .addComponent (getNodeChartPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
557
- .addComponent (getNodeChartColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
601
+ .addComponent (getNodeColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
602
+ .addComponent (getNodeShapePanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
603
+ .addComponent (getNodeChartPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
604
+ .addComponent (getNodeChartColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
605
+ .addComponent (getNodeDataSetColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
558
606
);
559
607
layout .setVerticalGroup (layout .createSequentialGroup ()
560
- .addComponent (getNodeColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
561
- .addComponent (getNodeShapePanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
562
- .addComponent (getNodeChartPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
563
- .addComponent (getNodeChartColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
608
+ .addComponent (getNodeColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
609
+ .addComponent (getNodeShapePanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
610
+ .addComponent (getNodeChartPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
611
+ .addComponent (getNodeChartColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
612
+ .addComponent (getNodeDataSetColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
564
613
);
565
614
566
615
if (isAquaLAF ())
@@ -581,10 +630,10 @@ BasicCollapsiblePanel getEdgeLegendPanel() {
581
630
layout .setAutoCreateGaps (true );
582
631
583
632
layout .setHorizontalGroup (layout .createParallelGroup (Alignment .CENTER , true )
584
- .addComponent (getEdgeColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
633
+ .addComponent (getEdgeColorPanel (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
585
634
);
586
635
layout .setVerticalGroup (layout .createSequentialGroup ()
587
- .addComponent (getEdgeColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
636
+ .addComponent (getEdgeColorPanel (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
588
637
);
589
638
590
639
if (isAquaLAF ())
@@ -674,6 +723,15 @@ private JPanel getEdgeColorPanel() {
674
723
675
724
return edgeColorPanel ;
676
725
}
726
+
727
+ private JPanel getNodeDataSetColorPanel () {
728
+ if (dataSetColorPanel == null ) {
729
+ dataSetColorPanel = createStyleLegendPanel (null );
730
+ dataSetColorPanel .setToolTipText (LegendContent .NODE_DATA_SET_COLOR_HEADER );
731
+ }
732
+
733
+ return dataSetColorPanel ;
734
+ }
677
735
678
736
private JPanel createStyleLegendPanel (JComponent [][] entries ) {
679
737
JPanel p = new JPanel ();
@@ -685,7 +743,7 @@ private JPanel createStyleLegendPanel(JComponent[][] entries) {
685
743
return p ;
686
744
}
687
745
688
- private void updateStyleLegendPanel (JComponent [][] entries , JPanel p ) {
746
+ private static void updateStyleLegendPanel (JComponent [][] entries , JPanel p ) {
689
747
p .removeAll ();
690
748
691
749
GroupLayout layout = new GroupLayout (p );
0 commit comments