@raruto/leaflet-elevation 1.7.5 → 1.8.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.
- package/README.md +19 -2
- package/dist/leaflet-elevation.css +0 -1
- package/dist/leaflet-elevation.js +721 -885
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +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 +11 -21
- package/src/altitude.js +21 -22
- package/src/chart.js +91 -178
- package/src/components.js +163 -115
- package/src/control.js +116 -209
- package/src/distance.js +15 -13
- package/src/index.css +0 -1
- package/src/index.js +12 -1
- package/src/marker.js +38 -98
- package/src/options.js +1 -8
- package/src/slope.js +9 -18
- package/src/speed.js +11 -21
- package/src/time.js +15 -10
- package/src/utils.js +77 -99
package/src/components.js
CHANGED
|
@@ -106,57 +106,65 @@ export const Grid = (props) => {
|
|
|
106
106
|
return Axis(props);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
export const
|
|
109
|
+
export const PositionMarker = ({
|
|
110
110
|
theme,
|
|
111
111
|
xCoord = 0,
|
|
112
112
|
yCoord = 0,
|
|
113
|
+
labels = {},
|
|
114
|
+
item = {},
|
|
113
115
|
length = 0,
|
|
114
116
|
}) => {
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
.
|
|
118
|
-
.
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
return g => {
|
|
118
|
+
|
|
119
|
+
let line = g.select('.height-focus.line');
|
|
120
|
+
let circle = g.select('.height-focus.circle-lower');
|
|
121
|
+
let text = g.select('.height-focus-label');
|
|
122
|
+
|
|
123
|
+
if (!line.node()) line = g.append('svg:line');
|
|
124
|
+
if (!circle.node()) circle = g.append('svg:circle');
|
|
125
|
+
if (!text.node()) text = g.append('svg:text');
|
|
126
|
+
|
|
127
|
+
if (isNaN(xCoord) || isNaN(yCoord)) return g;
|
|
128
|
+
|
|
129
|
+
circle
|
|
130
|
+
.attr("class", theme + " height-focus circle-lower")
|
|
131
|
+
.attr("transform", "translate(" + xCoord + "," + yCoord + ")")
|
|
132
|
+
.attr("r", 6)
|
|
133
|
+
.attr("cx", 0)
|
|
134
|
+
.attr("cy", 0);
|
|
135
|
+
|
|
136
|
+
line
|
|
137
|
+
.attr("class", theme + " height-focus line")
|
|
138
|
+
.attr("x1", xCoord)
|
|
139
|
+
.attr("x2", xCoord)
|
|
140
|
+
.attr("y1", yCoord)
|
|
141
|
+
.attr("y2", length);
|
|
122
142
|
|
|
123
|
-
export const HeightFocusLabel = ({
|
|
124
|
-
theme,
|
|
125
|
-
xCoord = 0,
|
|
126
|
-
yCoord = 0,
|
|
127
|
-
label,
|
|
128
|
-
}) => {
|
|
129
|
-
return text => {
|
|
130
143
|
text
|
|
131
144
|
.attr("class", theme + " height-focus-label")
|
|
132
145
|
.style("pointer-events", "none")
|
|
133
146
|
.attr("x", xCoord + 5)
|
|
134
|
-
.attr("y",
|
|
147
|
+
.attr("y", length);
|
|
135
148
|
|
|
136
|
-
let
|
|
137
|
-
if (!y.node()) y = text.append("svg:tspan");
|
|
149
|
+
let label;
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
.
|
|
141
|
-
.text(label);
|
|
151
|
+
for (var i in labels) {
|
|
152
|
+
label = text.select(".height-focus-" + labels[i].name);
|
|
142
153
|
|
|
143
|
-
|
|
154
|
+
if (!label.size()) {
|
|
155
|
+
label = text.append("svg:tspan")
|
|
156
|
+
.attr("class", "height-focus-" + labels[i].name)
|
|
157
|
+
.attr("dy", "1.5em");
|
|
158
|
+
}
|
|
144
159
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
160
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
161
|
+
}
|
|
148
162
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
return circle => circle
|
|
155
|
-
.attr("class", theme + " height-focus circle-lower")
|
|
156
|
-
.attr("transform", "translate(" + xCoord + "," + yCoord + ")")
|
|
157
|
-
.attr("r", 6)
|
|
158
|
-
.attr("cx", 0)
|
|
159
|
-
.attr("cy", 0);
|
|
163
|
+
text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
|
|
164
|
+
text.selectAll('tspan').attr("x", xCoord + 5);
|
|
165
|
+
|
|
166
|
+
return g;
|
|
167
|
+
}
|
|
160
168
|
};
|
|
161
169
|
|
|
162
170
|
export const LegendItem = ({
|
|
@@ -173,16 +181,16 @@ export const LegendItem = ({
|
|
|
173
181
|
.attr("class", "legend-item legend-" + name.toLowerCase())
|
|
174
182
|
.attr("data-name", name);
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
184
|
+
g.on('click.legend', () => d3.select(g.node().ownerSVGElement || g)
|
|
185
|
+
.dispatch("legend_clicked", {
|
|
186
|
+
detail: {
|
|
187
|
+
path: path.node(),
|
|
188
|
+
name: name,
|
|
189
|
+
legend: g.node(),
|
|
190
|
+
enabled: !path.classed('leaflet-hidden'),
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
);
|
|
186
194
|
|
|
187
195
|
g.append("svg:rect")
|
|
188
196
|
.attr("x", (width / 2) - 50)
|
|
@@ -207,41 +215,27 @@ export const LegendItem = ({
|
|
|
207
215
|
}
|
|
208
216
|
};
|
|
209
217
|
|
|
210
|
-
export const
|
|
211
|
-
xCoord = 0,
|
|
212
|
-
height,
|
|
213
|
-
}) => {
|
|
214
|
-
return line => line
|
|
215
|
-
.attr('class', 'mouse-focus-line')
|
|
216
|
-
.attr('x2', xCoord)
|
|
217
|
-
.attr('y2', 0)
|
|
218
|
-
.attr('x1', xCoord)
|
|
219
|
-
.attr('y1', height);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export const MouseFocusLabel = ({
|
|
218
|
+
export const Tooltip = ({
|
|
223
219
|
xCoord,
|
|
224
220
|
yCoord,
|
|
225
|
-
labelX = "",
|
|
226
|
-
labelY = "",
|
|
227
221
|
width,
|
|
222
|
+
height,
|
|
223
|
+
labels = {},
|
|
224
|
+
item = {},
|
|
228
225
|
}) => {
|
|
229
226
|
return g => {
|
|
230
227
|
|
|
231
|
-
g.
|
|
228
|
+
let line = g.select('.mouse-focus-line');
|
|
229
|
+
let box = g.select('.mouse-focus-label');
|
|
232
230
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
let y = text.select(".mouse-focus-label-y");
|
|
236
|
-
let x = text.select(".mouse-focus-label-x");
|
|
231
|
+
if (!line.node()) line = g.append('svg:line');
|
|
232
|
+
if (!box.node()) box = g.append("g");
|
|
237
233
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (!y.node()) y = text.append("svg:tspan");
|
|
241
|
-
if (!x.node()) x = text.append("svg:tspan");
|
|
234
|
+
let rect = box.select(".mouse-focus-label-rect");
|
|
235
|
+
let text = box.select(".mouse-focus-label-text");
|
|
242
236
|
|
|
243
|
-
|
|
244
|
-
|
|
237
|
+
if (!rect.node()) rect = box.append("svg:rect");
|
|
238
|
+
if (!text.node()) text = box.append("svg:text");
|
|
245
239
|
|
|
246
240
|
// Sets focus-label-text position to the left / right of the mouse-focus-line
|
|
247
241
|
let xAlign = 0;
|
|
@@ -252,6 +246,16 @@ export const MouseFocusLabel = ({
|
|
|
252
246
|
if (xCoord) xAlign = xCoord + (xCoord < width / 2 ? 10 : -bbox.width - 10);
|
|
253
247
|
if (yCoord) yAlign = Math.max(yCoord - bbox.height, L.Browser.webkit ? 0 : -Infinity);
|
|
254
248
|
|
|
249
|
+
line
|
|
250
|
+
.attr('class', 'mouse-focus-line')
|
|
251
|
+
.attr('x2', xCoord)
|
|
252
|
+
.attr('y2', 0)
|
|
253
|
+
.attr('x1', xCoord)
|
|
254
|
+
.attr('y1', height);
|
|
255
|
+
|
|
256
|
+
box
|
|
257
|
+
.attr('class', 'mouse-focus-label');
|
|
258
|
+
|
|
255
259
|
rect
|
|
256
260
|
.attr("class", "mouse-focus-label-rect")
|
|
257
261
|
.attr("x", xAlign - 5)
|
|
@@ -260,17 +264,27 @@ export const MouseFocusLabel = ({
|
|
|
260
264
|
.attr("height", bbox.height + 10)
|
|
261
265
|
.attr("rx", 3)
|
|
262
266
|
.attr("ry", 3);
|
|
267
|
+
|
|
263
268
|
text
|
|
264
269
|
.attr("class", "mouse-focus-label-text")
|
|
265
270
|
.style("font-weight", "700")
|
|
266
271
|
.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
272
|
|
|
273
|
+
let label;
|
|
274
|
+
|
|
275
|
+
for (let i in labels) {
|
|
276
|
+
label = text.select(".mouse-focus-label-" + labels[i].name);
|
|
277
|
+
|
|
278
|
+
if (!label.size()) {
|
|
279
|
+
label = text.append("svg:tspan", ".mouse-focus-label-x")
|
|
280
|
+
.attr("class", "mouse-focus-label-" + labels[i].name)
|
|
281
|
+
.attr("dy", "1.5em");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
text.select('tspan').attr("dy", "1em");
|
|
274
288
|
text.selectAll('tspan').attr("x", xAlign);
|
|
275
289
|
|
|
276
290
|
return g;
|
|
@@ -354,6 +368,65 @@ export const Ruler = ({
|
|
|
354
368
|
}
|
|
355
369
|
};
|
|
356
370
|
|
|
371
|
+
export const CheckPoint = ({
|
|
372
|
+
point,
|
|
373
|
+
height,
|
|
374
|
+
width,
|
|
375
|
+
x,
|
|
376
|
+
y
|
|
377
|
+
}) => {
|
|
378
|
+
return g => {
|
|
379
|
+
|
|
380
|
+
if (isNaN(x) || isNaN(y)) return g;
|
|
381
|
+
|
|
382
|
+
if (!point.item || !point.item.property('isConnected')) {
|
|
383
|
+
point.position = point.position || "bottom";
|
|
384
|
+
|
|
385
|
+
point.item = g.append('g');
|
|
386
|
+
|
|
387
|
+
point.item.append("svg:line")
|
|
388
|
+
.attr("y1", 0)
|
|
389
|
+
.attr("x1", 0)
|
|
390
|
+
.attr("style","stroke: rgb(51, 51, 51); stroke-width: 0.5; stroke-dasharray: 2, 2;");
|
|
391
|
+
|
|
392
|
+
point.item
|
|
393
|
+
.append("svg:circle")
|
|
394
|
+
.attr("class", " height-focus circle-lower")
|
|
395
|
+
.attr("r", 3);
|
|
396
|
+
|
|
397
|
+
if (point.label) {
|
|
398
|
+
point.item.append("svg:text")
|
|
399
|
+
.attr("dx", "4px")
|
|
400
|
+
.attr("dy", "-4px");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
point.item
|
|
405
|
+
.datum({
|
|
406
|
+
pos: point.position,
|
|
407
|
+
x: x,
|
|
408
|
+
y: y
|
|
409
|
+
})
|
|
410
|
+
.attr("class", d => "point " + d.pos)
|
|
411
|
+
.attr("transform", d => "translate(" + d.x + "," + d.y + ")");
|
|
412
|
+
|
|
413
|
+
point.item.select('line')
|
|
414
|
+
.datum({
|
|
415
|
+
y2: ({'top': -y, 'bottom': height - y})[point.position],
|
|
416
|
+
x2: ({'left': -x, 'right': width - x})[point.position] || 0
|
|
417
|
+
})
|
|
418
|
+
.attr("y2", d => d.y2)
|
|
419
|
+
.attr("x2", d => d.x2)
|
|
420
|
+
|
|
421
|
+
if (point.label) {
|
|
422
|
+
point.item.select('text')
|
|
423
|
+
.text(point.label);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return g;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
357
430
|
export const Domain = ({
|
|
358
431
|
min,
|
|
359
432
|
max,
|
|
@@ -432,52 +505,27 @@ export const Chart = ({
|
|
|
432
505
|
};
|
|
433
506
|
|
|
434
507
|
// SVG Paths
|
|
435
|
-
const
|
|
436
|
-
const
|
|
508
|
+
const mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
|
|
509
|
+
const maskRect = mask.append("svg:rect").attr('class', 'zoom').attr('fill', 'white'); // white = transparent
|
|
437
510
|
|
|
438
511
|
// Canvas Paths
|
|
439
|
-
const foreignObject = panes.area.append('svg:foreignObject');
|
|
512
|
+
const foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
|
|
440
513
|
const canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
|
|
441
514
|
const context = canvas.node().getContext('2d');
|
|
442
515
|
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
const focusG = panes.tooltip;
|
|
446
|
-
const brushG = panes.brush;
|
|
447
|
-
|
|
448
|
-
focusG.append('svg:line')
|
|
449
|
-
.call(
|
|
450
|
-
MouseFocusLine({
|
|
451
|
-
xCoord: 0,
|
|
452
|
-
height: _height
|
|
453
|
-
})
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
focusG.append("g")
|
|
457
|
-
.call(
|
|
458
|
-
MouseFocusLabel({
|
|
459
|
-
xCoord: 0,
|
|
460
|
-
yCoord: 0,
|
|
461
|
-
height: _height,
|
|
462
|
-
width : _width,
|
|
463
|
-
labelX: "",
|
|
464
|
-
labelY: "",
|
|
465
|
-
})
|
|
466
|
-
);
|
|
467
|
-
|
|
516
|
+
// Add tooltip
|
|
517
|
+
panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height: _height, width : _width, labels: {} }));
|
|
468
518
|
|
|
469
519
|
// Add the brushing
|
|
470
|
-
let brush
|
|
520
|
+
let brush = d3.brushX().on('start.cursor end.cursor brush.cursor', () => panes.brush.select(".overlay").attr('cursor', null));
|
|
471
521
|
|
|
472
522
|
// Scales
|
|
473
|
-
const scale
|
|
523
|
+
const scale = (opts) => ({ x: Scale(opts.x), y: Scale(opts.y)});
|
|
474
524
|
|
|
475
525
|
let utils = {
|
|
476
|
-
|
|
526
|
+
mask,
|
|
477
527
|
canvas,
|
|
478
528
|
context,
|
|
479
|
-
dragG,
|
|
480
|
-
focusG,
|
|
481
529
|
brush,
|
|
482
530
|
};
|
|
483
531
|
|
|
@@ -512,7 +560,7 @@ export const Chart = ({
|
|
|
512
560
|
.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
513
561
|
}
|
|
514
562
|
|
|
515
|
-
|
|
563
|
+
maskRect
|
|
516
564
|
.attr("x", 0)
|
|
517
565
|
.attr("y", 0)
|
|
518
566
|
.attr("width", _width)
|
|
@@ -527,11 +575,11 @@ export const Chart = ({
|
|
|
527
575
|
.attr('height', _height);
|
|
528
576
|
|
|
529
577
|
if (ruler) {
|
|
530
|
-
|
|
578
|
+
panes.ruler.call(Ruler({ height: _height, width: _width }));
|
|
531
579
|
}
|
|
532
580
|
|
|
533
|
-
|
|
534
|
-
|
|
581
|
+
panes.brush.call(brush.extent( [ [0,0], [_width, _height] ] ));
|
|
582
|
+
panes.brush.select(".overlay").attr('cursor', null);
|
|
535
583
|
|
|
536
584
|
chart._width = _width;
|
|
537
585
|
chart._height = _height;
|