@raruto/leaflet-elevation 1.9.3 → 1.9.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/README.md +5 -4
- package/dist/leaflet-elevation.js +564 -410
- 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 +18 -11
- package/src/control.js +108 -45
- package/src/distance.js +31 -40
- package/src/index.js +1 -1
- 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 +44 -42
package/src/acceleration.js
CHANGED
|
@@ -13,6 +13,48 @@ Elevation.addInitHook(function() {
|
|
|
13
13
|
acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
|
|
14
14
|
opts.accelerationFactor = opts.accelerationFactor || 1;
|
|
15
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
|
+
|
|
16
58
|
if (this.options.acceleration != "summary") {
|
|
17
59
|
|
|
18
60
|
this._registerAxisScale({
|
|
@@ -26,16 +68,16 @@ Elevation.addInitHook(function() {
|
|
|
26
68
|
label : acceleration.label,
|
|
27
69
|
labelX : 25,
|
|
28
70
|
labelY : -8,
|
|
29
|
-
name : 'acceleration'
|
|
71
|
+
name : 'acceleration',
|
|
30
72
|
});
|
|
31
73
|
|
|
32
74
|
this._registerAreaPath({
|
|
33
|
-
name
|
|
34
|
-
label
|
|
35
|
-
yAttr
|
|
36
|
-
scaleX
|
|
37
|
-
scaleY
|
|
38
|
-
color
|
|
75
|
+
name : 'acceleration',
|
|
76
|
+
label : 'Acceleration',
|
|
77
|
+
yAttr : 'acceleration',
|
|
78
|
+
scaleX : 'distance',
|
|
79
|
+
scaleY : 'acceleration',
|
|
80
|
+
color : '#050402',
|
|
39
81
|
strokeColor : '#000',
|
|
40
82
|
strokeOpacity: "0.5",
|
|
41
83
|
fillOpacity : "0.25",
|
|
@@ -43,65 +85,28 @@ Elevation.addInitHook(function() {
|
|
|
43
85
|
|
|
44
86
|
}
|
|
45
87
|
|
|
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) / 1000;
|
|
54
|
-
|
|
55
|
-
let track = this.track_info;
|
|
56
|
-
let sMax = track.acceleration_max || -Infinity; // Acceleration Max
|
|
57
|
-
let sMin = track.acceleration_min || +Infinity; // Acceleration Min
|
|
58
|
-
let sAvg = track.acceleration_avg || 0; // Acceleration Avg
|
|
59
|
-
let acceleration = 0;
|
|
60
|
-
|
|
61
|
-
if (deltaT > 0) {
|
|
62
|
-
let curr = data[i].speed;
|
|
63
|
-
let prev = i > 0 ? data[i - 1].speed : curr;
|
|
64
|
-
let delta = (curr - prev) * (1000 / opts.timeFactor);
|
|
65
|
-
acceleration = Math.abs((delta / deltaT)) * opts.accelerationFactor;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Try to smooth "crazy" acceleration values.
|
|
69
|
-
if (this.options.accelerationDeltaMax) {
|
|
70
|
-
let deltaA = i > 0 ? acceleration - data[i - 1].acceleration : 0;
|
|
71
|
-
let maxDeltaS = this.options.accelerationDeltaMax;
|
|
72
|
-
if (Math.abs(deltaA) > maxDeltaS) {
|
|
73
|
-
acceleration = data[i - 1].acceleration + maxDeltaS * Math.sign(deltaA);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Range of acceptable acceleration values.
|
|
78
|
-
acceleration = _.clamp(acceleration, this.options.accelerationRange);
|
|
79
|
-
|
|
80
|
-
track.acceleration_max = acceleration > sMax ? acceleration : sMax;
|
|
81
|
-
track.acceleration_min = acceleration < sMin ? acceleration : sMin;
|
|
82
|
-
track.acceleration_avg = (acceleration + sAvg) / 2.0;
|
|
83
|
-
|
|
84
|
-
data[i].acceleration = L.Util.formatNum(acceleration, 2);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
88
|
this._registerTooltip({
|
|
88
89
|
name : 'acceleration',
|
|
89
90
|
chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label,
|
|
90
91
|
marker: (item) => Math.round(item.acceleration) + " " + acceleration.label,
|
|
92
|
+
order: 60,
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
this._registerSummary({
|
|
94
96
|
"minacceleration" : {
|
|
95
97
|
label: "Min Acceleration: ",
|
|
96
|
-
value: (track) => Math.round(track.acceleration_min || 0) + ' ' + acceleration.label
|
|
98
|
+
value: (track) => Math.round(track.acceleration_min || 0) + ' ' + acceleration.label,
|
|
99
|
+
order: 60
|
|
97
100
|
},
|
|
98
101
|
"maxacceleration" : {
|
|
99
102
|
label: "Max Acceleration: ",
|
|
100
|
-
value: (track) => Math.round(track.acceleration_max || 0) + ' ' + acceleration.label
|
|
103
|
+
value: (track) => Math.round(track.acceleration_max || 0) + ' ' + acceleration.label,
|
|
104
|
+
order: 60
|
|
101
105
|
},
|
|
102
106
|
"avgacceleration": {
|
|
103
107
|
label: "Avg Acceleration: ",
|
|
104
|
-
value: (track) => Math.round(track.acceleration_avg || 0) + ' ' + acceleration.label
|
|
108
|
+
value: (track) => Math.round(track.acceleration_avg || 0) + ' ' + acceleration.label,
|
|
109
|
+
order: 60
|
|
105
110
|
}
|
|
106
111
|
});
|
|
107
112
|
|
package/src/altitude.js
CHANGED
|
@@ -5,8 +5,11 @@ import { Elevation } from './control';
|
|
|
5
5
|
|
|
6
6
|
Elevation.addInitHook(function() {
|
|
7
7
|
|
|
8
|
-
let opts
|
|
9
|
-
let altitude
|
|
8
|
+
let opts = this.options;
|
|
9
|
+
let altitude = {};
|
|
10
|
+
|
|
11
|
+
let theme = opts.theme.replace('-theme', '');
|
|
12
|
+
let color = D3.Colors[theme] || {};
|
|
10
13
|
|
|
11
14
|
if (opts.imperial) {
|
|
12
15
|
opts.altitudeFactor = this.__footFactor;
|
|
@@ -16,105 +19,101 @@ Elevation.addInitHook(function() {
|
|
|
16
19
|
altitude.label = opts.yLabel;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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);
|
|
40
50
|
}
|
|
41
|
-
if (!isNaN(prevZ)) return data.splice(i - 1, 1);
|
|
42
|
-
data[i - 1].z = prevZ;
|
|
43
51
|
}
|
|
44
|
-
}
|
|
45
|
-
// skip point if it has not elevation
|
|
46
|
-
if (!isNaN(z)) {
|
|
47
|
-
this._lastValidZ = z;
|
|
48
|
-
}
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
// Range of acceptable elevation values.
|
|
54
|
+
z = _.clamp(z, this.options.altitudeRange);
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.on("elechart_axis", function() {
|
|
56
|
+
if (z > track.elevation_max) track.elevation_max = z;
|
|
57
|
+
if (z < track.elevation_min) track.elevation_min = z;
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
axis : "y",
|
|
60
|
-
position : "left",
|
|
61
|
-
scale : this._chart._y,
|
|
62
|
-
});
|
|
59
|
+
track.elevation_avg = (z + track.elevation_avg) / 2.0;
|
|
63
60
|
|
|
61
|
+
return z;
|
|
62
|
+
}
|
|
64
63
|
});
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
labelY : -8,
|
|
77
|
-
name : "altitude",
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
this.on("elechart_init", function() {
|
|
83
|
-
|
|
84
|
-
let theme = this.options.theme.replace('-theme', '');
|
|
85
|
-
let color = D3.Colors[theme] || {};
|
|
86
|
-
|
|
87
|
-
this._chart._registerAreaPath({
|
|
88
|
-
name : 'altitude',
|
|
89
|
-
label : 'Altitude',
|
|
90
|
-
scaleX : 'distance',
|
|
91
|
-
scaleY : 'altitude',
|
|
92
|
-
color : color.area || theme,
|
|
93
|
-
strokeColor : this.options.detached ? color.stroke : '#000',
|
|
94
|
-
strokeOpacity: "1",
|
|
95
|
-
fillOpacity : this.options.detached ? (color.alpha || '0.8') : 1,
|
|
96
|
-
preferCanvas : this.options.preferCanvas,
|
|
97
|
-
});
|
|
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
|
+
});
|
|
98
75
|
|
|
99
|
-
|
|
76
|
+
this._registerAxisGrid({
|
|
77
|
+
axis : "y",
|
|
78
|
+
position : "left",
|
|
79
|
+
scale : "y" // this._chart._y,
|
|
80
|
+
});
|
|
100
81
|
|
|
101
|
-
|
|
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
|
+
});
|
|
102
94
|
|
|
103
95
|
this._registerTooltip({
|
|
104
96
|
name: 'y',
|
|
105
97
|
chart: (item) => L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label,
|
|
106
98
|
marker: (item) => d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label,
|
|
99
|
+
order: 10,
|
|
107
100
|
});
|
|
108
101
|
|
|
109
102
|
this._registerSummary({
|
|
110
103
|
"maxele" : {
|
|
111
104
|
label: "Max Elevation: ",
|
|
112
|
-
value: (track) => (track.elevation_max || 0).toFixed(2) + ' ' + altitude.label
|
|
105
|
+
value: (track) => (track.elevation_max || 0).toFixed(2) + ' ' + altitude.label,
|
|
106
|
+
order: 30,
|
|
113
107
|
},
|
|
114
108
|
"minele" : {
|
|
115
109
|
label: "Min Elevation: ",
|
|
116
|
-
value: (track) => (track.elevation_min || 0).toFixed(2) + ' ' + altitude.label
|
|
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
117
|
},
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
});
|
|
119
|
+
});
|
package/src/chart.js
CHANGED
|
@@ -344,6 +344,9 @@ export var Chart = L.Class.extend({
|
|
|
344
344
|
},
|
|
345
345
|
|
|
346
346
|
_registerAreaPath: function(props) {
|
|
347
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
348
|
+
else if (props.scale == 'x') props.scale = this._x;
|
|
349
|
+
|
|
347
350
|
let opts = this.options;
|
|
348
351
|
|
|
349
352
|
if (!props.xAttr) props.xAttr = opts.xAttr;
|
|
@@ -368,10 +371,16 @@ export var Chart = L.Class.extend({
|
|
|
368
371
|
},
|
|
369
372
|
|
|
370
373
|
_registerAxisGrid: function(props) {
|
|
374
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
375
|
+
else if(props.scale == 'x') props.scale = this._x;
|
|
376
|
+
|
|
371
377
|
this._props.grids[props.name || props.axis] = props;
|
|
372
378
|
},
|
|
373
379
|
|
|
374
380
|
_registerAxisScale: function(props) {
|
|
381
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
382
|
+
else if(props.scale == 'x') props.scale = this._x;
|
|
383
|
+
|
|
375
384
|
let opts = this.options;
|
|
376
385
|
let scale = props.scale;
|
|
377
386
|
|
|
@@ -433,6 +442,7 @@ export var Chart = L.Class.extend({
|
|
|
433
442
|
},
|
|
434
443
|
|
|
435
444
|
_registerTooltip: function(props) {
|
|
445
|
+
props.order = props.order ?? 100;
|
|
436
446
|
this._props.tooltipItems[props.name] = props;
|
|
437
447
|
},
|
|
438
448
|
|
package/src/components.js
CHANGED
|
@@ -150,7 +150,10 @@ export const PositionMarker = ({
|
|
|
150
150
|
|
|
151
151
|
let label;
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
Object
|
|
154
|
+
.keys(labels)
|
|
155
|
+
.sort((a, b) => labels[a].order - labels[b].order) // TODO: any performance issues?
|
|
156
|
+
.forEach((i)=> {
|
|
154
157
|
label = text.select(".height-focus-" + labels[i].name);
|
|
155
158
|
|
|
156
159
|
if (!label.size()) {
|
|
@@ -160,7 +163,8 @@ export const PositionMarker = ({
|
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
163
|
-
|
|
166
|
+
|
|
167
|
+
});
|
|
164
168
|
|
|
165
169
|
text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
|
|
166
170
|
text.selectAll('tspan').attr("x", xCoord + 5);
|
|
@@ -274,17 +278,20 @@ export const Tooltip = ({
|
|
|
274
278
|
|
|
275
279
|
let label;
|
|
276
280
|
|
|
277
|
-
|
|
278
|
-
|
|
281
|
+
Object
|
|
282
|
+
.keys(labels)
|
|
283
|
+
.sort((a, b) => labels[a].order - labels[b].order) // TODO: any performance issues?
|
|
284
|
+
.forEach((i)=> {
|
|
285
|
+
label = text.select(".mouse-focus-label-" + labels[i].name);
|
|
279
286
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
if (!label.size()) {
|
|
288
|
+
label = text.append("svg:tspan", ".mouse-focus-label-x")
|
|
289
|
+
.attr("class", "mouse-focus-label-" + labels[i].name)
|
|
290
|
+
.attr("dy", "1.5em");
|
|
291
|
+
}
|
|
285
292
|
|
|
286
|
-
|
|
287
|
-
|
|
293
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
294
|
+
});
|
|
288
295
|
|
|
289
296
|
text.select('tspan').attr("dy", "1em");
|
|
290
297
|
text.selectAll('tspan').attr("x", xAlign);
|