View Javadoc
1   package org.opentrafficsim.draw.graphs;
2   
3   import java.awt.Color;
4   
5   import org.djunits.unit.SpeedUnit;
6   import org.djunits.value.vdouble.scalar.Speed;
7   import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
8   import org.opentrafficsim.draw.core.BoundsPaintScale;
9   import org.opentrafficsim.draw.graphs.ContourDataSource.ContourDataType;
10  
11  /**
12   * Contour plot for speed.
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 4 okt. 2018 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public class ContourPlotSpeed extends AbstractContourPlot<Speed>
23  {
24  
25      /** */
26      private static final long serialVersionUID = 20181004L;
27  
28      /**
29       * Constructor.
30       * @param caption String; caption
31       * @param simulator OTSSimulatorInterface; simulator
32       * @param dataPool ContourDataSource&lt;?&gt;; data pool
33       */
34      public ContourPlotSpeed(final String caption, final OTSSimulatorInterface simulator, final ContourDataSource<?> dataPool)
35      {
36          super(caption, simulator, dataPool, createPaintScale(), new Speed(30.0, SpeedUnit.KM_PER_HOUR), "%.0fkm/h",
37                  "speed %.1f km/h");
38      }
39  
40      /**
41       * Creates a paint scale from red, via yellow to green.
42       * @return ContinuousColorPaintScale; paint scale
43       */
44      private static BoundsPaintScale createPaintScale()
45      {
46          double[] boundaries = { 0.0, 30.0 / 3.6, 60.0 / 3.6, 110.0 / 3.6, 160.0 / 3.6 };
47          Color[] colorValues = BoundsPaintScale.reverse(BoundsPaintScale.GREEN_RED_DARK);
48          return new BoundsPaintScale(boundaries, colorValues);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public GraphType getGraphType()
54      {
55          return GraphType.SPEED_CONTOUR;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      protected double scale(final double si)
61      {
62          return SpeedUnit.KM_PER_HOUR.getScale().fromStandardUnit(si);
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      protected double getValue(final int item, final double cellLength, final double cellSpan)
68      {
69          return getDataPool().getSpeed(item);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected ContourDataType<Speed, ?> getContourDataType()
75      {
76          return null; // speed is present by default
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public String toString()
82      {
83          return "ContourPlotSpeed []";
84      }
85  
86  }