Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/jfree/StableXYDifferenceRenderer.java @ 9602:6b2496d71936
Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline.
author | gernotbelger |
---|---|
date | Tue, 12 Feb 2019 14:08:16 +0100 |
parents | eec4df8165a1 |
children |
comparison
equal
deleted
inserted
replaced
9601:8f59aa01c22a | 9602:6b2496d71936 |
---|---|
118 import org.jfree.chart.plot.PlotRenderingInfo; | 118 import org.jfree.chart.plot.PlotRenderingInfo; |
119 import org.jfree.chart.plot.XYPlot; | 119 import org.jfree.chart.plot.XYPlot; |
120 import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; | 120 import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; |
121 import org.jfree.chart.renderer.xy.XYItemRendererState; | 121 import org.jfree.chart.renderer.xy.XYItemRendererState; |
122 import org.jfree.chart.urls.XYURLGenerator; | 122 import org.jfree.chart.urls.XYURLGenerator; |
123 import org.jfree.data.Range; | |
123 import org.jfree.data.xy.DefaultXYDataset; | 124 import org.jfree.data.xy.DefaultXYDataset; |
124 import org.jfree.data.xy.XYDataset; | 125 import org.jfree.data.xy.XYDataset; |
125 import org.jfree.data.xy.XYSeries; | 126 import org.jfree.data.xy.XYSeries; |
126 import org.jfree.data.xy.XYSeriesCollection; | 127 import org.jfree.data.xy.XYSeriesCollection; |
127 import org.jfree.io.SerialUtilities; | 128 import org.jfree.io.SerialUtilities; |
193 /** The background color of the label showing the calculated area. */ | 194 /** The background color of the label showing the calculated area. */ |
194 private Color labelBGColor; | 195 private Color labelBGColor; |
195 | 196 |
196 /** Font to draw label of calculated area with. */ | 197 /** Font to draw label of calculated area with. */ |
197 private Font labelFont; | 198 private Font labelFont; |
199 | |
200 private Color baseLineColor = null; | |
198 | 201 |
199 /** Whether or not to draw a label that shows the title of the theme. */ | 202 /** Whether or not to draw a label that shows the title of the theme. */ |
200 private boolean drawTitleLabel = false; | 203 private boolean drawTitleLabel = false; |
201 | 204 |
202 /** Whether or not to draw a label that shows the area of the polygon. */ | 205 /** Whether or not to draw a label that shows the area of the polygon. */ |
300 } | 303 } |
301 | 304 |
302 /** Set color with which to paint label bg. */ | 305 /** Set color with which to paint label bg. */ |
303 public void setLabelBGColor(final Color color) { | 306 public void setLabelBGColor(final Color color) { |
304 this.labelBGColor = color; | 307 this.labelBGColor = color; |
308 } | |
309 | |
310 public void setBaseLineColor(final Color baseLineColor) { | |
311 this.baseLineColor = baseLineColor; | |
305 } | 312 } |
306 | 313 |
307 /** | 314 /** |
308 * Sets color that is used if drawOutline is true. | 315 * Sets color that is used if drawOutline is true. |
309 */ | 316 */ |
1259 final int lastItem = dataset.getItemCount(series) - 1; | 1266 final int lastItem = dataset.getItemCount(series) - 1; |
1260 if (series == lastSeries && item == lastItem) { | 1267 if (series == lastSeries && item == lastItem) { |
1261 // draw labels: only once per theme! | 1268 // draw labels: only once per theme! |
1262 drawAreaLabel(g2, dataArea, plot, domainAxis, rangeAxis); | 1269 drawAreaLabel(g2, dataArea, plot, domainAxis, rangeAxis); |
1263 drawTitleLabel(g2, dataArea, info.getOwner().getEntityCollection(), dataset); | 1270 drawTitleLabel(g2, dataArea, info.getOwner().getEntityCollection(), dataset); |
1271 | |
1272 drawZeroBaseline(g2, dataArea, plot, domainAxis, rangeAxis); | |
1264 } | 1273 } |
1265 } | 1274 } |
1266 | 1275 |
1267 private void drawAreaLabel(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis) { | 1276 private void drawAreaLabel(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis) { |
1268 | 1277 |
1305 final XYSeries xYSeries = ((XYSeriesCollection) dataset).getSeries(0); | 1314 final XYSeries xYSeries = ((XYSeriesCollection) dataset).getSeries(0); |
1306 final String label = (xYSeries instanceof HasLabel) ? ((HasLabel) xYSeries).getLabel() : xYSeries.getKey().toString(); | 1315 final String label = (xYSeries instanceof HasLabel) ? ((HasLabel) xYSeries).getLabel() : xYSeries.getKey().toString(); |
1307 | 1316 |
1308 EnhancedLineAndShapeRenderer.drawLineLabel(g2, dataArea, entities, this.minimumScreenX, this.minimumScreenX_Y, this.labelFont, this.labelColor, | 1317 EnhancedLineAndShapeRenderer.drawLineLabel(g2, dataArea, entities, this.minimumScreenX, this.minimumScreenX_Y, this.labelFont, this.labelColor, |
1309 this.labelBGColor != null, this.labelBGColor, label); | 1318 this.labelBGColor != null, this.labelBGColor, label); |
1319 } | |
1320 } | |
1321 | |
1322 private void drawZeroBaseline(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis) { | |
1323 | |
1324 if (this.baseLineColor == null) | |
1325 return; | |
1326 | |
1327 final PlotOrientation orientation = plot.getOrientation(); | |
1328 final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); | |
1329 final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); | |
1330 | |
1331 final Range domainRange = domainAxis.getRange(); | |
1332 final double x0 = domainRange.getLowerBound(); | |
1333 final double x1 = domainRange.getUpperBound(); | |
1334 | |
1335 final double screenX0 = domainAxis.valueToJava2D(x0, dataArea, domainAxisLocation); | |
1336 final double screenX1 = domainAxis.valueToJava2D(x1, dataArea, domainAxisLocation); | |
1337 final double screenY = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); | |
1338 | |
1339 Shape baseLine; | |
1340 if (PlotOrientation.HORIZONTAL == orientation) | |
1341 baseLine = new Line2D.Double(screenY, screenX0, screenY, screenX1); | |
1342 else | |
1343 baseLine = new Line2D.Double(screenX0, screenY, screenX1, screenY); | |
1344 | |
1345 if (baseLine.intersects(dataArea)) { | |
1346 g2.setPaint(this.baseLineColor); | |
1347 g2.setStroke(new BasicStroke(2)); | |
1348 | |
1349 g2.draw(baseLine); | |
1310 } | 1350 } |
1311 } | 1351 } |
1312 | 1352 |
1313 /** | 1353 /** |
1314 * Draws the visual representation of a single data item, second pass. In | 1354 * Draws the visual representation of a single data item, second pass. In |