ContourPlotSpeed.java
package org.opentrafficsim.animation.graphs;
import java.awt.Color;
import org.djunits.unit.SpeedUnit;
import org.djunits.value.vdouble.scalar.Speed;
import org.opentrafficsim.animation.BoundsPaintScale;
import org.opentrafficsim.animation.Colors;
import org.opentrafficsim.animation.graphs.ContourDataSource.ContourEdieDataType;
/**
* Contour plot for speed.
* <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 ContourPlotSpeed extends AbstractContourPlot<Speed>
{
/**
* Constructor.
* @param caption caption
* @param source data source
*/
public ContourPlotSpeed(final String caption, final ContourDataSource source)
{
// speed is present by default, hence null contour data type
super(caption, source, ContourEdieDataType.SPEED, createPaintScale(),
new LabelData<>(new Speed(40.0, SpeedUnit.KM_PER_HOUR), "%.0fkm/h", "speed %.1f km/h"));
}
/**
* Creates a paint scale from red, via yellow to green.
* @return paint scale
*/
private static BoundsPaintScale createPaintScale()
{
double[] boundaries = {0.0, 40.0 / 3.6, 80.0 / 3.6, 120.0 / 3.6, 160.0 / 3.6};
Color[] colorValues = Colors.reverse(Colors.GREEN_RED_DARK);
return new BoundsPaintScale(boundaries, colorValues);
}
@Override
public GraphType getGraphType()
{
return GraphType.SPEED_CONTOUR;
}
@Override
protected double scale(final double si)
{
return SpeedUnit.KM_PER_HOUR.getScale().fromStandardUnit(si);
}
@Override
public String toString()
{
return "ContourPlotSpeed [" + getCaption() + "]";
}
}