teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports.minfo; raimund@3898: raimund@3898: import org.apache.log4j.Logger; raimund@3898: import org.jfree.data.xy.XYSeries; raimund@3898: import org.w3c.dom.Document; raimund@3898: teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult; teichmann@5831: import org.dive4elements.river.exports.StyledSeriesBuilder; teichmann@5831: import org.dive4elements.river.exports.fixings.FixChartGenerator; teichmann@5831: import org.dive4elements.river.exports.process.KMIndexProcessor; teichmann@5831: import org.dive4elements.river.exports.process.Processor; teichmann@5831: import org.dive4elements.river.jfree.Bounds; teichmann@5831: import org.dive4elements.river.jfree.DoubleBounds; teichmann@5831: import org.dive4elements.river.jfree.FLYSAnnotation; teichmann@5831: import org.dive4elements.river.jfree.StyledXYSeries; raimund@3898: raimund@3898: raimund@3898: public class BedDiffHeightYearGenerator bjoern@4446: extends FixChartGenerator raimund@3898: implements FacetTypes raimund@3898: { raimund@3898: public enum YAXIS { bjoern@4378: D(0), dW(1); raimund@3898: raimund@3898: protected int idx; raimund@3898: raimund@3898: private YAXIS(int c) { raimund@3898: idx = c; raimund@3898: } raimund@3898: } raimund@3898: raimund@3898: /** The logger that is used in this generator. */ raimund@3898: private static Logger logger = Logger.getLogger(BedDiffHeightYearGenerator.class); raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE = "chart.beddifference.height.title"; raimund@3898: public static final String I18N_XAXIS_LABEL = "chart.beddifference.height.xaxis.label"; raimund@3898: public static final String I18N_YAXIS_LABEL = "chart.beddifference.height.yaxis.label"; raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE_DEFAULT = "Sohlenhöhen Differenz"; raimund@3898: public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km"; raimund@3898: public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [cm / Jahr]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL_DEFAULT = bjoern@4446: "delta W [cm]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL = bjoern@4446: "chart.fixings.longitudinalsection.yaxis.label"; raimund@3898: raimund@3898: @Override raimund@3898: protected YAxisWalker getYAxisWalker() { raimund@3898: return new YAxisWalker() { raimund@3898: raimund@3898: @Override raimund@3898: public int length() { raimund@3898: return YAXIS.values().length; raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: public String getId(int idx) { raimund@3898: YAXIS[] yaxes = YAXIS.values(); raimund@3898: return yaxes[idx].toString(); raimund@3898: } raimund@3898: }; raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { raimund@3898: String name = bundle.getFacetName(); raimund@3898: raimund@3898: logger.debug("doOut: " + name); raimund@3898: raimund@3898: if (name == null) { raimund@3898: logger.error("No facet name for doOut(). No output generated!"); raimund@3898: return; raimund@3898: } raimund@3898: raimund@3898: Facet facet = bundle.getFacet(); raimund@3898: raimund@3898: if (facet == null) { raimund@3898: return; raimund@3898: } raimund@3898: rrenkert@4638: if (getXBounds(0) != null && getDomainAxisRange() != null) { rrenkert@4638: Bounds bounds = rrenkert@4638: calculateZoom(getXBounds(0), getDomainAxisRange()); rrenkert@4638: context.putContextValue("startkm", bounds.getLower()); rrenkert@4638: context.putContextValue("endkm", bounds.getUpper()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) != null && getDomainAxisRange() == null) { rrenkert@4638: context.putContextValue("startkm", getXBounds(0).getLower()); rrenkert@4638: context.putContextValue("endkm", getXBounds(0).getUpper()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) == null && getDomainAxisRange() == null) { rrenkert@4638: BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context); rrenkert@4638: context.putContextValue("startkm", data.getKms().min()); rrenkert@4638: context.putContextValue("endkm", data.getKms().max()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) == null && getDomainAxisRange() != null){ rrenkert@4638: BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context); rrenkert@4638: Bounds b = new DoubleBounds(data.getKms().min(), data.getKms().max()); rrenkert@4638: Bounds bounds = rrenkert@4638: calculateZoom(b, getDomainAxisRange()); rrenkert@4638: context.putContextValue("startkm", bounds.getLower()); rrenkert@4638: context.putContextValue("endkm", bounds.getUpper()); rrenkert@4638: } bjoern@4446: Processor processor = new KMIndexProcessor(); raimund@3898: if (name.equals(BED_DIFFERENCE_HEIGHT_YEAR)) { raimund@3898: doBedDifferenceYearOut( raimund@3898: (BedDiffYearResult) bundle.getData(context), raimund@3898: bundle, attr, visible); raimund@3898: } rrenkert@4673: else if (name.equals(BED_DIFFERENCE_HEIGHT_YEAR_FILTERED)) { rrenkert@4673: doBedDifferenceYearOut( rrenkert@4673: (BedDiffYearResult) bundle.getData(context), rrenkert@4673: bundle, attr, visible); rrenkert@4673: } raimund@3898: else if (name.equals(LONGITUDINAL_ANNOTATION)) { raimund@3898: doAnnotations( raimund@3898: (FLYSAnnotation) bundle.getData(context), raimund@3898: bundle, raimund@3898: attr, raimund@3898: visible); raimund@3898: } bjoern@4446: else if (processor.canHandle(name)) { bjoern@4446: processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx); bjoern@4446: } bjoern@4446: else { bjoern@4446: logger.warn("Unknown facet name " + name); bjoern@4446: } raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultChartTitle() { raimund@3898: return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultXAxisLabel() { raimund@3898: return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultYAxisLabel(int pos) { bjoern@4378: if (pos == YAXIS.D.idx) { bjoern@4378: return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); bjoern@4378: } bjoern@4378: else if (pos == YAXIS.dW.idx) { bjoern@4378: return msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); bjoern@4378: } bjoern@4378: return "default"; raimund@3898: } raimund@3898: raimund@3898: protected void doBedDifferenceYearOut(BedDiffYearResult data, raimund@3898: ArtifactAndFacet aandf, Document theme, boolean visible) { raimund@3898: raimund@3898: XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); raimund@3898: StyledSeriesBuilder.addPoints(series, data.getHeightPerYearData(), true); raimund@3898: raimund@3898: addAxisSeries(series, YAXIS.D.idx, visible); raimund@3898: } raimund@3898: }