comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java @ 7084:f0731aa7b735 generator-refactoring

Implement Label handling
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 20 Sep 2013 19:18:04 +0200
parents 3c4efd4b2c19
children 42e243c640a0
comparison
equal deleted inserted replaced
7083:74ebe5e7fa69 7084:f0731aa7b735
116 public JFreeChart generateChart() { 116 public JFreeChart generateChart() {
117 logger.debug("DiagramGenerator.generateChart"); 117 logger.debug("DiagramGenerator.generateChart");
118 118
119 JFreeChart chart = ChartFactory.createXYLineChart( 119 JFreeChart chart = ChartFactory.createXYLineChart(
120 getChartTitle(), 120 getChartTitle(),
121 getXAxisLabel(), 121 "",
122 getYAxisLabel(0), 122 "",
123 null, 123 null,
124 PlotOrientation.VERTICAL, 124 PlotOrientation.VERTICAL,
125 isLegendVisible(), 125 isLegendVisible(),
126 false, 126 false,
127 false); 127 false);
171 aggregateLegendEntries(plot); 171 aggregateLegendEntries(plot);
172 172
173 return chart; 173 return chart;
174 } 174 }
175 175
176 public String getOutName() {
177 return outName;
178 }
176 179
177 /** 180 /**
178 * Return left most data points x value (on first axis). 181 * Return left most data points x value (on first axis).
179 * Shortcut, especially to be overridden in (LS) charts where 182 * Shortcut, especially to be overridden in (LS) charts where
180 * axis could be inverted. 183 * axis could be inverted.
1019 /** 1022 /**
1020 * Get internationalized label for the x axis. 1023 * Get internationalized label for the x axis.
1021 */ 1024 */
1022 @Override 1025 @Override
1023 protected String getDefaultXAxisLabel() { 1026 protected String getDefaultXAxisLabel() {
1024 return "TODO X axis label"; 1027 DiagramAttributes.Title dTitle = diagramAttributes.getDomainAxisTitle();
1025 /* D4EArtifact flys = (D4EArtifact) master; 1028 if (dTitle == null) {
1026 1029 return "Domain Axis Title not configured in conf.xml";
1027 return msg( 1030 }
1028 I18N_XAXIS_LABEL, 1031
1029 I18N_XAXIS_LABEL_DEFAULT, 1032 return dTitle.evaluate((D4EArtifact)getMaster(), context);
1030 new Object[] { RiverUtils.getRiver(flys).getName() }); */ 1033 }
1031 } 1034
1032 1035 @Override
1033 @Override 1036 protected String getDefaultYAxisLabel(String axisName) {
1034 protected String getDefaultYAxisLabel(int index) { 1037 Processor pr = diagramAttributes.getProcessorForAxisName(axisName);
1035 return "TODO Y Axis label"; 1038 return pr == null ? "" : pr.getAxisLabel(this);
1036 /* String label = "default";
1037
1038 if (index == YAXIS.W.idx) {
1039 label = getWAxisLabel();
1040 }
1041 else if (index == YAXIS.Q.idx) {
1042 label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
1043 }
1044 else if (index == YAXIS.D.idx) {
1045 label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
1046 }
1047
1048 return label;*/
1049 } 1039 }
1050 1040
1051 1041
1052 /** 1042 /**
1053 * Creates a list of Section for the chart's Y axes. 1043 * Creates a list of Section for the chart's Y axes.
1059 1049
1060 List<DiagramAttributes.AxisAttributes> axesAttrs = diagramAttributes.getAxesAttributes(); 1050 List<DiagramAttributes.AxisAttributes> axesAttrs = diagramAttributes.getAxesAttributes();
1061 1051
1062 for (int i = 0, n = axesAttrs.size(); i < n; i++) { 1052 for (int i = 0, n = axesAttrs.size(); i < n; i++) {
1063 AxisSection ySection = new AxisSection(); 1053 AxisSection ySection = new AxisSection();
1064 ySection.setIdentifier(diagramAttributes.getAxisName(i)); 1054 String axisName = diagramAttributes.getAxisName(i);
1065 ySection.setLabel(getYAxisLabel(i)); 1055 ySection.setIdentifier(axisName);
1056 ySection.setLabel(getYAxisLabel(axisName));
1066 ySection.setFontSize(14); 1057 ySection.setFontSize(14);
1067 ySection.setFixed(false); 1058 ySection.setFixed(false);
1068 1059
1069 // XXX We are able to find better default ranges that [0,0], the 1060 // XXX We are able to find better default ranges that [0,0], the
1070 // only problem is, that we do NOT have a better range than [0,0] 1061 // only problem is, that we do NOT have a better range than [0,0]
1075 1066
1076 axisSections.add(ySection); 1067 axisSections.add(ySection);
1077 } 1068 }
1078 1069
1079 return axisSections; 1070 return axisSections;
1071 }
1072
1073 /**
1074 * Returns the Y-Axis label of a chart at position <i>pos</i>.
1075 *
1076 * @return the Y-Axis label of a chart at position <i>0</i>.
1077 */
1078 protected String getYAxisLabel(String axisName) {
1079 ChartSettings chartSettings = getChartSettings();
1080 if (chartSettings == null) {
1081 return getDefaultYAxisLabel(axisName);
1082 }
1083 AxisSection as = chartSettings.getAxisSection(axisName);
1084 if (as != null) {
1085 String label = as.getLabel();
1086 if (label != null) {
1087 return label;
1088 }
1089 }
1090
1091 return getDefaultYAxisLabel(axisName);
1080 } 1092 }
1081 1093
1082 protected String axisIndexToName(int index) { 1094 protected String axisIndexToName(int index) {
1083 return diagramAttributes.getAxisName(index); 1095 return diagramAttributes.getAxisName(index);
1084 } 1096 }

http://dive4elements.wald.intevation.org