@raruto/leaflet-elevation 1.9.2 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -13
- package/dist/leaflet-elevation.js +579 -425
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +2 -2
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/libs/leaflet-distance-marker.js +239 -80
- package/libs/leaflet-distance-marker.min.js +1 -1
- package/libs/leaflet-ruler.css +42 -0
- package/libs/leaflet-ruler.js +183 -0
- package/libs/leaflet-ruler.min.css +1 -0
- package/libs/leaflet-ruler.min.js +1 -0
- package/package.json +1 -1
- package/src/acceleration.js +56 -51
- package/src/altitude.js +78 -79
- package/src/chart.js +10 -0
- package/src/components.js +22 -13
- package/src/control.js +108 -45
- package/src/distance.js +31 -40
- package/src/index.js +1 -1
- package/src/marker.js +15 -15
- package/src/options.js +9 -5
- package/src/slope.js +87 -71
- package/src/speed.js +57 -49
- package/src/summary.js +12 -1
- package/src/time.js +43 -42
package/src/slope.js
CHANGED
|
@@ -12,100 +12,116 @@ Elevation.addInitHook(function() {
|
|
|
12
12
|
|
|
13
13
|
slope.label = opts.slopeLabel || '%';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let z = data[i].z;
|
|
49
|
-
let delta = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
50
|
-
|
|
51
|
-
// Slope / Gain
|
|
52
|
-
let track = this.track_info;
|
|
53
|
-
let tAsc = track.ascent || 0; // Total Ascent
|
|
54
|
-
let tDes = track.descent || 0; // Total Descent
|
|
55
|
-
let sMax = track.slope_max || 0; // Slope Max
|
|
56
|
-
let sMin = track.slope_min || 0; // Slope Min
|
|
57
|
-
let slope = 0;
|
|
58
|
-
|
|
59
|
-
if (!isNaN(z)) {
|
|
60
|
-
let deltaZ = i > 0 ? z - data[i - 1].z : 0;
|
|
61
|
-
if (deltaZ > 0) tAsc += deltaZ;
|
|
62
|
-
else if (deltaZ < 0) tDes -= deltaZ;
|
|
63
|
-
// slope in % = ( height / length ) * 100
|
|
64
|
-
if (delta !== 0) slope = (deltaZ / delta) * 100;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Try to smooth "crazy" slope values.
|
|
68
|
-
if (this.options.sDeltaMax) {
|
|
69
|
-
let deltaS = i > 0 ? slope - data[i - 1].slope : 0;
|
|
70
|
-
let maxDeltaS = this.options.sDeltaMax;
|
|
71
|
-
if (Math.abs(deltaS) > maxDeltaS) {
|
|
72
|
-
slope = data[i - 1].slope + maxDeltaS * Math.sign(deltaS);
|
|
15
|
+
this._registerDataAttribute({
|
|
16
|
+
name: 'slope',
|
|
17
|
+
// init: () => {
|
|
18
|
+
// // this.track_info.ascent = 0; // Total Ascent
|
|
19
|
+
// // this.track_info.descent = 0; // Total Descent
|
|
20
|
+
// // this.track_info.slope_max = -Infinity; // Slope Max
|
|
21
|
+
// // this.track_info.slope_min = +Infinity; // Slope Min
|
|
22
|
+
// // this.track_info.slope_avg = 0; // Acceleration Avg
|
|
23
|
+
// },
|
|
24
|
+
fetch: (i) => {
|
|
25
|
+
let data = this._data;
|
|
26
|
+
let dx = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
27
|
+
let dz = data[i].z - data[i > 0 ? i - 1 : i].z;
|
|
28
|
+
return (!isNaN(dz) && dx !== 0) ? (dz / dx) * 100 : 0; // slope in % = ( height / length ) * 100;
|
|
29
|
+
},
|
|
30
|
+
update: (slope, i) => {
|
|
31
|
+
this.track_info.ascent = this.track_info.ascent || 0; // Total Ascent
|
|
32
|
+
this.track_info.descent = this.track_info.descent || 0; // Total Descent
|
|
33
|
+
this.track_info.slope_max = this.track_info.slope_max || -Infinity; // Slope Max
|
|
34
|
+
this.track_info.slope_min = this.track_info.slope_min || +Infinity; // Slope Min
|
|
35
|
+
this.track_info.slope_avg = this.track_info.slope_avg || 0; // Acceleration Avg
|
|
36
|
+
|
|
37
|
+
let track = this.track_info;
|
|
38
|
+
let data = this._data;
|
|
39
|
+
let dz = data[i].z - data[i > 0 ? i - 1 : i].z;
|
|
40
|
+
|
|
41
|
+
// Try to smooth "crazy" acceleration values.
|
|
42
|
+
if (this.options.slopeDeltaMax) {
|
|
43
|
+
let delta = slop - data[i > 0 ? i - 1 : i].slope;
|
|
44
|
+
let deltaMax = this.options.slopeDeltaMax;
|
|
45
|
+
if (Math.abs(delta) > deltaMax) {
|
|
46
|
+
slope = data[i - 1].slope + deltaMax * Math.sign(delta);
|
|
47
|
+
}
|
|
73
48
|
}
|
|
74
|
-
}
|
|
75
49
|
|
|
76
|
-
|
|
77
|
-
|
|
50
|
+
// Range of acceptable slope values.
|
|
51
|
+
slope = _.clamp(slope, this.options.slopeRange);
|
|
52
|
+
|
|
53
|
+
if (dz > 0) this.track_info.ascent += dz;
|
|
54
|
+
else if (dz < 0) this.track_info.descent -= dz;
|
|
55
|
+
|
|
56
|
+
if (slope > track.slope_max) track.slope_max = slope;
|
|
57
|
+
if (slope < track.slope_min) track.slope_min = slope;
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
track.descent = tDes;
|
|
81
|
-
track.slope_max = slope > sMax ? slope : sMax;
|
|
82
|
-
track.slope_min = slope < sMin ? slope : sMin;
|
|
59
|
+
track.slope_avg = (slope + track.slope_avg) / 2.0;
|
|
83
60
|
|
|
84
|
-
|
|
61
|
+
return L.Util.formatNum(slope, 2);;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this._registerAxisScale({
|
|
66
|
+
axis : "y",
|
|
67
|
+
position : "right",
|
|
68
|
+
scale : {
|
|
69
|
+
min : -1,
|
|
70
|
+
max : +1,
|
|
71
|
+
},
|
|
72
|
+
tickPadding: 16,
|
|
73
|
+
label : slope.label,
|
|
74
|
+
labelX : 25,
|
|
75
|
+
labelY : -8,
|
|
76
|
+
name : 'slope',
|
|
77
|
+
visbile : this.options.slope != "summary"
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this._registerAreaPath({
|
|
81
|
+
name : 'slope',
|
|
82
|
+
label : 'Slope',
|
|
83
|
+
yAttr : 'slope',
|
|
84
|
+
scaleX : 'distance',
|
|
85
|
+
scaleY : 'slope',
|
|
86
|
+
color : '#F00',
|
|
87
|
+
strokeColor : '#000',
|
|
88
|
+
strokeOpacity: "0.5",
|
|
89
|
+
fillOpacity : "0.25",
|
|
90
|
+
visbile : this.options.slope != "summary"
|
|
85
91
|
});
|
|
86
92
|
|
|
87
93
|
this._registerTooltip({
|
|
88
94
|
name: 'slope',
|
|
89
95
|
chart: (item) => L._("m: ") + item.slope + slope.label,
|
|
90
|
-
marker: (item) => Math.round(item.slope) + slope.label
|
|
96
|
+
marker: (item) => Math.round(item.slope) + slope.label,
|
|
97
|
+
order: 40,
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
this._registerSummary({
|
|
94
101
|
"ascent" : {
|
|
95
102
|
label: "Total Ascent: ",
|
|
96
|
-
value: (track) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm')
|
|
103
|
+
value: (track) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
104
|
+
order: 40
|
|
97
105
|
},
|
|
98
106
|
"descent" : {
|
|
99
107
|
label: "Total Descent: ",
|
|
100
|
-
value: (track) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm')
|
|
108
|
+
value: (track) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
109
|
+
order: 40
|
|
101
110
|
},
|
|
102
111
|
"minslope": {
|
|
103
112
|
label: "Min Slope: ",
|
|
104
|
-
value: (track) => Math.round(track.slope_min || 0) + ' ' + slope.label
|
|
113
|
+
value: (track) => Math.round(track.slope_min || 0) + ' ' + slope.label,
|
|
114
|
+
order: 40
|
|
105
115
|
},
|
|
106
116
|
"maxslope": {
|
|
107
117
|
label: "Max Slope: ",
|
|
108
|
-
value: (track) => Math.round(track.slope_max || 0) + ' ' + slope.label
|
|
118
|
+
value: (track) => Math.round(track.slope_max || 0) + ' ' + slope.label,
|
|
119
|
+
order: 40
|
|
120
|
+
},
|
|
121
|
+
"avgslope": {
|
|
122
|
+
label: "Avg Slope: ",
|
|
123
|
+
value: (track) => Math.round(track.slope_avg || 0) + ' ' + slope.label,
|
|
124
|
+
order: 40
|
|
109
125
|
}
|
|
110
126
|
});
|
|
111
127
|
|
package/src/speed.js
CHANGED
|
@@ -13,6 +13,49 @@ Elevation.addInitHook(function() {
|
|
|
13
13
|
speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
|
|
14
14
|
opts.speedFactor = opts.speedFactor || 1;
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
this._registerDataAttribute({
|
|
18
|
+
name: 'speed',
|
|
19
|
+
init: () => {
|
|
20
|
+
// this.track_info.speed_max = -Infinity; // Speed Max
|
|
21
|
+
// this.track_info.speed_min = +Infinity; // Speed Min
|
|
22
|
+
// this.track_info.speed_avg = 0; // Speed Avg
|
|
23
|
+
},
|
|
24
|
+
fetch: (i) => {
|
|
25
|
+
let data = this._data;
|
|
26
|
+
let dx = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
27
|
+
let dt = data[i].time - data[ i > 0 ? i - 1 : i].time;
|
|
28
|
+
return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : 0;
|
|
29
|
+
},
|
|
30
|
+
update: (speed, i) => {
|
|
31
|
+
this.track_info.speed_max = this.track_info.speed_max || -Infinity; // Speed Max
|
|
32
|
+
this.track_info.speed_min = this.track_info.speed_min || +Infinity; // Speed Min
|
|
33
|
+
this.track_info.speed_avg = this.track_info.speed_avg || 0; // Speed Avg
|
|
34
|
+
|
|
35
|
+
let data = this._data;
|
|
36
|
+
let track = this.track_info;
|
|
37
|
+
|
|
38
|
+
// Try to smooth "crazy" speed values.
|
|
39
|
+
if (this.options.speedDeltaMax) {
|
|
40
|
+
let delta = speed - data[i > 0 ? i - 1 : i].speed;
|
|
41
|
+
let deltaMax = this.options.speedDeltaMax;
|
|
42
|
+
if (Math.abs(delta) > deltaMax) {
|
|
43
|
+
speed = data[i - 1].speed + deltaMax * Math.sign(delta);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Range of acceptable speed values.
|
|
48
|
+
speed = _.clamp(speed, this.options.speedRange);
|
|
49
|
+
|
|
50
|
+
if (speed > track.speed_max) track.speed_max = speed;
|
|
51
|
+
if (speed < track.speed_min) track.speed_min = speed;
|
|
52
|
+
|
|
53
|
+
track.speed_avg = (speed + track.speed_avg) / 2.0;
|
|
54
|
+
|
|
55
|
+
return L.Util.formatNum(speed, 2);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
16
59
|
if (this.options.speed && this.options.speed != "summary") {
|
|
17
60
|
|
|
18
61
|
this._registerAxisScale({
|
|
@@ -26,16 +69,16 @@ Elevation.addInitHook(function() {
|
|
|
26
69
|
label : speed.label,
|
|
27
70
|
labelX : 25,
|
|
28
71
|
labelY : -8,
|
|
29
|
-
name : "speed"
|
|
72
|
+
name : "speed",
|
|
30
73
|
});
|
|
31
74
|
|
|
32
75
|
this._registerAreaPath({
|
|
33
|
-
name
|
|
34
|
-
label
|
|
35
|
-
yAttr
|
|
36
|
-
scaleX
|
|
37
|
-
scaleY
|
|
38
|
-
color
|
|
76
|
+
name : 'speed',
|
|
77
|
+
label : 'Speed',
|
|
78
|
+
yAttr : "speed",
|
|
79
|
+
scaleX : 'distance',
|
|
80
|
+
scaleY : 'speed',
|
|
81
|
+
color : '#03ffff',
|
|
39
82
|
strokeColor : '#000',
|
|
40
83
|
strokeOpacity: "0.5",
|
|
41
84
|
fillOpacity : "0.25",
|
|
@@ -43,65 +86,30 @@ Elevation.addInitHook(function() {
|
|
|
43
86
|
|
|
44
87
|
}
|
|
45
88
|
|
|
46
|
-
this.on('elepoint_added', function(e) {
|
|
47
|
-
let data = this._data;
|
|
48
|
-
let i = e.index;
|
|
49
|
-
|
|
50
|
-
let currT = data[i].time;
|
|
51
|
-
let prevT = i > 0 ? data[i - 1].time : currT;
|
|
52
|
-
|
|
53
|
-
let deltaT = currT - prevT;
|
|
54
|
-
|
|
55
|
-
let track = this.track_info;
|
|
56
|
-
let sMax = track.speed_max || -Infinity; // Speed Max
|
|
57
|
-
let sMin = track.speed_min || +Infinity; // Speed Min
|
|
58
|
-
let sAvg = track.speed_avg || 0; // Speed Avg
|
|
59
|
-
let speed = 0;
|
|
60
|
-
|
|
61
|
-
if (deltaT > 0) {
|
|
62
|
-
let delta = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
63
|
-
speed = Math.abs((delta / deltaT) * opts.timeFactor) * opts.speedFactor;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Try to smooth "crazy" speed values.
|
|
67
|
-
if (this.options.speedDeltaMax) {
|
|
68
|
-
let deltaS = i > 0 ? speed - data[i - 1].speed : 0;
|
|
69
|
-
let maxDeltaS = this.options.speedDeltaMax;
|
|
70
|
-
if (Math.abs(deltaS) > maxDeltaS) {
|
|
71
|
-
speed = data[i - 1].speed + maxDeltaS * Math.sign(deltaS);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Range of acceptable speed values.
|
|
76
|
-
speed = _.clamp(speed, this.options.speedRange);
|
|
77
|
-
|
|
78
|
-
track.speed_max = speed > sMax ? speed : sMax;
|
|
79
|
-
track.speed_min = speed < sMin ? speed : sMin;
|
|
80
|
-
track.speed_avg = (speed + sAvg) / 2.0;
|
|
81
|
-
|
|
82
|
-
data[i].speed = L.Util.formatNum(speed, 2);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
89
|
if (this.options.speed) {
|
|
86
90
|
|
|
87
91
|
this._registerTooltip({
|
|
88
92
|
name: 'speed',
|
|
89
93
|
chart: (item) => L._('v: ') + item.speed + " " + speed.label,
|
|
90
94
|
marker: (item) => Math.round(item.speed) + " " + speed.label,
|
|
95
|
+
order: 50,
|
|
91
96
|
});
|
|
92
97
|
|
|
93
98
|
this._registerSummary({
|
|
94
99
|
"minspeed" : {
|
|
95
100
|
label: "Min Speed: ",
|
|
96
|
-
value: (track) => Math.round(track.speed_min || 0) + ' ' + speed.label
|
|
101
|
+
value: (track) => Math.round(track.speed_min || 0) + ' ' + speed.label,
|
|
102
|
+
order: 50
|
|
97
103
|
},
|
|
98
104
|
"maxspeed" : {
|
|
99
105
|
label: "Max Speed: ",
|
|
100
|
-
value: (track) => Math.round(track.speed_max || 0) + ' ' + speed.label
|
|
106
|
+
value: (track) => Math.round(track.speed_max || 0) + ' ' + speed.label,
|
|
107
|
+
order: 50
|
|
101
108
|
},
|
|
102
109
|
"avgspeed": {
|
|
103
110
|
label: "Avg Speed: ",
|
|
104
|
-
value: (track) => Math.round(track.speed_avg || 0) + ' ' + speed.label
|
|
111
|
+
value: (track) => Math.round(track.speed_avg || 0) + ' ' + speed.label,
|
|
112
|
+
order: 50
|
|
105
113
|
}
|
|
106
114
|
});
|
|
107
115
|
|
package/src/summary.js
CHANGED
|
@@ -6,6 +6,7 @@ export var Summary = L.Class.extend({
|
|
|
6
6
|
initialize: function(opts, control) {
|
|
7
7
|
this.options = opts;
|
|
8
8
|
this.control = control;
|
|
9
|
+
this.labels = {};
|
|
9
10
|
|
|
10
11
|
let summary = this._container = _.create("div", "elevation-summary " + (opts.summary ? opts.summary + "-summary" : ''));
|
|
11
12
|
_.style(summary, 'max-width', opts.width ? opts.width + 'px' : '');
|
|
@@ -24,9 +25,19 @@ export var Summary = L.Class.extend({
|
|
|
24
25
|
return this;
|
|
25
26
|
},
|
|
26
27
|
|
|
28
|
+
update: function() {
|
|
29
|
+
Object
|
|
30
|
+
.keys(this.labels)
|
|
31
|
+
.sort((a, b) => this.labels[a].order - this.labels[b].order) // TODO: any performance issues?
|
|
32
|
+
.forEach((i)=> {
|
|
33
|
+
this.append(i, L._(this.labels[i].label), typeof this.labels[i].value !== "function" ? this.labels[i].value : this.labels[i].value(this.control.track_info));
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
|
|
27
37
|
_registerSummary: function(data) {
|
|
28
38
|
for (let i in data) {
|
|
29
|
-
|
|
39
|
+
data[i].order = data[i].order ?? 100;
|
|
40
|
+
this.labels[i] = data[i];
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
|
package/src/time.js
CHANGED
|
@@ -15,7 +15,7 @@ Elevation.addInitHook(function() {
|
|
|
15
15
|
* Common AVG speeds:
|
|
16
16
|
* ----------------------
|
|
17
17
|
* slow walk = 1.8 km/h
|
|
18
|
-
* walking = 3.6 km/h
|
|
18
|
+
* walking = 3.6 km/h <-- default: 3.6
|
|
19
19
|
* running = 10.8 km/h
|
|
20
20
|
* cycling = 18 km/h
|
|
21
21
|
* driving = 72 km/h
|
|
@@ -33,6 +33,42 @@ Elevation.addInitHook(function() {
|
|
|
33
33
|
|
|
34
34
|
opts.xTimeFormat = opts.xTimeFormat || ((t) => _.formatTime(t).split("'")[0]);
|
|
35
35
|
|
|
36
|
+
this._registerDataAttribute({
|
|
37
|
+
name: 'time',
|
|
38
|
+
init: function({ point, props, id }) {
|
|
39
|
+
// "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
|
|
40
|
+
if (props) {
|
|
41
|
+
if("coordTimes" in props) point.meta.time = new Date(Date.parse(props.coordTimes[id]));
|
|
42
|
+
else if("times" in props) point.meta.time = new Date(Date.parse(props.times[id]));
|
|
43
|
+
else if("time" in props) point.meta.time = new Date(Date.parse((typeof props.time === 'object' ? props.time[id] : props.time)));
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
fetch: function(i, point) {
|
|
47
|
+
// Add missing timestamps (see: options.timeAVGSpeed)
|
|
48
|
+
if (!point.meta || !point.meta.time) {
|
|
49
|
+
point.meta = point.meta || {};
|
|
50
|
+
if(i > 0) {
|
|
51
|
+
let dx = (this._data[i].dist - this._data[i - 1].dist);
|
|
52
|
+
let t0 = this._data[i - 1].time.getTime();
|
|
53
|
+
let dt = ( dx / this._timeAVGSpeed) * this.options.timeFactor * 1000;
|
|
54
|
+
point.meta.time = new Date(t0 + dt);
|
|
55
|
+
} else {
|
|
56
|
+
point.meta.time = new Date(Date.now())
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Handle timezone offset
|
|
60
|
+
if (point.meta.time.getTime() - point.meta.time.getTimezoneOffset() * 60 * 1000 === 0) {
|
|
61
|
+
point.meta.time = 0;
|
|
62
|
+
}
|
|
63
|
+
return point.meta.time.getTime();
|
|
64
|
+
},
|
|
65
|
+
update: function(time, i) {
|
|
66
|
+
this.track_info.time = (this.track_info.time || 0) + Math.abs(this._data[i].time - this._data[i > 0 ? i - 1 : i].time);
|
|
67
|
+
this._data[i].duration = this.track_info.time;
|
|
68
|
+
return new Date(time);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
36
72
|
if (opts.time && opts.time != "summary" && !L.Browser.mobile) {
|
|
37
73
|
|
|
38
74
|
this._registerAxisScale({
|
|
@@ -63,60 +99,25 @@ Elevation.addInitHook(function() {
|
|
|
63
99
|
|
|
64
100
|
}
|
|
65
101
|
|
|
66
|
-
this.on('elepoint_added', function(e) {
|
|
67
|
-
let data = this._data;
|
|
68
|
-
let i = e.index;
|
|
69
|
-
|
|
70
|
-
// Add missing timestamps (see: options.timeAVGSpeed)
|
|
71
|
-
if (!e.point.meta || !e.point.meta.time) {
|
|
72
|
-
e.point.meta = e.point.meta || {};
|
|
73
|
-
let delta = (data[i].dist - data[i > 0 ? i - 1 : i].dist);
|
|
74
|
-
let speed = this._timeAVGSpeed;
|
|
75
|
-
e.point.meta.time = new Date(
|
|
76
|
-
(
|
|
77
|
-
i > 0
|
|
78
|
-
? data[i - 1].time.getTime() + ((( delta / speed) * opts.timeFactor) * 1000)
|
|
79
|
-
: Date.now()
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let time = e.point.meta.time;
|
|
85
|
-
|
|
86
|
-
// Handle timezone offset
|
|
87
|
-
if (time.getTime() - time.getTimezoneOffset() * 60 * 1000 === 0) {
|
|
88
|
-
time = 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
let currT = time;
|
|
92
|
-
let prevT = i > 0 ? data[i - 1].time : currT;
|
|
93
|
-
|
|
94
|
-
let deltaT = Math.abs(currT - prevT);
|
|
95
|
-
let duration = (this.track_info.time || 0) + deltaT;
|
|
96
|
-
|
|
97
|
-
this.track_info.time = duration;
|
|
98
|
-
|
|
99
|
-
data[i].time = time;
|
|
100
|
-
data[i].duration = duration;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
|
|
104
102
|
if (this.options.timestamps) {
|
|
105
103
|
this._registerTooltip({
|
|
106
104
|
name: 'date',
|
|
107
|
-
chart: (item) => L._("t: ") + this.options.timeFormat(item.time)
|
|
105
|
+
chart: (item) => L._("t: ") + this.options.timeFormat(item.time),
|
|
106
|
+
order: 20,
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
if (this.options.time) {
|
|
112
111
|
this._registerTooltip({
|
|
113
112
|
name: 'time',
|
|
114
|
-
chart: (item) => L._("T: ") + _.formatTime(item.duration || 0)
|
|
113
|
+
chart: (item) => L._("T: ") + _.formatTime(item.duration || 0),
|
|
114
|
+
order: 20
|
|
115
115
|
});
|
|
116
116
|
this._registerSummary({
|
|
117
117
|
"tottime" : {
|
|
118
118
|
label: "Total Time: ",
|
|
119
|
-
value: (track) => _.formatTime(track.time || 0)
|
|
119
|
+
value: (track) => _.formatTime(track.time || 0),
|
|
120
|
+
order: 20
|
|
120
121
|
}
|
|
121
122
|
});
|
|
122
123
|
}
|