Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedTkhProcessor.java @ 9016:6e5ff436febe
Added datacage select and chart display for TKH series loaded from database
author | mschaefer |
---|---|
date | Mon, 23 Apr 2018 15:18:48 +0200 |
parents | |
children | 384eee4b4135 |
comparison
equal
deleted
inserted
replaced
9015:baef34f54ee2 | 9016:6e5ff436febe |
---|---|
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 | |
11 package org.dive4elements.river.artifacts.sinfo.common; | |
12 | |
13 import java.util.HashSet; | |
14 import java.util.Map; | |
15 import java.util.Set; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.exports.DiagramGenerator; | |
21 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
22 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | |
23 import org.dive4elements.river.jfree.StyledXYSeries; | |
24 import org.dive4elements.river.themes.ThemeDocument; | |
25 | |
26 /** | |
27 * Processor to generate a data series for tkh data loaded from the database | |
28 * | |
29 * @author Matthias Schäfer | |
30 * | |
31 */ | |
32 public class PredefinedTkhProcessor extends AbstractSInfoProcessor { | |
33 | |
34 private final static Logger log = Logger.getLogger(PredefinedTkhProcessor.class); | |
35 | |
36 public static final String FACET_PREDEFINED_TKH = "sinfo_facet_predefined_tkh"; | |
37 | |
38 private static final String I18N_AXIS_LABEL = "sinfo.chart.tkh.section.yaxis.label"; | |
39 | |
40 private static final String I18N_FACET_TKH_DESCRIPTION = "sinfo.facet.tkh.description"; | |
41 | |
42 private static final String SINFO_CHART_TKH_YAXIS_LABEL = "sinfo.chart.tkh.yaxis.label"; | |
43 | |
44 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); | |
45 | |
46 static { | |
47 HANDLED_FACET_TYPES.add(FACET_PREDEFINED_TKH); | |
48 } | |
49 | |
50 public PredefinedTkhProcessor() { | |
51 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); | |
52 } | |
53 | |
54 protected String generateSeries1(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
55 final CallContext context = generator.getCallContext(); | |
56 final Map<String, String> metaData = bundle.getFacet().getMetaData(bundle.getArtifact(), context); | |
57 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | |
58 series.putMetaData(metaData, bundle.getArtifact(), context); | |
59 | |
60 final Object raw = bundle.getData(context); | |
61 if (raw == null) { | |
62 return null; | |
63 } | |
64 if (!(raw instanceof double[][])) { | |
65 log.error("Unkown datatype: " + raw.getClass().getName()); | |
66 return null; | |
67 } | |
68 final double[][] data = (double[][]) raw; | |
69 StyledSeriesBuilder.addPoints(series, data, true); | |
70 | |
71 // REMARK: we add " " because the description is misused as id, which must be unique. | |
72 final StyledXYSeries seriesDown = new StyledXYSeries(bundle.getFacetDescription() + " ", theme); | |
73 // final double[][] pointsDown = data.getTkhDownPoints(); | |
74 final double[][] datadown = (double[][]) raw; | |
75 for (int i = 0; i <= datadown[0].length - 1; i++) | |
76 datadown[1][i] = 0; | |
77 StyledSeriesBuilder.addPoints(seriesDown, datadown, true); | |
78 | |
79 final StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); | |
80 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); | |
81 area.addSeries(series); | |
82 area.addSeries(seriesDown); | |
83 generator.addAreaSeries(area, getAxisName(), visible); | |
84 // generator.addAxisSeries(series, getAxisName(), visible); | |
85 return null; | |
86 } | |
87 | |
88 @Override | |
89 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
90 final CallContext context = generator.getCallContext(); | |
91 | |
92 final String facetName = bundle.getFacetName(); | |
93 final AbstractTkhCalculationResult data = (AbstractTkhCalculationResult) bundle.getData(context); | |
94 if (data == null) { | |
95 // Check has been here before so we keep it for security reasons | |
96 // this should never happen though. | |
97 throw new IllegalStateException("Data is null for facet: " + facetName); | |
98 } | |
99 | |
100 final StyledXYSeries seriesUp = new StyledXYSeries(bundle.getFacetDescription(), theme); | |
101 final double[][] pointsUp = data.getTkhUpPoints(); | |
102 StyledSeriesBuilder.addPoints(seriesUp, pointsUp, true); | |
103 | |
104 // REMARK: we add " " because the description is misused as id, which must be unique. | |
105 final StyledXYSeries seriesDown = new StyledXYSeries(bundle.getFacetDescription() + " ", theme); | |
106 final double[][] pointsDown = data.getTkhDownPoints(); | |
107 StyledSeriesBuilder.addPoints(seriesDown, pointsDown, true); | |
108 | |
109 final StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); | |
110 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); | |
111 area.addSeries(seriesUp); | |
112 area.addSeries(seriesDown); | |
113 | |
114 generator.addAreaSeries(area, getAxisName(), visible); | |
115 | |
116 return null; | |
117 } | |
118 } |