@raruto/leaflet-elevation 1.9.6 → 2.0.2
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 +7 -5
- package/dist/leaflet-elevation.css +52 -161
- package/dist/leaflet-elevation.js +1550 -3884
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +1 -3
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/checkered.png +0 -0
- package/libs/leaflet-distance-marker.js +97 -92
- package/libs/leaflet-distance-marker.min.js +1 -1
- package/libs/leaflet-gpxgroup.js +2 -2
- package/package.json +9 -11
- package/src/{chart.js → components/chart.js} +147 -144
- package/src/{components.js → components/d3.js} +43 -71
- package/src/{marker.js → components/marker.js} +11 -14
- package/src/{summary.js → components/summary.js} +4 -5
- package/src/control.js +492 -434
- package/src/handlers/acceleration.js +64 -0
- package/src/handlers/altitude.js +79 -0
- package/src/handlers/cadence.js +54 -0
- package/src/handlers/distance.js +45 -0
- package/src/handlers/heart.js +53 -0
- package/src/handlers/slope.js +79 -0
- package/src/handlers/speed.js +66 -0
- package/src/{time.js → handlers/time.js} +31 -54
- package/src/index.css +52 -161
- package/src/index.js +0 -24
- package/src/options.js +20 -28
- package/src/utils.js +74 -102
- package/src/acceleration.js +0 -113
- package/src/altitude.js +0 -119
- package/src/distance.js +0 -69
- package/src/slope.js +0 -129
- package/src/speed.js +0 -118
package/src/acceleration.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import 'leaflet-i18n';
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
4
|
-
import { Elevation } from './control';
|
|
5
|
-
|
|
6
|
-
Elevation.addInitHook(function() {
|
|
7
|
-
|
|
8
|
-
if (!this.options.acceleration) return;
|
|
9
|
-
|
|
10
|
-
let opts = this.options;
|
|
11
|
-
let acceleration = {};
|
|
12
|
-
|
|
13
|
-
acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
|
|
14
|
-
opts.accelerationFactor = opts.accelerationFactor || 1;
|
|
15
|
-
|
|
16
|
-
this._registerDataAttribute({
|
|
17
|
-
name: 'acceleration',
|
|
18
|
-
init: () => {
|
|
19
|
-
// this.track_info.acceleration_max = -Infinity; // Acceleration Max
|
|
20
|
-
// this.track_info.acceleration_min = +Infinity; // Acceleration Min
|
|
21
|
-
// this.track_info.acceleration_avg = 0; // Acceleration Avg
|
|
22
|
-
},
|
|
23
|
-
fetch: (i) => {
|
|
24
|
-
let data = this._data;
|
|
25
|
-
let dv = (data[i].speed - data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor);
|
|
26
|
-
let dt = (data[i].time - data[i > 0 ? i - 1 : i].time) / 1000;
|
|
27
|
-
return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : 0;
|
|
28
|
-
},
|
|
29
|
-
update: (acceleration, i) => {
|
|
30
|
-
this.track_info.acceleration_max = this.track_info.acceleration_max || -Infinity; // Acceleration Max
|
|
31
|
-
this.track_info.acceleration_min = this.track_info.acceleration_min || +Infinity; // Acceleration Min
|
|
32
|
-
this.track_info.acceleration_avg = this.track_info.acceleration_avg || 0; // Acceleration Avg
|
|
33
|
-
|
|
34
|
-
let data = this._data;
|
|
35
|
-
let track = this.track_info;
|
|
36
|
-
|
|
37
|
-
// Try to smooth "crazy" acceleration values.
|
|
38
|
-
if (this.options.accelerationDeltaMax) {
|
|
39
|
-
let delta = acceleration - data[i > 0 ? i - 1 : i].acceleration;
|
|
40
|
-
let deltaMax = this.options.accelerationDeltaMax;
|
|
41
|
-
if (Math.abs(delta) > deltaMax) {
|
|
42
|
-
acceleration = data[i - 1].acceleration + deltaMax * Math.sign(delta);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Range of acceptable acceleration values.
|
|
47
|
-
acceleration = _.clamp(acceleration, this.options.accelerationRange);
|
|
48
|
-
|
|
49
|
-
if (acceleration > track.acceleration_max) track.acceleration_max = acceleration;
|
|
50
|
-
if (acceleration < track.acceleration_min) track.acceleration_min = acceleration;
|
|
51
|
-
|
|
52
|
-
track.acceleration_avg = (acceleration + track.acceleration_avg) / 2.0;
|
|
53
|
-
|
|
54
|
-
return L.Util.formatNum(acceleration, 2);
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (this.options.acceleration != "summary") {
|
|
59
|
-
|
|
60
|
-
this._registerAxisScale({
|
|
61
|
-
axis : "y",
|
|
62
|
-
position : "right",
|
|
63
|
-
scale : {
|
|
64
|
-
min : 0,
|
|
65
|
-
max : +1,
|
|
66
|
-
},
|
|
67
|
-
tickPadding: 16,
|
|
68
|
-
label : acceleration.label,
|
|
69
|
-
labelX : 25,
|
|
70
|
-
labelY : -8,
|
|
71
|
-
name : 'acceleration',
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
this._registerAreaPath({
|
|
75
|
-
name : 'acceleration',
|
|
76
|
-
label : 'Acceleration',
|
|
77
|
-
yAttr : 'acceleration',
|
|
78
|
-
scaleX : 'distance',
|
|
79
|
-
scaleY : 'acceleration',
|
|
80
|
-
color : '#050402',
|
|
81
|
-
strokeColor : '#000',
|
|
82
|
-
strokeOpacity: "0.5",
|
|
83
|
-
fillOpacity : "0.25",
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this._registerTooltip({
|
|
89
|
-
name : 'acceleration',
|
|
90
|
-
chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label,
|
|
91
|
-
marker: (item) => Math.round(item.acceleration) + " " + acceleration.label,
|
|
92
|
-
order: 60,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
this._registerSummary({
|
|
96
|
-
"minacceleration" : {
|
|
97
|
-
label: "Min Acceleration: ",
|
|
98
|
-
value: (track) => Math.round(track.acceleration_min || 0) + ' ' + acceleration.label,
|
|
99
|
-
order: 60
|
|
100
|
-
},
|
|
101
|
-
"maxacceleration" : {
|
|
102
|
-
label: "Max Acceleration: ",
|
|
103
|
-
value: (track) => Math.round(track.acceleration_max || 0) + ' ' + acceleration.label,
|
|
104
|
-
order: 60
|
|
105
|
-
},
|
|
106
|
-
"avgacceleration": {
|
|
107
|
-
label: "Avg Acceleration: ",
|
|
108
|
-
value: (track) => Math.round(track.acceleration_avg || 0) + ' ' + acceleration.label,
|
|
109
|
-
order: 60
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
});
|
package/src/altitude.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import 'leaflet-i18n';
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
4
|
-
import { Elevation } from './control';
|
|
5
|
-
|
|
6
|
-
Elevation.addInitHook(function() {
|
|
7
|
-
|
|
8
|
-
let opts = this.options;
|
|
9
|
-
let altitude = {};
|
|
10
|
-
|
|
11
|
-
let theme = opts.theme.replace('-theme', '');
|
|
12
|
-
let color = D3.Colors[theme] || {};
|
|
13
|
-
|
|
14
|
-
if (opts.imperial) {
|
|
15
|
-
opts.altitudeFactor = this.__footFactor;
|
|
16
|
-
altitude.label = "ft";
|
|
17
|
-
} else {
|
|
18
|
-
opts.altitudeFactor = opts.heightFactor || opts.altitudeFactor || 1;
|
|
19
|
-
altitude.label = opts.yLabel;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this._registerDataAttribute({
|
|
23
|
-
name: 'z',
|
|
24
|
-
skipNull: this.options.skipNullZCoords,
|
|
25
|
-
init: ({point, }) => {
|
|
26
|
-
// "alt" property is generated inside "leaflet"
|
|
27
|
-
if ("alt" in point) point.meta.ele = point.alt;
|
|
28
|
-
|
|
29
|
-
// this.track_info.elevation_max = -Infinity;
|
|
30
|
-
// this.track_info.elevation_min = +Infinity;
|
|
31
|
-
// this.track_info.elevation_avg = 0;
|
|
32
|
-
},
|
|
33
|
-
fetch: (i) => {
|
|
34
|
-
return this._data[i].z * opts.altitudeFactor;
|
|
35
|
-
},
|
|
36
|
-
update: (z, i) => {
|
|
37
|
-
this.track_info.elevation_max = this.track_info.elevation_max || -Infinity;
|
|
38
|
-
this.track_info.elevation_min = this.track_info.elevation_max || +Infinity;
|
|
39
|
-
this.track_info.elevation_avg = this.track_info.elevation_avg || 0;
|
|
40
|
-
|
|
41
|
-
let data = this._data;
|
|
42
|
-
let track = this.track_info;
|
|
43
|
-
|
|
44
|
-
// Try to smooth "crazy" elevation values.
|
|
45
|
-
if (this.options.altitudeDeltaMax) {
|
|
46
|
-
let delta = z - data[i > 0 ? i - 1 : i].z;
|
|
47
|
-
let deltaMax = this.options.altitudeDeltaMax;
|
|
48
|
-
if (Math.abs(delta) > deltaMax) {
|
|
49
|
-
z = data[i - 1].z + deltaMax * Math.sign(delta);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Range of acceptable elevation values.
|
|
54
|
-
z = _.clamp(z, this.options.altitudeRange);
|
|
55
|
-
|
|
56
|
-
if (z > track.elevation_max) track.elevation_max = z;
|
|
57
|
-
if (z < track.elevation_min) track.elevation_min = z;
|
|
58
|
-
|
|
59
|
-
track.elevation_avg = (z + track.elevation_avg) / 2.0;
|
|
60
|
-
|
|
61
|
-
return z;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
this._registerAxisScale({
|
|
66
|
-
axis : "y",
|
|
67
|
-
position: "left",
|
|
68
|
-
scale : "y", // this._chart._y,
|
|
69
|
-
label : altitude.label,
|
|
70
|
-
labelX : -3,
|
|
71
|
-
labelY : -8,
|
|
72
|
-
name : "altitude",
|
|
73
|
-
visbile : this.options.altitude != "summary"
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this._registerAxisGrid({
|
|
77
|
-
axis : "y",
|
|
78
|
-
position : "left",
|
|
79
|
-
scale : "y" // this._chart._y,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
this._registerAreaPath({
|
|
83
|
-
name : 'altitude',
|
|
84
|
-
label : 'Altitude',
|
|
85
|
-
scaleX : 'distance',
|
|
86
|
-
scaleY : 'altitude',
|
|
87
|
-
color : color.area || theme,
|
|
88
|
-
strokeColor : opts.detached ? color.stroke : '#000',
|
|
89
|
-
strokeOpacity: "1",
|
|
90
|
-
fillOpacity : opts.detached ? (color.alpha || '0.8') : 1,
|
|
91
|
-
preferCanvas : opts.preferCanvas,
|
|
92
|
-
visbile : this.options.altitude != "summary"
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
this._registerTooltip({
|
|
96
|
-
name: 'y',
|
|
97
|
-
chart: (item) => L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label,
|
|
98
|
-
marker: (item) => d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label,
|
|
99
|
-
order: 10,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this._registerSummary({
|
|
103
|
-
"maxele" : {
|
|
104
|
-
label: "Max Elevation: ",
|
|
105
|
-
value: (track) => (track.elevation_max || 0).toFixed(2) + ' ' + altitude.label,
|
|
106
|
-
order: 30,
|
|
107
|
-
},
|
|
108
|
-
"minele" : {
|
|
109
|
-
label: "Min Elevation: ",
|
|
110
|
-
value: (track) => (track.elevation_min || 0).toFixed(2) + ' ' + altitude.label,
|
|
111
|
-
order: 30,
|
|
112
|
-
},
|
|
113
|
-
"avgele" : {
|
|
114
|
-
label: "Avg Elevation: ",
|
|
115
|
-
value: (track) => (track.elevation_avg || 0).toFixed(2) + ' ' + altitude.label,
|
|
116
|
-
order: 30,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
});
|
package/src/distance.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import 'leaflet-i18n';
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
4
|
-
import { Elevation } from './control';
|
|
5
|
-
|
|
6
|
-
Elevation.addInitHook(function() {
|
|
7
|
-
|
|
8
|
-
let opts = this.options;
|
|
9
|
-
let distance = {};
|
|
10
|
-
|
|
11
|
-
if (opts.imperial) {
|
|
12
|
-
opts.distanceFactor = this.__mileFactor;
|
|
13
|
-
distance.label = "mi";
|
|
14
|
-
} else {
|
|
15
|
-
opts.distanceFactor = opts.distanceFactor || 1;
|
|
16
|
-
distance.label = opts.xLabel;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
this._registerDataAttribute({
|
|
20
|
-
name: 'dist',
|
|
21
|
-
init: () => {
|
|
22
|
-
// this.track_info.distance = 0;
|
|
23
|
-
},
|
|
24
|
-
fetch: (i) => {
|
|
25
|
-
let delta = this._data[i].latlng.distanceTo(this._data[i > 0 ? i - 1 : i].latlng) * opts.distanceFactor;
|
|
26
|
-
return Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
|
|
27
|
-
},
|
|
28
|
-
update: (distance) => {
|
|
29
|
-
this.track_info.distance = this.track_info.distance || 0;
|
|
30
|
-
this.track_info.distance += distance;
|
|
31
|
-
return this.track_info.distance;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (this.options.distance != "summary") {
|
|
36
|
-
|
|
37
|
-
this._registerAxisScale({
|
|
38
|
-
axis : "x",
|
|
39
|
-
position: "bottom",
|
|
40
|
-
scale : "x", // this._chart._x,
|
|
41
|
-
label : distance.label,
|
|
42
|
-
labelY : 25,
|
|
43
|
-
labelX : () => this._width() + 6,
|
|
44
|
-
name : "distance",
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this._registerAxisGrid({
|
|
50
|
-
axis : "x",
|
|
51
|
-
position : "bottom",
|
|
52
|
-
scale : "x" // this._chart._x,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
this._registerTooltip({
|
|
56
|
-
name: 'x',
|
|
57
|
-
chart: (item) => L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + distance.label,
|
|
58
|
-
order: 20
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this._registerSummary({
|
|
62
|
-
"totlen" : {
|
|
63
|
-
label: "Total Length: ",
|
|
64
|
-
value: (track) => (track.distance || 0).toFixed(2) + ' ' + distance.label,
|
|
65
|
-
order: 10
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
});
|
package/src/slope.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import 'leaflet-i18n';
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
4
|
-
import { Elevation } from './control';
|
|
5
|
-
|
|
6
|
-
Elevation.addInitHook(function() {
|
|
7
|
-
|
|
8
|
-
if (!this.options.slope) return;
|
|
9
|
-
|
|
10
|
-
let opts = this.options;
|
|
11
|
-
let slope = {};
|
|
12
|
-
|
|
13
|
-
slope.label = opts.slopeLabel || '%';
|
|
14
|
-
|
|
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
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
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;
|
|
58
|
-
|
|
59
|
-
track.slope_avg = (slope + track.slope_avg) / 2.0;
|
|
60
|
-
|
|
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"
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
this._registerTooltip({
|
|
94
|
-
name: 'slope',
|
|
95
|
-
chart: (item) => L._("m: ") + item.slope + slope.label,
|
|
96
|
-
marker: (item) => Math.round(item.slope) + slope.label,
|
|
97
|
-
order: 40,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this._registerSummary({
|
|
101
|
-
"ascent" : {
|
|
102
|
-
label: "Total Ascent: ",
|
|
103
|
-
value: (track) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
104
|
-
order: 40
|
|
105
|
-
},
|
|
106
|
-
"descent" : {
|
|
107
|
-
label: "Total Descent: ",
|
|
108
|
-
value: (track) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
|
|
109
|
-
order: 40
|
|
110
|
-
},
|
|
111
|
-
"minslope": {
|
|
112
|
-
label: "Min Slope: ",
|
|
113
|
-
value: (track) => Math.round(track.slope_min || 0) + ' ' + slope.label,
|
|
114
|
-
order: 40
|
|
115
|
-
},
|
|
116
|
-
"maxslope": {
|
|
117
|
-
label: "Max Slope: ",
|
|
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
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
package/src/speed.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import 'leaflet-i18n';
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
4
|
-
import { Elevation } from './control';
|
|
5
|
-
|
|
6
|
-
Elevation.addInitHook(function() {
|
|
7
|
-
|
|
8
|
-
if (!this.options.speed && !this.options.acceleration) return;
|
|
9
|
-
|
|
10
|
-
let opts = this.options;
|
|
11
|
-
let speed = {};
|
|
12
|
-
|
|
13
|
-
speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
|
|
14
|
-
opts.speedFactor = opts.speedFactor || 1;
|
|
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
|
-
|
|
59
|
-
if (this.options.speed && this.options.speed != "summary") {
|
|
60
|
-
|
|
61
|
-
this._registerAxisScale({
|
|
62
|
-
axis : "y",
|
|
63
|
-
position : "right",
|
|
64
|
-
scale : {
|
|
65
|
-
min : 0,
|
|
66
|
-
max : +1,
|
|
67
|
-
},
|
|
68
|
-
tickPadding: 16,
|
|
69
|
-
label : speed.label,
|
|
70
|
-
labelX : 25,
|
|
71
|
-
labelY : -8,
|
|
72
|
-
name : "speed",
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
this._registerAreaPath({
|
|
76
|
-
name : 'speed',
|
|
77
|
-
label : 'Speed',
|
|
78
|
-
yAttr : "speed",
|
|
79
|
-
scaleX : 'distance',
|
|
80
|
-
scaleY : 'speed',
|
|
81
|
-
color : '#03ffff',
|
|
82
|
-
strokeColor : '#000',
|
|
83
|
-
strokeOpacity: "0.5",
|
|
84
|
-
fillOpacity : "0.25",
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (this.options.speed) {
|
|
90
|
-
|
|
91
|
-
this._registerTooltip({
|
|
92
|
-
name: 'speed',
|
|
93
|
-
chart: (item) => L._('v: ') + item.speed + " " + speed.label,
|
|
94
|
-
marker: (item) => Math.round(item.speed) + " " + speed.label,
|
|
95
|
-
order: 50,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
this._registerSummary({
|
|
99
|
-
"minspeed" : {
|
|
100
|
-
label: "Min Speed: ",
|
|
101
|
-
value: (track) => Math.round(track.speed_min || 0) + ' ' + speed.label,
|
|
102
|
-
order: 50
|
|
103
|
-
},
|
|
104
|
-
"maxspeed" : {
|
|
105
|
-
label: "Max Speed: ",
|
|
106
|
-
value: (track) => Math.round(track.speed_max || 0) + ' ' + speed.label,
|
|
107
|
-
order: 50
|
|
108
|
-
},
|
|
109
|
-
"avgspeed": {
|
|
110
|
-
label: "Avg Speed: ",
|
|
111
|
-
value: (track) => Math.round(track.speed_avg || 0) + ' ' + speed.label,
|
|
112
|
-
order: 50
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
});
|