comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2000:e71719483546

Improved the ChartSettings - now, each chart writes proper AxisSections into the ChartSettings. flys-artifacts/trunk@3441 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 16 Dec 2011 13:37:58 +0000
parents 210020108ca4
children 79b15491177a
comparison
equal deleted inserted replaced
1999:02ce03329ef5 2000:e71719483546
110 } 110 }
111 111
112 } 112 }
113 113
114 114
115 /**
116 * A mini interface that allows to walk over the YAXIS enums defined in
117 * subclasses.
118 */
119 public interface YAxisWalker {
120 int length();
121 String getId(int idx);
122 }
123
124
125 protected YAxisWalker getYAxisWalker() {
126 return new YAxisWalker() {
127 @Override
128 public int length() {
129 return 0;
130 }
131
132 @Override
133 public String getId(int idx) {
134 return null;
135 }
136 };
137 }
138
139
115 /** The logger that is used in this generator. */ 140 /** The logger that is used in this generator. */
116 private static Logger logger = Logger.getLogger(XYChartGenerator.class); 141 private static Logger logger = Logger.getLogger(XYChartGenerator.class);
117 142
118 /** Map of datasets ("index"). */ 143 /** Map of datasets ("index"). */
119 protected SortedMap<Integer, AxisDataset> datasets; 144 protected SortedMap<Integer, AxisDataset> datasets;
203 * Returns the Y-Axis label of a chart. 228 * Returns the Y-Axis label of a chart.
204 * 229 *
205 * @return the Y-Axis label of a chart. 230 * @return the Y-Axis label of a chart.
206 */ 231 */
207 protected abstract String getYAxisLabel(); 232 protected abstract String getYAxisLabel();
233
234
235 /**
236 * Returns the Y-Axis label of a chart at position <i>pos</i>.
237 *
238 * @return the Y-Axis label of a chart at position <i>0</i>.
239 */
240 protected String getYAxisLabel(int pos) {
241 return getYAxisLabel();
242 }
208 243
209 /** 244 /**
210 * Generate chart. 245 * Generate chart.
211 */ 246 */
212 public void generate() 247 public void generate()
920 return legendSection; 955 return legendSection;
921 } 956 }
922 957
923 958
924 /** 959 /**
925 * Creates new Sections for chart axes. Subclasses of this ChartGenerator 960 * Creates a list of Sections that contains all axes of the chart (including
926 * should override this method to include all necessary Y axes in that 961 * X and Y axes).
927 * concrete chart. The only Section contained in the list is the X axis. 962 *
963 * @return a list of Sections for each axis in this chart.
964 */
965 protected List<Section> buildAxisSections() {
966 List<Section> axisSections = new ArrayList<Section>();
967
968 axisSections.addAll(buildXAxisSections());
969 axisSections.addAll(buildYAxisSections());
970
971 return axisSections;
972 }
973
974
975 /**
976 * Creates a new Section for chart's X axis.
928 * 977 *
929 * @return a List that contains a Section for the X axis. 978 * @return a List that contains a Section for the X axis.
930 */ 979 */
931 protected List<Section> buildAxisSections() { 980 protected List<Section> buildXAxisSections() {
932 List<Section> axisSections = new ArrayList<Section>(); 981 List<Section> axisSections = new ArrayList<Section>();
933 982
934 String identifier = "X"; 983 String identifier = "X";
935 984
936 AxisSection axisSection = new AxisSection(); 985 AxisSection axisSection = new AxisSection();
946 995
947 axisSections.add(axisSection); 996 axisSections.add(axisSection);
948 997
949 return axisSections; 998 return axisSections;
950 } 999 }
1000
1001
1002 /**
1003 * Creates a list of Section for the chart's Y axes. This method makes use
1004 * of <i>getYAxisWalker</i> to be able to access all Y axes defined in
1005 * subclasses.
1006 *
1007 * @return a list of Y axis sections.
1008 */
1009 protected List<Section> buildYAxisSections() {
1010 List<Section> axisSections = new ArrayList<Section>();
1011
1012 YAxisWalker walker = getYAxisWalker();
1013 for (int i = 0, n = walker.length(); i < n; i++) {
1014 AxisSection ySection = new AxisSection();
1015 ySection.setIdentifier(walker.getId(i));
1016 ySection.setLabel(getYAxisLabel(i));
1017 ySection.setFontSize(14);
1018 ySection.setFixed(false);
1019
1020 // XXX We are able to find better default ranges that [0,0], the
1021 // only problem is, that we do NOT have a better range than [0,0]
1022 // for each axis, because the initial chart will not have a dataset
1023 // for each axis set!
1024 ySection.setUpperRange(0d);
1025 ySection.setLowerRange(0d);
1026
1027 axisSections.add(ySection);
1028 }
1029
1030 return axisSections;
1031 }
951 } 1032 }
952 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 1033 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org