Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java @ 9123:1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
author | gernotbelger |
---|---|
date | Tue, 05 Jun 2018 19:21:16 +0200 |
parents | 5e38e2924c07 |
children | bd5f5d2220fa |
comparison
equal
deleted
inserted
replaced
9122:b8e7f6becf78 | 9123:1cc7653ca84f |
---|---|
14 import java.awt.Stroke; | 14 import java.awt.Stroke; |
15 import java.text.NumberFormat; | 15 import java.text.NumberFormat; |
16 import java.util.List; | 16 import java.util.List; |
17 | 17 |
18 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
19 import org.jfree.chart.LegendItemCollection; | |
20 import org.jfree.chart.annotations.XYBoxAnnotation; | |
21 import org.jfree.chart.annotations.XYTextAnnotation; | |
22 import org.jfree.chart.plot.XYPlot; | |
23 import org.jfree.data.xy.XYSeries; | |
24 | |
25 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 19 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
20 import org.dive4elements.artifacts.CallContext; | |
26 import org.dive4elements.artifacts.DataProvider; | 21 import org.dive4elements.artifacts.DataProvider; |
27 import org.dive4elements.river.artifacts.D4EArtifact; | 22 import org.dive4elements.river.artifacts.D4EArtifact; |
28 import org.dive4elements.river.artifacts.geom.Lines; | 23 import org.dive4elements.river.artifacts.geom.Lines; |
29 import org.dive4elements.river.artifacts.model.CrossSectionFacet; | 24 import org.dive4elements.river.artifacts.model.CrossSectionFacet; |
30 import org.dive4elements.river.artifacts.model.FacetTypes; | 25 import org.dive4elements.river.artifacts.model.FacetTypes; |
33 import org.dive4elements.river.jfree.RiverAnnotation; | 28 import org.dive4elements.river.jfree.RiverAnnotation; |
34 import org.dive4elements.river.jfree.StyledXYSeries; | 29 import org.dive4elements.river.jfree.StyledXYSeries; |
35 import org.dive4elements.river.model.FastCrossSectionLine; | 30 import org.dive4elements.river.model.FastCrossSectionLine; |
36 import org.dive4elements.river.themes.TextStyle; | 31 import org.dive4elements.river.themes.TextStyle; |
37 import org.dive4elements.river.themes.ThemeDocument; | 32 import org.dive4elements.river.themes.ThemeDocument; |
33 import org.dive4elements.river.utils.Formatter; | |
38 import org.dive4elements.river.utils.RiverUtils; | 34 import org.dive4elements.river.utils.RiverUtils; |
39 import org.dive4elements.river.utils.Formatter; | 35 import org.jfree.chart.LegendItemCollection; |
36 import org.jfree.chart.annotations.XYBoxAnnotation; | |
37 import org.jfree.chart.annotations.XYTextAnnotation; | |
38 import org.jfree.chart.plot.XYPlot; | |
39 import org.jfree.data.xy.XYSeries; | |
40 | 40 |
41 | 41 |
42 /** | 42 /** |
43 * An OutGenerator that generates cross section graphs. | 43 * An OutGenerator that generates cross section graphs. |
44 */ | 44 */ |
91 | 91 |
92 /** | 92 /** |
93 * Get localized chart title. | 93 * Get localized chart title. |
94 */ | 94 */ |
95 @Override | 95 @Override |
96 public String getDefaultChartTitle() { | 96 public String getDefaultChartTitle(final CallContext context) { |
97 Object[] i18n_msg_args = new Object[] { | 97 Object[] i18n_msg_args = new Object[] { |
98 getRiverName() | 98 getRiverName() |
99 }; | 99 }; |
100 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, i18n_msg_args); | 100 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, i18n_msg_args); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 /** Always return default subtitle. */ | 104 /** Always return default subtitle. */ |
105 @Override | 105 @Override |
106 protected String getChartSubtitle() { | 106 protected String getChartSubtitle(CallContext context) { |
107 // XXX NOTE: overriding this method disables ChartSettings subtitle! | 107 // XXX NOTE: overriding this method disables ChartSettings subtitle! |
108 // The default implementation of this method in ChartGenerator returns | 108 // The default implementation of this method in ChartGenerator returns |
109 // the subtitle changed via the chart settings dialog. This method | 109 // the subtitle changed via the chart settings dialog. This method |
110 // always returns the subtitle containing river and km, NEVER the | 110 // always returns the subtitle containing river and km, NEVER the |
111 // ChartSettings subtitle! | 111 // ChartSettings subtitle! |
112 return getDefaultChartSubtitle(); | 112 return getDefaultChartSubtitle(context); |
113 } | 113 } |
114 | 114 |
115 | 115 |
116 /** Get Charts default subtitle. */ | 116 /** Get Charts default subtitle. */ |
117 @Override | 117 @Override |
118 protected String getDefaultChartSubtitle() { | 118 protected String getDefaultChartSubtitle(final CallContext context) { |
119 List<DataProvider> providers = | 119 List<DataProvider> providers = |
120 context.getDataProvider( | 120 context.getDataProvider( |
121 CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); | 121 CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); |
122 double km = 0d; | 122 double km = 0d; |
123 if (providers.size() > 0) { | 123 if (providers.size() > 0) { |
162 return new Color(255, 0, 0); | 162 return new Color(255, 0, 0); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 @Override | 166 @Override |
167 protected void addAnnotationsToRenderer(XYPlot plot) { | 167 protected void doAddFurtherAnnotations(XYPlot plot, List<RiverAnnotation> annotations) { |
168 super.addAnnotationsToRenderer(plot); | |
169 | 168 |
170 // Paints for the boxes/lines. | 169 // Paints for the boxes/lines. |
171 Stroke basicStroke = new BasicStroke(1.0f); | 170 Stroke basicStroke = new BasicStroke(1.0f); |
172 | 171 |
173 // XXX: DEAD CODE // Paint linePaint = new Color(255, 0,0,60); | 172 // XXX: DEAD CODE // Paint linePaint = new Color(255, 0,0,60); |
177 // OPTMIMIZE: Pre-calculate positions | 176 // OPTMIMIZE: Pre-calculate positions |
178 ChartArea area = new ChartArea( | 177 ChartArea area = new ChartArea( |
179 plot.getDomainAxis(0), | 178 plot.getDomainAxis(0), |
180 plot.getRangeAxis()); | 179 plot.getRangeAxis()); |
181 | 180 |
182 for(RiverAnnotation fa : this.annotations) { | 181 for(RiverAnnotation fa : annotations) { |
183 | 182 |
184 // Access text styling, if any. | 183 // Access text styling, if any. |
185 ThemeDocument theme = fa.getTheme(); | 184 ThemeDocument theme = fa.getTheme(); |
186 TextStyle textStyle = null; | 185 TextStyle textStyle = null; |
187 | 186 |
243 } | 242 } |
244 } | 243 } |
245 } | 244 } |
246 | 245 |
247 @Override | 246 @Override |
248 protected String getDefaultXAxisLabel() { | 247 protected String getDefaultXAxisLabel(final CallContext context) { |
249 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | 248 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); |
250 } | 249 } |
251 | 250 |
252 | 251 |
253 @Override | 252 @Override |
254 protected String getDefaultYAxisLabel(int pos) { | 253 protected String getDefaultYAxisLabel(int pos) { |
255 D4EArtifact flys = (D4EArtifact) master; | 254 D4EArtifact flys = getArtifact(); |
256 | 255 |
257 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); | 256 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); |
258 | 257 |
259 return msg(I18N_YAXIS_LABEL, | 258 return msg(I18N_YAXIS_LABEL, |
260 I18N_YAXIS_LABEL_DEFAULT, | 259 I18N_YAXIS_LABEL_DEFAULT, |
277 | 276 |
278 if (name == null) { | 277 if (name == null) { |
279 log.error("No facet name for doOut(). No output generated!"); | 278 log.error("No facet name for doOut(). No output generated!"); |
280 return; | 279 return; |
281 } | 280 } |
281 | |
282 CallContext context = getContext(); | |
282 | 283 |
283 if (name.equals(CROSS_SECTION)) { | 284 if (name.equals(CROSS_SECTION)) { |
284 doCrossSectionOut( | 285 doCrossSectionOut( |
285 artifactFacet.getData(context), | 286 artifactFacet.getData(context), |
286 artifactFacet.getFacetDescription(), | 287 artifactFacet.getFacetDescription(), |
349 | 350 |
350 Lines.LineData lines = (Lines.LineData) o; | 351 Lines.LineData lines = (Lines.LineData) o; |
351 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. | 352 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. |
352 StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); | 353 StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); |
353 | 354 |
355 CallContext context = getContext(); | |
356 | |
354 if (!theme.parseShowLineLabel()) { | 357 if (!theme.parseShowLineLabel()) { |
355 series.setLabel(""); | 358 series.setLabel(""); |
356 } | 359 } |
357 if (theme.parseShowWidth()) { | 360 if (theme.parseShowWidth()) { |
358 NumberFormat nf = Formatter.getMeterFormat(this.context); | 361 NumberFormat nf = Formatter.getMeterFormat(context); |
359 String labelAdd = "b=" + nf.format(lines.width) + "m"; | 362 String labelAdd = "b=" + nf.format(lines.width) + "m"; |
360 if (series.getLabel().length() == 0) { | 363 if (series.getLabel().length() == 0) { |
361 series.setLabel(labelAdd); | 364 series.setLabel(labelAdd); |
362 } | 365 } |
363 else { | 366 else { |
364 series.setLabel(series.getLabel() + ", " + labelAdd); | 367 series.setLabel(series.getLabel() + ", " + labelAdd); |
365 } | 368 } |
366 } | 369 } |
367 if (theme.parseShowLevel() && lines.points.length > 1 | 370 if (theme.parseShowLevel() && lines.points.length > 1 |
368 && lines.points[1].length > 0) { | 371 && lines.points[1].length > 0) { |
369 NumberFormat nf = Formatter.getMeterFormat(this.context); | 372 NumberFormat nf = Formatter.getMeterFormat(context); |
370 D4EArtifact flys = (D4EArtifact) master; | 373 D4EArtifact flys = getArtifact(); |
371 | 374 |
372 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); | 375 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); |
373 | 376 |
374 String labelAdd = "W=" + nf.format(lines.points[1][0]) + unit; | 377 String labelAdd = "W=" + nf.format(lines.points[1][0]) + unit; |
375 if (series.getLabel().length() == 0) { | 378 if (series.getLabel().length() == 0) { |
378 else { | 381 else { |
379 series.setLabel(series.getLabel() + ", " + labelAdd); | 382 series.setLabel(series.getLabel() + ", " + labelAdd); |
380 } | 383 } |
381 } | 384 } |
382 if (theme.parseShowMiddleHeight() && lines.width != 0) { | 385 if (theme.parseShowMiddleHeight() && lines.width != 0) { |
383 NumberFormat nf = Formatter.getMeterFormat(this.context); | 386 NumberFormat nf = Formatter.getMeterFormat(context); |
384 String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; | 387 String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; |
385 // : " + lines.area + "/" + lines.width); | 388 // : " + lines.area + "/" + lines.width); |
386 if (series.getLabel().length() == 0) { | 389 if (series.getLabel().length() == 0) { |
387 series.setLabel(labelAdd); | 390 series.setLabel(labelAdd); |
388 } | 391 } |
448 * Overridden to prevent inclusion of subtitle. | 451 * Overridden to prevent inclusion of subtitle. |
449 * | 452 * |
450 * @return a new <i>ChartSection</i>. | 453 * @return a new <i>ChartSection</i>. |
451 */ | 454 */ |
452 @Override | 455 @Override |
453 protected ChartSection buildChartSection() { | 456 protected ChartSection buildChartSection(final CallContext context) { |
454 ChartSection chartSection = new ChartSection(); | 457 ChartSection chartSection = new ChartSection(); |
455 chartSection.setTitle(getChartTitle()); | 458 chartSection.setTitle(getChartTitle(context)); |
456 chartSection.setDisplayGrid(isGridVisible()); | 459 chartSection.setDisplayGrid(isGridVisible()); |
457 chartSection.setDisplayLogo(showLogo()); | 460 chartSection.setDisplayLogo(showLogo()); |
458 chartSection.setLogoVPlacement(logoVPlace()); | 461 chartSection.setLogoVPlacement(logoVPlace()); |
459 chartSection.setLogoHPlacement(logoHPlace()); | 462 chartSection.setLogoHPlacement(logoHPlace()); |
460 return chartSection; | 463 return chartSection; |