8884
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
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 |
8916
|
11 package org.dive4elements.river.artifacts.sinfo.common; |
8884
|
12 |
|
13 import java.util.HashSet; |
|
14 import java.util.Set; |
|
15 |
8886
|
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
8916
|
17 import org.dive4elements.artifactdatabase.state.Facet; |
8886
|
18 import org.dive4elements.artifacts.CallContext; |
8916
|
19 import org.dive4elements.river.artifacts.resources.Resources; |
|
20 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
8886
|
21 import org.dive4elements.river.exports.DiagramGenerator; |
|
22 import org.dive4elements.river.exports.StyledSeriesBuilder; |
|
23 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; |
|
24 import org.dive4elements.river.jfree.StyledXYSeries; |
|
25 import org.dive4elements.river.themes.ThemeDocument; |
|
26 |
8884
|
27 public final class TkhProcessor extends AbstractSInfoProcessor { |
|
28 |
8916
|
29 public static String FACET_TKH = "sinfo_flow_depth.tkh"; |
|
30 |
|
31 public static final String I18N_FACET_TKH_DESCRIPTION = "sinfo.facet.tkh.description"; |
|
32 |
|
33 public static final String SINFO_CHART_TKX_YAXIS_LABEL = "sinfo.chart.tkh.yaxis.label"; |
8884
|
34 |
|
35 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
|
36 |
|
37 static { |
|
38 HANDLED_FACET_TYPES.add(FACET_TKH); |
|
39 } |
|
40 |
|
41 private static final String I18N_AXIS_LABEL = "sinfo.chart.tkh.section.yaxis.label"; |
|
42 |
|
43 public TkhProcessor() { |
|
44 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); |
|
45 } |
|
46 |
|
47 @Override |
8886
|
48 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
|
49 final CallContext context = generator.getCallContext(); |
8884
|
50 |
8886
|
51 final String facetName = bundle.getFacetName(); |
8916
|
52 final AbstractSInfoCalculationResult<?> data = (AbstractSInfoCalculationResult<?>) bundle.getData(context); |
8886
|
53 if (data == null) { |
|
54 // Check has been here before so we keep it for security reasons |
|
55 // this should never happen though. |
|
56 throw new IllegalStateException("Data is null for facet: " + facetName); |
|
57 } |
|
58 |
|
59 final StyledXYSeries seriesUp = new StyledXYSeries(bundle.getFacetDescription(), theme); |
|
60 final double[][] pointsUp = data.getTkhUpPoints(); |
|
61 StyledSeriesBuilder.addPoints(seriesUp, pointsUp, true); |
|
62 |
|
63 // REMARK: we add " " because the description is misused as id, which must be unique. |
|
64 final StyledXYSeries seriesDown = new StyledXYSeries(bundle.getFacetDescription() + " ", theme); |
|
65 final double[][] pointsDown = data.getTkhDownPoints(); |
|
66 StyledSeriesBuilder.addPoints(seriesDown, pointsDown, true); |
|
67 |
|
68 final StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); |
|
69 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); |
|
70 area.addSeries(seriesUp); |
|
71 area.addSeries(seriesDown); |
|
72 |
|
73 generator.addAreaSeries(area, getAxisName(), visible); |
|
74 |
|
75 return null; |
8884
|
76 } |
8916
|
77 |
|
78 public static Facet createTkhFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult<?> result, |
|
79 final int index) { |
|
80 |
|
81 final String facetTkhDescription = Resources.getMsg(context.getMeta(), I18N_FACET_TKH_DESCRIPTION, I18N_FACET_TKH_DESCRIPTION, |
|
82 result.getLabel()); |
|
83 // FIXME: doe not work yet... |
|
84 return new SInfoResultFacet(index, TkhProcessor.FACET_TKH, facetTkhDescription, TkhProcessor.SINFO_CHART_TKX_YAXIS_LABEL, ComputeType.ADVANCE, id, |
|
85 hash); |
|
86 } |
8884
|
87 } |