View Javadoc
1   package org.opentrafficsim.draw.graphs;
2   
3   import java.awt.Color;
4   
5   import org.djunits.unit.FrequencyUnit;
6   import org.djunits.value.vdouble.scalar.Frequency;
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 flow.
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 10 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 ContourPlotFlow extends AbstractContourPlot<Frequency>
23  {
24  
25      /** */
26      private static final long serialVersionUID = 20181010L;
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 ContourPlotFlow(final String caption, final OTSSimulatorInterface simulator, final ContourDataSource<?> dataPool)
35      {
36          super(caption, simulator, dataPool, createPaintScale(), new Frequency(500.0, FrequencyUnit.PER_HOUR), "%.0f/h",
37                  "flow %.1f veh/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, 500.0 / 3600, 1000.0 / 3600, 1500.0 / 3600, 2000.0 / 3600, 2500.0 / 3600, 3000.0 / 3600};
47          Color[] colorValues = BoundsPaintScale.hue(7);
48          return new BoundsPaintScale(boundaries, colorValues);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public GraphType getGraphType()
54      {
55          return GraphType.FLOW_CONTOUR;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      protected double scale(final double si)
61      {
62          return FrequencyUnit.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().getTotalDistance(item) / (cellLength * cellSpan);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected ContourDataType<Frequency, ?> getContourDataType()
75      {
76          return null; // flow is present by default
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public String toString()
82      {
83          return "ContourPlotFlow []";
84      }
85  
86  }