Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixLongitudinalSectionGenerator.java @ 6140:60b94dec104b
Add handling of bound artifacts.
When an artifact is bound to an out its facets will only be shown
in that Out. They will be removed in the blackboard pass and marked
as incompatible by the AttributeWriter
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 31 May 2013 15:29:30 +0200 |
parents | af13ceeba52a |
children | b02f3a948858 |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.exports.fixings; import java.awt.BasicStroke; import java.awt.Color; import org.apache.log4j.Logger; import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.ValueMarker; import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod; import org.dive4elements.river.artifacts.model.fixings.QWD; import org.dive4elements.river.exports.ChartGenerator; import org.dive4elements.river.exports.process.KMIndexProcessor; import org.dive4elements.river.exports.process.Processor; import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledAreaSeriesCollection; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.utils.KMIndex; public class FixLongitudinalSectionGenerator extends FixChartGenerator implements FacetTypes { private static Logger logger = Logger.getLogger(FixLongitudinalSectionGenerator.class); public static final String I18N_CHART_TITLE = "chart.fixings.longitudinalsection.title"; public static final String I18N_CHART_SUBTITLE = "chart.fixings.longitudinalsection.subtitle"; public static final String I18N_XAXIS_LABEL = "chart.fixings.longitudinalsection.xaxis.label"; public static final String I18N_CHART_TITLE_DEFAULT = "Fixierungsanalyse"; public static final String I18N_XAXIS_LABEL_DEFAULT = "[km]"; public static final String I18N_DW_YAXIS_LABEL_DEFAULT = "delta W [cm]"; public static final String I18N_DW_YAXIS_LABEL = "chart.fixings.longitudinalsection.yaxis.label"; public static enum YAXIS { dW(0); public int idx; private YAXIS(int c) { idx = c; } } @Override public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) { String name = aaf.getFacetName(); logger.debug("FixLongitudinalSectionGenerator: doOut: " + name); Processor processor = new KMIndexProcessor(); if (name.contains(FIX_SECTOR_AVERAGE_LS_DEVIATION)) { doSectorAverageDeviationOut(aaf, doc, visible); } else if (processor.canHandle(name)) { processor.doOut(this, aaf, doc, visible, YAXIS.dW.idx); } else if (name.equals(FIX_DEVIATION_LS)) { doReferenceDeviationOut(aaf, doc, visible); } else if (name.equals(LONGITUDINAL_ANNOTATION)) { doAnnotations( (RiverAnnotation) aaf.getData(context), aaf, doc, visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints (aaf.getData(context), aaf, doc, visible, YAXIS.dW.idx); } else { logger.warn("Unknown facet name " + name); } } @SuppressWarnings("unchecked") protected void doSectorAverageDeviationOut( ArtifactAndFacet aaf, Document doc, boolean visible) { logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex()); int index = aaf.getFacet().getIndex(); int sectorNdx = index & 3; KMIndex<AnalysisPeriod> kms = (KMIndex<AnalysisPeriod>)aaf.getData(context); if(kms == null) { return; } StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(doc); XYSeries upper = new StyledXYSeries(aaf.getFacetDescription(), false, doc); XYSeries lower = new StyledXYSeries(aaf.getFacetDescription() + " ", false, doc); for (KMIndex.Entry<AnalysisPeriod> entry: kms) { double km = entry.getKm(); AnalysisPeriod ap = entry.getValue(); QWD qwd = ap.getQSectorAverages()[sectorNdx]; double dev = ap.getQSectorStdDev(sectorNdx); logger.debug("std-dev: " + dev); if (qwd == null) { continue; } double deltaW = qwd.getDeltaW(); double up = deltaW + dev; double lo = deltaW - dev; upper.add(km, up); lower.add(km, lo); } area.addSeries(upper); area.addSeries(lower); addAreaSeries(area, 0, visible); } @SuppressWarnings("unchecked") protected void doReferenceDeviationOut( ArtifactAndFacet aaf, Document doc, boolean visible) { logger.debug("doReferenceOut"); KMIndex<double[]> kms = (KMIndex<double[]>)aaf.getData(context); if(kms == null) { return; } StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(doc); XYSeries upper = new StyledXYSeries(aaf.getFacetDescription(), false, doc); XYSeries lower = new StyledXYSeries(aaf.getFacetDescription() + " ", false, doc); for (KMIndex.Entry<double[]> entry: kms) { double km = entry.getKm(); double[] devArray = entry.getValue(); if (devArray == null) { continue; } double dev = devArray[0]; double up = dev; double lo = -dev; upper.add(km, up, false); lower.add(km, lo, false); } area.addSeries(upper); area.addSeries(lower); Marker marker = new ValueMarker(0); marker.setStroke(new BasicStroke(2)); marker.setPaint(Color.BLACK); addValueMarker(marker); addAreaSeries(area, 0, visible); } @Override protected String getDefaultChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @Override protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } @Override protected String getDefaultYAxisLabel(int pos) { return msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); } @Override protected ChartGenerator.YAxisWalker getYAxisWalker() { return new YAxisWalker() { @Override public int length() { return YAXIS.values().length; } @Override public String getId(int idx) { YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :