Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.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 | 06a9a241faac |
children | 0a337f0005c2 |
comparison
equal
deleted
inserted
replaced
7067:eb24d5203d17 | 7068:726d998dce29 |
---|---|
124 protected SortedMap<Integer, AxisDataset> datasets; | 124 protected SortedMap<Integer, AxisDataset> datasets; |
125 | 125 |
126 /** List of annotations to insert in plot. */ | 126 /** List of annotations to insert in plot. */ |
127 protected List<RiverAnnotation> annotations = new ArrayList<RiverAnnotation>(); | 127 protected List<RiverAnnotation> annotations = new ArrayList<RiverAnnotation>(); |
128 | 128 |
129 /** | 129 protected abstract List<AxisSection> buildYAxisSections(); |
130 * A mini interface that allows to walk over the YAXIS enums defined in | |
131 * subclasses. | |
132 */ | |
133 public interface YAxisWalker { | |
134 | |
135 int length(); | |
136 | |
137 String getId(int idx); | |
138 } // end of YAxisWalker interface | |
139 | 130 |
140 /** | 131 /** |
141 * Default constructor that initializes internal data structures. | 132 * Default constructor that initializes internal data structures. |
142 */ | 133 */ |
143 public ChartGenerator2() { | 134 public ChartGenerator2() { |
167 ArtifactAndFacet bundle, | 158 ArtifactAndFacet bundle, |
168 ThemeDocument attr, | 159 ThemeDocument attr, |
169 boolean visible); | 160 boolean visible); |
170 | 161 |
171 | 162 |
172 protected abstract YAxisWalker getYAxisWalker(); | |
173 | |
174 | 163 |
175 protected abstract Series getSeriesOf(XYDataset dataset, int idx); | 164 protected abstract Series getSeriesOf(XYDataset dataset, int idx); |
176 | 165 |
177 /** | 166 /** |
178 * Returns the default title of a chart. | 167 * Returns the default title of a chart. |
179 * | 168 * |
180 * @return the default title of a chart. | 169 * @return the default title of a chart. |
181 */ | 170 */ |
182 protected abstract String getDefaultChartTitle(); | 171 protected abstract String getDefaultChartTitle(); |
183 | 172 |
173 /** | |
174 * Returns the default Y-Axis label of a chart. | |
175 * | |
176 * @return the default Y-Axis label of a chart. | |
177 */ | |
178 protected abstract String getDefaultYAxisLabel(int index); | |
179 | |
184 | 180 |
185 /** | 181 /** |
186 * Returns the default X-Axis label of a chart. | 182 * Returns the default X-Axis label of a chart. |
187 * | 183 * |
188 * @return the default X-Axis label of a chart. | 184 * @return the default X-Axis label of a chart. |
189 */ | 185 */ |
190 protected abstract String getDefaultXAxisLabel(); | 186 protected abstract String getDefaultXAxisLabel(); |
191 | |
192 | |
193 /** | |
194 * This method is called to retrieve the default label for an Y axis at | |
195 * position <i>pos</i>. | |
196 * | |
197 * @param pos The position of an Y axis. | |
198 * | |
199 * @return the default Y axis label at position <i>pos</i>. | |
200 */ | |
201 protected abstract String getDefaultYAxisLabel(int pos); | |
202 | |
203 | 187 |
204 /** | 188 /** |
205 * This method is used to create new AxisDataset instances which may differ | 189 * This method is used to create new AxisDataset instances which may differ |
206 * in concrete subclasses. | 190 * in concrete subclasses. |
207 * | 191 * |
479 return axisSections; | 463 return axisSections; |
480 } | 464 } |
481 | 465 |
482 | 466 |
483 /** | 467 /** |
484 * Creates a list of Section for the chart's Y axes. This method makes use | |
485 * of <i>getYAxisWalker</i> to be able to access all Y axes defined in | |
486 * subclasses. | |
487 * | |
488 * @return a list of Y axis sections. | |
489 */ | |
490 protected List<AxisSection> buildYAxisSections() { | |
491 List<AxisSection> axisSections = new ArrayList<AxisSection>(); | |
492 | |
493 YAxisWalker walker = getYAxisWalker(); | |
494 for (int i = 0, n = walker.length(); i < n; i++) { | |
495 AxisSection ySection = new AxisSection(); | |
496 ySection.setIdentifier(walker.getId(i)); | |
497 ySection.setLabel(getYAxisLabel(i)); | |
498 ySection.setFontSize(14); | |
499 ySection.setFixed(false); | |
500 | |
501 // XXX We are able to find better default ranges that [0,0], the | |
502 // only problem is, that we do NOT have a better range than [0,0] | |
503 // for each axis, because the initial chart will not have a dataset | |
504 // for each axis set! | |
505 ySection.setUpperRange(0d); | |
506 ySection.setLowerRange(0d); | |
507 | |
508 axisSections.add(ySection); | |
509 } | |
510 | |
511 return axisSections; | |
512 } | |
513 | |
514 | |
515 /** | |
516 * Returns the <i>settings</i> as <i>ChartSettings</i>. | 468 * Returns the <i>settings</i> as <i>ChartSettings</i>. |
517 * | 469 * |
518 * @return the <i>settings</i> as <i>ChartSettings</i> or null, if | 470 * @return the <i>settings</i> as <i>ChartSettings</i> or null, if |
519 * <i>settings</i> is not an instance of <i>ChartSettings</i>. | 471 * <i>settings</i> is not an instance of <i>ChartSettings</i>. |
520 */ | 472 */ |
802 Integer fontSize = as.getFontSize(); | 754 Integer fontSize = as.getFontSize(); |
803 | 755 |
804 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; | 756 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; |
805 } | 757 } |
806 | 758 |
759 /** | |
760 * Glue between axis names and index. | |
761 */ | |
762 protected abstract String axisIndexToName(int index); | |
807 | 763 |
808 /** | 764 /** |
809 * This method returns the font size for an Y axis. If the font size is | 765 * This method returns the font size for an Y axis. If the font size is |
810 * specified in ChartSettings (if <i>chartSettings</i> is set), this size is | 766 * specified in ChartSettings (if <i>chartSettings</i> is set), this size is |
811 * returned. Otherwise the default font size 12 is returned. | 767 * returned. Otherwise the default font size 12 is returned. |
812 * | 768 * |
813 * @return the font size for the x axis. | 769 * @return the font size for the x axis. |
814 */ | 770 */ |
815 protected int getYAxisFontSize(int pos) { | 771 protected int getYAxisFontSize(int index) { |
816 ChartSettings chartSettings = getChartSettings(); | 772 ChartSettings chartSettings = getChartSettings(); |
817 if (chartSettings == null) { | 773 if (chartSettings == null) { |
818 return DEFAULT_FONT_SIZE; | 774 return DEFAULT_FONT_SIZE; |
819 } | 775 } |
820 | 776 |
821 YAxisWalker walker = getYAxisWalker(); | 777 AxisSection as = chartSettings.getAxisSection(axisIndexToName(index)); |
822 | |
823 AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); | |
824 if (as == null) { | 778 if (as == null) { |
825 return DEFAULT_FONT_SIZE; | 779 return DEFAULT_FONT_SIZE; |
826 } | 780 } |
827 Integer fontSize = as.getFontSize(); | 781 Integer fontSize = as.getFontSize(); |
828 | 782 |
829 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; | 783 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; |
830 } | 784 } |
831 | |
832 | 785 |
833 /** | 786 /** |
834 * This method returns the export dimension specified in ChartSettings as | 787 * This method returns the export dimension specified in ChartSettings as |
835 * int array [width,height]. | 788 * int array [width,height]. |
836 * | 789 * |
858 * Returns the Y-Axis label of a chart at position <i>pos</i>. | 811 * Returns the Y-Axis label of a chart at position <i>pos</i>. |
859 * | 812 * |
860 * @return the Y-Axis label of a chart at position <i>0</i>. | 813 * @return the Y-Axis label of a chart at position <i>0</i>. |
861 */ | 814 */ |
862 protected String getYAxisLabel(int pos) { | 815 protected String getYAxisLabel(int pos) { |
816 return "TODO lalal"; | |
817 /* | |
863 ChartSettings chartSettings = getChartSettings(); | 818 ChartSettings chartSettings = getChartSettings(); |
864 if (chartSettings == null) { | 819 if (chartSettings == null) { |
865 return getDefaultYAxisLabel(pos); | 820 return getDefaultYAxisLabel(pos); |
866 } | 821 } |
867 | 822 |
873 if (label != null) { | 828 if (label != null) { |
874 return label; | 829 return label; |
875 } | 830 } |
876 } | 831 } |
877 | 832 |
878 return getDefaultYAxisLabel(pos); | 833 return getDefaultYAxisLabel(pos);*/ |
879 } | 834 } |
880 | 835 |
881 | 836 |
882 /** | 837 /** |
883 * This method searches for a specific axis in the <i>settings</i> if | 838 * This method searches for a specific axis in the <i>settings</i> if |
1415 * @param label The label of the new axis. | 1370 * @param label The label of the new axis. |
1416 * | 1371 * |
1417 * @return an instance of IdentifiableNumberAxis. | 1372 * @return an instance of IdentifiableNumberAxis. |
1418 */ | 1373 */ |
1419 protected NumberAxis createNumberAxis(int idx, String label) { | 1374 protected NumberAxis createNumberAxis(int idx, String label) { |
1420 YAxisWalker walker = getYAxisWalker(); | 1375 return new IdentifiableNumberAxis(axisIndexToName(idx), label); |
1421 | |
1422 return new IdentifiableNumberAxis(walker.getId(idx), label); | |
1423 } | 1376 } |
1424 | 1377 |
1425 | 1378 |
1426 /** | 1379 /** |
1427 * Create Y (range) axis for given index. | 1380 * Create Y (range) axis for given index. |
1428 * Shall be overriden by subclasses. | 1381 * Shall be overriden by subclasses. |
1429 */ | 1382 */ |
1430 protected NumberAxis createYAxis(int index) { | 1383 protected NumberAxis createYAxis(int index) { |
1431 YAxisWalker walker = getYAxisWalker(); | |
1432 | 1384 |
1433 Font labelFont = new Font( | 1385 Font labelFont = new Font( |
1434 DEFAULT_FONT_NAME, | 1386 DEFAULT_FONT_NAME, |
1435 Font.BOLD, | 1387 Font.BOLD, |
1436 getYAxisFontSize(index)); | 1388 getYAxisFontSize(index)); |
1437 | 1389 |
1438 IdentifiableNumberAxis axis = new IdentifiableNumberAxis( | 1390 IdentifiableNumberAxis axis = new IdentifiableNumberAxis( |
1439 walker.getId(index), | 1391 axisIndexToName(index), |
1440 getYAxisLabel(index)); | 1392 getYAxisLabel(index)); |
1441 | 1393 |
1442 axis.setAutoRangeIncludesZero(false); | 1394 axis.setAutoRangeIncludesZero(false); |
1443 axis.setLabelFont(labelFont); | 1395 axis.setLabelFont(labelFont); |
1444 axis.setTickLabelFont(labelFont); | 1396 axis.setTickLabelFont(labelFont); |