@raruto/leaflet-elevation 1.7.5 → 1.7.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 -2
- package/dist/leaflet-elevation.js +160 -134
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +3 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/package.json +1 -1
- package/src/acceleration.js +1 -1
- package/src/altitude.js +6 -0
- package/src/chart.js +3 -24
- package/src/components.js +35 -23
- package/src/control.js +5 -3
- package/src/distance.js +5 -0
- package/src/index.js +12 -1
- package/src/marker.js +3 -20
- package/src/options.js +1 -0
- package/src/slope.js +1 -1
- package/src/speed.js +2 -2
- package/src/time.js +9 -4
package/package.json
CHANGED
package/src/acceleration.js
CHANGED
|
@@ -96,7 +96,7 @@ Elevation.addInitHook(function() {
|
|
|
96
96
|
|
|
97
97
|
this._registerFocusLabel({
|
|
98
98
|
name : 'acceleration',
|
|
99
|
-
chart
|
|
99
|
+
chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label,
|
|
100
100
|
marker: (item) => Math.round(item.acceleration) + " " + acceleration.label,
|
|
101
101
|
});
|
|
102
102
|
|
package/src/altitude.js
CHANGED
|
@@ -107,6 +107,12 @@ Elevation.addInitHook(function() {
|
|
|
107
107
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
this._registerFocusLabel({
|
|
111
|
+
name: 'y',
|
|
112
|
+
chart: (item) => L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + this._yLabel,
|
|
113
|
+
marker: (item) => d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + this._yLabel,
|
|
114
|
+
});
|
|
115
|
+
|
|
110
116
|
this._registerSummary({
|
|
111
117
|
"maxele" : {
|
|
112
118
|
label: "Max Elevation: ",
|
package/src/chart.js
CHANGED
|
@@ -783,38 +783,17 @@ export var Chart = L.Class.extend({
|
|
|
783
783
|
height: this._height()
|
|
784
784
|
})
|
|
785
785
|
);
|
|
786
|
+
|
|
786
787
|
this._focuslabel.call(
|
|
787
788
|
D3.MouseFocusLabel({
|
|
788
789
|
xCoord: xCoordinate,
|
|
789
790
|
yCoord: yCoordinate,
|
|
790
791
|
height: this._height(),
|
|
791
792
|
width : this._width(),
|
|
792
|
-
|
|
793
|
-
|
|
793
|
+
labels: this._props.focusLabels,
|
|
794
|
+
item: item
|
|
794
795
|
})
|
|
795
796
|
);
|
|
796
|
-
|
|
797
|
-
// this._focuslabel.selectAll('tspan').data(Object.values(this._focuslabels));
|
|
798
|
-
|
|
799
|
-
let labels = this._props.focusLabels;
|
|
800
|
-
let tooltip = this._focuslabel.select('text');
|
|
801
|
-
let label;
|
|
802
|
-
|
|
803
|
-
for (var i in labels) {
|
|
804
|
-
label = tooltip.select(".mouse-focus-label-" + labels[i].name);
|
|
805
|
-
|
|
806
|
-
if (!label.size()) {
|
|
807
|
-
label = tooltip.append("svg:tspan", ".mouse-focus-label-x")
|
|
808
|
-
.attr("class", "mouse-focus-label-" + labels[i].name)
|
|
809
|
-
.attr("dy", "1.5em");
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item) );
|
|
813
|
-
|
|
814
|
-
this._focuslabel.select('.mouse-focus-label-x')
|
|
815
|
-
.attr("dy", "1.5em");
|
|
816
|
-
}
|
|
817
|
-
|
|
818
797
|
},
|
|
819
798
|
|
|
820
799
|
_hideDiagramIndicator: function() {
|
package/src/components.js
CHANGED
|
@@ -124,7 +124,8 @@ export const HeightFocusLabel = ({
|
|
|
124
124
|
theme,
|
|
125
125
|
xCoord = 0,
|
|
126
126
|
yCoord = 0,
|
|
127
|
-
|
|
127
|
+
labels = {},
|
|
128
|
+
item = {}
|
|
128
129
|
}) => {
|
|
129
130
|
return text => {
|
|
130
131
|
text
|
|
@@ -133,13 +134,21 @@ export const HeightFocusLabel = ({
|
|
|
133
134
|
.attr("x", xCoord + 5)
|
|
134
135
|
.attr("y", yCoord);
|
|
135
136
|
|
|
136
|
-
let
|
|
137
|
-
|
|
137
|
+
let label;
|
|
138
|
+
|
|
139
|
+
for (var i in labels) {
|
|
140
|
+
label = text.select(".height-focus-" + labels[i].name);
|
|
141
|
+
|
|
142
|
+
if (!label.size()) {
|
|
143
|
+
label = text.append("svg:tspan")
|
|
144
|
+
.attr("class", "height-focus-" + labels[i].name)
|
|
145
|
+
.attr("dy", "1.5em");
|
|
146
|
+
}
|
|
138
147
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.text(label);
|
|
148
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
149
|
+
}
|
|
142
150
|
|
|
151
|
+
text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
|
|
143
152
|
text.selectAll('tspan').attr("x", xCoord + 5);
|
|
144
153
|
|
|
145
154
|
return text;
|
|
@@ -222,9 +231,9 @@ export const MouseFocusLine = ({
|
|
|
222
231
|
export const MouseFocusLabel = ({
|
|
223
232
|
xCoord,
|
|
224
233
|
yCoord,
|
|
225
|
-
labelX = "",
|
|
226
|
-
labelY = "",
|
|
227
234
|
width,
|
|
235
|
+
labels = {},
|
|
236
|
+
item = {},
|
|
228
237
|
}) => {
|
|
229
238
|
return g => {
|
|
230
239
|
|
|
@@ -232,16 +241,9 @@ export const MouseFocusLabel = ({
|
|
|
232
241
|
|
|
233
242
|
let rect = g.select(".mouse-focus-label-rect");
|
|
234
243
|
let text = g.select(".mouse-focus-label-text");
|
|
235
|
-
let y = text.select(".mouse-focus-label-y");
|
|
236
|
-
let x = text.select(".mouse-focus-label-x");
|
|
237
244
|
|
|
238
245
|
if (!rect.node()) rect = g.append("svg:rect");
|
|
239
246
|
if (!text.node()) text = g.append("svg:text");
|
|
240
|
-
if (!y.node()) y = text.append("svg:tspan");
|
|
241
|
-
if (!x.node()) x = text.append("svg:tspan");
|
|
242
|
-
|
|
243
|
-
y.text(labelY);
|
|
244
|
-
x.text(labelX);
|
|
245
247
|
|
|
246
248
|
// Sets focus-label-text position to the left / right of the mouse-focus-line
|
|
247
249
|
let xAlign = 0;
|
|
@@ -264,13 +266,22 @@ export const MouseFocusLabel = ({
|
|
|
264
266
|
.attr("class", "mouse-focus-label-text")
|
|
265
267
|
.style("font-weight", "700")
|
|
266
268
|
.attr("y", yAlign);
|
|
267
|
-
y
|
|
268
|
-
.attr("class", "mouse-focus-label-y")
|
|
269
|
-
.attr("dy", "1em");
|
|
270
|
-
x
|
|
271
|
-
.attr("class", "mouse-focus-label-x")
|
|
272
|
-
.attr("dy", "2em");
|
|
273
269
|
|
|
270
|
+
let label;
|
|
271
|
+
|
|
272
|
+
for (var i in labels) {
|
|
273
|
+
label = text.select(".mouse-focus-label-" + labels[i].name);
|
|
274
|
+
|
|
275
|
+
if (!label.size()) {
|
|
276
|
+
label = text.append("svg:tspan", ".mouse-focus-label-x")
|
|
277
|
+
.attr("class", "mouse-focus-label-" + labels[i].name)
|
|
278
|
+
.attr("dy", "1.5em");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
text.select('tspan').attr("dy", "1em");
|
|
274
285
|
text.selectAll('tspan').attr("x", xAlign);
|
|
275
286
|
|
|
276
287
|
return g;
|
|
@@ -460,8 +471,9 @@ export const Chart = ({
|
|
|
460
471
|
yCoord: 0,
|
|
461
472
|
height: _height,
|
|
462
473
|
width : _width,
|
|
463
|
-
|
|
464
|
-
|
|
474
|
+
labels: {}
|
|
475
|
+
// labelX: "",
|
|
476
|
+
// labelY: "",
|
|
465
477
|
})
|
|
466
478
|
);
|
|
467
479
|
|
package/src/control.js
CHANGED
|
@@ -17,7 +17,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
17
17
|
__TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
|
|
18
18
|
__LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
|
|
19
19
|
__LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
|
|
20
|
-
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.
|
|
20
|
+
__LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.6/libs/leaflet-distance-marker.min.js',
|
|
21
21
|
|
|
22
22
|
/*
|
|
23
23
|
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
|
|
@@ -832,6 +832,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
832
832
|
* Hacky way for handling chart resize. Deletes it and redraw chart.
|
|
833
833
|
*/
|
|
834
834
|
_resizeChart: function() {
|
|
835
|
+
if(!this._container) return;
|
|
836
|
+
|
|
835
837
|
// prevent displaying chart on resize if hidden
|
|
836
838
|
if (_.style(this._container, "display") == "none") return;
|
|
837
839
|
|
|
@@ -920,7 +922,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({
|
|
|
920
922
|
* Calculates [x, y] domain and then update chart.
|
|
921
923
|
*/
|
|
922
924
|
_updateChart: function() {
|
|
923
|
-
if (/*!this._data.length ||*/ !this._container) return;
|
|
925
|
+
if (/*!this._data.length ||*/ !this._chart || !this._container) return;
|
|
924
926
|
|
|
925
927
|
this._fireEvt("elechart_axis");
|
|
926
928
|
this._fireEvt("elechart_area");
|
|
@@ -1112,7 +1114,7 @@ Elevation.addInitHook(function() {
|
|
|
1112
1114
|
if (options.stroke && options.weight !== 0) {
|
|
1113
1115
|
let oldVal = ctx.globalCompositeOperation || 'source-over';
|
|
1114
1116
|
ctx.globalCompositeOperation = 'destination-over'
|
|
1115
|
-
ctx.strokeStyle = '#FFF';
|
|
1117
|
+
ctx.strokeStyle = color.outline || '#FFF';
|
|
1116
1118
|
ctx.lineWidth = options.weight * 1.75;
|
|
1117
1119
|
ctx.stroke();
|
|
1118
1120
|
ctx.globalCompositeOperation = oldVal;
|
package/src/distance.js
CHANGED
|
@@ -66,6 +66,11 @@ Elevation.addInitHook(function() {
|
|
|
66
66
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
this._registerFocusLabel({
|
|
70
|
+
name: 'x',
|
|
71
|
+
chart: (item) => L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + this._xLabel,
|
|
72
|
+
});
|
|
73
|
+
|
|
69
74
|
this._registerSummary({
|
|
70
75
|
"totlen" : {
|
|
71
76
|
label: "Total Length: ",
|
package/src/index.js
CHANGED
|
@@ -39,8 +39,8 @@ import * as _ from './utils';
|
|
|
39
39
|
import * as D3 from './components';
|
|
40
40
|
import { Chart } from './chart';
|
|
41
41
|
import { Elevation } from './control';
|
|
42
|
-
import './distance';
|
|
43
42
|
import './altitude';
|
|
43
|
+
import './distance';
|
|
44
44
|
import './time';
|
|
45
45
|
import './slope';
|
|
46
46
|
import './speed';
|
|
@@ -50,4 +50,15 @@ Elevation.Utils = _;
|
|
|
50
50
|
Elevation.Components = D3;
|
|
51
51
|
Elevation.Chart = Chart;
|
|
52
52
|
|
|
53
|
+
/* Temporary fix for empty values evaluated as false (leaflet-i18n v0.3.1) */
|
|
54
|
+
(function(){
|
|
55
|
+
let proto = L.i18n.bind({});
|
|
56
|
+
L.i18n = L._ = (string, data) => {
|
|
57
|
+
if (L.locale && L.locales[L.locale] && L.locales[L.locale][string] == "") {
|
|
58
|
+
L.locales[L.locale][string] = "\u200B";
|
|
59
|
+
}
|
|
60
|
+
return proto.call(null, string, data);
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
|
|
53
64
|
L.control.elevation = (options) => new Elevation(options);
|
package/src/marker.js
CHANGED
|
@@ -93,35 +93,18 @@ export var Marker = L.Class.extend({
|
|
|
93
93
|
length: normalizedY
|
|
94
94
|
})
|
|
95
95
|
);
|
|
96
|
+
|
|
96
97
|
this._focuslabel
|
|
97
98
|
.call(
|
|
98
99
|
D3.HeightFocusLabel({
|
|
99
100
|
theme : opts.theme,
|
|
100
101
|
xCoord: point.x,
|
|
101
102
|
yCoord: normalizedY,
|
|
102
|
-
|
|
103
|
+
labels: this._focuslabels,
|
|
104
|
+
item: point
|
|
103
105
|
})
|
|
104
106
|
);
|
|
105
107
|
|
|
106
|
-
let labels = this._focuslabels;
|
|
107
|
-
let tooltip = this._focuslabel;
|
|
108
|
-
let label;
|
|
109
|
-
|
|
110
|
-
for (var i in labels) {
|
|
111
|
-
label = tooltip.select(".height-focus-" + labels[i].name);
|
|
112
|
-
|
|
113
|
-
if (!label.size()) {
|
|
114
|
-
label = tooltip.append("svg:tspan")
|
|
115
|
-
.attr("class", "height-focus-" + labels[i].name)
|
|
116
|
-
.attr("dy", "1.5em");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(props.item) );
|
|
120
|
-
|
|
121
|
-
this._focuslabel.select('.height-focus-y')
|
|
122
|
-
.attr("dy", "-1.5em");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
108
|
} else if (this.options.marker == 'position-marker') {
|
|
126
109
|
_.removeClass(this._marker.getElement(), 'leaflet-hidden');
|
|
127
110
|
this._marker.setLatLng(this._latlng);
|
package/src/options.js
CHANGED
package/src/slope.js
CHANGED
|
@@ -95,7 +95,7 @@ Elevation.addInitHook(function() {
|
|
|
95
95
|
|
|
96
96
|
this._registerFocusLabel({
|
|
97
97
|
name: 'slope',
|
|
98
|
-
chart: (item) => item.slope + slope.label,
|
|
98
|
+
chart: (item) => L._("m: ") + item.slope + slope.label,
|
|
99
99
|
marker: (item) => Math.round(item.slope) + slope.label
|
|
100
100
|
});
|
|
101
101
|
|
package/src/speed.js
CHANGED
|
@@ -96,8 +96,8 @@ Elevation.addInitHook(function() {
|
|
|
96
96
|
|
|
97
97
|
this._registerFocusLabel({
|
|
98
98
|
name: 'speed',
|
|
99
|
-
chart: (item) => item.speed + " " + speed.label,
|
|
100
|
-
marker: (item) => Math.round(item.speed) + " " + speed.label
|
|
99
|
+
chart: (item) => L._('v: ') + item.speed + " " + speed.label,
|
|
100
|
+
marker: (item) => Math.round(item.speed) + " " + speed.label,
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
this._registerSummary({
|
package/src/time.js
CHANGED
|
@@ -100,20 +100,25 @@ Elevation.addInitHook(function() {
|
|
|
100
100
|
this.track_info.time = duration;
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
if (this.options.time) {
|
|
104
103
|
|
|
104
|
+
if (this.options.timestamps) {
|
|
105
105
|
this._registerFocusLabel({
|
|
106
|
-
name: '
|
|
107
|
-
chart: (item) => this.options.timeFormat(item.time)
|
|
106
|
+
name: 'date',
|
|
107
|
+
chart: (item) => L._("t: ") + this.options.timeFormat(item.time)
|
|
108
108
|
});
|
|
109
|
+
}
|
|
109
110
|
|
|
111
|
+
if (this.options.time) {
|
|
112
|
+
this._registerFocusLabel({
|
|
113
|
+
name: 'time',
|
|
114
|
+
chart: (item) => L._("T: ") + _.formatTime(item.duration || 0)
|
|
115
|
+
});
|
|
110
116
|
this._registerSummary({
|
|
111
117
|
"tottime" : {
|
|
112
118
|
label: "Total Time: ",
|
|
113
119
|
value: (track) => _.formatTime(track.time || 0)
|
|
114
120
|
}
|
|
115
121
|
});
|
|
116
|
-
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
});
|