Skip to content

Commit f756d78

Browse files
committed
Better Chart Legend labels for Heat Strips.
1 parent 9c84b5d commit f756d78

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,20 @@ private JPanel getNodeChartPanel() {
508508
nodeChartPanel = createStyleLegendPanel(null);
509509
nodeChartPanel.setToolTipText("Node Charts");
510510

511+
int h = 200;
512+
513+
if (options.getChartOptions() != null
514+
&& options.getChartOptions().getType() == ChartType.HEAT_STRIPS
515+
&& options.getDataSets().size() > 4)
516+
h = 300;
517+
511518
GroupLayout layout = (GroupLayout) nodeChartPanel.getLayout();
512519

513520
layout.setHorizontalGroup(layout.createSequentialGroup()
514521
.addComponent(chartLegendPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)
515522
);
516523
layout.setVerticalGroup(layout.createSequentialGroup()
517-
.addComponent(chartLegendPanel, PREFERRED_SIZE, 200, 200)
524+
.addComponent(chartLegendPanel, PREFERRED_SIZE, h, h)
518525
);
519526
}
520527

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/ChartUtil.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOpti
210210
chart.setBorderVisible(false);
211211
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
212212
chart.setBackgroundImageAlpha(0.0f);
213-
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
213+
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 20.0));
214214

215215
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
216216
plot.setOutlineVisible(false);
@@ -281,27 +281,33 @@ public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartO
281281
false); // urls
282282

283283
chart.setAntiAlias(true);
284-
chart.setBorderVisible(false);
285-
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
286-
chart.setBackgroundImageAlpha(0.0f);
287-
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
288-
289-
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
284+
chart.setBorderVisible(false);
285+
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
286+
chart.setBackgroundImageAlpha(0.0f);
287+
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
288+
289+
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
290290
plot.setOutlineVisible(false);
291291
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
292292
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
293293
plot.setDomainGridlinesVisible(false);
294-
plot.setRangeGridlinesVisible(false);
295-
294+
plot.setRangeGridlinesVisible(false);
295+
296296
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
297-
domainAxis.setVisible(true);
298-
domainAxis.setAxisLineVisible(false);
299-
domainAxis.setTickMarksVisible(false);
300-
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
301-
domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
302-
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
303-
domainAxis.setMaximumCategoryLabelLines(1);
304-
domainAxis.setCategoryMargin(0.0);
297+
domainAxis.setVisible(true);
298+
domainAxis.setAxisLineVisible(false);
299+
domainAxis.setTickMarksVisible(false);
300+
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
301+
domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
302+
domainAxis.setMaximumCategoryLabelLines(1);
303+
domainAxis.setCategoryMargin(0.0);
304+
305+
if (total > 4) {
306+
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
307+
domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
308+
} else {
309+
domainAxis.setMaximumCategoryLabelLines(2);
310+
}
305311

306312
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
307313
rangeAxis.setVisible(false);

0 commit comments

Comments
 (0)