1 package org.opentrafficsim.draw.graphs;
2
3 import java.awt.Color;
4
5 import org.djunits.unit.LinearDensityUnit;
6 import org.djunits.value.vdouble.scalar.LinearDensity;
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
13
14
15
16
17
18
19
20
21
22 public class ContourPlotDensity extends AbstractContourPlot<LinearDensity>
23 {
24
25
26 private static final long serialVersionUID = 20181010L;
27
28
29
30
31
32
33
34 public ContourPlotDensity(final String caption, final OTSSimulatorInterface simulator, final ContourDataSource<?> dataPool)
35 {
36 super(caption, simulator, dataPool, createPaintScale(), new LinearDensity(30.0, LinearDensityUnit.PER_KILOMETER),
37 "%.0f/km", "density %.1f veh/km");
38 }
39
40
41
42
43
44 private static BoundsPaintScale createPaintScale()
45 {
46 double[] boundaries = { 0.0, 20.0 / 1000, 150.0 / 1000 };
47 Color[] colorValues = BoundsPaintScale.GREEN_RED;
48 return new BoundsPaintScale(boundaries, colorValues);
49 }
50
51
52 @Override
53 public GraphType getGraphType()
54 {
55 return GraphType.DENSITY_CONTOUR;
56 }
57
58
59 @Override
60 protected double scale(final double si)
61 {
62 return LinearDensityUnit.PER_KILOMETER.getScale().fromStandardUnit(si);
63 }
64
65
66 @Override
67 protected double getValue(final int item, final double cellLength, final double cellSpan)
68 {
69 return getDataPool().getTotalTime(item) / (cellLength * cellSpan);
70 }
71
72
73 @Override
74 protected ContourDataType<LinearDensity, ?> getContourDataType()
75 {
76 return null;
77 }
78
79
80 @Override
81 public String toString()
82 {
83 return "ContourPlotDensity []";
84 }
85
86 }