ContourPlotDensity.java

package org.opentrafficsim.animation.graphs;

import java.awt.Color;

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

/**
 * Contour plot for density.
 * <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 ContourPlotDensity extends AbstractContourPlot<LinearDensity>
{

    /**
     * Constructor.
     * @param caption caption
     * @param source data source
     */
    public ContourPlotDensity(final String caption, final ContourDataSource source)
    {
        // density is present by default, hence null contour data type
        super(caption, source, ContourEdieDataType.DENSITY, createPaintScale(),
                new LabelData<>(new LinearDensity(30.0, LinearDensityUnit.PER_KILOMETER), "%.0f/km", "density %.1f veh/km"));
    }

    /**
     * Creates a paint scale from red, via yellow to green.
     * @return paint scale
     */
    private static BoundsPaintScale createPaintScale()
    {
        double[] boundaries = {0.0, 20.0 / 1000, 150.0 / 1000};
        Color[] colorValues = Colors.GREEN_RED;
        return new BoundsPaintScale(boundaries, colorValues);
    }

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

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

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

}