@raruto/leaflet-elevation 2.2.3 → 2.2.6
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/LICENSE +674 -674
- package/README.md +291 -285
- package/dist/leaflet-elevation.css +337 -337
- package/dist/leaflet-elevation.js +1586 -1580
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/elevation-position.svg +1 -1
- package/images/elevation-pushpin.svg +1 -1
- package/images/elevation.svg +1 -1
- package/libs/leaflet-distance-marker.css +8 -8
- package/libs/leaflet-distance-marker.js +314 -314
- package/package.json +71 -71
- package/src/components/chart.js +783 -783
- package/src/components/d3.js +641 -641
- package/src/components/marker.js +96 -96
- package/src/components/summary.js +43 -43
- package/src/control.js +1313 -1307
- package/src/handlers/acceleration.js +64 -64
- package/src/handlers/altitude.js +79 -79
- package/src/handlers/distance.js +46 -45
- package/src/handlers/heart.js +52 -52
- package/src/handlers/pace.js +65 -65
- package/src/handlers/slope.js +79 -79
- package/src/handlers/speed.js +66 -66
- package/src/handlers/time.js +102 -102
- package/src/index.css +329 -329
- package/src/index.js +42 -42
- package/src/options.js +85 -85
- package/src/utils.js +158 -158
package/src/handlers/slope.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
export function Slope() {
|
|
2
|
-
|
|
3
|
-
const _ = L.Control.Elevation.Utils;
|
|
4
|
-
|
|
5
|
-
let opts = this.options;
|
|
6
|
-
let slope = {};
|
|
7
|
-
|
|
8
|
-
slope.label = opts.slopeLabel || '%';
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
name: 'slope',
|
|
12
|
-
meta: 'slope',
|
|
13
|
-
unit: slope.label,
|
|
14
|
-
deltaMax: this.options.slopedDeltaMax,
|
|
15
|
-
clampRange: this.options.slopeRange,
|
|
16
|
-
decimals: 2,
|
|
17
|
-
pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100;
|
|
18
|
-
let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
19
|
-
let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
|
|
20
|
-
return (!isNaN(dy) && dx !== 0) ? (dy / dx) * 100 : 0;
|
|
21
|
-
},
|
|
22
|
-
onPointAdded: (_, i) => {
|
|
23
|
-
let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
|
|
24
|
-
if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
|
|
25
|
-
else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
|
|
26
|
-
},
|
|
27
|
-
stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, },
|
|
28
|
-
scale: {
|
|
29
|
-
axis : "y",
|
|
30
|
-
position : "right",
|
|
31
|
-
scale : { min: -1, max: +1 },
|
|
32
|
-
tickPadding: 16,
|
|
33
|
-
labelX : 25,
|
|
34
|
-
labelY : -8,
|
|
35
|
-
},
|
|
36
|
-
path: {
|
|
37
|
-
label : 'Slope',
|
|
38
|
-
yAttr : 'slope',
|
|
39
|
-
scaleX : 'distance',
|
|
40
|
-
scaleY : 'slope',
|
|
41
|
-
color : '#F00',
|
|
42
|
-
strokeColor : '#000',
|
|
43
|
-
strokeOpacity: "0.5",
|
|
44
|
-
fillOpacity : "0.25",
|
|
45
|
-
},
|
|
46
|
-
tooltip: {
|
|
47
|
-
chart: (item) => L._("m: ") + item.slope + slope.label,
|
|
48
|
-
marker: (item) => Math.round(item.slope) + slope.label,
|
|
49
|
-
order: 40,
|
|
50
|
-
},
|
|
51
|
-
summary: {
|
|
52
|
-
"minslope": {
|
|
53
|
-
label: "Min Slope: ",
|
|
54
|
-
value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit,
|
|
55
|
-
order: 40
|
|
56
|
-
},
|
|
57
|
-
"maxslope": {
|
|
58
|
-
label: "Max Slope: ",
|
|
59
|
-
value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit,
|
|
60
|
-
order: 41
|
|
61
|
-
},
|
|
62
|
-
"avgslope": {
|
|
63
|
-
label: "Avg Slope: ",
|
|
64
|
-
value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit,
|
|
65
|
-
order: 42
|
|
66
|
-
},
|
|
67
|
-
"ascent" : {
|
|
68
|
-
label: "Total Ascent: ",
|
|
69
|
-
value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
70
|
-
order: 43
|
|
71
|
-
},
|
|
72
|
-
"descent" : {
|
|
73
|
-
label: "Total Descent: ",
|
|
74
|
-
value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
75
|
-
order: 45
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
1
|
+
export function Slope() {
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
let opts = this.options;
|
|
6
|
+
let slope = {};
|
|
7
|
+
|
|
8
|
+
slope.label = opts.slopeLabel || '%';
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
name: 'slope',
|
|
12
|
+
meta: 'slope',
|
|
13
|
+
unit: slope.label,
|
|
14
|
+
deltaMax: this.options.slopedDeltaMax,
|
|
15
|
+
clampRange: this.options.slopeRange,
|
|
16
|
+
decimals: 2,
|
|
17
|
+
pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100;
|
|
18
|
+
let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
19
|
+
let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
|
|
20
|
+
return (!isNaN(dy) && dx !== 0) ? (dy / dx) * 100 : 0;
|
|
21
|
+
},
|
|
22
|
+
onPointAdded: (_, i) => {
|
|
23
|
+
let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
|
|
24
|
+
if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
|
|
25
|
+
else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
|
|
26
|
+
},
|
|
27
|
+
stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, },
|
|
28
|
+
scale: {
|
|
29
|
+
axis : "y",
|
|
30
|
+
position : "right",
|
|
31
|
+
scale : { min: -1, max: +1 },
|
|
32
|
+
tickPadding: 16,
|
|
33
|
+
labelX : 25,
|
|
34
|
+
labelY : -8,
|
|
35
|
+
},
|
|
36
|
+
path: {
|
|
37
|
+
label : 'Slope',
|
|
38
|
+
yAttr : 'slope',
|
|
39
|
+
scaleX : 'distance',
|
|
40
|
+
scaleY : 'slope',
|
|
41
|
+
color : '#F00',
|
|
42
|
+
strokeColor : '#000',
|
|
43
|
+
strokeOpacity: "0.5",
|
|
44
|
+
fillOpacity : "0.25",
|
|
45
|
+
},
|
|
46
|
+
tooltip: {
|
|
47
|
+
chart: (item) => L._("m: ") + item.slope + slope.label,
|
|
48
|
+
marker: (item) => Math.round(item.slope) + slope.label,
|
|
49
|
+
order: 40,
|
|
50
|
+
},
|
|
51
|
+
summary: {
|
|
52
|
+
"minslope": {
|
|
53
|
+
label: "Min Slope: ",
|
|
54
|
+
value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit,
|
|
55
|
+
order: 40
|
|
56
|
+
},
|
|
57
|
+
"maxslope": {
|
|
58
|
+
label: "Max Slope: ",
|
|
59
|
+
value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit,
|
|
60
|
+
order: 41
|
|
61
|
+
},
|
|
62
|
+
"avgslope": {
|
|
63
|
+
label: "Avg Slope: ",
|
|
64
|
+
value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit,
|
|
65
|
+
order: 42
|
|
66
|
+
},
|
|
67
|
+
"ascent" : {
|
|
68
|
+
label: "Total Ascent: ",
|
|
69
|
+
value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
70
|
+
order: 43
|
|
71
|
+
},
|
|
72
|
+
"descent" : {
|
|
73
|
+
label: "Total Descent: ",
|
|
74
|
+
value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
75
|
+
order: 45
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
package/src/handlers/speed.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
export function Speed() {
|
|
2
|
-
|
|
3
|
-
const _ = L.Control.Elevation.Utils;
|
|
4
|
-
|
|
5
|
-
let opts = this.options;
|
|
6
|
-
let speed = {};
|
|
7
|
-
|
|
8
|
-
speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
|
|
9
|
-
opts.speedFactor = opts.speedFactor || 1;
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
name: 'speed',
|
|
13
|
-
required: (this.options.acceleration),
|
|
14
|
-
unit: speed.label,
|
|
15
|
-
deltaMax: this.options.speedDeltaMax,
|
|
16
|
-
clampRange: this.options.speedRange,
|
|
17
|
-
decimals: 2,
|
|
18
|
-
pointToAttr: (_, i) => {
|
|
19
|
-
let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
20
|
-
let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
|
|
21
|
-
return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : 0;
|
|
22
|
-
},
|
|
23
|
-
stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
|
|
24
|
-
scale : (this.options.speed && this.options.speed != "summary") && {
|
|
25
|
-
axis : "y",
|
|
26
|
-
position : "right",
|
|
27
|
-
scale : { min : 0, max : +1 },
|
|
28
|
-
tickPadding: 16,
|
|
29
|
-
labelX : 25,
|
|
30
|
-
labelY : -8,
|
|
31
|
-
},
|
|
32
|
-
path: (this.options.speed && this.options.speed != "summary") && {
|
|
33
|
-
// name : 'speed',
|
|
34
|
-
label : 'Speed',
|
|
35
|
-
yAttr : "speed",
|
|
36
|
-
scaleX : 'distance',
|
|
37
|
-
scaleY : 'speed',
|
|
38
|
-
color : '#03ffff',
|
|
39
|
-
strokeColor : '#000',
|
|
40
|
-
strokeOpacity: "0.5",
|
|
41
|
-
fillOpacity : "0.25",
|
|
42
|
-
},
|
|
43
|
-
tooltip: (this.options.speed) && {
|
|
44
|
-
chart: (item) => L._('v: ') + item.speed + " " + speed.label,
|
|
45
|
-
marker: (item) => Math.round(item.speed) + " " + speed.label,
|
|
46
|
-
order: 50,
|
|
47
|
-
},
|
|
48
|
-
summary: (this.options.speed) && {
|
|
49
|
-
"minspeed" : {
|
|
50
|
-
label: "Min Speed: ",
|
|
51
|
-
value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit,
|
|
52
|
-
order: 51
|
|
53
|
-
},
|
|
54
|
-
"maxspeed" : {
|
|
55
|
-
label: "Max Speed: ",
|
|
56
|
-
value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit,
|
|
57
|
-
order: 51
|
|
58
|
-
},
|
|
59
|
-
"avgspeed": {
|
|
60
|
-
label: "Avg Speed: ",
|
|
61
|
-
value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit,
|
|
62
|
-
order: 52
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
1
|
+
export function Speed() {
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
let opts = this.options;
|
|
6
|
+
let speed = {};
|
|
7
|
+
|
|
8
|
+
speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
|
|
9
|
+
opts.speedFactor = opts.speedFactor || 1;
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: 'speed',
|
|
13
|
+
required: (this.options.acceleration),
|
|
14
|
+
unit: speed.label,
|
|
15
|
+
deltaMax: this.options.speedDeltaMax,
|
|
16
|
+
clampRange: this.options.speedRange,
|
|
17
|
+
decimals: 2,
|
|
18
|
+
pointToAttr: (_, i) => {
|
|
19
|
+
let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
20
|
+
let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
|
|
21
|
+
return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : 0;
|
|
22
|
+
},
|
|
23
|
+
stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
|
|
24
|
+
scale : (this.options.speed && this.options.speed != "summary") && {
|
|
25
|
+
axis : "y",
|
|
26
|
+
position : "right",
|
|
27
|
+
scale : { min : 0, max : +1 },
|
|
28
|
+
tickPadding: 16,
|
|
29
|
+
labelX : 25,
|
|
30
|
+
labelY : -8,
|
|
31
|
+
},
|
|
32
|
+
path: (this.options.speed && this.options.speed != "summary") && {
|
|
33
|
+
// name : 'speed',
|
|
34
|
+
label : 'Speed',
|
|
35
|
+
yAttr : "speed",
|
|
36
|
+
scaleX : 'distance',
|
|
37
|
+
scaleY : 'speed',
|
|
38
|
+
color : '#03ffff',
|
|
39
|
+
strokeColor : '#000',
|
|
40
|
+
strokeOpacity: "0.5",
|
|
41
|
+
fillOpacity : "0.25",
|
|
42
|
+
},
|
|
43
|
+
tooltip: (this.options.speed) && {
|
|
44
|
+
chart: (item) => L._('v: ') + item.speed + " " + speed.label,
|
|
45
|
+
marker: (item) => Math.round(item.speed) + " " + speed.label,
|
|
46
|
+
order: 50,
|
|
47
|
+
},
|
|
48
|
+
summary: (this.options.speed) && {
|
|
49
|
+
"minspeed" : {
|
|
50
|
+
label: "Min Speed: ",
|
|
51
|
+
value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit,
|
|
52
|
+
order: 51
|
|
53
|
+
},
|
|
54
|
+
"maxspeed" : {
|
|
55
|
+
label: "Max Speed: ",
|
|
56
|
+
value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit,
|
|
57
|
+
order: 51
|
|
58
|
+
},
|
|
59
|
+
"avgspeed": {
|
|
60
|
+
label: "Avg Speed: ",
|
|
61
|
+
value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit,
|
|
62
|
+
order: 52
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/handlers/time.js
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
export function Time() {
|
|
2
|
-
|
|
3
|
-
const _ = L.Control.Elevation.Utils;
|
|
4
|
-
|
|
5
|
-
let opts = this.options;
|
|
6
|
-
let time = {};
|
|
7
|
-
|
|
8
|
-
time.label = opts.timeLabel || 't';
|
|
9
|
-
opts.timeFactor = opts.timeFactor || 3600;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Common AVG speeds:
|
|
13
|
-
* ----------------------
|
|
14
|
-
* slow walk = 1.8 km/h
|
|
15
|
-
* walking = 3.6 km/h <-- default: 3.6
|
|
16
|
-
* running = 10.8 km/h
|
|
17
|
-
* cycling = 18 km/h
|
|
18
|
-
* driving = 72 km/h
|
|
19
|
-
* ----------------------
|
|
20
|
-
*/
|
|
21
|
-
this._timeAVGSpeed = (opts.timeAVGSpeed || 3.6) * (opts.speedFactor || 1);
|
|
22
|
-
|
|
23
|
-
if (!opts.timeFormat) {
|
|
24
|
-
opts.timeFormat = (time) => (new Date(time)).toLocaleString().replaceAll('/', '-').replaceAll(',', ' ');
|
|
25
|
-
} else if (opts.timeFormat == 'time') {
|
|
26
|
-
opts.timeFormat = (time) => (new Date(time)).toLocaleTimeString();
|
|
27
|
-
} else if (opts.timeFormat == 'date') {
|
|
28
|
-
opts.timeFormat = (time) => (new Date(time)).toLocaleDateString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
opts.xTimeFormat = opts.xTimeFormat || ((t) => _.formatTime(t).split("'")[0]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
name: 'time',
|
|
35
|
-
required: (this.options.speed || this.options.acceleration || this.options.timestamps),
|
|
36
|
-
coordinateProperties: ["coordTimes", "times", "time"],
|
|
37
|
-
coordPropsToMeta: _.parseDate,
|
|
38
|
-
pointToAttr: function(point, i) {
|
|
39
|
-
// Add missing timestamps (see: options.timeAVGSpeed)
|
|
40
|
-
if (!point.meta || !point.meta.time) {
|
|
41
|
-
point.meta = point.meta || {};
|
|
42
|
-
if(i > 0) {
|
|
43
|
-
let dx = (this._data[i].dist - this._data[i - 1].dist);
|
|
44
|
-
let t0 = this._data[i - 1].time.getTime();
|
|
45
|
-
point.meta.time = new Date(t0 + ( dx / this._timeAVGSpeed) * this.options.timeFactor * 1000);
|
|
46
|
-
} else {
|
|
47
|
-
point.meta.time = new Date(Date.now())
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Handle timezone offset
|
|
51
|
-
let time = (point.meta.time.getTime() - point.meta.time.getTimezoneOffset() * 60 * 1000 !== 0) ? point.meta.time : 0;
|
|
52
|
-
// Update duration
|
|
53
|
-
this._data[i].duration = i > 0 ? (this._data[i - 1].duration || 0) + Math.abs(time - this._data[i - 1].time) : 0;
|
|
54
|
-
return time;
|
|
55
|
-
},
|
|
56
|
-
onPointAdded: (_, i) => this.track_info.time = this._data[i].duration,
|
|
57
|
-
scale: (opts.time && opts.time != "summary" && !L.Browser.mobile) && {
|
|
58
|
-
axis : "x",
|
|
59
|
-
position : "top",
|
|
60
|
-
scale : {
|
|
61
|
-
attr : "duration",
|
|
62
|
-
min : 0,
|
|
63
|
-
},
|
|
64
|
-
label : time.label,
|
|
65
|
-
labelY : -10,
|
|
66
|
-
labelX : () => this._width(),
|
|
67
|
-
name : "time",
|
|
68
|
-
ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]),
|
|
69
|
-
tickFormat : (d) => (d == 0 ? '' : opts.xTimeFormat(d)),
|
|
70
|
-
onAxisMount: axis => {
|
|
71
|
-
axis.select(".domain")
|
|
72
|
-
.remove();
|
|
73
|
-
axis.selectAll("text")
|
|
74
|
-
.attr('opacity', 0.65)
|
|
75
|
-
.style('font-family', 'Monospace')
|
|
76
|
-
.style('font-size', '110%');
|
|
77
|
-
axis.selectAll(".tick line")
|
|
78
|
-
.attr('y2', this._height())
|
|
79
|
-
.attr('stroke-dasharray', 2)
|
|
80
|
-
.attr('opacity', 0.75);
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
tooltips: [
|
|
84
|
-
(this.options.time) && {
|
|
85
|
-
name: 'time',
|
|
86
|
-
chart: (item) => L._("T: ") + _.formatTime(item.duration || 0),
|
|
87
|
-
order: 20
|
|
88
|
-
},
|
|
89
|
-
(this.options.timestamps) && {
|
|
90
|
-
name: 'date',
|
|
91
|
-
chart: (item) => L._("t: ") + this.options.timeFormat(item.time),
|
|
92
|
-
order: 21,
|
|
93
|
-
}
|
|
94
|
-
],
|
|
95
|
-
summary: (this.options.time) && {
|
|
96
|
-
"tottime" : {
|
|
97
|
-
label: "Total Time: ",
|
|
98
|
-
value: (track) => _.formatTime(track.time || 0),
|
|
99
|
-
order: 20
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
1
|
+
export function Time() {
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
let opts = this.options;
|
|
6
|
+
let time = {};
|
|
7
|
+
|
|
8
|
+
time.label = opts.timeLabel || 't';
|
|
9
|
+
opts.timeFactor = opts.timeFactor || 3600;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Common AVG speeds:
|
|
13
|
+
* ----------------------
|
|
14
|
+
* slow walk = 1.8 km/h
|
|
15
|
+
* walking = 3.6 km/h <-- default: 3.6
|
|
16
|
+
* running = 10.8 km/h
|
|
17
|
+
* cycling = 18 km/h
|
|
18
|
+
* driving = 72 km/h
|
|
19
|
+
* ----------------------
|
|
20
|
+
*/
|
|
21
|
+
this._timeAVGSpeed = (opts.timeAVGSpeed || 3.6) * (opts.speedFactor || 1);
|
|
22
|
+
|
|
23
|
+
if (!opts.timeFormat) {
|
|
24
|
+
opts.timeFormat = (time) => (new Date(time)).toLocaleString().replaceAll('/', '-').replaceAll(',', ' ');
|
|
25
|
+
} else if (opts.timeFormat == 'time') {
|
|
26
|
+
opts.timeFormat = (time) => (new Date(time)).toLocaleTimeString();
|
|
27
|
+
} else if (opts.timeFormat == 'date') {
|
|
28
|
+
opts.timeFormat = (time) => (new Date(time)).toLocaleDateString();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
opts.xTimeFormat = opts.xTimeFormat || ((t) => _.formatTime(t).split("'")[0]);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: 'time',
|
|
35
|
+
required: (this.options.speed || this.options.acceleration || this.options.timestamps),
|
|
36
|
+
coordinateProperties: ["coordTimes", "times", "time"],
|
|
37
|
+
coordPropsToMeta: _.parseDate,
|
|
38
|
+
pointToAttr: function(point, i) {
|
|
39
|
+
// Add missing timestamps (see: options.timeAVGSpeed)
|
|
40
|
+
if (!point.meta || !point.meta.time) {
|
|
41
|
+
point.meta = point.meta || {};
|
|
42
|
+
if(i > 0) {
|
|
43
|
+
let dx = (this._data[i].dist - this._data[i - 1].dist);
|
|
44
|
+
let t0 = this._data[i - 1].time.getTime();
|
|
45
|
+
point.meta.time = new Date(t0 + ( dx / this._timeAVGSpeed) * this.options.timeFactor * 1000);
|
|
46
|
+
} else {
|
|
47
|
+
point.meta.time = new Date(Date.now())
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Handle timezone offset
|
|
51
|
+
let time = (point.meta.time.getTime() - point.meta.time.getTimezoneOffset() * 60 * 1000 !== 0) ? point.meta.time : 0;
|
|
52
|
+
// Update duration
|
|
53
|
+
this._data[i].duration = i > 0 ? (this._data[i - 1].duration || 0) + Math.abs(time - this._data[i - 1].time) : 0;
|
|
54
|
+
return time;
|
|
55
|
+
},
|
|
56
|
+
onPointAdded: (_, i) => this.track_info.time = this._data[i].duration,
|
|
57
|
+
scale: (opts.time && opts.time != "summary" && !L.Browser.mobile) && {
|
|
58
|
+
axis : "x",
|
|
59
|
+
position : "top",
|
|
60
|
+
scale : {
|
|
61
|
+
attr : "duration",
|
|
62
|
+
min : 0,
|
|
63
|
+
},
|
|
64
|
+
label : time.label,
|
|
65
|
+
labelY : -10,
|
|
66
|
+
labelX : () => this._width(),
|
|
67
|
+
name : "time",
|
|
68
|
+
ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]),
|
|
69
|
+
tickFormat : (d) => (d == 0 ? '' : opts.xTimeFormat(d)),
|
|
70
|
+
onAxisMount: axis => {
|
|
71
|
+
axis.select(".domain")
|
|
72
|
+
.remove();
|
|
73
|
+
axis.selectAll("text")
|
|
74
|
+
.attr('opacity', 0.65)
|
|
75
|
+
.style('font-family', 'Monospace')
|
|
76
|
+
.style('font-size', '110%');
|
|
77
|
+
axis.selectAll(".tick line")
|
|
78
|
+
.attr('y2', this._height())
|
|
79
|
+
.attr('stroke-dasharray', 2)
|
|
80
|
+
.attr('opacity', 0.75);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
tooltips: [
|
|
84
|
+
(this.options.time) && {
|
|
85
|
+
name: 'time',
|
|
86
|
+
chart: (item) => L._("T: ") + _.formatTime(item.duration || 0),
|
|
87
|
+
order: 20
|
|
88
|
+
},
|
|
89
|
+
(this.options.timestamps) && {
|
|
90
|
+
name: 'date',
|
|
91
|
+
chart: (item) => L._("t: ") + this.options.timeFormat(item.time),
|
|
92
|
+
order: 21,
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
summary: (this.options.time) && {
|
|
96
|
+
"tottime" : {
|
|
97
|
+
label: "Total Time: ",
|
|
98
|
+
value: (track) => _.formatTime(track.time || 0),
|
|
99
|
+
order: 20
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
103
|
}
|