Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/exports/process/AreaProcessor.java @ 7691:fa4fbd66e752
(issue1579) Fix axes syncronisation at Gauges
The SyncNumberAxis was completely broken. It only synced
in one direction and even that did not work correctly when
data was added to the axis (and the syncAxis rescaled but
forgot the old axis) then there were lots of ways to bypass
that scaling. And i also think the trans calculation was wrong.
It has been replaced by a "mostly" simple method to just keep
the W in M and W in CM+Datum axes in sync. I say "Mostly" because
it had to deal with the Bounds interface.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 13 Dec 2013 19:03:00 +0100 |
parents | 9344aa0fb021 |
children | dfe3f78fd3e5 |
line wrap: on
line source
/* Copyright (C) 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.process; import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.geom.Lines; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.model.WQKms; import org.dive4elements.river.artifacts.model.AreaFacet; import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.exports.DiagramGenerator; import org.dive4elements.river.exports.StyledSeriesBuilder; import org.dive4elements.river.jfree.StyledAreaSeriesCollection; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; import org.jfree.data.xy.XYSeries; public class AreaProcessor extends DefaultProcessor { private static final Logger logger = Logger.getLogger(AreaProcessor.class); @Override public void doOut( DiagramGenerator generator, ArtifactAndFacet bundle, ThemeDocument theme, boolean visible) { CallContext context = generator.getCallContext(); String seriesName = bundle.getFacetDescription(); StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); logger.debug("Area Processor processing: " + seriesName); AreaFacet.Data data = (AreaFacet.Data) bundle.getData(context); XYSeries up = null; XYSeries down = null; if (data.getUpperData() != null) { up = new StyledXYSeries(seriesName, false, theme); if (data.getUpperData() instanceof WQKms) { if (FacetTypes.IS.Q(data.getRootFacetName())) { StyledSeriesBuilder.addPointsKmQ(up, (WQKms) data.getUpperData()); } else { StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); } } else if (data.getUpperData() instanceof double[][]) { StyledSeriesBuilder.addPoints(up, (double [][]) data.getUpperData(), false); } else if (data.getUpperData() instanceof WKms) { StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); } else if (data.getUpperData() instanceof Lines.LineData) { StyledSeriesBuilder.addPoints(up, ((Lines.LineData) data.getUpperData()).points, false); } else { logger.error("Do not know how to deal with (up) area info from: " + data.getUpperData()); } } // TODO Depending on style, the area (e.g. 20m^2) should be added as annotation. if (data.getLowerData() != null) { // TODO: Sort this out: when the two series have the same name, // the renderer (or anything in between) will not work correctly. down = new StyledXYSeries(seriesName + " ", false, theme); if (data.getLowerData() instanceof WQKms) { if (FacetTypes.IS.Q(data.getRootFacetName())) { StyledSeriesBuilder.addPointsKmQ(down, (WQKms) data.getLowerData()); } else { StyledSeriesBuilder.addPoints(down, (WQKms) data.getLowerData()); } } else if (data.getLowerData() instanceof double[][]) { StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData(), false); } else if (data.getLowerData() instanceof WKms) { StyledSeriesBuilder.addPoints(down, (WKms) data.getLowerData()); } else if (data.getLowerData() instanceof Lines.LineData) { StyledSeriesBuilder.addPoints(down, ((Lines.LineData) data.getLowerData()).points, false); } else { logger.error("Do not know how to deal with (down) area info from: " + data.getLowerData()); } } if (up == null && down != null) { area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); down.setKey(seriesName); area.addSeries(down); area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(down)); } else if (up != null && down == null) { area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER); area.addSeries(up); area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(up)); } else if (up != null && down != null) { if (data.doPaintBetween()) { area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); } else { area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); } area.addSeries(up); area.addSeries(down); } /* Decide axis name based on facet name */ generator.addAreaSeries(area, axisNameForFacet(data.getRootFacetName()), visible); } /** Look up the axis identifier for a given facet type. */ private String axisNameForFacet(String facetName) { if (FacetTypes.IS.W(facetName)) { return "W"; } else if (FacetTypes.IS.Q(facetName)) { return "Q"; } else { logger.warn("Could not find axis for facet " + facetName); return "W"; } } @Override public boolean canHandle(String facetType) { if (facetType == null) { return false; } return FacetTypes.IS.AREA(facetType); } }