view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java @ 8886:cc86b0f9b3c3

SINFO-FlowDepth - work on tkh themes
author gernotbelger
date Wed, 14 Feb 2018 18:10:53 +0100
parents 7a8c12706834
children 90b7f45ff4ae
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * 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.artifacts.sinfo.flowdepth;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifacts.CallContext;
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 final class FlowDepthProcessor extends AbstractSInfoProcessor {

    /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */
    // REMARK: these mustend with 'filtered' so extra handling happens in chart: point are always recalculated, because data
    // changes depending on zoom state
    static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered";

    static String FACET_FLOW_DEPTH_TKH_FILTERED = "sinfo_flow_depth.tkh.filtered";

    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();

    static {
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_TKH_FILTERED);
    }

    private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label";

    public FlowDepthProcessor() {
        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
    }

    @Override
    protected final String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {

        final CallContext context = generator.getCallContext();
        final Map<String, String> metaData = bundle.getFacet().getMetaData();

        final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
        series.putMetaData(metaData, bundle.getArtifact(), context);

        final String facetName = bundle.getFacetName();
        final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context);
        if (data == null) {
            // Check has been here before so we keep it for security reasons
            // this should never happen though.
            throw new IllegalStateException("Data is null for facet: " + facetName);
        }

        final double[][] points = generatePoints(data, facetName);

        StyledSeriesBuilder.addPoints(series, points, true);
        generator.addAxisSeries(series, getAxisName(), visible);

        return metaData.get("Y");
    }

    // FIXME: do filtering
    private double[][] generatePoints(final FlowDepthCalculationResult data, final String facetName) {

        if (FACET_FLOW_DEPTH_FILTERED.contentEquals(facetName))
            return data.getFlowDepthPoints();

        if (FACET_FLOW_DEPTH_TKH_FILTERED.contentEquals(facetName))
            return data.getFlowDepthTkhPoints();

        final String error = String.format("Unknown facet name: %s", facetName);
        throw new UnsupportedOperationException(error);
    }
}

http://dive4elements.wald.intevation.org