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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  13.  * </p>
  14.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  15.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  16.  * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
  17.  */
  18. public class ContourPlotDensity extends AbstractContourPlot<LinearDensity>
  19. {

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

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

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

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

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

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

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

  71. }