ContourPlotFlow.java

package org.opentrafficsim.animation.graphs;

import java.awt.Color;

import org.djunits.unit.FrequencyUnit;
import org.djunits.value.vdouble.scalar.Frequency;
import org.opentrafficsim.animation.BoundsPaintScale;
import org.opentrafficsim.animation.Colors;
import org.opentrafficsim.animation.graphs.ContourDataSource.ContourEdieDataType;

/**
 * Contour plot for flow.
 * <p>
 * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
 * </p>
 * @author Alexander Verbraeck
 * @author Peter Knoppers
 * @author Wouter Schakel
 */
public class ContourPlotFlow extends AbstractContourPlot<Frequency>
{

    /**
     * Constructor.
     * @param caption caption
     * @param source data source
     */
    public ContourPlotFlow(final String caption, final ContourDataSource source)
    {
        // flow is present by default, hence null contour data type
        super(caption, source, ContourEdieDataType.FLOW, createPaintScale(),
                new LabelData<>(new Frequency(500.0, FrequencyUnit.PER_HOUR), "%.0f/h", "flow %.1f veh/h"));
    }

    /**
     * Creates a paint scale from red, via yellow to green.
     * @return paint scale
     */
    private static BoundsPaintScale createPaintScale()
    {
        double[] boundaries = {0.0, 500.0 / 3600, 1000.0 / 3600, 1500.0 / 3600, 2000.0 / 3600, 2500.0 / 3600, 3000.0 / 3600};
        Color[] colorValues = Colors.hue(7);
        return new BoundsPaintScale(boundaries, colorValues);
    }

    @Override
    public GraphType getGraphType()
    {
        return GraphType.FLOW_CONTOUR;
    }

    @Override
    protected double scale(final double si)
    {
        return FrequencyUnit.PER_HOUR.getScale().fromStandardUnit(si);
    }

    @Override
    public String toString()
    {
        return "ContourPlotFlow [" + getCaption() + "]";
    }

}