From 2c6f3d1431f91445ff6cf7276e8d954f6074506d Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Mon, 23 Aug 2010 11:39:11 +0000 Subject: [PATCH] LMS-1697 Improved several cosmetic issues with the graphs. SVN: 17578 --- .../graph/AbstractTabularDataGraph.java | 42 ++++++++++++++++++- .../server/graph/TabularDataHeatmap.java | 11 +++++ .../server/graph/TabularDataTickUnit.java | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/AbstractTabularDataGraph.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/AbstractTabularDataGraph.java index bbb2ed9b454..c10515cbc78 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/AbstractTabularDataGraph.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/AbstractTabularDataGraph.java @@ -29,6 +29,7 @@ import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.title.TextTitle; import org.jfree.data.general.Dataset; import org.jfree.data.xy.DefaultXYDataset; @@ -43,6 +44,14 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CodeAndLabel; abstract class AbstractTabularDataGraph<T extends TabularDataGraphConfiguration> implements ITabularDataGraph { + private static final int SMALL_TICK_LABEL_FONT_SIZE = 7; + + private static final int SMALL_LABEL_FONT_SIZE = 9; + + private static final int SMALL_TITLE_FONT_SIZE = 12; + + private static final int SMALL_FONT_TRANSITION_SIZE = 400; + protected final T configuration; protected final ITabularData fileLines; @@ -113,7 +122,7 @@ abstract class AbstractTabularDataGraph<T extends TabularDataGraphConfiguration> { return getColumnLabel(configuration.getYAxisColumn()); } - + /** * Maps specified column code onto a column label. Returns column code if mapping doesn't work. */ @@ -249,8 +258,18 @@ abstract class AbstractTabularDataGraph<T extends TabularDataGraphConfiguration> protected void configureChart(JFreeChart chart, int imageWidth, int imageHeight) { + // Set the background color chart.setBackgroundPaint(Color.WHITE); + // Set the font size + if (imageWidth < SMALL_FONT_TRANSITION_SIZE) + { + TextTitle title = chart.getTitle(); + Font oldFont = title.getFont(); + title.setFont(new Font(oldFont.getName(), oldFont.getStyle(), SMALL_TITLE_FONT_SIZE)); + } + + // Configure the plot XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(false); @@ -259,12 +278,31 @@ abstract class AbstractTabularDataGraph<T extends TabularDataGraphConfiguration> plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); + // Configure the domain axis ValueAxis axis = plot.getDomainAxis(); - axis.setAutoRange(true); axis.setStandardTickUnits(new TabularDataTickUnitSource()); + axis.setAutoRange(true); + configureAxisFonts(imageWidth, axis); + // Configure the range axis axis = plot.getRangeAxis(); axis.setStandardTickUnits(new TabularDataTickUnitSource()); + axis.setAutoRange(true); + configureAxisFonts(imageWidth, axis); + } + + protected void configureAxisFonts(int imageWidth, ValueAxis axis) + { + if (imageWidth < SMALL_FONT_TRANSITION_SIZE) + { + Font oldFont = axis.getLabelFont(); + axis + .setLabelFont(new Font(oldFont.getName(), oldFont.getStyle(), + SMALL_LABEL_FONT_SIZE)); + oldFont = axis.getTickLabelFont(); + axis.setTickLabelFont(new Font(oldFont.getName(), oldFont.getStyle(), + SMALL_TICK_LABEL_FONT_SIZE)); + } } protected void setAxisLabelFontSize(Axis axis) diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataHeatmap.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataHeatmap.java index 8043e385201..d79a0b47cc0 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataHeatmap.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataHeatmap.java @@ -24,6 +24,7 @@ import java.util.List; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.LookupPaintScale; @@ -139,6 +140,7 @@ public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeat psl.setPosition(RectangleEdge.RIGHT); psl.setAxisOffset(5.0); chart.addSubtitle(psl); + return chart; } @@ -200,6 +202,15 @@ public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeat return paintScale; } + @Override + protected void configureChart(JFreeChart chart, int imageWidth, int imageHeight) + { + super.configureChart(chart, imageWidth, imageHeight); + PaintScaleLegend psl = (PaintScaleLegend) chart.getSubtitle(0); + ValueAxis axis = psl.getAxis(); + configureAxisFonts(imageWidth, axis); + } + private HeatmapData parseData(int xColumn, int yColumn, int zColumn) { HeatmapData heatmapData = new HeatmapData(); diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataTickUnit.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataTickUnit.java index ba324822b2e..318c1ce0d4b 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataTickUnit.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/graph/TabularDataTickUnit.java @@ -95,7 +95,7 @@ public class TabularDataTickUnit extends NumberTickUnit StringBuilder sb = new StringBuilder(); if (greaterThan1) { - for (int i = 1; i < precision; ++i) + for (int i = 0; i < precision; ++i) { sb.append("#"); } -- GitLab