1 package tim.prune.gui.profile;
3 import tim.prune.I18nManager;
4 import tim.prune.config.Config;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Distance;
7 import tim.prune.data.Track;
8 import tim.prune.data.Distance.Units;
11 * Class to provide a source of speed data for the profile chart
13 public class SpeedData extends ProfileData
15 /** Flag for metric units */
16 private boolean _metric = true;
20 * @param inTrack track object
22 public SpeedData(Track inTrack) {
27 * Get the data and populate the instance arrays
32 _metric = Config.getConfigBoolean(Config.KEY_METRIC_UNITS);
34 _minValue = _maxValue = 0.0;
36 DataPoint prevPrevPoint = null, prevPoint = null, point = null;
37 for (int i=0; i<_track.getNumPoints(); i++)
39 point = _track.getPoint(i);
40 if (prevPrevPoint != null && prevPrevPoint.hasTimestamp()
41 && prevPoint != null && prevPoint.hasTimestamp()
42 && point != null && point.hasTimestamp())
44 // All three points have timestamps
45 double seconds = point.getTimestamp().getSecondsSince(prevPrevPoint.getTimestamp());
48 double distInRads = DataPoint.calculateRadiansBetween(prevPrevPoint, prevPoint)
49 + DataPoint.calculateRadiansBetween(prevPoint, point);
50 double dist = Distance.convertRadiansToDistance(distInRads, _metric?Units.KILOMETRES:Units.MILES);
51 // Store the value and maintain max and min values
52 double value = dist / seconds * 60.0 * 60.0;
53 _pointValues[i-1] = value;
54 if (value < _minValue || _minValue == 0.0) {_minValue = value;}
55 if (value > _maxValue) {_maxValue = value;}
58 _pointHasData[i-1] = true;
62 prevPrevPoint = prevPoint;
69 * @return text description including units
71 public String getLabel()
73 return I18nManager.getText("fieldname.speed") + " ("
74 + I18nManager.getText(_metric?"units.kmh":"units.mph") + ")";
78 * @return key for message when no speeds present
80 public String getNoDataKey() {
81 return "display.notimestamps";