comparison artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.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 740d65e4aa14
comparison
equal deleted inserted replaced
9122:b8e7f6becf78 9123:1cc7653ca84f
26 import org.dive4elements.river.model.Gauge; 26 import org.dive4elements.river.model.Gauge;
27 import org.dive4elements.river.model.River; 27 import org.dive4elements.river.model.River;
28 import org.dive4elements.river.themes.ThemeDocument; 28 import org.dive4elements.river.themes.ThemeDocument;
29 29
30 import org.dive4elements.artifactdatabase.state.State; 30 import org.dive4elements.artifactdatabase.state.State;
31 import org.dive4elements.artifacts.CallContext;
31 import org.dive4elements.river.artifacts.GaugeDischargeCurveArtifact; 32 import org.dive4elements.river.artifacts.GaugeDischargeCurveArtifact;
32 33
33 import org.apache.log4j.Logger; 34 import org.apache.log4j.Logger;
34 import org.jfree.chart.annotations.XYTextAnnotation; 35 import org.jfree.chart.annotations.XYTextAnnotation;
35 import org.jfree.chart.axis.ValueAxis; 36 import org.jfree.chart.axis.ValueAxis;
119 // This should be made unecessary in a Q Diagram refactoring with 120 // This should be made unecessary in a Q Diagram refactoring with
120 // decent inheritance. 121 // decent inheritance.
121 if (getMaster() instanceof GaugeDischargeCurveArtifact) { 122 if (getMaster() instanceof GaugeDischargeCurveArtifact) {
122 GaugeDischargeCurveArtifact myMaster = 123 GaugeDischargeCurveArtifact myMaster =
123 (GaugeDischargeCurveArtifact) getMaster(); 124 (GaugeDischargeCurveArtifact) getMaster();
124 State state = myMaster.getCurrentState(context); 125 State state = myMaster.getCurrentState(getContext());
125 if (myMaster.STATIC_STATE_NAME.equals(state.getID())) { 126 if (GaugeDischargeCurveArtifact.STATIC_STATE_NAME.equals(state.getID())) {
126 return; 127 return;
127 } 128 }
128 } 129 }
129 // End Hack 130 // End Hack
130 131
211 212
212 /** 213 /**
213 * Returns always null to suppress subtitles. 214 * Returns always null to suppress subtitles.
214 */ 215 */
215 @Override 216 @Override
216 protected String getDefaultChartTitle() { 217 protected String getDefaultChartTitle(final CallContext context) {
217 return null; 218 return null;
218 } 219 }
219 220
220 221
221 @Override 222 @Override
222 protected String getDefaultXAxisLabel() { 223 protected String getDefaultXAxisLabel(final CallContext context) {
223 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); 224 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
224 } 225 }
225 226
226 @Override 227 @Override
227 protected String getDefaultYAxisLabel(int pos) { 228 protected String getDefaultYAxisLabel(int pos) {
276 boolean visible 277 boolean visible
277 ) { 278 ) {
278 String name = artifactFacet.getFacetName(); 279 String name = artifactFacet.getFacetName();
279 log.debug("DischargeCurveGenerator.doOut: " + name); 280 log.debug("DischargeCurveGenerator.doOut: " + name);
280 281
282 final CallContext context = getContext();
283
281 MiscDischargeProcessor dProcessor = new MiscDischargeProcessor( 284 MiscDischargeProcessor dProcessor = new MiscDischargeProcessor(
282 getRange()[0]); 285 getRange()[0]);
283 if (dProcessor.canHandle(name)) { 286 if (dProcessor.canHandle(name)) {
284 // In Base DischargeCurveGenerator, always at gauge, use WCm axis. 287 // In Base DischargeCurveGenerator, always at gauge, use WCm axis.
285 dProcessor.doOut( 288 dProcessor.doOut(
374 String title, 377 String title,
375 double x, 378 double x,
376 double y, 379 double y,
377 ThemeDocument theme 380 ThemeDocument theme
378 ) { 381 ) {
379 List<XYTextAnnotation> textAnnos = 382 final List<XYTextAnnotation> textAnnos = new ArrayList<>();
380 new ArrayList<XYTextAnnotation>();
381 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( 383 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
382 title, 384 title,
383 x, 385 x,
384 y); 386 y);
385 textAnnos.add(anno); 387 textAnnos.add(anno);
427 429
428 double translate = getCurrentGaugeDatum(); 430 double translate = getCurrentGaugeDatum();
429 431
430 // If no Q values (i.e. all -1) found, add annotations. 432 // If no Q values (i.e. all -1) found, add annotations.
431 if (hasNoDischarge(data)) { 433 if (hasNoDischarge(data)) {
432 List<StickyAxisAnnotation> xy = 434 final List<StickyAxisAnnotation> xy = new ArrayList<>();
433 new ArrayList<StickyAxisAnnotation>();
434 435
435 for (double y: data[1]) { 436 for (double y: data[1]) {
436 if (translate != 0d) { 437 if (translate != 0d) {
437 y = (y-translate)*100d; 438 y = (y-translate)*100d;
438 } 439 }

http://dive4elements.wald.intevation.org