ContourPlotSpeed.java

  1. package org.opentrafficsim.draw.graphs;

  2. import java.awt.Color;

  3. import org.djunits.unit.SpeedUnit;
  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
  6. import org.opentrafficsim.draw.core.BoundsPaintScale;
  7. import org.opentrafficsim.draw.graphs.ContourDataSource.ContourDataType;

  8. /**
  9.  * Contour plot for speed.
  10.  * <p>
  11.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  13.  * <p>
  14.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 4 okt. 2018 <br>
  15.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  16.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  17.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  18.  */
  19. public class ContourPlotSpeed extends AbstractContourPlot<Speed>
  20. {

  21.     /** */
  22.     private static final long serialVersionUID = 20181004L;

  23.     /**
  24.      * Constructor.
  25.      * @param caption String; caption
  26.      * @param simulator OTSSimulatorInterface; simulator
  27.      * @param dataPool ContourDataSource&lt;?&gt;; data pool
  28.      */
  29.     public ContourPlotSpeed(final String caption, final OTSSimulatorInterface simulator, final ContourDataSource<?> dataPool)
  30.     {
  31.         super(caption, simulator, dataPool, createPaintScale(), new Speed(30.0, SpeedUnit.KM_PER_HOUR), "%.0fkm/h",
  32.                 "speed %.1f km/h");
  33.     }

  34.     /**
  35.      * Creates a paint scale from red, via yellow to green.
  36.      * @return ContinuousColorPaintScale; paint scale
  37.      */
  38.     private static BoundsPaintScale createPaintScale()
  39.     {
  40.         double[] boundaries = {0.0, 30.0 / 3.6, 60.0 / 3.6, 110.0 / 3.6, 160.0 / 3.6};
  41.         Color[] colorValues = BoundsPaintScale.reverse(BoundsPaintScale.GREEN_RED_DARK);
  42.         return new BoundsPaintScale(boundaries, colorValues);
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public GraphType getGraphType()
  47.     {
  48.         return GraphType.SPEED_CONTOUR;
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     protected double scale(final double si)
  53.     {
  54.         return SpeedUnit.KM_PER_HOUR.getScale().fromStandardUnit(si);
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     protected double getValue(final int item, final double cellLength, final double cellSpan)
  59.     {
  60.         return getDataPool().getSpeed(item);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     protected ContourDataType<Speed, ?> getContourDataType()
  65.     {
  66.         return null; // speed is present by default
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public String toString()
  71.     {
  72.         return "ContourPlotSpeed []";
  73.     }

  74. }