view artifacts/src/main/java/org/dive4elements/river/exports/process/BedWidthProcessor.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 4374a8d26706
children 8faa8cfd2385
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 java.util.List;

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

import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult;
import org.dive4elements.river.model.BedHeightSingleValue;
import org.dive4elements.river.artifacts.model.minfo.BedHeightSingleData;

import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth;

public class BedWidthProcessor extends DefaultProcessor {

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

    public static final String I18N_AXIS_LABEL_DEFAULT =
        "Breite [m]";
    public static final String I18N_AXIS_LABEL =
        "chart.beddifference.yaxis.label.morph";

    @Override
    public void doOut(
            DiagramGenerator generator,
            ArtifactAndFacet bundle,
            ThemeDocument    theme,
            boolean          visible) {
        CallContext context = generator.getCallContext();
        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
                theme);
        Object data = bundle.getData(context);

        if (data instanceof BedDiffYearResult) {
            BedDiffYearResult bData = (BedDiffYearResult) data;
            StyledSeriesBuilder.addPoints(series, bData.getMorphWidthData(), true);
        } else if (data instanceof MorphologicWidth) {
            MorphologicWidth bData = (MorphologicWidth) data;
            StyledSeriesBuilder.addPoints(series, bData.getAsArray(), true);
        } else if (data instanceof BedHeightSingleData) {
            BedHeightSingleData bData = (BedHeightSingleData)data;
            double[] width = bData.getMorphWidths();
            double[] stations = bData.getStations().toNativeArray();

            for (int i = 0; i < width.length; i++) {
                series.add(stations[i], width[i], false);
            }
        } else if (data instanceof List<?>) {
            List<BedHeightSingleValue> bData = (List<BedHeightSingleValue>)data;

            for(BedHeightSingleValue bvalue: bData) {
                series.add(bvalue.getStation(), bvalue.getSoundingWidth());
            }
        } else {
            logger.error("Unknown data for facet: " + bundle.getFacetName());
        }

        generator.addAxisSeries(series, axisName, visible);
    }

    @Override
    public boolean canHandle(String facettype) {
        return facettype.equals(FacetTypes.BED_DIFFERENCE_MORPH_WIDTH) ||
            facettype.equals(FacetTypes.MORPHOLOGIC_WIDTH) ||
            facettype.equals(FacetTypes.BEDHEIGHT_SOUNDING_WIDTH);
    }

    @Override
    public String getAxisLabel(DiagramGenerator generator) {
        return generator.msg(
                I18N_AXIS_LABEL,
                I18N_AXIS_LABEL_DEFAULT);
    }
}

http://dive4elements.wald.intevation.org