teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports.process; bjoern@4446: bjoern@4446: import org.apache.log4j.Logger; aheinecke@7120: aheinecke@7120: import java.awt.BasicStroke; aheinecke@7120: import java.awt.Color; aheinecke@7120: bjoern@4446: import org.jfree.data.xy.XYSeries; bjoern@4446: import org.jfree.data.xy.XYSeriesCollection; bjoern@4446: aheinecke@7120: import org.jfree.chart.plot.Marker; aheinecke@7120: import org.jfree.chart.plot.ValueMarker; aheinecke@7120: teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod; teichmann@5831: import org.dive4elements.river.artifacts.model.fixings.QWD; aheinecke@7120: import org.dive4elements.river.exports.DiagramGenerator; teichmann@5831: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7120: import org.dive4elements.river.jfree.StyledAreaSeriesCollection; teichmann@6905: import org.dive4elements.river.themes.ThemeDocument; teichmann@5831: import org.dive4elements.river.utils.KMIndex; bjoern@4446: aheinecke@7120: public class DeltaWProcessor extends DefaultProcessor { aheinecke@7120: /* This is basically a collection of different processors. The aheinecke@7120: * historic reason for this is that they have in common that they aheinecke@7120: * work on deltaW data from the fixing analysis. */ bjoern@4446: aheinecke@7120: private static final Logger logger = Logger.getLogger(DeltaWProcessor.class); aheinecke@7120: aheinecke@7120: public static final String I18N_DW_YAXIS_LABEL_DEFAULT = aheinecke@7120: "delta W [cm]"; aheinecke@7120: aheinecke@7120: public static final String I18N_DW_YAXIS_LABEL = aheinecke@7120: "chart.fixings.longitudinalsection.yaxis.label"; bjoern@4446: bjoern@4446: @Override aheinecke@7120: public void doOut( aheinecke@7120: DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, aheinecke@7120: ThemeDocument theme, aheinecke@7120: boolean visible) { aheinecke@7075: String facettype = bundle.getFacetName(); aheinecke@7120: if (!visible) { aheinecke@7120: return; bjoern@4446: } aheinecke@7120: logger.debug("Doing out for: " + bundle.getFacetName()); aheinecke@7120: if (facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)) { aheinecke@7120: doReferenceEventsOut(generator, bundle, theme, visible); aheinecke@7120: } else if (facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS)) { aheinecke@7120: doAnalysisEventsOut(generator, bundle, theme, visible); aheinecke@7120: } else if (facettype.startsWith(FacetTypes.FIX_SECTOR_AVERAGE_LS_DEVIATION)) { aheinecke@7120: doSectorAverageDeviationOut(generator, bundle, theme, visible); aheinecke@7120: } else if (facettype.equals(FacetTypes.FIX_DEVIATION_LS)) { aheinecke@7120: doReferenceDeviationOut(generator, bundle, theme, visible); aheinecke@7120: } else if (facettype.startsWith(FacetTypes.FIX_SECTOR_AVERAGE_LS)) { aheinecke@7120: doSectorAverageOut(generator, bundle, theme, visible); aheinecke@7120: } else { aheinecke@7120: logger.error("Could not handle: " + facettype); bjoern@4446: } bjoern@4446: } bjoern@4446: bjoern@4446: @Override bjoern@4446: public boolean canHandle(String facettype) { bjoern@4446: if (facettype == null) { bjoern@4446: return false; bjoern@4446: } bjoern@4446: aheinecke@7120: if (facettype.startsWith(FacetTypes.FIX_SECTOR_AVERAGE_LS) bjoern@4446: || facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS) aheinecke@7120: || facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS) aheinecke@7120: || facettype.equals(FacetTypes.FIX_DEVIATION_LS)) { bjoern@4446: return true; bjoern@4446: } bjoern@4446: return false; bjoern@4446: } bjoern@4446: aheinecke@7120: private void doSectorAverageOut(DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, aheinecke@7120: ThemeDocument doc, boolean visible) { bjoern@4446: CallContext context = generator.getCallContext(); aheinecke@7075: int index = bundle.getFacet().getIndex(); bjoern@4446: int sectorNdx = index & 3; bjoern@4446: bjoern@4446: KMIndex kms = aheinecke@7075: (KMIndex)bundle.getData(context); bjoern@4446: bjoern@4446: if(kms == null) { bjoern@4446: return; bjoern@4446: } bjoern@4446: aheinecke@7075: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), doc); bjoern@4446: bjoern@4446: for (KMIndex.Entry entry: kms) { bjoern@4446: double km = entry.getKm(); bjoern@4446: AnalysisPeriod ap = entry.getValue(); bjoern@4446: QWD qwd = ap.getQSectorAverages()[sectorNdx]; bjoern@4446: if (qwd == null) { bjoern@4446: continue; bjoern@4446: } bjoern@4446: double deltaW = qwd.getDeltaW(); bjoern@4446: series.add(km, deltaW); bjoern@4446: } bjoern@4446: aheinecke@7120: generator.addAxisSeries(series, axisName, visible); bjoern@4446: } bjoern@4446: aheinecke@7120: private void doReferenceEventsOut(DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, ThemeDocument doc, boolean visible) { bjoern@4446: CallContext context = generator.getCallContext(); bjoern@4446: bjoern@4446: KMIndex kms = aheinecke@7075: (KMIndex)bundle.getData(context); bjoern@4446: bjoern@4446: if(kms == null) { bjoern@4446: return; bjoern@4446: } bjoern@4446: bjoern@4446: XYSeriesCollection col = new XYSeriesCollection(); bjoern@4446: aheinecke@7075: StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), false, bjoern@4446: doc); bjoern@4446: bjoern@4446: for (KMIndex.Entry entry: kms) { bjoern@4446: double km = entry.getKm(); bjoern@4446: QWD qwd = entry.getValue(); bjoern@4446: bjoern@4446: series.add(km, qwd.getDeltaW()); bjoern@4446: } bjoern@4446: col.addSeries(series); bjoern@4446: aheinecke@7120: generator.addAxisDataset(col, axisName, visible); bjoern@4446: } bjoern@4446: aheinecke@7120: private void doAnalysisEventsOut( aheinecke@7120: DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, aheinecke@7120: ThemeDocument doc, aheinecke@7120: boolean visible) { bjoern@4446: CallContext context = generator.getCallContext(); bjoern@4446: bjoern@4446: KMIndex kms = aheinecke@7075: (KMIndex)bundle.getData(context); bjoern@4446: bjoern@4446: if(kms == null) { bjoern@4446: return; bjoern@4446: } bjoern@4446: bjoern@4446: XYSeriesCollection col = new XYSeriesCollection(); bjoern@4446: aheinecke@7075: StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), false, doc); bjoern@4446: bjoern@4446: for (KMIndex.Entry entry: kms) { bjoern@4446: double km = entry.getKm(); bjoern@4446: QWD qwd = entry.getValue(); bjoern@4446: bjoern@4446: series.add(km, qwd.getDeltaW()); bjoern@4446: } bjoern@4446: col.addSeries(series); bjoern@4446: aheinecke@7120: generator.addAxisDataset(col, axisName, visible); aheinecke@7120: } aheinecke@7120: aheinecke@7120: protected void doSectorAverageDeviationOut( aheinecke@7120: DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, aheinecke@7120: ThemeDocument doc, aheinecke@7120: boolean visible) { aheinecke@7120: CallContext context = generator.getCallContext(); aheinecke@7120: aheinecke@7120: int index = bundle.getFacet().getIndex(); aheinecke@7120: int sectorNdx = index & 3; aheinecke@7120: aheinecke@7120: KMIndex kms = aheinecke@7120: (KMIndex)bundle.getData(context); aheinecke@7120: aheinecke@7120: if(kms == null) { aheinecke@7120: return; aheinecke@7120: } aheinecke@7120: aheinecke@7120: StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(doc); aheinecke@7120: XYSeries upper = aheinecke@7120: new StyledXYSeries(bundle.getFacetDescription(), false, doc); aheinecke@7120: XYSeries lower = aheinecke@7120: new StyledXYSeries(bundle.getFacetDescription() + " ", false, doc); aheinecke@7120: aheinecke@7120: for (KMIndex.Entry entry: kms) { aheinecke@7120: double km = entry.getKm(); aheinecke@7120: AnalysisPeriod ap = entry.getValue(); aheinecke@7120: QWD qwd = ap.getQSectorAverages()[sectorNdx]; aheinecke@7120: double dev = ap.getQSectorStdDev(sectorNdx); aheinecke@7120: if (qwd == null) { aheinecke@7120: continue; aheinecke@7120: } aheinecke@7120: double deltaW = qwd.getDeltaW(); aheinecke@7120: double up = deltaW + dev; aheinecke@7120: double lo = deltaW - dev; aheinecke@7120: upper.add(km, up); aheinecke@7120: lower.add(km, lo); aheinecke@7120: } aheinecke@7120: area.addSeries(upper); aheinecke@7120: area.addSeries(lower); aheinecke@7120: aheinecke@7120: generator.addAreaSeries(area, axisName, visible); aheinecke@7120: } aheinecke@7120: aheinecke@7120: protected void doReferenceDeviationOut( aheinecke@7120: DiagramGenerator generator, aheinecke@7120: ArtifactAndFacet bundle, aheinecke@7120: ThemeDocument doc, aheinecke@7120: boolean visible) { aheinecke@7120: CallContext context = generator.getCallContext(); aheinecke@7120: aheinecke@7120: KMIndex kms = aheinecke@7120: (KMIndex)bundle.getData(context); aheinecke@7120: aheinecke@7120: if(kms == null) { aheinecke@7120: return; aheinecke@7120: } aheinecke@7120: aheinecke@7120: StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(doc); aheinecke@7120: XYSeries upper = aheinecke@7120: new StyledXYSeries(bundle.getFacetDescription(), false, doc); aheinecke@7120: XYSeries lower = aheinecke@7120: new StyledXYSeries(bundle.getFacetDescription() + " ", false, doc); aheinecke@7120: aheinecke@7120: for (KMIndex.Entry entry: kms) { aheinecke@7120: double km = entry.getKm(); aheinecke@7120: double[] devArray = entry.getValue(); aheinecke@7120: if (devArray == null) { aheinecke@7120: continue; aheinecke@7120: } aheinecke@7120: double dev = devArray[0]; aheinecke@7120: double up = dev; aheinecke@7120: double lo = -dev; aheinecke@7120: upper.add(km, up, false); aheinecke@7120: lower.add(km, lo, false); aheinecke@7120: } aheinecke@7120: area.addSeries(upper); aheinecke@7120: area.addSeries(lower); aheinecke@7120: aheinecke@7120: Marker marker = new ValueMarker(0); aheinecke@7120: marker.setStroke(new BasicStroke(2)); aheinecke@7120: marker.setPaint(Color.BLACK); aheinecke@7120: generator.addValueMarker(marker); aheinecke@7120: generator.addAreaSeries(area, axisName, visible); aheinecke@7120: } aheinecke@7120: aheinecke@7120: @Override aheinecke@7120: public String getAxisLabel(DiagramGenerator generator) { aheinecke@7120: return generator.msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); bjoern@4446: } bjoern@4446: } felix@6577: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :