view artifacts/src/main/java/org/dive4elements/river/exports/process/BedDiffYearProcessor.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 28758f51f1b2
children f1257717fa4b
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.process;

import org.apache.log4j.Logger;
import org.jfree.data.xy.XYSeries;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult;
import org.dive4elements.river.exports.StyledSeriesBuilder;
import org.dive4elements.river.exports.XYChartGenerator;
import org.dive4elements.river.exports.DiagramGenerator;
import org.dive4elements.river.jfree.StyledXYSeries;
import org.dive4elements.river.themes.ThemeDocument;


public class BedDiffYearProcessor
extends DefaultProcessor implements FacetTypes {

    private final static Logger logger =
            Logger.getLogger(BedDiffYearProcessor.class);

    protected static double GAP_TOLERANCE = 0.101d;

    public static final String I18N_AXIS_LABEL =
        "chart.beddifference.yaxis.label.diff";
    public static final String I18N_AXIS_LABEL_DEFAULT =
        "delta S [cm]";

    @Override
    public void doOut(
            DiagramGenerator generator,
            ArtifactAndFacet bundle,
            ThemeDocument    theme,
            boolean          visible) {
        CallContext context = generator.getCallContext();
        Object data = bundle.getData(context);
        if (data instanceof BedDiffYearResult) {
            String facetType = bundle.getFacetName();
            BedDiffYearResult bData = (BedDiffYearResult) data;

            double[][] points;
            if (BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType)) {
                points = bData.getHeights1Data();
            } else {
                points = bData.getHeights2Data();
            }
            XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
            StyledSeriesBuilder.addPointsFactorY(series,
                points,
                false,
                GAP_TOLERANCE,
                100d);

            generator.addAxisSeries(series, axisName, visible);

            return;
        }
        logger.error("Can't process " + data.getClass().getName() + " objects");
    }

    @Override
    public void doOut(
            XYChartGenerator generator,
            ArtifactAndFacet bundle,
            ThemeDocument theme,
            boolean visible,
            int axidx
    ) {
        CallContext context = generator.getCallContext();
        Object data = bundle.getData(context);
        if (data instanceof BedDiffYearResult) {
            String facetType = bundle.getFacetName();
            BedDiffYearResult bData = (BedDiffYearResult) data;

            double[][] points;
            if (BED_DIFFERENCE_YEAR.equals(facetType)
                || BED_DIFFERENCE_YEAR_FILTERED.equals(facetType)) {
                points = bData.getHeightPerYearData();
            }
            else if (BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType)) {
                points = bData.getHeights1Data();
            } else {
                points = bData.getHeights2Data();
            }
            XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
            StyledSeriesBuilder.addPointsFactorY(series,
                points,
                false,
                GAP_TOLERANCE,
                100d);

            generator.addAxisSeries(series, axidx, visible);

            return;
        }
        logger.error("Can't process " + data.getClass().getName() + " objects");
    }

    @Override
    public boolean canHandle(String facetType) {
        return
               BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType)
            || BED_DIFFERENCE_YEAR_HEIGHT2.equals(facetType)
            || BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED.equals(facetType)
            || BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED.equals(facetType)
            || BED_DIFFERENCE_YEAR.equals(facetType) // from BedDifferencesYear
            || BED_DIFFERENCE_YEAR_FILTERED.equals(facetType); // from BedDifferencesYear
    }

    @Override
    public String getAxisLabel(DiagramGenerator generator) {
        return generator.msg(
                I18N_AXIS_LABEL,
                I18N_AXIS_LABEL_DEFAULT);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org