view artifacts/src/main/java/org/dive4elements/river/exports/process/BedQualityDiameterProcessor.java @ 8472:3f505fba522f

(issue1772) Use 0.001km tolarance instead of 0.1 to find matching km. There is no sense to use a define here. I will not write static final double NULLPOINTNULLNULLONE=0.001 if i just want to use that value and not any other value which may make sense in some other place. Using hardcoded values can have its merits and makes the code easier to read.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 18 Nov 2014 15:24:40 +0100
parents 48d4921665e3
children 36faef4f8acb
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 java.util.Map;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.CallMeta;

import org.dive4elements.river.artifacts.resources.Resources;
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;

public class BedQualityDiameterProcessor extends DefaultProcessor {

    private final static Logger log =
            Logger.getLogger(BedQualityDiameterProcessor.class);

    public static final String I18N_AXIS_LABEL =
        "chart.bedquality.yaxis.label.diameter";

    protected String yAxisLabel;
    @Override
    public void doOut(
            DiagramGenerator generator,
            ArtifactAndFacet bundle,
            ThemeDocument    theme,
            boolean          visible) {
        CallContext context = generator.getCallContext();
        Map<String, String> metaData = bundle.getFacet().getMetaData();
        StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
                theme);
        series.putMetaData(metaData, bundle.getArtifact(), context);
        yAxisLabel = metaData.get("Y");
        Object data = bundle.getData(context);
        if (data == null) {
            return;
        }
        if (!(data instanceof double[][])) {
            log.error("Unknown data type: " + data.getClass().getName());
            return;
        }
        double[][] values = (double[][])data;
        StyledSeriesBuilder.addPoints(series, values, true);

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

    @Override
    public boolean canHandle(String facettype) {
        return facettype.equals(FacetTypes.BED_QUALITY_BED_DIAMETER_TOPLAYER) ||
            facettype.equals(FacetTypes.BED_QUALITY_BED_DIAMETER_SUBLAYER) ||
            facettype.equals(FacetTypes.BED_QUALITY_BEDLOAD_DIAMETER) ||
            facettype.equals(FacetTypes.BED_DIAMETER_DATA_TOP) ||
            facettype.equals(FacetTypes.BED_DIAMETER_DATA_SUB) ||
            facettype.equals(FacetTypes.BEDLOAD_DIAMETER_DATA);
    }

    @Override
    public String getAxisLabel(DiagramGenerator generator) {

        CallMeta meta = generator.getCallContext().getMeta();

        if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
            return Resources.getMsg(meta, yAxisLabel);
        }
        return Resources.getMsg(meta, I18N_AXIS_LABEL);
    }
}

http://dive4elements.wald.intevation.org