Mercurial > dive4elements > river
changeset 2206:e2124ca11adb
Add manual point handling for many different chart types.
flys-artifacts/trunk@3830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Jan 30 13:33:18 2012 +0000 @@ -1,3 +1,35 @@ +2012-01-30 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Allow manual points in more diagram types. + + * doc/conf/artifacts/winfo.xml: Add respective facet types to + compatibility lists of output modes. + + * doc/conf/artifacts/manualpoints.xml: Mention facet types. + + * src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: + Added ChartType enum to ease later iteration. + (IS.MANUALPOINTS): Added helper. + + * src/main/java/de/intevation/flys/artifacts/model/ManualPointsFacet.java: + Help artifact figuring out which data to provide by passing facet + name. + + * src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java: + Respond to getPointData with correct data item, depending on facet + name. + + * src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java: + Iterate over chart types. Add facets if corresponding data is found. + + * src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java, + src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/XYChartGenerator.java, + src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java: + Handle manual point facets. + 2012-01-30 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Clone
--- a/flys-artifacts/doc/conf/artifacts/manualpoints.xml Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/doc/conf/artifacts/manualpoints.xml Mon Jan 30 13:33:18 2012 +0000 @@ -7,7 +7,12 @@ <outputmodes> <outputmode name="longitudinal_section" description="output.longitudinal_section" mime-type="image/png" type="chart"> <facets> - <facet name="manualpoints" description="Points provided by user." /> + <facet name="longitudinal_section.manualpoints" description="Points provided by user." /> + <facet name="discharge_longitudinal_section.manualpoints" description="Points provided by user." /> + <facet name="discharge_curve.manualpoints" description="Points provided by user." /> + <facet name="w_differences.manualpoints" description="Points provided by user." /> + <facet name="duration_curve.manualpoints" description="Points provided by user." /> + <facet name="computed_discharge_curve.manualpoints" description="Points provided by user." /> </facets> </outputmode> </outputmodes>
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Mon Jan 30 13:33:18 2012 +0000 @@ -76,6 +76,7 @@ <facets> <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/> <facet name="mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/> + <facet name="discharge_curve.manualpoints" description="Manuelle Punkte"/> <facet name="mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/> </facets> </outputmode> @@ -98,6 +99,7 @@ <facets> <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/> <facet name="mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/> + <facet name="discharge_curve.manualpoints" description="Manuelle Punkte"/> <facet name="mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/> </facets> </outputmode> @@ -121,6 +123,7 @@ <facets> <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/> <facet name="mainvalues.q" description="facet.computed_discharge_curve.mainvalues.q"/> + <facet name="discharge_curve.manualpoints" description="Manuelle Punkte"/> <facet name="mainvalues.w" description="facet.computed_discharge_curve.mainvalues.w"/> </facets> </outputmode> @@ -194,6 +197,7 @@ <facet name="other.wkms" description="facet.other.wkms"/> <facet name="other.wqkms" description="facet.other.wqkms"/> <facet name="heightmarks_points" description="facet.other.wkms.heightmarks_points"/> + <facet name="w_differences.manualpoints" description="Manuelle Punkte"/> <facet name="longitudinal_section.annotations" description="facet.longitudinal_section.annotations"/> </facets> </outputmode> @@ -214,6 +218,7 @@ <facet name="duration_curve.q" description="facet.duration_curve.q"/> <facet name="duration_curve.mainvalues.q" description="Q Main Values at optional second axis"/> <facet name="computed_discharge_curve.mainvalues.w" description="W Main Values"/> + <facet name="duration_curve.manualpoints" description="Manuelle Punkte"/> </facets> </outputmode> <outputmode name="durationcurve_export" description="output.durationcurve_export" mime-type="text/plain" type="export"> @@ -241,6 +246,7 @@ <facet name="other.wq" description="Point-like data like fixations"/> <facet name="other.wq" description="Point-like data like fixations"/> <facet name="other.wkms.interpol" description="Height over km, like flood protections."/> + <facet name="computed_discharge_curve.manualpoints" description="Manuelle Punkte"/> </facets> </outputmode> <outputmode name="computed_dischargecurve_export" description="output.computed_dischargecurve_export" mime-type="text/plain" type="export"> @@ -283,7 +289,7 @@ <facet name="other.wq" description="WQ-Type of data" /> <facet name="other.wqkms.q" description="Q-Type of data" /> <facet name="other.wkms" description="facet.other.wkms"/> - <facet name="manualpoints" description="Manuelle Punkte"/> + <facet name="longitudinal_section.manualpoints" description="Manuelle Punkte"/> <facet name="other.wqkms" description="facet.other.wqkms"/> <facet name="heightmarks_points" description="facet.other.wkms.heightmarks_points"/> <facet name="longitudinal_section.area" description="an area"/> @@ -321,6 +327,7 @@ <facet name="discharge_longitudinal_section.w"/> <facet name="discharge_longitudinal_section.q"/> <facet name="discharge_longitudinal_section.c"/> + <facet name="discharge_longitudinal_section.manualpoints" description="Manuelle Punkte"/> <facet name="other.wqkms.w"/> <facet name="other.wq"/> <facet name="other.wqkms.q"/>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java Mon Jan 30 13:33:18 2012 +0000 @@ -32,14 +32,12 @@ /** The name of the artifact. */ public static final String ARTIFACT_NAME = "manualpoints"; - /** Name of data item where points are stored (jsonized). */ - public static final String POINT_DATA = "manualpoints.data"; /** * Trivial Constructor. */ public ManualPointsArtifact() { - logger.debug("ManualPointsArtifact.ManualPointsartifact()"); + logger.debug("ManualPointsArtifact.ManualPointsArtifact()"); } @@ -67,9 +65,8 @@ /** Access state data storing the jsonstring with points. */ - public String getPointsData() { - // TODO probably revive and deliver NamedDoubles. - return getDataAsString(POINT_DATA); + public String getPointsData(String facetName) { + return getDataAsString(facetName + ".data"); } @@ -78,7 +75,6 @@ protected void initialize(Artifact artifact, Object context, CallMeta meta) { logger.debug("ManualPointsArtifact.initialize"); List<Facet> fs = new ArrayList<Facet>(); - addStringData(POINT_DATA, "[]"); DefaultState state = (DefaultState) getCurrentState(context); state.computeInit(this, hash(), context, meta, fs);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Mon Jan 30 13:33:18 2012 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.artifacts.model; +/** 'Types' of facets. */ public interface FacetTypes { public class IS { @@ -30,8 +31,30 @@ || type.equals(DURATION_Q) || type.equals(STATIC_WQKMS_Q); } + public static boolean MANUALPOINTS(String type) { + return type.endsWith("manualpoints"); + } }; + public enum ChartType { + LS("longitudinal_section"), + CS("cross_section"), + DLS("discharge_longitudinal_section"), + CDC("computed_discharge_curve"), + DC("duration_curve"), + WD("wdifferences"); + + private String chartTypeString; + + ChartType(String description) { + this.chartTypeString = description; + } + + public String toString() { + return chartTypeString; + } + } + String AREA = "area"; String CROSS_SECTION_AREA = "cross_section.area"; String LONGITUDINAL_SECTION_AREA = "longitudinal_section.area"; @@ -57,6 +80,7 @@ String LONGITUDINAL_W = "longitudinal_section.w"; String LONGITUDINAL_Q = "longitudinal_section.q"; String LONGITUDINAL_ANNOTATION = "longitudinal_section.annotations"; + String LONGITUDINAL_MANUALPOINTS = "longitudinal_section.manualpoints"; String W_DIFFERENCES = "w_differences";
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ManualPointsFacet.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ManualPointsFacet.java Mon Jan 30 13:33:18 2012 +0000 @@ -49,7 +49,7 @@ @Override public Object getData(Artifact artifact, CallContext context) { ManualPointsArtifact pointsArtifact = (ManualPointsArtifact) artifact; - return pointsArtifact.getPointsData(); + return pointsArtifact.getPointsData(this.name); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java Mon Jan 30 13:33:18 2012 +0000 @@ -10,6 +10,7 @@ import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.ManualPointsArtifact; import de.intevation.flys.artifacts.model.ManualPointsFacet; import de.intevation.flys.artifacts.model.FacetTypes; @@ -48,14 +49,25 @@ CallMeta meta, List<Facet> facets ) { - logger.debug("ManualPointsSingleState.computeInit()"); + logger.debug("ManualPointsSingleState.compute()"); + ManualPointsArtifact points = (ManualPointsArtifact) artifact; - ManualPointsFacet facet = new ManualPointsFacet( - 0, - MANUALPOINTS, - Resources.getMsg(meta, "manualpoints", "Manuel Points")); - - facets.add(facet); + // Add Facet per Diagram type if data given. + for (ChartType ct: ChartType.values()) { + String pointData = points.getDataAsString(ct + "." + MANUALPOINTS + ".data"); + if (pointData != null && !pointData.equals("") && !pointData.equals("[]")) { + String fName = ct + "." + MANUALPOINTS; + ManualPointsFacet facet = new ManualPointsFacet( + 0, + fName, + Resources.getMsg(meta, "manualpoints", "Manual Points")); + + facets.add(facet); + } + else { + //logger.debug("No points for " + ct); + } + } return null; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -128,12 +128,18 @@ else if (name.equals(STATIC_WKMS_INTERPOL)) { doWAnnotations(artifactFacet.getData(context), facet, attr, visible); } + else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, visible, YAXIS.W.idx); + } else { logger.warn("Unknown facet type for computed discharge: " + name); return; } } + /** * Add WQ Data to plot. */
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -183,6 +183,11 @@ attr, visible); } + else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, visible, YAXIS.W.idx); + } else { logger.warn("CrossSection.doOut: Unknown facet name: " + name); return;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -9,6 +9,7 @@ import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQCKms; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.WKms; @@ -17,6 +18,7 @@ import de.intevation.flys.jfree.StyledXYSeries; + /** * An OutGenerator that generates discharge longitudinal section curves. * @@ -24,6 +26,7 @@ */ public class DischargeLongitudinalSectionGenerator extends LongitudinalSectionGenerator +implements FacetTypes { private static Logger logger = Logger.getLogger(DischargeLongitudinalSectionGenerator.class); @@ -70,6 +73,11 @@ doAnnotations((FLYSAnnotation) artifactFacet.getData(context), facet, attr, visible); } + else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, visible, YAXIS.W.idx); + } else { logger.warn("Unknown facet name: " + name); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -191,6 +191,11 @@ (FLYSAnnotation) artifactFacet.getData(context), artifactFacet.getFacet(), attr, visible); } + else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, visible, YAXIS.W.idx); + } else { logger.warn("Unknown facet name: " + name); return;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -38,7 +38,7 @@ import org.json.JSONException; /** - * An OutGenerator that generates discharge curves. + * An OutGenerator that generates longitudinal section curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ @@ -376,10 +376,10 @@ visible); } - else if (FacetTypes.MANUALPOINTS.equals(name)) { + else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints(artifactAndFacet.getData(context), artifactAndFacet.getFacetDescription(), - attr, visible); + attr, visible, YAXIS.W.idx); } else { logger.warn("Unknown facet name: " + name); @@ -624,47 +624,5 @@ // Add area to the respective axis. addAreaSeries(area, axisIdxForFacet(data.getRootFacetName()), visible); } - - - /** - * Do Points out. - */ - protected void doPoints( - Object o, - String seriesName, - Document theme, - boolean visible - ) { - XYSeries series = new StyledXYSeries(seriesName, theme); - - // Add text annotations for single points. - List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>(); - - try { - JSONArray points = new JSONArray((String) o); - for (int i = 0; i < points.length(); i++) { - JSONArray array = points.getJSONArray(i); - double x = array.getDouble(0); - double y = array.getDouble(1); - String name = array.getString(2); - boolean act = array.getBoolean(3); - if (!act) { - continue; - } - //logger.debug(" x " + x + " y " + y ); - series.add(x, y, false); - xy.add(new CollisionFreeXYTextAnnotation(name, x, y)); - } - } - catch(JSONException e){ - logger.error("Could not decode json."); - } - - FLYSAnnotation annotations = new FLYSAnnotation(null, null, null, theme); - annotations.setTextAnnotations(xy); - - doAnnotations(annotations, null, theme, visible); - addAxisSeries(series, YAXIS.W.idx, visible); - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Mon Jan 30 13:29:07 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Mon Jan 30 13:33:18 2012 +0000 @@ -65,6 +65,10 @@ import de.intevation.flys.artifacts.model.HYKFactory; +import org.json.JSONArray; +import org.json.JSONException; + + /** * An abstract base class for creating XY charts. * @@ -1634,6 +1638,49 @@ } + /** + * Do Points out. + */ + protected void doPoints( + Object o, + String seriesName, + Document theme, + boolean visible, + int axisIndex + ) { + XYSeries series = new StyledXYSeries(seriesName, theme); + + // Add text annotations for single points. + List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>(); + + try { + JSONArray points = new JSONArray((String) o); + for (int i = 0; i < points.length(); i++) { + JSONArray array = points.getJSONArray(i); + double x = array.getDouble(0); + double y = array.getDouble(1); + String name = array.getString(2); + boolean act = array.getBoolean(3); + if (!act) { + continue; + } + //logger.debug(" x " + x + " y " + y ); + series.add(x, y, false); + xy.add(new CollisionFreeXYTextAnnotation(name, x, y)); + } + } + catch(JSONException e){ + logger.error("Could not decode json."); + } + + FLYSAnnotation annotations = new FLYSAnnotation(null, null, null, theme); + annotations.setTextAnnotations(xy); + + doAnnotations(annotations, null, theme, visible); + addAxisSeries(series, axisIndex, visible); + } + + /** Two Ranges that span a rectangular area. */ public static class Area { protected Range xRange;