Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java @ 9601:8f59aa01c22a
Fixed some warnings
author | gernotbelger |
---|---|
date | Tue, 12 Feb 2019 14:06:27 +0100 |
parents | ef5754ba5573 |
children |
comparison
equal
deleted
inserted
replaced
9600:bf79a865f6df | 9601:8f59aa01c22a |
---|---|
17 import java.util.Map; | 17 import java.util.Map; |
18 | 18 |
19 import javax.swing.ImageIcon; | 19 import javax.swing.ImageIcon; |
20 | 20 |
21 import org.apache.log4j.Logger; | 21 import org.apache.log4j.Logger; |
22 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
23 import org.dive4elements.artifacts.CallContext; | |
24 import org.dive4elements.river.jfree.AxisDataset; | |
25 import org.dive4elements.river.jfree.Bounds; | |
26 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; | |
27 import org.dive4elements.river.jfree.DoubleBounds; | |
28 import org.dive4elements.river.jfree.RiverAnnotation; | |
29 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | |
30 import org.dive4elements.river.jfree.StyledXYSeries; | |
31 import org.dive4elements.river.themes.ThemeDocument; | |
22 import org.jfree.chart.ChartFactory; | 32 import org.jfree.chart.ChartFactory; |
23 import org.jfree.chart.JFreeChart; | 33 import org.jfree.chart.JFreeChart; |
24 import org.jfree.chart.LegendItem; | |
25 import org.jfree.chart.annotations.XYAnnotation; | 34 import org.jfree.chart.annotations.XYAnnotation; |
26 import org.jfree.chart.annotations.XYImageAnnotation; | 35 import org.jfree.chart.annotations.XYImageAnnotation; |
27 import org.jfree.chart.annotations.XYTextAnnotation; | 36 import org.jfree.chart.annotations.XYTextAnnotation; |
37 import org.jfree.chart.axis.LogarithmicAxis; | |
28 import org.jfree.chart.axis.NumberAxis; | 38 import org.jfree.chart.axis.NumberAxis; |
29 import org.jfree.chart.axis.ValueAxis; | 39 import org.jfree.chart.axis.ValueAxis; |
30 import org.jfree.chart.axis.LogarithmicAxis; | |
31 import org.jfree.chart.plot.Marker; | 40 import org.jfree.chart.plot.Marker; |
32 import org.jfree.chart.plot.PlotOrientation; | 41 import org.jfree.chart.plot.PlotOrientation; |
33 import org.jfree.chart.plot.XYPlot; | 42 import org.jfree.chart.plot.XYPlot; |
34 import org.jfree.data.Range; | 43 import org.jfree.data.Range; |
35 import org.jfree.data.general.Series; | 44 import org.jfree.data.general.Series; |
36 import org.jfree.data.xy.XYDataset; | 45 import org.jfree.data.xy.XYDataset; |
37 import org.jfree.data.xy.XYSeries; | 46 import org.jfree.data.xy.XYSeries; |
38 import org.jfree.data.xy.XYSeriesCollection; | 47 import org.jfree.data.xy.XYSeriesCollection; |
39 import org.jfree.ui.RectangleInsets; | |
40 import org.json.JSONArray; | 48 import org.json.JSONArray; |
41 import org.json.JSONException; | 49 import org.json.JSONException; |
42 | |
43 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
44 import org.dive4elements.artifacts.CallContext; | |
45 import org.dive4elements.river.jfree.Bounds; | |
46 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; | |
47 import org.dive4elements.river.jfree.DoubleBounds; | |
48 import org.dive4elements.river.jfree.RiverAnnotation; | |
49 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | |
50 import org.dive4elements.river.jfree.StyledXYSeries; | |
51 import org.dive4elements.river.jfree.AxisDataset; | |
52 import org.dive4elements.river.themes.ThemeDocument; | |
53 | 50 |
54 | 51 |
55 /** | 52 /** |
56 * An abstract base class for creating XY charts. | 53 * An abstract base class for creating XY charts. |
57 * | 54 * |
383 if (area == null) { | 380 if (area == null) { |
384 log.warn("Cannot yet render above/under curve."); | 381 log.warn("Cannot yet render above/under curve."); |
385 return; | 382 return; |
386 } | 383 } |
387 | 384 |
388 AxisDataset axisDataset = (AxisDataset) getAxisDataset(index); | 385 AxisDataset axisDataset = getAxisDataset(index); |
389 | 386 |
390 if (visible) { | 387 if (visible) { |
391 axisDataset.addDataset(area); | 388 axisDataset.addDataset(area); |
392 } | 389 } |
393 else { | 390 else { |
482 return; | 479 return; |
483 } | 480 } |
484 | 481 |
485 DoubleBounds dBounds = (DoubleBounds) bounds; | 482 DoubleBounds dBounds = (DoubleBounds) bounds; |
486 | 483 |
487 if (dBounds == null | 484 if ( Double.isNaN((Double) dBounds.getLower()) || Double.isNaN((Double) dBounds.getUpper())) |
488 || Double.isNaN((Double) dBounds.getLower()) | |
489 || Double.isNaN((Double) dBounds.getUpper())) { | |
490 return; | 485 return; |
491 } | |
492 | 486 |
493 Bounds old = getXBounds(index); | 487 Bounds old = getXBounds(index); |
494 | 488 |
495 if (old != null) { | 489 if (old != null) { |
496 dBounds = (DoubleBounds) dBounds.combine(old); | 490 dBounds = (DoubleBounds) dBounds.combine(old); |
507 return; | 501 return; |
508 } | 502 } |
509 | 503 |
510 DoubleBounds dBounds = (DoubleBounds) bounds; | 504 DoubleBounds dBounds = (DoubleBounds) bounds; |
511 | 505 |
512 if (dBounds == null | 506 if ( Double.isNaN((Double) dBounds.getLower()) || Double.isNaN((Double) dBounds.getUpper())) |
513 || Double.isNaN((Double) dBounds.getLower()) | |
514 || Double.isNaN((Double) dBounds.getUpper())) { | |
515 return; | 507 return; |
516 } | |
517 | 508 |
518 Bounds old = getYBounds(index); | 509 Bounds old = getYBounds(index); |
519 | 510 |
520 if (old != null) { | 511 if (old != null) { |
521 dBounds = (DoubleBounds) dBounds.combine(old); | 512 dBounds = (DoubleBounds) dBounds.combine(old); |
629 } | 620 } |
630 | 621 |
631 return new Range(from, to); | 622 return new Range(from, to); |
632 } | 623 } |
633 catch (NumberFormatException nfe) { | 624 catch (NumberFormatException nfe) { |
634 log.warn("Wrong values for domain axis range."); | 625 log.warn("Wrong values for domain axis range.", nfe); |
635 } | 626 } |
636 } | 627 } |
637 | 628 |
638 return null; | 629 return null; |
639 } | 630 } |
660 return from > to | 651 return from > to |
661 ? new Range(to, from) | 652 ? new Range(to, from) |
662 : new Range(from, to); | 653 : new Range(from, to); |
663 } | 654 } |
664 catch (NumberFormatException nfe) { | 655 catch (NumberFormatException nfe) { |
665 log.warn("Wrong values for value axis range."); | 656 log.warn("Wrong values for value axis range.", nfe); |
666 } | 657 } |
667 } | 658 } |
668 | 659 |
669 return null; | 660 return null; |
670 } | 661 } |
908 ) { | 899 ) { |
909 String seriesName = aandf.getFacetDescription(); | 900 String seriesName = aandf.getFacetDescription(); |
910 XYSeries series = new StyledXYSeries(aandf.getFacetName(), seriesName, theme); | 901 XYSeries series = new StyledXYSeries(aandf.getFacetName(), seriesName, theme); |
911 | 902 |
912 // Add text annotations for single points. | 903 // Add text annotations for single points. |
913 List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>(); | 904 List<XYTextAnnotation> xy = new ArrayList<>(); |
914 | 905 |
915 try { | 906 try { |
916 JSONArray points = new JSONArray((String) o); | 907 JSONArray points = new JSONArray((String) o); |
917 for (int i = 0, P = points.length(); i < P; i++) { | 908 for (int i = 0, P = points.length(); i < P; i++) { |
918 JSONArray array = points.getJSONArray(i); | 909 JSONArray array = points.getJSONArray(i); |
927 series.add(x, y, false); | 918 series.add(x, y, false); |
928 xy.add(new CollisionFreeXYTextAnnotation(name, x, y)); | 919 xy.add(new CollisionFreeXYTextAnnotation(name, x, y)); |
929 } | 920 } |
930 } | 921 } |
931 catch(JSONException e){ | 922 catch(JSONException e){ |
932 log.error("Could not decode json."); | 923 log.error("Could not decode json.", e); |
933 } | 924 } |
934 | 925 |
935 RiverAnnotation annotations = | 926 RiverAnnotation annotations = |
936 new RiverAnnotation(null, null, null, theme); | 927 new RiverAnnotation(null, null, null, theme); |
937 annotations.setTextAnnotations(xy); | 928 annotations.setTextAnnotations(xy); |