8854
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
8884
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
8854
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 |
|
11 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
|
12 |
8884
|
13 import java.util.HashSet; |
8886
|
14 import java.util.Map; |
8884
|
15 import java.util.Set; |
8854
|
16 |
8886
|
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
|
18 import org.dive4elements.artifacts.CallContext; |
|
19 import org.dive4elements.river.exports.DiagramGenerator; |
|
20 import org.dive4elements.river.exports.StyledSeriesBuilder; |
|
21 import org.dive4elements.river.jfree.StyledXYSeries; |
|
22 import org.dive4elements.river.themes.ThemeDocument; |
|
23 |
8884
|
24 public final class FlowDepthProcessor extends AbstractSInfoProcessor { |
8854
|
25 |
8884
|
26 /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */ |
|
27 // REMARK: these mustend with 'filtered' so extra handling happens in chart: point are always recalculated, because data |
|
28 // changes depending on zoom state |
8854
|
29 static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered"; |
|
30 |
8884
|
31 static String FACET_FLOW_DEPTH_TKH_FILTERED = "sinfo_flow_depth.tkh.filtered"; |
|
32 |
|
33 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
|
34 |
|
35 static { |
|
36 HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_FILTERED); |
|
37 HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_TKH_FILTERED); |
|
38 } |
8854
|
39 |
|
40 private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label"; |
|
41 |
8884
|
42 public FlowDepthProcessor() { |
|
43 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); |
8854
|
44 } |
|
45 |
8886
|
46 @Override |
|
47 protected final String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
|
48 |
|
49 final CallContext context = generator.getCallContext(); |
|
50 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
|
51 |
|
52 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
|
53 series.putMetaData(metaData, bundle.getArtifact(), context); |
|
54 |
|
55 final String facetName = bundle.getFacetName(); |
|
56 final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context); |
|
57 if (data == null) { |
|
58 // Check has been here before so we keep it for security reasons |
|
59 // this should never happen though. |
|
60 throw new IllegalStateException("Data is null for facet: " + facetName); |
|
61 } |
|
62 |
|
63 final double[][] points = generatePoints(data, facetName); |
|
64 |
|
65 StyledSeriesBuilder.addPoints(series, points, true); |
|
66 generator.addAxisSeries(series, getAxisName(), visible); |
|
67 |
|
68 return metaData.get("Y"); |
|
69 } |
|
70 |
8884
|
71 // FIXME: do filtering |
8886
|
72 private double[][] generatePoints(final FlowDepthCalculationResult data, final String facetName) { |
8854
|
73 |
8884
|
74 if (FACET_FLOW_DEPTH_FILTERED.contentEquals(facetName)) |
|
75 return data.getFlowDepthPoints(); |
8854
|
76 |
8884
|
77 if (FACET_FLOW_DEPTH_TKH_FILTERED.contentEquals(facetName)) |
|
78 return data.getFlowDepthTkhPoints(); |
8854
|
79 |
8886
|
80 final String error = String.format("Unknown facet name: %s", facetName); |
|
81 throw new UnsupportedOperationException(error); |
8854
|
82 } |
|
83 } |