@raruto/leaflet-elevation 2.4.0 → 2.5.1

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.
@@ -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
  }
package/src/utils.js CHANGED
@@ -70,8 +70,8 @@ export function formatTime(t) {
70
70
  ctx.moveTo(0, 0);
71
71
  let p = new Path2D(path.attr('d'));
72
72
 
73
- ctx.strokeStyle = path.attr('stroke');
74
- ctx.fillStyle = path.attr('fill');
73
+ ctx.strokeStyle = path.__strokeStyle || path.attr('stroke');
74
+ ctx.fillStyle = path.__fillStyle || path.attr('fill');
75
75
  ctx.lineWidth = 1.25;
76
76
  ctx.globalCompositeOperation = 'source-over';
77
77