comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java @ 7068:726d998dce29 generator-refactoring

Remove Axis Walker, unabstract Diagram generator Diagram generator can now be used as an instance configured in the out-generators config
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 20 Sep 2013 14:55:44 +0200
parents f9d5020af0af
children 7f600001c807
comparison
equal deleted inserted replaced
7067:eb24d5203d17 7068:726d998dce29
39 import org.json.JSONArray; 39 import org.json.JSONArray;
40 import org.json.JSONException; 40 import org.json.JSONException;
41 41
42 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; 42 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
43 import org.dive4elements.artifactdatabase.state.Facet; 43 import org.dive4elements.artifactdatabase.state.Facet;
44 import org.dive4elements.river.artifacts.D4EArtifact;
44 import org.dive4elements.river.exports.process.Processor; 45 import org.dive4elements.river.exports.process.Processor;
45 import org.dive4elements.river.jfree.AxisDataset; 46 import org.dive4elements.river.jfree.AxisDataset;
46 import org.dive4elements.river.jfree.AnnotationHelper; 47 import org.dive4elements.river.jfree.AnnotationHelper;
47 import org.dive4elements.river.jfree.Bounds; 48 import org.dive4elements.river.jfree.Bounds;
48 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; 49 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
69 * show data for this axis (even invisible ones). Motivation: Once 70 * show data for this axis (even invisible ones). Motivation: Once
70 * a dataset (theme) has been activated, it should be on screen. </li> 71 * a dataset (theme) has been activated, it should be on screen. </li>
71 * <li> There should always be a Y-Axis on the "left". </li> 72 * <li> There should always be a Y-Axis on the "left". </li>
72 * </ul> 73 * </ul>
73 */ 74 */
74 public abstract class DiagramGenerator extends ChartGenerator2 { 75 public class DiagramGenerator extends ChartGenerator2 {
75
76 /** Enumerator over existing axes. */
77 @Override
78 protected abstract YAxisWalker getYAxisWalker();
79 76
80 public static final int AXIS_SPACE = 5; 77 public static final int AXIS_SPACE = 5;
81 78
82 /** The logger that is used in this generator. */ 79 /** The logger that is used in this generator. */
83 private static Logger logger = Logger.getLogger(DiagramGenerator.class); 80 private static Logger logger = Logger.getLogger(DiagramGenerator.class);
107 @Override 104 @Override
108 public void setup(Element config) { 105 public void setup(Element config) {
109 logger.debug("DiagramGenerator.setup"); 106 logger.debug("DiagramGenerator.setup");
110 diagramAttributes = new DiagramAttributes(config); 107 diagramAttributes = new DiagramAttributes(config);
111 } 108 }
112
113 109
114 /** 110 /**
115 * Generate the chart anew (including localized axis and all). 111 * Generate the chart anew (including localized axis and all).
116 */ 112 */
117 @Override 113 @Override
373 } 369 }
374 } 370 }
375 logger.debug("..............."); 371 logger.debug("...............");
376 } 372 }
377 373
374 /**
375 * Registers an area to be drawn.
376 * @param area Area to be drawn.
377 * @param axisName Name of the axis.
378 * @param visible Whether or not to be visible (important for range calculations).
379 */
380 public void addAreaSeries(StyledAreaSeriesCollection area, String axisName, boolean visible) {
381 addAreaSeries(area, diagramAttributes.getAxisIndex(axisName), visible);
382 }
378 383
379 /** 384 /**
380 * Registers an area to be drawn. 385 * Registers an area to be drawn.
381 * @param area Area to be drawn. 386 * @param area Area to be drawn.
382 * @param index 'axis index' 387 * @param index 'axis index'
397 /* No range merging, for areas extending to infinity this 402 /* No range merging, for areas extending to infinity this
398 * causes problems. */ 403 * causes problems. */
399 } 404 }
400 } 405 }
401 406
402
403 /** 407 /**
404 * Add given series if visible, if not visible adjust ranges (such that 408 * Add given series if visible, if not visible adjust ranges (such that
405 * all points in data would be plotted once visible). 409 * all points in data would be plotted once visible).
406 * @param series the data series to include in plot. 410 * @param series the data series to include in plot.
407 * @param index ('symbolic') index of the series and of its axis. 411 * @param index index of the axis.
408 * @param visible whether or not the data should be plotted. 412 * @param visible whether or not the data should be plotted.
409 */ 413 */
410 public void addAxisSeries(XYSeries series, int index, boolean visible) { 414 public void addAxisSeries(XYSeries series, int index, boolean visible) {
411 if (series == null) { 415 if (series == null) {
412 return; 416 return;
413 } 417 }
414 418
415 logger.debug("Y Range of XYSeries: " + 419 logger.debug("Y Range of XYSeries: " +
416 series.getMinY() + " | " + series.getMaxY()); 420 series.getMinY() + " | " + series.getMaxY());
417 421
418 addAxisDataset(new XYSeriesCollection(series), index, visible); 422 addAxisDataset(new XYSeriesCollection(series), index, visible);
419 423 }
420 AxisDataset axisDataset = (AxisDataset) getAxisDataset(index); 424
425 /**
426 * Add given series if visible, if not visible adjust ranges (such that
427 * all points in data would be plotted once visible).
428 * @param series the data series to include in plot.
429 * @param axisName name of the axis.
430 * @param visible whether or not the data should be plotted.
431 */
432 public void addAxisSeries(XYSeries series, String axisName, boolean visible) {
433 addAxisSeries(series, diagramAttributes.getAxisIndex(axisName), visible);
421 } 434 }
422 435
423 436
424 /** 437 /**
425 * Add the given vertical marker to the chart. 438 * Add the given vertical marker to the chart.
979 /** Set to true if x axis has been inverted. */ 992 /** Set to true if x axis has been inverted. */
980 public void setInverted(boolean inverted) { 993 public void setInverted(boolean inverted) {
981 this.inverted = inverted; 994 this.inverted = inverted;
982 } 995 }
983 996
997 @Override
998 public String getDefaultChartTitle() {
999 DiagramAttributes.Title dTitle = diagramAttributes.getTitle();
1000 if (dTitle == null) {
1001 return "Title not configured in conf.xml";
1002 }
1003
1004 return dTitle.evaluate((D4EArtifact)getMaster(), context);
1005 }
1006
1007 @Override
1008 public String getDefaultChartSubtitle() {
1009 DiagramAttributes.Title dTitle = diagramAttributes.getSubtitle();
1010 if (dTitle == null) {
1011 return "Subtitle not configured in conf.xml";
1012 }
1013
1014 return dTitle.evaluate((D4EArtifact)getMaster(), context);
1015 }
1016
1017 /**
1018 * Get internationalized label for the x axis.
1019 */
1020 @Override
1021 protected String getDefaultXAxisLabel() {
1022 return "TODO X axis label";
1023 /* D4EArtifact flys = (D4EArtifact) master;
1024
1025 return msg(
1026 I18N_XAXIS_LABEL,
1027 I18N_XAXIS_LABEL_DEFAULT,
1028 new Object[] { RiverUtils.getRiver(flys).getName() }); */
1029 }
1030
1031 @Override
1032 protected String getDefaultYAxisLabel(int index) {
1033 return "TODO Y Axis label";
1034 /* String label = "default";
1035
1036 if (index == YAXIS.W.idx) {
1037 label = getWAxisLabel();
1038 }
1039 else if (index == YAXIS.Q.idx) {
1040 label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
1041 }
1042 else if (index == YAXIS.D.idx) {
1043 label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
1044 }
1045
1046 return label;*/
1047 }
1048
1049
1050 /**
1051 * Creates a list of Section for the chart's Y axes.
1052 *
1053 * @return a list of Y axis sections.
1054 */
1055 protected List<AxisSection> buildYAxisSections() {
1056 List<AxisSection> axisSections = new ArrayList<AxisSection>();
1057
1058 List<DiagramAttributes.AxisAttributes> axesAttrs = diagramAttributes.getAxesAttributes();
1059
1060 for (int i = 0, n = axesAttrs.size(); i < n; i++) {
1061 AxisSection ySection = new AxisSection();
1062 ySection.setIdentifier(diagramAttributes.getAxisName(i));
1063 ySection.setLabel(getYAxisLabel(i));
1064 ySection.setFontSize(14);
1065 ySection.setFixed(false);
1066
1067 // XXX We are able to find better default ranges that [0,0], the
1068 // only problem is, that we do NOT have a better range than [0,0]
1069 // for each axis, because the initial chart will not have a dataset
1070 // for each axis set!
1071 ySection.setUpperRange(0d);
1072 ySection.setLowerRange(0d);
1073
1074 axisSections.add(ySection);
1075 }
1076
1077 return axisSections;
1078 }
1079
1080 protected String axisIndexToName(int index) {
1081 return diagramAttributes.getAxisName(index);
1082 }
1083
984 /** Add the acutal data to the diagram according to the processors. 1084 /** Add the acutal data to the diagram according to the processors.
985 * For every outable facets, this function is 1085 * For every outable facets, this function is
986 * called and handles the data accordingly. */ 1086 * called and handles the data accordingly. */
987 @Override 1087 @Override
988 public void doOut( 1088 public void doOut(
1002 1102
1003 logger.debug("DoOut for facet: " + facetName); 1103 logger.debug("DoOut for facet: " + facetName);
1004 1104
1005 for (Processor pr: diagramAttributes.getProcessors()) { 1105 for (Processor pr: diagramAttributes.getProcessors()) {
1006 if (pr.canHandle(facetName)) { 1106 if (pr.canHandle(facetName)) {
1007 // pr.doOut(this, bundle, theme, visible, 0); 1107 pr.doOut(this, bundle, theme, visible);
1008 } 1108 }
1009 } 1109 }
1010 } 1110 }
1011 } 1111 }

http://dive4elements.wald.intevation.org