ContourPlotDensity.java

  1. package org.opentrafficsim.draw.graphs;

  2. import java.awt.Color;

  3. import org.djunits.unit.LinearDensityUnit;
  4. import org.djunits.value.vdouble.scalar.LinearDensity;
  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 density.
  10.  * <p>
  11.  * Copyright (c) 2013-2022 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 10 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 ContourPlotDensity extends AbstractContourPlot<LinearDensity>
  20. {

  21.     /**
  22.      * Constructor.
  23.      * @param caption String; caption
  24.      * @param simulator OTSSimulatorInterface; simulator
  25.      * @param dataPool ContourDataSource&lt;?&gt;; data pool
  26.      */
  27.     public ContourPlotDensity(final String caption, final OTSSimulatorInterface simulator, final ContourDataSource<?> dataPool)
  28.     {
  29.         super(caption, simulator, dataPool, createPaintScale(), new LinearDensity(30.0, LinearDensityUnit.PER_KILOMETER),
  30.                 "%.0f/km", "density %.1f veh/km");
  31.     }

  32.     /**
  33.      * Creates a paint scale from red, via yellow to green.
  34.      * @return ContinuousColorPaintScale; paint scale
  35.      */
  36.     private static BoundsPaintScale createPaintScale()
  37.     {
  38.         double[] boundaries = {0.0, 20.0 / 1000, 150.0 / 1000};
  39.         Color[] colorValues = BoundsPaintScale.GREEN_RED;
  40.         return new BoundsPaintScale(boundaries, colorValues);
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public GraphType getGraphType()
  45.     {
  46.         return GraphType.DENSITY_CONTOUR;
  47.     }

  48.     /** {@inheritDoc} */
  49.     @Override
  50.     protected double scale(final double si)
  51.     {
  52.         return LinearDensityUnit.PER_KILOMETER.getScale().fromStandardUnit(si);
  53.     }

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

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     protected ContourDataType<LinearDensity, ?> getContourDataType()
  63.     {
  64.         return null; // density is present by default
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public String toString()
  69.     {
  70.         return "ContourPlotDensity []";
  71.     }

  72. }