@raruto/leaflet-elevation 1.7.6 → 1.8.0
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 +14 -0
- package/dist/leaflet-elevation.js +506 -737
- 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/package.json +1 -1
- package/src/acceleration.js +10 -20
- package/src/altitude.js +18 -25
- package/src/chart.js +54 -153
- package/src/components.js +130 -94
- package/src/control.js +111 -207
- package/src/distance.js +12 -15
- package/src/marker.js +38 -81
- package/src/options.js +0 -8
- package/src/slope.js +8 -17
- package/src/speed.js +9 -19
- package/src/time.js +7 -7
- package/src/utils.js +77 -99
|
@@ -101,31 +101,6 @@
|
|
|
101
101
|
|
|
102
102
|
return deepMerge.apply(void 0, [target].concat(sources));
|
|
103
103
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Wait for document load before execute function.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
function deferFunc(f) {
|
|
109
|
-
if (document.readyState !== 'complete') window.addEventListener("load", f, {
|
|
110
|
-
once: true
|
|
111
|
-
});else f();
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Debounce function to limit events are being fired.
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
function debounce(func, wait, context, immediate) {
|
|
118
|
-
var timeout;
|
|
119
|
-
return function () {
|
|
120
|
-
var args = arguments;
|
|
121
|
-
clearTimeout(timeout);
|
|
122
|
-
timeout = setTimeout(function () {
|
|
123
|
-
timeout = null;
|
|
124
|
-
if (!immediate) func.apply(context, args);
|
|
125
|
-
}, wait);
|
|
126
|
-
if (immediate && !timeout) func.apply(context, args);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
104
|
var SEC = 1000;
|
|
130
105
|
var MIN = SEC * 60;
|
|
131
106
|
var HOUR = MIN * 60;
|
|
@@ -283,13 +258,6 @@
|
|
|
283
258
|
|
|
284
259
|
return layer;
|
|
285
260
|
}
|
|
286
|
-
/**
|
|
287
|
-
* Check DOM element visibility.
|
|
288
|
-
*/
|
|
289
|
-
|
|
290
|
-
function isDomVisible(elem) {
|
|
291
|
-
return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
|
|
292
|
-
}
|
|
293
261
|
/**
|
|
294
262
|
* Check object type.
|
|
295
263
|
*/
|
|
@@ -297,40 +265,6 @@
|
|
|
297
265
|
function isObject(item) {
|
|
298
266
|
return item && _typeof(item) === 'object' && !Array.isArray(item);
|
|
299
267
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Check DOM element viewport visibility.
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
function isVisible(elem) {
|
|
305
|
-
if (!elem) return false;
|
|
306
|
-
var styles = window.getComputedStyle(elem);
|
|
307
|
-
|
|
308
|
-
function isVisibleByStyles(elem, styles) {
|
|
309
|
-
return styles.visibility !== 'hidden' && styles.display !== 'none';
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function isAboveOtherElements(elem, styles) {
|
|
313
|
-
var boundingRect = elem.getBoundingClientRect();
|
|
314
|
-
var left = boundingRect.left + 1;
|
|
315
|
-
var right = boundingRect.right - 1;
|
|
316
|
-
var top = boundingRect.top + 1;
|
|
317
|
-
var bottom = boundingRect.bottom - 1;
|
|
318
|
-
var above = true;
|
|
319
|
-
var pointerEvents = elem.style.pointerEvents;
|
|
320
|
-
if (styles['pointer-events'] == 'none') elem.style.pointerEvents = 'auto';
|
|
321
|
-
if (document.elementFromPoint(left, top) !== elem) above = false;
|
|
322
|
-
if (document.elementFromPoint(right, top) !== elem) above = false; // Only for completely visible elements
|
|
323
|
-
// if (document.elementFromPoint(left, bottom) !== elem) above = false;
|
|
324
|
-
// if (document.elementFromPoint(right, bottom) !== elem) above = false;
|
|
325
|
-
|
|
326
|
-
elem.style.pointerEvents = pointerEvents;
|
|
327
|
-
return above;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!isVisibleByStyles(elem, styles)) return false;
|
|
331
|
-
if (!isAboveOtherElements(elem, styles)) return false;
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
268
|
/**
|
|
335
269
|
* Check JSON object type.
|
|
336
270
|
*/
|
|
@@ -368,6 +302,22 @@
|
|
|
368
302
|
return documentElement ? documentElement.nodeName !== "HTML" : false;
|
|
369
303
|
}
|
|
370
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Generate download data event.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
function saveFile(dataURI, fileName) {
|
|
310
|
+
var a = create('a', '', {
|
|
311
|
+
href: dataURI,
|
|
312
|
+
target: '_new',
|
|
313
|
+
download: fileName || "",
|
|
314
|
+
style: "display:none;"
|
|
315
|
+
});
|
|
316
|
+
var b = document.body;
|
|
317
|
+
b.appendChild(a);
|
|
318
|
+
a.click();
|
|
319
|
+
b.removeChild(a);
|
|
320
|
+
}
|
|
371
321
|
/**
|
|
372
322
|
* Async JS script download.
|
|
373
323
|
*/
|
|
@@ -390,50 +340,69 @@
|
|
|
390
340
|
document.head.appendChild(tag);
|
|
391
341
|
});
|
|
392
342
|
}
|
|
343
|
+
function lazyLoad(src, control) {
|
|
344
|
+
if (!control.options.lazyLoadJS) return Promise.resolve();
|
|
345
|
+
var Elevation = L.Control.Elevation;
|
|
346
|
+
var loader = '';
|
|
347
|
+
var condition = false;
|
|
348
|
+
|
|
349
|
+
switch (src) {
|
|
350
|
+
case control.__D3:
|
|
351
|
+
loader = '_d3LazyLoader';
|
|
352
|
+
condition = (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object';
|
|
353
|
+
break;
|
|
354
|
+
|
|
355
|
+
case control.__TOGEOJSON:
|
|
356
|
+
loader = '_togeojsonLazyLoader';
|
|
357
|
+
condition = (typeof toGeoJSON === "undefined" ? "undefined" : _typeof(toGeoJSON)) !== 'object';
|
|
358
|
+
break;
|
|
359
|
+
|
|
360
|
+
case control.__LGEOMUTIL:
|
|
361
|
+
loader = '_geomutilLazyLoader';
|
|
362
|
+
condition = _typeof(L.GeometryUtil) !== 'object';
|
|
363
|
+
|
|
364
|
+
case control.__LALMOSTOVER:
|
|
365
|
+
loader = '_almostoverLazyLoader';
|
|
366
|
+
condition = typeof L.Handler.AlmostOver !== 'function ';
|
|
367
|
+
break;
|
|
368
|
+
|
|
369
|
+
case control.__LDISTANCEM:
|
|
370
|
+
loader = '_distanceMarkersLazyLoader';
|
|
371
|
+
condition = typeof L.DistanceMarkers !== 'function';
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return Elevation[loader] = lazyLoader(src, condition, Elevation[loader]);
|
|
376
|
+
}
|
|
393
377
|
/**
|
|
394
|
-
*
|
|
378
|
+
* Convert SVG Path into Path2D and then update canvas
|
|
395
379
|
*/
|
|
396
380
|
|
|
397
|
-
function
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
381
|
+
function drawCanvas(ctx, path) {
|
|
382
|
+
path.classed('canvas-path', true);
|
|
383
|
+
ctx.beginPath();
|
|
384
|
+
ctx.moveTo(0, 0);
|
|
385
|
+
var p = new Path2D(path.attr('d'));
|
|
386
|
+
ctx.strokeStyle = path.attr('stroke');
|
|
387
|
+
ctx.fillStyle = path.attr('fill');
|
|
388
|
+
ctx.lineWidth = 1.25;
|
|
389
|
+
ctx.globalCompositeOperation = 'source-over'; // stroke opacity
|
|
390
|
+
|
|
391
|
+
ctx.globalAlpha = path.attr('stroke-opacity') || 0.3;
|
|
392
|
+
ctx.stroke(p); // fill opacity
|
|
393
|
+
|
|
394
|
+
ctx.globalAlpha = path.attr('fill-opacity') || 0.45;
|
|
395
|
+
ctx.fill(p);
|
|
396
|
+
ctx.globalAlpha = 1;
|
|
397
|
+
ctx.closePath();
|
|
408
398
|
}
|
|
409
399
|
/**
|
|
410
|
-
*
|
|
400
|
+
* Limit a number between min / max values
|
|
411
401
|
*/
|
|
412
402
|
|
|
413
|
-
function
|
|
414
|
-
return
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
var scrollFn = function scrollFn() {
|
|
418
|
-
if (!ticking) {
|
|
419
|
-
L.Util.requestAnimFrame(function () {
|
|
420
|
-
if (isVisible(elem)) {
|
|
421
|
-
window.removeEventListener('scroll', scrollFn);
|
|
422
|
-
resolve();
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
ticking = false;
|
|
426
|
-
});
|
|
427
|
-
ticking = true;
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
window.addEventListener('scroll', scrollFn);
|
|
432
|
-
if (elem) elem.addEventListener('mouseenter', scrollFn, {
|
|
433
|
-
once: true
|
|
434
|
-
});
|
|
435
|
-
scrollFn();
|
|
436
|
-
});
|
|
403
|
+
function clamp(val, range) {
|
|
404
|
+
if (range) return val < range[0] ? range[0] : val > range[1] ? range[1] : val;
|
|
405
|
+
return val;
|
|
437
406
|
}
|
|
438
407
|
/**
|
|
439
408
|
* A little bit safier than L.DomUtil.addClass
|
|
@@ -524,9 +493,17 @@
|
|
|
524
493
|
*/
|
|
525
494
|
|
|
526
495
|
var hasClass = L.DomUtil.hasClass;
|
|
496
|
+
/**
|
|
497
|
+
* Generate a random string
|
|
498
|
+
*/
|
|
499
|
+
|
|
527
500
|
function randomId() {
|
|
528
501
|
return Math.random().toString(36).substr(2, 9);
|
|
529
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* Execute a function foreach element in object
|
|
505
|
+
*/
|
|
506
|
+
|
|
530
507
|
function each(obj, fn) {
|
|
531
508
|
for (var i in obj) {
|
|
532
509
|
fn(obj[i], i);
|
|
@@ -536,18 +513,16 @@
|
|
|
536
513
|
var _ = /*#__PURE__*/Object.freeze({
|
|
537
514
|
__proto__: null,
|
|
538
515
|
deepMerge: deepMerge,
|
|
539
|
-
deferFunc: deferFunc,
|
|
540
|
-
debounce: debounce,
|
|
541
516
|
formatTime: formatTime,
|
|
542
517
|
GeoJSONLoader: GeoJSONLoader,
|
|
543
|
-
isDomVisible: isDomVisible,
|
|
544
518
|
isObject: isObject,
|
|
545
|
-
isVisible: isVisible,
|
|
546
519
|
isJSONDoc: isJSONDoc,
|
|
547
520
|
isXMLDoc: isXMLDoc,
|
|
548
|
-
lazyLoader: lazyLoader,
|
|
549
521
|
saveFile: saveFile,
|
|
550
|
-
|
|
522
|
+
lazyLoader: lazyLoader,
|
|
523
|
+
lazyLoad: lazyLoad,
|
|
524
|
+
drawCanvas: drawCanvas,
|
|
525
|
+
clamp: clamp,
|
|
551
526
|
addClass: addClass,
|
|
552
527
|
removeClass: removeClass,
|
|
553
528
|
toggleClass: toggleClass,
|
|
@@ -672,30 +647,29 @@
|
|
|
672
647
|
props.type = "grid";
|
|
673
648
|
return Axis(props);
|
|
674
649
|
};
|
|
675
|
-
var
|
|
650
|
+
var PositionMarker = function PositionMarker(_ref4) {
|
|
676
651
|
var theme = _ref4.theme,
|
|
677
652
|
_ref4$xCoord = _ref4.xCoord,
|
|
678
653
|
xCoord = _ref4$xCoord === void 0 ? 0 : _ref4$xCoord,
|
|
679
654
|
_ref4$yCoord = _ref4.yCoord,
|
|
680
655
|
yCoord = _ref4$yCoord === void 0 ? 0 : _ref4$yCoord,
|
|
656
|
+
_ref4$labels = _ref4.labels,
|
|
657
|
+
labels = _ref4$labels === void 0 ? {} : _ref4$labels,
|
|
658
|
+
_ref4$item = _ref4.item,
|
|
659
|
+
item = _ref4$item === void 0 ? {} : _ref4$item,
|
|
681
660
|
_ref4$length = _ref4.length,
|
|
682
661
|
length = _ref4$length === void 0 ? 0 : _ref4$length;
|
|
683
|
-
return function (
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
labels = _ref5$labels === void 0 ? {} : _ref5$labels,
|
|
695
|
-
_ref5$item = _ref5.item,
|
|
696
|
-
item = _ref5$item === void 0 ? {} : _ref5$item;
|
|
697
|
-
return function (text) {
|
|
698
|
-
text.attr("class", theme + " height-focus-label").style("pointer-events", "none").attr("x", xCoord + 5).attr("y", yCoord);
|
|
662
|
+
return function (g) {
|
|
663
|
+
var line = g.select('.height-focus.line');
|
|
664
|
+
var circle = g.select('.height-focus.circle-lower');
|
|
665
|
+
var text = g.select('.height-focus-label');
|
|
666
|
+
if (!line.node()) line = g.append('svg:line');
|
|
667
|
+
if (!circle.node()) circle = g.append('svg:circle');
|
|
668
|
+
if (!text.node()) text = g.append('svg:text');
|
|
669
|
+
if (isNaN(xCoord) || isNaN(yCoord)) return g;
|
|
670
|
+
circle.attr("class", theme + " height-focus circle-lower").attr("transform", "translate(" + xCoord + "," + yCoord + ")").attr("r", 6).attr("cx", 0).attr("cy", 0);
|
|
671
|
+
line.attr("class", theme + " height-focus line").attr("x1", xCoord).attr("x2", xCoord).attr("y1", yCoord).attr("y2", length);
|
|
672
|
+
text.attr("class", theme + " height-focus-label").style("pointer-events", "none").attr("x", xCoord + 5).attr("y", length);
|
|
699
673
|
var label;
|
|
700
674
|
|
|
701
675
|
for (var i in labels) {
|
|
@@ -710,33 +684,22 @@
|
|
|
710
684
|
|
|
711
685
|
text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em");
|
|
712
686
|
text.selectAll('tspan').attr("x", xCoord + 5);
|
|
713
|
-
return
|
|
714
|
-
};
|
|
715
|
-
};
|
|
716
|
-
var HeightFocusMarker = function HeightFocusMarker(_ref6) {
|
|
717
|
-
var theme = _ref6.theme,
|
|
718
|
-
_ref6$xCoord = _ref6.xCoord,
|
|
719
|
-
xCoord = _ref6$xCoord === void 0 ? 0 : _ref6$xCoord,
|
|
720
|
-
_ref6$yCoord = _ref6.yCoord,
|
|
721
|
-
yCoord = _ref6$yCoord === void 0 ? 0 : _ref6$yCoord;
|
|
722
|
-
return function (circle) {
|
|
723
|
-
return circle.attr("class", theme + " height-focus circle-lower").attr("transform", "translate(" + xCoord + "," + yCoord + ")").attr("r", 6).attr("cx", 0).attr("cy", 0);
|
|
687
|
+
return g;
|
|
724
688
|
};
|
|
725
689
|
};
|
|
726
|
-
var LegendItem = function LegendItem(
|
|
727
|
-
var name =
|
|
728
|
-
label =
|
|
729
|
-
width =
|
|
730
|
-
height =
|
|
731
|
-
|
|
732
|
-
margins =
|
|
733
|
-
color =
|
|
734
|
-
path =
|
|
690
|
+
var LegendItem = function LegendItem(_ref5) {
|
|
691
|
+
var name = _ref5.name,
|
|
692
|
+
label = _ref5.label,
|
|
693
|
+
width = _ref5.width,
|
|
694
|
+
height = _ref5.height,
|
|
695
|
+
_ref5$margins = _ref5.margins,
|
|
696
|
+
margins = _ref5$margins === void 0 ? {} : _ref5$margins,
|
|
697
|
+
color = _ref5.color,
|
|
698
|
+
path = _ref5.path;
|
|
735
699
|
return function (g) {
|
|
736
700
|
g.attr("class", "legend-item legend-" + name.toLowerCase()).attr("data-name", name);
|
|
737
|
-
var svg = d3.select(g.node().ownerSVGElement || g);
|
|
738
701
|
g.on('click.legend', function () {
|
|
739
|
-
return
|
|
702
|
+
return d3.select(g.node().ownerSVGElement || g).dispatch("legend_clicked", {
|
|
740
703
|
detail: {
|
|
741
704
|
path: path.node(),
|
|
742
705
|
name: name,
|
|
@@ -750,28 +713,24 @@
|
|
|
750
713
|
return g;
|
|
751
714
|
};
|
|
752
715
|
};
|
|
753
|
-
var
|
|
754
|
-
var
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
var xCoord = _ref9.xCoord,
|
|
763
|
-
yCoord = _ref9.yCoord,
|
|
764
|
-
width = _ref9.width,
|
|
765
|
-
_ref9$labels = _ref9.labels,
|
|
766
|
-
labels = _ref9$labels === void 0 ? {} : _ref9$labels,
|
|
767
|
-
_ref9$item = _ref9.item,
|
|
768
|
-
item = _ref9$item === void 0 ? {} : _ref9$item;
|
|
716
|
+
var Tooltip = function Tooltip(_ref6) {
|
|
717
|
+
var xCoord = _ref6.xCoord,
|
|
718
|
+
yCoord = _ref6.yCoord,
|
|
719
|
+
width = _ref6.width,
|
|
720
|
+
height = _ref6.height,
|
|
721
|
+
_ref6$labels = _ref6.labels,
|
|
722
|
+
labels = _ref6$labels === void 0 ? {} : _ref6$labels,
|
|
723
|
+
_ref6$item = _ref6.item,
|
|
724
|
+
item = _ref6$item === void 0 ? {} : _ref6$item;
|
|
769
725
|
return function (g) {
|
|
770
|
-
g.
|
|
771
|
-
var
|
|
772
|
-
|
|
773
|
-
if (!
|
|
774
|
-
|
|
726
|
+
var line = g.select('.mouse-focus-line');
|
|
727
|
+
var box = g.select('.mouse-focus-label');
|
|
728
|
+
if (!line.node()) line = g.append('svg:line');
|
|
729
|
+
if (!box.node()) box = g.append("g");
|
|
730
|
+
var rect = box.select(".mouse-focus-label-rect");
|
|
731
|
+
var text = box.select(".mouse-focus-label-text");
|
|
732
|
+
if (!rect.node()) rect = box.append("svg:rect");
|
|
733
|
+
if (!text.node()) text = box.append("svg:text"); // Sets focus-label-text position to the left / right of the mouse-focus-line
|
|
775
734
|
|
|
776
735
|
var xAlign = 0;
|
|
777
736
|
var yAlign = 0;
|
|
@@ -788,6 +747,8 @@
|
|
|
788
747
|
|
|
789
748
|
if (xCoord) xAlign = xCoord + (xCoord < width / 2 ? 10 : -bbox.width - 10);
|
|
790
749
|
if (yCoord) yAlign = Math.max(yCoord - bbox.height, L.Browser.webkit ? 0 : -Infinity);
|
|
750
|
+
line.attr('class', 'mouse-focus-line').attr('x2', xCoord).attr('y2', 0).attr('x1', xCoord).attr('y1', height);
|
|
751
|
+
box.attr('class', 'mouse-focus-label');
|
|
791
752
|
rect.attr("class", "mouse-focus-label-rect").attr("x", xAlign - 5).attr("y", yAlign - 5).attr("width", bbox.width + 10).attr("height", bbox.height + 10).attr("rx", 3).attr("ry", 3);
|
|
792
753
|
text.attr("class", "mouse-focus-label-text").style("font-weight", "700").attr("y", yAlign);
|
|
793
754
|
var label;
|
|
@@ -807,9 +768,9 @@
|
|
|
807
768
|
return g;
|
|
808
769
|
};
|
|
809
770
|
};
|
|
810
|
-
var Ruler = function Ruler(
|
|
811
|
-
var height =
|
|
812
|
-
width =
|
|
771
|
+
var Ruler = function Ruler(_ref7) {
|
|
772
|
+
var height = _ref7.height,
|
|
773
|
+
width = _ref7.width;
|
|
813
774
|
return function (g) {
|
|
814
775
|
g.data([{
|
|
815
776
|
"x": 0,
|
|
@@ -856,13 +817,64 @@
|
|
|
856
817
|
return g;
|
|
857
818
|
};
|
|
858
819
|
};
|
|
859
|
-
var
|
|
860
|
-
var
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
820
|
+
var CheckPoint = function CheckPoint(_ref8) {
|
|
821
|
+
var point = _ref8.point,
|
|
822
|
+
height = _ref8.height,
|
|
823
|
+
width = _ref8.width,
|
|
824
|
+
x = _ref8.x,
|
|
825
|
+
y = _ref8.y;
|
|
826
|
+
return function (g) {
|
|
827
|
+
if (isNaN(x) || isNaN(y)) return g;
|
|
828
|
+
|
|
829
|
+
if (!point.item || !point.item.property('isConnected')) {
|
|
830
|
+
point.position = point.position || "bottom";
|
|
831
|
+
point.item = g.append('g');
|
|
832
|
+
point.item.append("svg:line").attr("y1", 0).attr("x1", 0).attr("style", "stroke: rgb(51, 51, 51); stroke-width: 0.5; stroke-dasharray: 2, 2;");
|
|
833
|
+
point.item.append("svg:circle").attr("class", " height-focus circle-lower").attr("r", 3);
|
|
834
|
+
|
|
835
|
+
if (point.label) {
|
|
836
|
+
point.item.append("svg:text").attr("dx", "4px").attr("dy", "-4px");
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
point.item.datum({
|
|
841
|
+
pos: point.position,
|
|
842
|
+
x: x,
|
|
843
|
+
y: y
|
|
844
|
+
}).attr("class", function (d) {
|
|
845
|
+
return "point " + d.pos;
|
|
846
|
+
}).attr("transform", function (d) {
|
|
847
|
+
return "translate(" + d.x + "," + d.y + ")";
|
|
848
|
+
});
|
|
849
|
+
point.item.select('line').datum({
|
|
850
|
+
y2: {
|
|
851
|
+
'top': -y,
|
|
852
|
+
'bottom': height - y
|
|
853
|
+
}[point.position],
|
|
854
|
+
x2: {
|
|
855
|
+
'left': -x,
|
|
856
|
+
'right': width - x
|
|
857
|
+
}[point.position] || 0
|
|
858
|
+
}).attr("y2", function (d) {
|
|
859
|
+
return d.y2;
|
|
860
|
+
}).attr("x2", function (d) {
|
|
861
|
+
return d.x2;
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
if (point.label) {
|
|
865
|
+
point.item.select('text').text(point.label);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return g;
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
var Domain = function Domain(_ref9) {
|
|
872
|
+
var min = _ref9.min,
|
|
873
|
+
max = _ref9.max,
|
|
874
|
+
attr = _ref9.attr,
|
|
875
|
+
name = _ref9.name,
|
|
876
|
+
forceBounds = _ref9.forceBounds,
|
|
877
|
+
scale = _ref9.scale;
|
|
866
878
|
return function (data) {
|
|
867
879
|
attr = attr || name;
|
|
868
880
|
if (scale && scale.attr) attr = scale.attr;
|
|
@@ -881,19 +893,19 @@
|
|
|
881
893
|
return domain;
|
|
882
894
|
};
|
|
883
895
|
};
|
|
884
|
-
var Range = function Range(
|
|
885
|
-
var axis =
|
|
896
|
+
var Range = function Range(_ref10) {
|
|
897
|
+
var axis = _ref10.axis;
|
|
886
898
|
return function (width, height) {
|
|
887
899
|
if (axis == 'x') return [0, width];else if (axis == 'y') return [height, 0];
|
|
888
900
|
};
|
|
889
901
|
};
|
|
890
|
-
var Scale = function Scale(
|
|
891
|
-
var data =
|
|
892
|
-
attr =
|
|
893
|
-
min =
|
|
894
|
-
max =
|
|
895
|
-
forceBounds =
|
|
896
|
-
range =
|
|
902
|
+
var Scale = function Scale(_ref11) {
|
|
903
|
+
var data = _ref11.data,
|
|
904
|
+
attr = _ref11.attr,
|
|
905
|
+
min = _ref11.min,
|
|
906
|
+
max = _ref11.max,
|
|
907
|
+
forceBounds = _ref11.forceBounds,
|
|
908
|
+
range = _ref11.range;
|
|
897
909
|
return d3.scaleLinear().range(range).domain(Domain({
|
|
898
910
|
min: min,
|
|
899
911
|
max: max,
|
|
@@ -901,22 +913,22 @@
|
|
|
901
913
|
forceBounds: forceBounds
|
|
902
914
|
})(data));
|
|
903
915
|
};
|
|
904
|
-
var Bisect = function Bisect(
|
|
905
|
-
var
|
|
906
|
-
data =
|
|
907
|
-
scale =
|
|
908
|
-
x =
|
|
909
|
-
attr =
|
|
916
|
+
var Bisect = function Bisect(_ref12) {
|
|
917
|
+
var _ref12$data = _ref12.data,
|
|
918
|
+
data = _ref12$data === void 0 ? [0, 1] : _ref12$data,
|
|
919
|
+
scale = _ref12.scale,
|
|
920
|
+
x = _ref12.x,
|
|
921
|
+
attr = _ref12.attr;
|
|
910
922
|
return d3.bisector(function (d) {
|
|
911
923
|
return d[attr];
|
|
912
924
|
}).left(data, scale.invert(x));
|
|
913
925
|
};
|
|
914
|
-
var Chart = function Chart(
|
|
915
|
-
var width =
|
|
916
|
-
height =
|
|
917
|
-
|
|
918
|
-
margins =
|
|
919
|
-
ruler =
|
|
926
|
+
var Chart = function Chart(_ref13) {
|
|
927
|
+
var width = _ref13.width,
|
|
928
|
+
height = _ref13.height,
|
|
929
|
+
_ref13$margins = _ref13.margins,
|
|
930
|
+
margins = _ref13$margins === void 0 ? {} : _ref13$margins,
|
|
931
|
+
ruler = _ref13.ruler;
|
|
920
932
|
|
|
921
933
|
var _width = width - margins.left - margins.right;
|
|
922
934
|
|
|
@@ -942,27 +954,18 @@
|
|
|
942
954
|
|
|
943
955
|
var foreignObject = panes.area.append('svg:foreignObject');
|
|
944
956
|
var canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
|
|
945
|
-
var context = canvas.node().getContext('2d'); //
|
|
957
|
+
var context = canvas.node().getContext('2d'); // Add tooltip
|
|
946
958
|
|
|
947
|
-
|
|
948
|
-
var focusG = panes.tooltip;
|
|
949
|
-
var brushG = panes.brush;
|
|
950
|
-
focusG.append('svg:line').call(MouseFocusLine({
|
|
951
|
-
xCoord: 0,
|
|
952
|
-
height: _height
|
|
953
|
-
}));
|
|
954
|
-
focusG.append("g").call(MouseFocusLabel({
|
|
959
|
+
panes.tooltip.call(Tooltip({
|
|
955
960
|
xCoord: 0,
|
|
956
961
|
yCoord: 0,
|
|
957
962
|
height: _height,
|
|
958
963
|
width: _width,
|
|
959
|
-
labels: {}
|
|
960
|
-
// labelY: "",
|
|
961
|
-
|
|
964
|
+
labels: {}
|
|
962
965
|
})); // Add the brushing
|
|
963
966
|
|
|
964
967
|
var brush = d3.brushX().on('start.cursor end.cursor brush.cursor', function () {
|
|
965
|
-
return
|
|
968
|
+
return panes.brush.select(".overlay").attr('cursor', null);
|
|
966
969
|
}); // Scales
|
|
967
970
|
|
|
968
971
|
var scale = function scale(opts) {
|
|
@@ -976,8 +979,6 @@
|
|
|
976
979
|
clipPath: clipPath,
|
|
977
980
|
canvas: canvas,
|
|
978
981
|
context: context,
|
|
979
|
-
dragG: dragG,
|
|
980
|
-
focusG: focusG,
|
|
981
982
|
brush: brush
|
|
982
983
|
};
|
|
983
984
|
var chart = {
|
|
@@ -988,12 +989,12 @@
|
|
|
988
989
|
scale: scale
|
|
989
990
|
}; // Resize
|
|
990
991
|
|
|
991
|
-
chart._resize = function (
|
|
992
|
-
var width =
|
|
993
|
-
height =
|
|
994
|
-
|
|
995
|
-
margins =
|
|
996
|
-
ruler =
|
|
992
|
+
chart._resize = function (_ref14) {
|
|
993
|
+
var width = _ref14.width,
|
|
994
|
+
height = _ref14.height,
|
|
995
|
+
_ref14$margins = _ref14.margins,
|
|
996
|
+
margins = _ref14$margins === void 0 ? {} : _ref14$margins,
|
|
997
|
+
ruler = _ref14.ruler;
|
|
997
998
|
|
|
998
999
|
var _width = width - margins.left - margins.right;
|
|
999
1000
|
|
|
@@ -1011,14 +1012,14 @@
|
|
|
1011
1012
|
canvas.attr('width', _width).attr('height', _height);
|
|
1012
1013
|
|
|
1013
1014
|
if (ruler) {
|
|
1014
|
-
|
|
1015
|
+
panes.ruler.call(Ruler({
|
|
1015
1016
|
height: _height,
|
|
1016
1017
|
width: _width
|
|
1017
1018
|
}));
|
|
1018
1019
|
}
|
|
1019
1020
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1021
|
+
panes.brush.call(brush.extent([[0, 0], [_width, _height]]));
|
|
1022
|
+
panes.brush.select(".overlay").attr('cursor', null);
|
|
1022
1023
|
chart._width = _width;
|
|
1023
1024
|
chart._height = _height;
|
|
1024
1025
|
chart.svg.dispatch('resize', {
|
|
@@ -1057,13 +1058,11 @@
|
|
|
1057
1058
|
Path: Path,
|
|
1058
1059
|
Axis: Axis,
|
|
1059
1060
|
Grid: Grid,
|
|
1060
|
-
|
|
1061
|
-
HeightFocusLabel: HeightFocusLabel,
|
|
1062
|
-
HeightFocusMarker: HeightFocusMarker,
|
|
1061
|
+
PositionMarker: PositionMarker,
|
|
1063
1062
|
LegendItem: LegendItem,
|
|
1064
|
-
|
|
1065
|
-
MouseFocusLabel: MouseFocusLabel,
|
|
1063
|
+
Tooltip: Tooltip,
|
|
1066
1064
|
Ruler: Ruler,
|
|
1065
|
+
CheckPoint: CheckPoint,
|
|
1067
1066
|
Domain: Domain,
|
|
1068
1067
|
Range: Range,
|
|
1069
1068
|
Scale: Scale,
|
|
@@ -1085,7 +1084,7 @@
|
|
|
1085
1084
|
grids: {},
|
|
1086
1085
|
axes: {},
|
|
1087
1086
|
legendItems: {},
|
|
1088
|
-
|
|
1087
|
+
tooltipItems: {}
|
|
1089
1088
|
};
|
|
1090
1089
|
this._scales = {};
|
|
1091
1090
|
this._domains = {};
|
|
@@ -1093,15 +1092,6 @@
|
|
|
1093
1092
|
this._paths = {};
|
|
1094
1093
|
this._brushEnabled = opts.dragging;
|
|
1095
1094
|
this._zoomEnabled = opts.zooming;
|
|
1096
|
-
|
|
1097
|
-
if (opts.imperial) {
|
|
1098
|
-
this._xLabel = "mi";
|
|
1099
|
-
this._yLabel = "ft";
|
|
1100
|
-
} else {
|
|
1101
|
-
this._xLabel = opts.xLabel;
|
|
1102
|
-
this._yLabel = opts.yLabel;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
1095
|
var chart = this._chart = Chart(opts); // SVG Container
|
|
1106
1096
|
|
|
1107
1097
|
var svg = this._container = chart.svg; // Panes
|
|
@@ -1110,20 +1100,16 @@
|
|
|
1110
1100
|
this._area = chart.pane('area');
|
|
1111
1101
|
this._point = chart.pane('point');
|
|
1112
1102
|
this._axis = chart.pane('axis');
|
|
1113
|
-
this._legend = chart.pane('legend');
|
|
1103
|
+
this._legend = chart.pane('legend');
|
|
1104
|
+
this._tooltip = chart.pane('tooltip');
|
|
1105
|
+
this._ruler = chart.pane('ruler'); // Scales
|
|
1114
1106
|
|
|
1115
1107
|
this._initScale(); // Helpers
|
|
1116
1108
|
|
|
1117
1109
|
|
|
1118
1110
|
this._clipPath = chart.get('clipPath');
|
|
1119
|
-
this._canvas = chart.get('canvas');
|
|
1120
1111
|
this._context = chart.get('context');
|
|
1121
|
-
this.
|
|
1122
|
-
this._focusG = chart.get('focusG');
|
|
1123
|
-
this._brush = chart.get('brush'); // Tooltip
|
|
1124
|
-
|
|
1125
|
-
this._focusline = this._focusG.select('.mouse-focus-line');
|
|
1126
|
-
this._focuslabel = this._focusG.select('.mouse-focus-label');
|
|
1112
|
+
this._brush = chart.get('brush');
|
|
1127
1113
|
this._zoom = d3.zoom();
|
|
1128
1114
|
this._drag = d3.drag(); // Interactions
|
|
1129
1115
|
|
|
@@ -1164,52 +1150,28 @@
|
|
|
1164
1150
|
|
|
1165
1151
|
this._area.selectAll('path').attr("d", "M0 0");
|
|
1166
1152
|
|
|
1167
|
-
this._context.clearRect(0, 0, this._width(), this._height());
|
|
1153
|
+
this._context.clearRect(0, 0, this._width(), this._height()); // if (this._path) {
|
|
1154
|
+
// this._x.domain([0, 1]);
|
|
1155
|
+
// this._y.domain([0, 1]);
|
|
1156
|
+
// }
|
|
1168
1157
|
|
|
1169
|
-
if (this._path) ;
|
|
1170
1158
|
},
|
|
1171
1159
|
_drawPath: function _drawPath(name) {
|
|
1172
|
-
var opts = this.options;
|
|
1173
|
-
var ctx = this._context;
|
|
1174
1160
|
var path = this._paths[name];
|
|
1175
1161
|
var area = this._props.areas[name];
|
|
1176
|
-
|
|
1177
|
-
var scaleX = this._scales[area.scaleX];
|
|
1178
|
-
var scaleY = this._scales[area.scaleY];
|
|
1179
|
-
area = L.extend({}, area, {
|
|
1162
|
+
path.datum(this._data).attr("d", Area(L.extend({}, area, {
|
|
1180
1163
|
width: this._width(),
|
|
1181
1164
|
height: this._height(),
|
|
1182
|
-
scaleX: scaleX,
|
|
1183
|
-
scaleY: scaleY
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
if (!scaleY || !scaleY) {
|
|
1187
|
-
return console.warn('Unable to render path:' + name);
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
path.datum(this._data).attr("d", Area(area));
|
|
1165
|
+
scaleX: this._scales[area.scaleX],
|
|
1166
|
+
scaleY: this._scales[area.scaleY]
|
|
1167
|
+
})));
|
|
1191
1168
|
if (path.classed('leaflet-hidden')) return;
|
|
1192
1169
|
|
|
1193
|
-
if (
|
|
1194
|
-
|
|
1195
|
-
ctx.beginPath();
|
|
1196
|
-
ctx.moveTo(0, 0);
|
|
1197
|
-
var p = new Path2D(path.attr('d'));
|
|
1198
|
-
ctx.strokeStyle = path.attr('stroke');
|
|
1199
|
-
ctx.fillStyle = path.attr('fill');
|
|
1200
|
-
ctx.lineWidth = 1.25;
|
|
1201
|
-
ctx.globalCompositeOperation = 'source-over'; // stroke opacity
|
|
1202
|
-
|
|
1203
|
-
ctx.globalAlpha = path.attr('stroke-opacity') || 0.3;
|
|
1204
|
-
ctx.stroke(p); // fill opacity
|
|
1205
|
-
|
|
1206
|
-
ctx.globalAlpha = path.attr('fill-opacity') || 0.45;
|
|
1207
|
-
ctx.fill(p);
|
|
1208
|
-
ctx.globalAlpha = 1;
|
|
1209
|
-
ctx.closePath();
|
|
1170
|
+
if (this.options.preferCanvas) {
|
|
1171
|
+
drawCanvas(this._context, path);
|
|
1210
1172
|
} else {
|
|
1211
1173
|
this._area.append(function () {
|
|
1212
|
-
return node;
|
|
1174
|
+
return path.node();
|
|
1213
1175
|
});
|
|
1214
1176
|
}
|
|
1215
1177
|
},
|
|
@@ -1384,9 +1346,9 @@
|
|
|
1384
1346
|
var label = function label(e, d) {
|
|
1385
1347
|
var yMax = _this5._height();
|
|
1386
1348
|
|
|
1387
|
-
var y = _this5.
|
|
1349
|
+
var y = _this5._ruler.data()[0].y;
|
|
1388
1350
|
|
|
1389
|
-
if (y >= yMax || y <= 0) _this5.
|
|
1351
|
+
if (y >= yMax || y <= 0) _this5._ruler.select(".horizontal-drag-label").text('');
|
|
1390
1352
|
|
|
1391
1353
|
_this5._hideDiagramIndicator();
|
|
1392
1354
|
};
|
|
@@ -1399,15 +1361,15 @@
|
|
|
1399
1361
|
|
|
1400
1362
|
var z = _this5._y.invert(y);
|
|
1401
1363
|
|
|
1402
|
-
var data = L.extend(_this5.
|
|
1364
|
+
var data = L.extend(_this5._ruler.data()[0], {
|
|
1403
1365
|
y: y
|
|
1404
1366
|
});
|
|
1405
1367
|
|
|
1406
|
-
_this5.
|
|
1368
|
+
_this5._ruler.data([data]).attr("transform", function (d) {
|
|
1407
1369
|
return "translate(" + d.x + "," + d.y + ")";
|
|
1408
1370
|
}).classed('active', y < yMax);
|
|
1409
1371
|
|
|
1410
|
-
_this5._container.select(".horizontal-drag-label").text(formatNum(z) + " " + _this5.
|
|
1372
|
+
_this5._container.select(".horizontal-drag-label").text(formatNum(z) + " " + (_this5.options.imperial ? 'ft' : 'm'));
|
|
1411
1373
|
|
|
1412
1374
|
_this5.fire('ruler_filter', {
|
|
1413
1375
|
coords: yCoord < yMax && yCoord > 0 ? _this5._findCoordsForY(yCoord) : []
|
|
@@ -1416,7 +1378,7 @@
|
|
|
1416
1378
|
|
|
1417
1379
|
drag.on("start end", label).on("drag", position);
|
|
1418
1380
|
|
|
1419
|
-
this.
|
|
1381
|
+
this._ruler.call(drag);
|
|
1420
1382
|
},
|
|
1421
1383
|
|
|
1422
1384
|
/**
|
|
@@ -1495,7 +1457,7 @@
|
|
|
1495
1457
|
},
|
|
1496
1458
|
|
|
1497
1459
|
/**
|
|
1498
|
-
* Add a
|
|
1460
|
+
* Add a point of interest over the chart
|
|
1499
1461
|
*/
|
|
1500
1462
|
_registerCheckPoint: function _registerCheckPoint(point) {
|
|
1501
1463
|
if (!this._data.length) return;
|
|
@@ -1509,49 +1471,18 @@
|
|
|
1509
1471
|
x = this._x(point.dist);
|
|
1510
1472
|
item = this._data[this._findIndexForXCoord(x)];
|
|
1511
1473
|
y = this._y(item.z);
|
|
1512
|
-
} else if (isNaN(x) || isNaN(y)) return;
|
|
1513
|
-
|
|
1514
|
-
if (!point.item || !point.item.property('isConnected')) {
|
|
1515
|
-
point.position = point.position || "bottom";
|
|
1516
|
-
point.item = this._point.append('g');
|
|
1517
|
-
point.item.append("svg:line").attr("y1", 0).attr("x1", 0).attr("style", "stroke: rgb(51, 51, 51); stroke-width: 0.5; stroke-dasharray: 2, 2;");
|
|
1518
|
-
point.item.append("svg:circle").attr("class", " height-focus circle-lower").attr("r", 3);
|
|
1519
|
-
|
|
1520
|
-
if (point.label) {
|
|
1521
|
-
point.item.append("svg:text").attr("dx", "4px").attr("dy", "-4px");
|
|
1522
|
-
}
|
|
1523
1474
|
}
|
|
1524
1475
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1476
|
+
this._point.call(CheckPoint({
|
|
1477
|
+
point: point,
|
|
1478
|
+
width: this._width(),
|
|
1479
|
+
height: this._height(),
|
|
1527
1480
|
x: x,
|
|
1528
1481
|
y: y
|
|
1529
|
-
})
|
|
1530
|
-
return "point " + d.pos;
|
|
1531
|
-
}).attr("transform", function (d) {
|
|
1532
|
-
return "translate(" + d.x + "," + d.y + ")";
|
|
1533
|
-
});
|
|
1534
|
-
point.item.select('line').datum({
|
|
1535
|
-
y2: {
|
|
1536
|
-
'top': -y,
|
|
1537
|
-
'bottom': this._height() - y
|
|
1538
|
-
}[point.position],
|
|
1539
|
-
x2: {
|
|
1540
|
-
'left': -x,
|
|
1541
|
-
'right': this._width() - x
|
|
1542
|
-
}[point.position] || 0
|
|
1543
|
-
}).attr("y2", function (d) {
|
|
1544
|
-
return d.y2;
|
|
1545
|
-
}).attr("x2", function (d) {
|
|
1546
|
-
return d.x2;
|
|
1547
|
-
});
|
|
1548
|
-
|
|
1549
|
-
if (point.label) {
|
|
1550
|
-
point.item.select('text').text(point.label);
|
|
1551
|
-
}
|
|
1482
|
+
}));
|
|
1552
1483
|
},
|
|
1553
|
-
|
|
1554
|
-
this._props.
|
|
1484
|
+
_registerTooltip: function _registerTooltip(props) {
|
|
1485
|
+
this._props.tooltipItems[props.name] = props;
|
|
1555
1486
|
},
|
|
1556
1487
|
_updateArea: function _updateArea() {
|
|
1557
1488
|
var paths = this._paths; // Reset and update chart profiles
|
|
@@ -1621,7 +1552,7 @@
|
|
|
1621
1552
|
_updateLegend: function _updateLegend() {
|
|
1622
1553
|
var _this6 = this;
|
|
1623
1554
|
|
|
1624
|
-
if (this.options.legend
|
|
1555
|
+
if (this.options.legend === false) return;
|
|
1625
1556
|
var legends = this._props.legendItems;
|
|
1626
1557
|
var legend; // Reset legend items
|
|
1627
1558
|
|
|
@@ -1698,13 +1629,9 @@
|
|
|
1698
1629
|
x: this._x,
|
|
1699
1630
|
y: this._y
|
|
1700
1631
|
};
|
|
1701
|
-
var opts = this.options;
|
|
1702
|
-
var scales = this._scales;
|
|
1703
|
-
var d = this._domains;
|
|
1704
|
-
var r = this._ranges;
|
|
1705
1632
|
|
|
1706
|
-
for (var i in
|
|
1707
|
-
|
|
1633
|
+
for (var i in this._scales) {
|
|
1634
|
+
this._scales[i].domain(this._domains[i](this._data)).range(this._ranges[i](this._width(), this._height()));
|
|
1708
1635
|
}
|
|
1709
1636
|
|
|
1710
1637
|
return {
|
|
@@ -1810,28 +1737,17 @@
|
|
|
1810
1737
|
* Display distance and altitude level ("focus-rect").
|
|
1811
1738
|
*/
|
|
1812
1739
|
_showDiagramIndicator: function _showDiagramIndicator(item, xCoordinate) {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
var yCoordinate = this._y(item[opts.yAttr]);
|
|
1816
|
-
|
|
1817
|
-
this._focusG.attr("display", null);
|
|
1818
|
-
|
|
1819
|
-
this._focusline.call(MouseFocusLine({
|
|
1820
|
-
xCoord: xCoordinate,
|
|
1821
|
-
height: this._height()
|
|
1822
|
-
}));
|
|
1823
|
-
|
|
1824
|
-
this._focuslabel.call(MouseFocusLabel({
|
|
1740
|
+
this._tooltip.attr("display", null).call(Tooltip({
|
|
1825
1741
|
xCoord: xCoordinate,
|
|
1826
|
-
yCoord:
|
|
1742
|
+
yCoord: this._y(item[this.options.yAttr]),
|
|
1827
1743
|
height: this._height(),
|
|
1828
1744
|
width: this._width(),
|
|
1829
|
-
labels: this._props.
|
|
1745
|
+
labels: this._props.tooltipItems,
|
|
1830
1746
|
item: item
|
|
1831
1747
|
}));
|
|
1832
1748
|
},
|
|
1833
1749
|
_hideDiagramIndicator: function _hideDiagramIndicator() {
|
|
1834
|
-
this.
|
|
1750
|
+
this._tooltip.attr("display", 'none');
|
|
1835
1751
|
}
|
|
1836
1752
|
});
|
|
1837
1753
|
|
|
@@ -1839,51 +1755,40 @@
|
|
|
1839
1755
|
initialize: function initialize(options) {
|
|
1840
1756
|
this.options = options;
|
|
1841
1757
|
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
// this._marker = L.circleMarker([0, 0], { pane: 'overlayPane', radius: 6, fillColor: '#fff', fillOpacity:1, color: '#000', weight:1, interactive: false });
|
|
1857
|
-
this._marker = L.marker([0, 0], {
|
|
1858
|
-
icon: this.options.markerIcon,
|
|
1859
|
-
zIndexOffset: 1000000,
|
|
1860
|
-
interactive: false
|
|
1861
|
-
});
|
|
1758
|
+
switch (this.options.marker) {
|
|
1759
|
+
case 'elevation-line':
|
|
1760
|
+
// this._container = d3.create("g").attr("class", "height-focus-group");
|
|
1761
|
+
this._container = d3.select(map.getPane('elevationPane')).select("svg > g").attr("class", "height-focus-group");
|
|
1762
|
+
break;
|
|
1763
|
+
|
|
1764
|
+
case 'position-marker':
|
|
1765
|
+
// this._marker = L.circleMarker([0, 0], { pane: 'overlayPane', radius: 6, fillColor: '#fff', fillOpacity:1, color: '#000', weight:1, interactive: false });
|
|
1766
|
+
this._marker = L.marker([0, 0], {
|
|
1767
|
+
icon: this.options.markerIcon,
|
|
1768
|
+
zIndexOffset: 1000000,
|
|
1769
|
+
interactive: false
|
|
1770
|
+
});
|
|
1771
|
+
break;
|
|
1862
1772
|
}
|
|
1863
1773
|
|
|
1864
|
-
this.
|
|
1774
|
+
this._labels = {};
|
|
1865
1775
|
return this;
|
|
1866
1776
|
},
|
|
1867
1777
|
addTo: function addTo(map) {
|
|
1868
|
-
var _this = this;
|
|
1869
|
-
|
|
1870
1778
|
this._map = map;
|
|
1871
1779
|
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
this._marker.addTo(map, {
|
|
1885
|
-
pane: 'overlayPane'
|
|
1886
|
-
});
|
|
1780
|
+
switch (this.options.marker) {
|
|
1781
|
+
case 'elevation-line':
|
|
1782
|
+
this._container.call(PositionMarker({}));
|
|
1783
|
+
|
|
1784
|
+
break;
|
|
1785
|
+
|
|
1786
|
+
case 'position-marker':
|
|
1787
|
+
this._marker.addTo(map, {
|
|
1788
|
+
pane: 'overlayPane'
|
|
1789
|
+
});
|
|
1790
|
+
|
|
1791
|
+
break;
|
|
1887
1792
|
}
|
|
1888
1793
|
|
|
1889
1794
|
return this;
|
|
@@ -1897,47 +1802,34 @@
|
|
|
1897
1802
|
if (!props) return;
|
|
1898
1803
|
if (props.options) this.options = props.options;
|
|
1899
1804
|
if (!this._map) this.addTo(props.map);
|
|
1900
|
-
var opts = this.options;
|
|
1901
|
-
var map = this._map;
|
|
1902
1805
|
this._latlng = props.item.latlng;
|
|
1903
|
-
var pos = map.latLngToLayerPoint(this._latlng);
|
|
1904
1806
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1807
|
+
switch (this.options.marker) {
|
|
1808
|
+
case 'elevation-line':
|
|
1809
|
+
var point = this._map.latLngToLayerPoint(this._latlng);
|
|
1908
1810
|
|
|
1909
|
-
|
|
1811
|
+
point = L.extend({}, props.item, this._map._rotate ? this._map.rotatedPointToMapPanePoint(point) : point);
|
|
1910
1812
|
|
|
1911
|
-
|
|
1912
|
-
var normalizedAlt = this._height() / props.maxElevation * point.z;
|
|
1913
|
-
var normalizedY = point.y - normalizedAlt;
|
|
1813
|
+
this._container.classed("leaflet-hidden", false);
|
|
1914
1814
|
|
|
1915
|
-
|
|
1815
|
+
this._container.call(PositionMarker({
|
|
1816
|
+
theme: this.options.theme,
|
|
1817
|
+
xCoord: point.x,
|
|
1818
|
+
yCoord: point.y,
|
|
1819
|
+
length: point.y - this._height() / props.maxElevation * point.z,
|
|
1820
|
+
// normalized Y
|
|
1821
|
+
labels: this._labels,
|
|
1822
|
+
item: point
|
|
1823
|
+
}));
|
|
1916
1824
|
|
|
1917
|
-
|
|
1918
|
-
theme: opts.theme,
|
|
1919
|
-
xCoord: point.x,
|
|
1920
|
-
yCoord: point.y
|
|
1921
|
-
}));
|
|
1825
|
+
break;
|
|
1922
1826
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
xCoord: point.x,
|
|
1926
|
-
yCoord: point.y,
|
|
1927
|
-
length: normalizedY
|
|
1928
|
-
}));
|
|
1827
|
+
case 'position-marker':
|
|
1828
|
+
removeClass(this._marker.getElement(), 'leaflet-hidden');
|
|
1929
1829
|
|
|
1930
|
-
|
|
1931
|
-
theme: opts.theme,
|
|
1932
|
-
xCoord: point.x,
|
|
1933
|
-
yCoord: normalizedY,
|
|
1934
|
-
labels: this._focuslabels,
|
|
1935
|
-
item: point
|
|
1936
|
-
}));
|
|
1937
|
-
} else if (this.options.marker == 'position-marker') {
|
|
1938
|
-
removeClass(this._marker.getElement(), 'leaflet-hidden');
|
|
1830
|
+
this._marker.setLatLng(this._latlng);
|
|
1939
1831
|
|
|
1940
|
-
|
|
1832
|
+
break;
|
|
1941
1833
|
}
|
|
1942
1834
|
},
|
|
1943
1835
|
|
|
@@ -1947,10 +1839,15 @@
|
|
|
1947
1839
|
remove: function remove() {
|
|
1948
1840
|
this._props = null;
|
|
1949
1841
|
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1842
|
+
switch (this.options.marker) {
|
|
1843
|
+
case 'elevation-line':
|
|
1844
|
+
this._container && this._container.classed("leaflet-hidden", true);
|
|
1845
|
+
break;
|
|
1846
|
+
|
|
1847
|
+
case 'position-marker':
|
|
1848
|
+
addClass(this._marker.getElement(), 'leaflet-hidden');
|
|
1849
|
+
|
|
1850
|
+
break;
|
|
1954
1851
|
}
|
|
1955
1852
|
},
|
|
1956
1853
|
getLatLng: function getLatLng() {
|
|
@@ -1964,8 +1861,8 @@
|
|
|
1964
1861
|
var opts = this.options;
|
|
1965
1862
|
return opts.height - opts.margins.top - opts.margins.bottom;
|
|
1966
1863
|
},
|
|
1967
|
-
|
|
1968
|
-
this.
|
|
1864
|
+
_registerTooltip: function _registerTooltip(props) {
|
|
1865
|
+
this._labels[props.name] = props;
|
|
1969
1866
|
}
|
|
1970
1867
|
});
|
|
1971
1868
|
|
|
@@ -2010,7 +1907,6 @@
|
|
|
2010
1907
|
collapsed: false,
|
|
2011
1908
|
detached: true,
|
|
2012
1909
|
distance: true,
|
|
2013
|
-
distanceFactor: 1,
|
|
2014
1910
|
distanceMarkers: false,
|
|
2015
1911
|
decimalsX: 2,
|
|
2016
1912
|
decimalsY: 0,
|
|
@@ -2020,15 +1916,10 @@
|
|
|
2020
1916
|
followMarker: true,
|
|
2021
1917
|
forceAxisBounds: false,
|
|
2022
1918
|
height: 200,
|
|
2023
|
-
heightFactor: 1,
|
|
2024
1919
|
imperial: false,
|
|
2025
1920
|
interpolation: "curveLinear",
|
|
2026
1921
|
lazyLoadJS: true,
|
|
2027
1922
|
legend: true,
|
|
2028
|
-
loadData: {
|
|
2029
|
-
defer: false,
|
|
2030
|
-
lazy: false
|
|
2031
|
-
},
|
|
2032
1923
|
margins: {
|
|
2033
1924
|
top: 30,
|
|
2034
1925
|
right: 30,
|
|
@@ -2042,7 +1933,6 @@
|
|
|
2042
1933
|
iconSize: [32, 32],
|
|
2043
1934
|
iconAnchor: [16, 16]
|
|
2044
1935
|
}),
|
|
2045
|
-
placeholder: false,
|
|
2046
1936
|
position: "topright",
|
|
2047
1937
|
polyline: {
|
|
2048
1938
|
className: 'elevation-polyline',
|
|
@@ -2061,7 +1951,6 @@
|
|
|
2061
1951
|
ruler: true,
|
|
2062
1952
|
skipNullZCoords: false,
|
|
2063
1953
|
theme: "lightblue-theme",
|
|
2064
|
-
responsive: true,
|
|
2065
1954
|
summary: 'inline',
|
|
2066
1955
|
slope: false,
|
|
2067
1956
|
speed: false,
|
|
@@ -2113,11 +2002,11 @@
|
|
|
2113
2002
|
addData: function addData(d, layer) {
|
|
2114
2003
|
var _this = this;
|
|
2115
2004
|
|
|
2116
|
-
|
|
2117
|
-
layer
|
|
2118
|
-
|
|
2005
|
+
this.lazyLoad(this.__D3).then(function () {
|
|
2006
|
+
if (typeof layer === "undefined" && d.on) {
|
|
2007
|
+
layer = d;
|
|
2008
|
+
}
|
|
2119
2009
|
|
|
2120
|
-
Elevation._d3LazyLoader = lazyLoader(this.__D3, (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object' || !this.options.lazyLoadJS, Elevation._d3LazyLoader).then(function () {
|
|
2121
2010
|
_this._addData(d);
|
|
2122
2011
|
|
|
2123
2012
|
_this._addLayer(layer);
|
|
@@ -2212,20 +2101,6 @@
|
|
|
2212
2101
|
this._chart._brushEnabled = true;
|
|
2213
2102
|
},
|
|
2214
2103
|
|
|
2215
|
-
/**
|
|
2216
|
-
* Alias for enableBrush
|
|
2217
|
-
*/
|
|
2218
|
-
enableDragging: function enableDragging() {
|
|
2219
|
-
this.enableBrushing();
|
|
2220
|
-
},
|
|
2221
|
-
|
|
2222
|
-
/**
|
|
2223
|
-
* Alias for disableBrush
|
|
2224
|
-
*/
|
|
2225
|
-
disableDragging: function disableDragging() {
|
|
2226
|
-
this.disableBrushing();
|
|
2227
|
-
},
|
|
2228
|
-
|
|
2229
2104
|
/**
|
|
2230
2105
|
* Disable chart zooming.
|
|
2231
2106
|
*/
|
|
@@ -2260,7 +2135,7 @@
|
|
|
2260
2135
|
* Get default zoom level when "followMarker" is true.
|
|
2261
2136
|
*/
|
|
2262
2137
|
getZFollow: function getZFollow() {
|
|
2263
|
-
return this.
|
|
2138
|
+
return this.options.zFollow;
|
|
2264
2139
|
},
|
|
2265
2140
|
|
|
2266
2141
|
/**
|
|
@@ -2280,50 +2155,29 @@
|
|
|
2280
2155
|
this._markedSegments = L.polyline([]);
|
|
2281
2156
|
this._chartEnabled = true, this.track_info = {};
|
|
2282
2157
|
this.options = deepMerge({}, this.options, options);
|
|
2283
|
-
this._zFollow = this.options.zFollow;
|
|
2284
2158
|
if (this.options.followMarker) this._setMapView = L.Util.throttle(this._setMapView, 300, this);
|
|
2285
|
-
if (this.options.placeholder) this.options.loadData.lazy = this.options.loadData.defer = true;
|
|
2286
2159
|
if (this.options.legend) this.options.margins.bottom += 30;
|
|
2287
2160
|
if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
|
|
2161
|
+
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
|
|
2288
2162
|
|
|
2289
|
-
this._markedSegments.setStyle(this.options.polylineSegments); //
|
|
2290
|
-
// this._resizeChart = L.Util.throttle(this._resizeChart, 300, this);
|
|
2291
|
-
// if (L.Browser.mobile) {
|
|
2292
|
-
// this._updateChart = _.debounce(this._updateChart, 300, this);
|
|
2293
|
-
// this._updateSummary = _.debounce(this._updateSummary, 300, this);
|
|
2294
|
-
// }
|
|
2163
|
+
this._markedSegments.setStyle(this.options.polylineSegments); // Leaflet canvas renderer colors
|
|
2295
2164
|
|
|
2296
2165
|
|
|
2297
|
-
if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons; // Leaflet canvas renderer colors
|
|
2298
|
-
|
|
2299
2166
|
L.extend(Colors, this.options.colors || {});
|
|
2300
2167
|
},
|
|
2301
2168
|
|
|
2302
2169
|
/**
|
|
2303
|
-
*
|
|
2304
|
-
*/
|
|
2305
|
-
load: function load(data, opts) {
|
|
2306
|
-
this.loadData(data, opts);
|
|
2307
|
-
},
|
|
2308
|
-
|
|
2309
|
-
/**
|
|
2310
|
-
* Alias for addTo
|
|
2170
|
+
* Javascript scripts downloader (lazy loader)
|
|
2311
2171
|
*/
|
|
2312
|
-
|
|
2313
|
-
this
|
|
2172
|
+
lazyLoad: function lazyLoad$1(src) {
|
|
2173
|
+
return lazyLoad(src, this);
|
|
2314
2174
|
},
|
|
2315
2175
|
|
|
2316
2176
|
/**
|
|
2317
2177
|
* Load elevation data (GPX, GeoJSON or KML).
|
|
2318
2178
|
*/
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
if (opts.defer) {
|
|
2323
|
-
this.loadDefer(data, opts);
|
|
2324
|
-
} else if (opts.lazy) {
|
|
2325
|
-
this.loadLazy(data, opts);
|
|
2326
|
-
} else if (isXMLDoc(data)) {
|
|
2179
|
+
load: function load(data) {
|
|
2180
|
+
if (isXMLDoc(data)) {
|
|
2327
2181
|
this.loadXML(data);
|
|
2328
2182
|
} else if (isJSONDoc(data)) {
|
|
2329
2183
|
this.loadGeoJSON(data);
|
|
@@ -2332,16 +2186,6 @@
|
|
|
2332
2186
|
}
|
|
2333
2187
|
},
|
|
2334
2188
|
|
|
2335
|
-
/**
|
|
2336
|
-
* Wait for document load before download data.
|
|
2337
|
-
*/
|
|
2338
|
-
loadDefer: function loadDefer(data, opts) {
|
|
2339
|
-
opts = L.extend({}, this.options.loadData, opts);
|
|
2340
|
-
opts.defer = false;
|
|
2341
|
-
|
|
2342
|
-
deferFunc(L.bind(this.loadData, this, data, opts));
|
|
2343
|
-
},
|
|
2344
|
-
|
|
2345
2189
|
/**
|
|
2346
2190
|
* Load data from a remote url.
|
|
2347
2191
|
*/
|
|
@@ -2353,10 +2197,7 @@
|
|
|
2353
2197
|
}).then(function (data) {
|
|
2354
2198
|
_this3._downloadURL = url; // TODO: handle multiple urls?
|
|
2355
2199
|
|
|
2356
|
-
_this3.
|
|
2357
|
-
lazy: false,
|
|
2358
|
-
defer: false
|
|
2359
|
-
});
|
|
2200
|
+
_this3.load(data);
|
|
2360
2201
|
}).catch(function (err) {
|
|
2361
2202
|
return console.warn(err);
|
|
2362
2203
|
});
|
|
@@ -2369,20 +2210,13 @@
|
|
|
2369
2210
|
GeoJSONLoader(data, this);
|
|
2370
2211
|
},
|
|
2371
2212
|
|
|
2372
|
-
/**
|
|
2373
|
-
* Alias for loadXML
|
|
2374
|
-
*/
|
|
2375
|
-
loadGPX: function loadGPX(data) {
|
|
2376
|
-
this.loadXML(data);
|
|
2377
|
-
},
|
|
2378
|
-
|
|
2379
2213
|
/**
|
|
2380
2214
|
* Load raw XML data.
|
|
2381
2215
|
*/
|
|
2382
2216
|
loadXML: function loadXML(data) {
|
|
2383
2217
|
var _this4 = this;
|
|
2384
2218
|
|
|
2385
|
-
|
|
2219
|
+
this.lazyLoad(this.__TOGEOJSON).then(function () {
|
|
2386
2220
|
var xml = new DOMParser().parseFromString(data, "text/xml");
|
|
2387
2221
|
var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
|
|
2388
2222
|
|
|
@@ -2403,32 +2237,12 @@
|
|
|
2403
2237
|
});
|
|
2404
2238
|
},
|
|
2405
2239
|
|
|
2406
|
-
/**
|
|
2407
|
-
* Wait for chart container visible before download data.
|
|
2408
|
-
*/
|
|
2409
|
-
loadLazy: function loadLazy(data, opts) {
|
|
2410
|
-
var _this5 = this;
|
|
2411
|
-
|
|
2412
|
-
opts = L.extend({}, this.options.loadData, opts);
|
|
2413
|
-
var elem = opts.lazy.parentNode ? opts.lazy : this.placeholder;
|
|
2414
|
-
|
|
2415
|
-
waitHolder(elem).then(function () {
|
|
2416
|
-
opts.lazy = false;
|
|
2417
|
-
|
|
2418
|
-
_this5.loadData(data, opts);
|
|
2419
|
-
|
|
2420
|
-
_this5.once('eledata_loaded', function () {
|
|
2421
|
-
return _this5.placeholder.parentNode.removeChild(elem);
|
|
2422
|
-
});
|
|
2423
|
-
});
|
|
2424
|
-
},
|
|
2425
|
-
|
|
2426
2240
|
/**
|
|
2427
2241
|
* Create container DOM element and related event listeners.
|
|
2428
2242
|
* Called on control.addTo(map).
|
|
2429
2243
|
*/
|
|
2430
2244
|
onAdd: function onAdd(map) {
|
|
2431
|
-
var
|
|
2245
|
+
var _this5 = this;
|
|
2432
2246
|
|
|
2433
2247
|
this._map = map;
|
|
2434
2248
|
|
|
@@ -2438,37 +2252,28 @@
|
|
|
2438
2252
|
addClass(container, 'leaflet-control');
|
|
2439
2253
|
}
|
|
2440
2254
|
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
src: this.options.placeholder,
|
|
2444
|
-
alt: ''
|
|
2445
|
-
} : this.options.placeholder);
|
|
2255
|
+
this.lazyLoad(this.__D3).then(function () {
|
|
2256
|
+
_this5._initButton(container);
|
|
2446
2257
|
|
|
2447
|
-
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
Elevation._d3LazyLoader = lazyLoader(this.__D3, (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object' || !this.options.lazyLoadJS, Elevation._d3LazyLoader).then(function () {
|
|
2451
|
-
_this6._initButton(container);
|
|
2452
|
-
|
|
2453
|
-
_this6._initChart(container);
|
|
2258
|
+
_this5._initChart(container);
|
|
2454
2259
|
|
|
2455
|
-
|
|
2260
|
+
_this5._initSummary(container);
|
|
2456
2261
|
|
|
2457
|
-
|
|
2262
|
+
_this5._initMarker(map);
|
|
2458
2263
|
|
|
2459
|
-
|
|
2264
|
+
_this5._initLayer(map);
|
|
2460
2265
|
|
|
2461
|
-
map.on('zoom viewreset zoomanim',
|
|
2266
|
+
map.on('zoom viewreset zoomanim', _this5._hideMarker, _this5).on('resize', _this5._resetView, _this5).on('resize', _this5._resizeChart, _this5).on('rotate', _this5._rotateMarker, _this5).on('mousedown', _this5._resetDrag, _this5);
|
|
2462
2267
|
|
|
2463
|
-
on(map.getContainer(), 'mousewheel',
|
|
2268
|
+
on(map.getContainer(), 'mousewheel', _this5._resetDrag, _this5);
|
|
2464
2269
|
|
|
2465
|
-
on(map.getContainer(), 'touchstart',
|
|
2270
|
+
on(map.getContainer(), 'touchstart', _this5._resetDrag, _this5);
|
|
2466
2271
|
|
|
2467
|
-
|
|
2272
|
+
_this5.on('eledata_added eledata_loaded', _this5._updateChart, _this5).on('eledata_added eledata_loaded', _this5._updateSummary, _this5);
|
|
2468
2273
|
|
|
2469
|
-
|
|
2274
|
+
_this5._updateChart();
|
|
2470
2275
|
|
|
2471
|
-
|
|
2276
|
+
_this5._updateSummary();
|
|
2472
2277
|
});
|
|
2473
2278
|
return container;
|
|
2474
2279
|
},
|
|
@@ -2499,7 +2304,7 @@
|
|
|
2499
2304
|
* Set default zoom level when "followMarker" is true.
|
|
2500
2305
|
*/
|
|
2501
2306
|
setZFollow: function setZFollow(zoom) {
|
|
2502
|
-
this.
|
|
2307
|
+
this.options.zFollow = zoom;
|
|
2503
2308
|
},
|
|
2504
2309
|
|
|
2505
2310
|
/**
|
|
@@ -2513,7 +2318,7 @@
|
|
|
2513
2318
|
* Parsing data either from GPX or GeoJSON and update the diagram data
|
|
2514
2319
|
*/
|
|
2515
2320
|
_addData: function _addData(d) {
|
|
2516
|
-
var
|
|
2321
|
+
var _this6 = this;
|
|
2517
2322
|
|
|
2518
2323
|
if (!d) {
|
|
2519
2324
|
return;
|
|
@@ -2530,7 +2335,7 @@
|
|
|
2530
2335
|
|
|
2531
2336
|
case 'MultiLineString':
|
|
2532
2337
|
each(geom.coordinates, function (coords) {
|
|
2533
|
-
return
|
|
2338
|
+
return _this6._addGeoJSONData(coords);
|
|
2534
2339
|
});
|
|
2535
2340
|
|
|
2536
2341
|
break;
|
|
@@ -2542,7 +2347,7 @@
|
|
|
2542
2347
|
|
|
2543
2348
|
if (d.type === "FeatureCollection") {
|
|
2544
2349
|
each(d.features, function (feature) {
|
|
2545
|
-
return
|
|
2350
|
+
return _this6._addData(feature);
|
|
2546
2351
|
});
|
|
2547
2352
|
}
|
|
2548
2353
|
|
|
@@ -2555,14 +2360,14 @@
|
|
|
2555
2360
|
* Parsing of GeoJSON data lines and their elevation in z-coordinate
|
|
2556
2361
|
*/
|
|
2557
2362
|
_addGeoJSONData: function _addGeoJSONData(coords) {
|
|
2558
|
-
var
|
|
2363
|
+
var _this7 = this;
|
|
2559
2364
|
|
|
2560
2365
|
each(coords, function (point) {
|
|
2561
|
-
|
|
2366
|
+
_this7._addPoint(point[1], point[0], point[2]);
|
|
2562
2367
|
|
|
2563
|
-
|
|
2368
|
+
_this7._fireEvt("elepoint_added", {
|
|
2564
2369
|
point: point,
|
|
2565
|
-
index:
|
|
2370
|
+
index: _this7._data.length - 1
|
|
2566
2371
|
});
|
|
2567
2372
|
});
|
|
2568
2373
|
|
|
@@ -2576,14 +2381,16 @@
|
|
|
2576
2381
|
* Parsing function for GPX data and their elevation in z-coordinate
|
|
2577
2382
|
*/
|
|
2578
2383
|
_addGPXData: function _addGPXData(coords) {
|
|
2579
|
-
var
|
|
2384
|
+
var _this8 = this;
|
|
2580
2385
|
|
|
2581
2386
|
each(coords, function (point) {
|
|
2582
|
-
|
|
2387
|
+
var _point$alt;
|
|
2388
|
+
|
|
2389
|
+
_this8._addPoint(point.lat, point.lng, (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele);
|
|
2583
2390
|
|
|
2584
|
-
|
|
2391
|
+
_this8._fireEvt("elepoint_added", {
|
|
2585
2392
|
point: point,
|
|
2586
|
-
index:
|
|
2393
|
+
index: _this8._data.length - 1
|
|
2587
2394
|
});
|
|
2588
2395
|
});
|
|
2589
2396
|
|
|
@@ -2704,21 +2511,19 @@
|
|
|
2704
2511
|
opts.xTicks = this._xTicks();
|
|
2705
2512
|
opts.yTicks = this._yTicks();
|
|
2706
2513
|
|
|
2707
|
-
if (opts.
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
clientWidth = _this$_map$getContain.clientWidth;
|
|
2514
|
+
if (opts.detached) {
|
|
2515
|
+
var _this$eleDiv = this.eleDiv,
|
|
2516
|
+
offsetWidth = _this$eleDiv.offsetWidth,
|
|
2517
|
+
offsetHeight = _this$eleDiv.offsetHeight;
|
|
2518
|
+
if (offsetWidth > 0) opts.width = offsetWidth;
|
|
2519
|
+
if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
|
|
2520
|
+
} else {
|
|
2521
|
+
var _this$_map$getContain = this._map.getContainer(),
|
|
2522
|
+
clientWidth = _this$_map$getContain.clientWidth;
|
|
2717
2523
|
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
}
|
|
2524
|
+
opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
|
|
2525
|
+
this._container.style.maxWidth = opts._maxWidth + 'px';
|
|
2526
|
+
if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
|
|
2722
2527
|
}
|
|
2723
2528
|
|
|
2724
2529
|
var chart = this._chart = new Chart$1(opts, this);
|
|
@@ -2734,17 +2539,17 @@
|
|
|
2734
2539
|
this._fireEvt("elechart_init");
|
|
2735
2540
|
},
|
|
2736
2541
|
_initLayer: function _initLayer() {
|
|
2737
|
-
var
|
|
2542
|
+
var _this9 = this;
|
|
2738
2543
|
|
|
2739
2544
|
this._layers.on('layeradd layerremove', function (e) {
|
|
2740
2545
|
var layer = e.layer;
|
|
2741
2546
|
var node = layer.getElement && layer.getElement();
|
|
2742
2547
|
|
|
2743
|
-
toggleClass(node,
|
|
2548
|
+
toggleClass(node, _this9.options.polyline.className + ' ' + _this9.options.theme, e.type == 'layeradd');
|
|
2744
2549
|
|
|
2745
|
-
toggleEvent(layer, "mousemove",
|
|
2550
|
+
toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
|
|
2746
2551
|
|
|
2747
|
-
toggleEvent(layer, "mouseout",
|
|
2552
|
+
toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
|
|
2748
2553
|
});
|
|
2749
2554
|
},
|
|
2750
2555
|
_initMarker: function _initMarker(map) {
|
|
@@ -2775,7 +2580,7 @@
|
|
|
2775
2580
|
container.setAttribute('aria-haspopup', true);
|
|
2776
2581
|
|
|
2777
2582
|
if (!this.options.detached) {
|
|
2778
|
-
L.DomEvent.disableClickPropagation(container)
|
|
2583
|
+
L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
|
|
2779
2584
|
}
|
|
2780
2585
|
|
|
2781
2586
|
if (L.Browser.mobile) {
|
|
@@ -2918,10 +2723,10 @@
|
|
|
2918
2723
|
* Add a waypoint marker to the diagram
|
|
2919
2724
|
*/
|
|
2920
2725
|
_registerCheckPoint: function _registerCheckPoint(props) {
|
|
2921
|
-
var
|
|
2726
|
+
var _this10 = this;
|
|
2922
2727
|
|
|
2923
2728
|
this.on("elechart_updated", function () {
|
|
2924
|
-
return
|
|
2729
|
+
return _this10._chart._registerCheckPoint(props);
|
|
2925
2730
|
});
|
|
2926
2731
|
},
|
|
2927
2732
|
|
|
@@ -2929,10 +2734,10 @@
|
|
|
2929
2734
|
* Add chart profile to diagram
|
|
2930
2735
|
*/
|
|
2931
2736
|
_registerAreaPath: function _registerAreaPath(props) {
|
|
2932
|
-
var
|
|
2737
|
+
var _this11 = this;
|
|
2933
2738
|
|
|
2934
2739
|
this.on("elechart_init", function () {
|
|
2935
|
-
return
|
|
2740
|
+
return _this11._chart._registerAreaPath(props);
|
|
2936
2741
|
});
|
|
2937
2742
|
},
|
|
2938
2743
|
|
|
@@ -2940,10 +2745,10 @@
|
|
|
2940
2745
|
* Add chart grid to diagram
|
|
2941
2746
|
*/
|
|
2942
2747
|
_registerAxisGrid: function _registerAxisGrid(props) {
|
|
2943
|
-
var
|
|
2748
|
+
var _this12 = this;
|
|
2944
2749
|
|
|
2945
2750
|
this.on("elechart_axis", function () {
|
|
2946
|
-
return
|
|
2751
|
+
return _this12._chart._registerAxisGrid(props);
|
|
2947
2752
|
});
|
|
2948
2753
|
},
|
|
2949
2754
|
|
|
@@ -2951,25 +2756,25 @@
|
|
|
2951
2756
|
* Add chart axis to diagram
|
|
2952
2757
|
*/
|
|
2953
2758
|
_registerAxisScale: function _registerAxisScale(props) {
|
|
2954
|
-
var
|
|
2759
|
+
var _this13 = this;
|
|
2955
2760
|
|
|
2956
2761
|
this.on("elechart_axis", function () {
|
|
2957
|
-
return
|
|
2762
|
+
return _this13._chart._registerAxisScale(props);
|
|
2958
2763
|
});
|
|
2959
2764
|
},
|
|
2960
2765
|
|
|
2961
2766
|
/**
|
|
2962
2767
|
* Add chart or marker tooltip info
|
|
2963
2768
|
*/
|
|
2964
|
-
|
|
2965
|
-
var
|
|
2769
|
+
_registerTooltip: function _registerTooltip(props) {
|
|
2770
|
+
var _this14 = this;
|
|
2966
2771
|
|
|
2967
2772
|
if (props.chart) {
|
|
2968
2773
|
var label = L.extend({}, props, {
|
|
2969
2774
|
value: props.chart
|
|
2970
2775
|
});
|
|
2971
2776
|
this.on("elechart_init", function () {
|
|
2972
|
-
return
|
|
2777
|
+
return _this14._chart._registerTooltip(label);
|
|
2973
2778
|
});
|
|
2974
2779
|
}
|
|
2975
2780
|
|
|
@@ -2979,7 +2784,7 @@
|
|
|
2979
2784
|
});
|
|
2980
2785
|
|
|
2981
2786
|
this.on("elechart_marker", function () {
|
|
2982
|
-
return
|
|
2787
|
+
return _this14._marker._registerTooltip(_label);
|
|
2983
2788
|
});
|
|
2984
2789
|
}
|
|
2985
2790
|
},
|
|
@@ -2988,10 +2793,10 @@
|
|
|
2988
2793
|
* Add summary info to diagram
|
|
2989
2794
|
*/
|
|
2990
2795
|
_registerSummary: function _registerSummary(props) {
|
|
2991
|
-
var
|
|
2796
|
+
var _this15 = this;
|
|
2992
2797
|
|
|
2993
2798
|
this.on('elechart_summary', function () {
|
|
2994
|
-
return
|
|
2799
|
+
return _this15._summary._registerSummary(props);
|
|
2995
2800
|
});
|
|
2996
2801
|
},
|
|
2997
2802
|
|
|
@@ -3027,31 +2832,28 @@
|
|
|
3027
2832
|
|
|
3028
2833
|
if (style(this._container, "display") == "none") return;
|
|
3029
2834
|
var opts = this.options;
|
|
2835
|
+
var newWidth;
|
|
3030
2836
|
|
|
3031
|
-
if (opts.
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
} else {
|
|
3037
|
-
var _this$_map$getContain2 = this._map.getContainer(),
|
|
3038
|
-
clientWidth = _this$_map$getContain2.clientWidth;
|
|
2837
|
+
if (opts.detached) {
|
|
2838
|
+
newWidth = (this.eleDiv || this._container).offsetWidth;
|
|
2839
|
+
} else {
|
|
2840
|
+
var _this$_map$getContain2 = this._map.getContainer(),
|
|
2841
|
+
clientWidth = _this$_map$getContain2.clientWidth;
|
|
3039
2842
|
|
|
3040
|
-
|
|
3041
|
-
|
|
2843
|
+
newWidth = opts._maxWidth > clientWidth ? clientWidth - 30 : opts._maxWidth;
|
|
2844
|
+
}
|
|
3042
2845
|
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
2846
|
+
if (newWidth) {
|
|
2847
|
+
var chart = this._chart;
|
|
2848
|
+
opts.width = newWidth;
|
|
3046
2849
|
|
|
3047
|
-
|
|
3048
|
-
|
|
2850
|
+
if (chart && chart._chart) {
|
|
2851
|
+
chart._chart._resize(opts);
|
|
3049
2852
|
|
|
3050
|
-
|
|
3051
|
-
|
|
2853
|
+
opts.xTicks = this._xTicks();
|
|
2854
|
+
opts.yTicks = this._yTicks();
|
|
3052
2855
|
|
|
3053
|
-
|
|
3054
|
-
}
|
|
2856
|
+
this._updateChart();
|
|
3055
2857
|
}
|
|
3056
2858
|
}
|
|
3057
2859
|
|
|
@@ -3080,10 +2882,10 @@
|
|
|
3080
2882
|
|
|
3081
2883
|
var zoom = this._map.getZoom();
|
|
3082
2884
|
|
|
3083
|
-
|
|
3084
|
-
if (zoom < this._zFollow) zoom = this._zFollow;
|
|
2885
|
+
var z = this.options.zFollow;
|
|
3085
2886
|
|
|
3086
|
-
|
|
2887
|
+
if (typeof z === "number") {
|
|
2888
|
+
this._map.setView(item.latlng, zoom < z ? z : zoom, {
|
|
3087
2889
|
animate: true,
|
|
3088
2890
|
duration: 0.25
|
|
3089
2891
|
});
|
|
@@ -3099,7 +2901,7 @@
|
|
|
3099
2901
|
* Toggle chart data on legend click
|
|
3100
2902
|
*/
|
|
3101
2903
|
_toggleChartHandler: function _toggleChartHandler(e) {
|
|
3102
|
-
var
|
|
2904
|
+
var _this16 = this;
|
|
3103
2905
|
|
|
3104
2906
|
var path = e.path,
|
|
3105
2907
|
name = e.name,
|
|
@@ -3109,7 +2911,7 @@
|
|
|
3109
2911
|
this._layers.eachLayer(function (layer) {
|
|
3110
2912
|
var node = layer.getElement && layer.getElement();
|
|
3111
2913
|
|
|
3112
|
-
toggleClass(node,
|
|
2914
|
+
toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
|
|
3113
2915
|
}); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
|
|
3114
2916
|
|
|
3115
2917
|
|
|
@@ -3149,23 +2951,23 @@
|
|
|
3149
2951
|
* Update the position/height indicator marker drawn onto the map
|
|
3150
2952
|
*/
|
|
3151
2953
|
_updateMarker: function _updateMarker(item) {
|
|
3152
|
-
if (
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
}
|
|
2954
|
+
if (this._marker) {
|
|
2955
|
+
this._marker.update({
|
|
2956
|
+
map: this._map,
|
|
2957
|
+
item: item,
|
|
2958
|
+
maxElevation: this.track_info.elevation_max || 0,
|
|
2959
|
+
options: this.options
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
3160
2962
|
},
|
|
3161
2963
|
|
|
3162
2964
|
/**
|
|
3163
2965
|
* Fix marker rotation on rotated maps
|
|
3164
2966
|
*/
|
|
3165
2967
|
_rotateMarker: function _rotateMarker() {
|
|
3166
|
-
if (
|
|
3167
|
-
|
|
3168
|
-
|
|
2968
|
+
if (this._marker) {
|
|
2969
|
+
this._marker.update();
|
|
2970
|
+
}
|
|
3169
2971
|
},
|
|
3170
2972
|
|
|
3171
2973
|
/**
|
|
@@ -3183,7 +2985,7 @@
|
|
|
3183
2985
|
* Update chart summary.
|
|
3184
2986
|
*/
|
|
3185
2987
|
_updateSummary: function _updateSummary() {
|
|
3186
|
-
var
|
|
2988
|
+
var _this17 = this;
|
|
3187
2989
|
|
|
3188
2990
|
this._summary.reset();
|
|
3189
2991
|
|
|
@@ -3198,9 +3000,9 @@
|
|
|
3198
3000
|
select('.download a', this.summaryDiv).onclick = function (e) {
|
|
3199
3001
|
e.preventDefault();
|
|
3200
3002
|
|
|
3201
|
-
|
|
3202
|
-
downloadLink:
|
|
3203
|
-
confirm: saveFile.bind(
|
|
3003
|
+
_this17._fireEvt('eletrack_download', {
|
|
3004
|
+
downloadLink: _this17.options.downloadLink,
|
|
3005
|
+
confirm: saveFile.bind(_this17, _this17._downloadURL)
|
|
3204
3006
|
});
|
|
3205
3007
|
};
|
|
3206
3008
|
}
|
|
@@ -3236,6 +3038,12 @@
|
|
|
3236
3038
|
*/
|
|
3237
3039
|
|
|
3238
3040
|
Elevation.addInitHook(function () {
|
|
3041
|
+
// Alias deprecated functions
|
|
3042
|
+
this.enableDragging = this.enableBrush;
|
|
3043
|
+
this.disableDragging = this.disableBrush;
|
|
3044
|
+
this.loadChart = this.addTo;
|
|
3045
|
+
this.loadData = this.load;
|
|
3046
|
+
this.loadGPX = this.loadXML;
|
|
3239
3047
|
this.on('waypoint_added', function (e) {
|
|
3240
3048
|
var p = e.point,
|
|
3241
3049
|
pop = p._popup;
|
|
@@ -3264,7 +3072,7 @@
|
|
|
3264
3072
|
}
|
|
3265
3073
|
});
|
|
3266
3074
|
this.on('eledata_loaded', function (e) {
|
|
3267
|
-
var
|
|
3075
|
+
var _this18 = this;
|
|
3268
3076
|
|
|
3269
3077
|
var map = this._map;
|
|
3270
3078
|
var layer = e.layer;
|
|
@@ -3275,37 +3083,37 @@
|
|
|
3275
3083
|
}
|
|
3276
3084
|
|
|
3277
3085
|
map.once('layeradd', function (e) {
|
|
3278
|
-
return
|
|
3086
|
+
return _this18.options.autofitBounds && _this18.fitBounds(layer.getBounds());
|
|
3279
3087
|
});
|
|
3280
3088
|
|
|
3281
3089
|
if (L.Browser.mobile) {
|
|
3282
3090
|
if (this.options.polyline) layer.addTo(map);
|
|
3283
3091
|
} else {
|
|
3284
3092
|
// leaflet-geometryutil
|
|
3285
|
-
|
|
3093
|
+
this.lazyLoad(this.__LGEOMUTIL).then(function () {
|
|
3286
3094
|
// leaflet-almostover
|
|
3287
|
-
if (
|
|
3288
|
-
|
|
3095
|
+
if (_this18.options.almostOver) {
|
|
3096
|
+
_this18.lazyLoad(_this18.__LALMOSTOVER).then(function () {
|
|
3289
3097
|
map.addHandler('almostOver', L.Handler.AlmostOver);
|
|
3290
3098
|
|
|
3291
3099
|
if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
|
|
3292
3100
|
map.almostOver.addLayer(layer);
|
|
3293
3101
|
map.on('almost:move', function (e) {
|
|
3294
|
-
return
|
|
3102
|
+
return _this18._mousemoveLayerHandler(e);
|
|
3295
3103
|
}).on('almost:out', function (e) {
|
|
3296
|
-
return
|
|
3104
|
+
return _this18._mouseoutHandler(e);
|
|
3297
3105
|
});
|
|
3298
3106
|
}
|
|
3299
3107
|
});
|
|
3300
3108
|
} // leaflet-distance-markers
|
|
3301
3109
|
|
|
3302
3110
|
|
|
3303
|
-
if (
|
|
3304
|
-
|
|
3305
|
-
return
|
|
3111
|
+
if (_this18.options.distanceMarkers) {
|
|
3112
|
+
_this18.lazyLoad(_this18.__LDISTANCEM).then(function () {
|
|
3113
|
+
return _this18.options.polyline && layer.addTo(map);
|
|
3306
3114
|
});
|
|
3307
3115
|
} else {
|
|
3308
|
-
if (
|
|
3116
|
+
if (_this18.options.polyline) layer.addTo(map);
|
|
3309
3117
|
}
|
|
3310
3118
|
});
|
|
3311
3119
|
}
|
|
@@ -3351,26 +3159,24 @@
|
|
|
3351
3159
|
});
|
|
3352
3160
|
|
|
3353
3161
|
Elevation.addInitHook(function () {
|
|
3354
|
-
var _this = this;
|
|
3355
|
-
|
|
3356
3162
|
var opts = this.options;
|
|
3357
3163
|
var altitude = {};
|
|
3358
3164
|
|
|
3359
3165
|
if (opts.imperial) {
|
|
3360
|
-
|
|
3361
|
-
|
|
3166
|
+
opts.altitudeFactor = this.__footFactor;
|
|
3167
|
+
altitude.label = "ft";
|
|
3362
3168
|
} else {
|
|
3363
|
-
|
|
3364
|
-
|
|
3169
|
+
opts.altitudeFactor = opts.heightFactor || opts.altitudeFactor || 1;
|
|
3170
|
+
altitude.label = opts.yLabel;
|
|
3365
3171
|
}
|
|
3366
3172
|
|
|
3367
3173
|
this.on("eledata_updated", function (e) {
|
|
3368
3174
|
var data = this._data;
|
|
3369
3175
|
var i = e.index;
|
|
3370
|
-
var z = data[i].z *
|
|
3176
|
+
var z = data[i].z * opts.altitudeFactor;
|
|
3371
3177
|
var track = this.track_info;
|
|
3372
|
-
var
|
|
3373
|
-
var
|
|
3178
|
+
var zMax = track.elevation_max || -Infinity;
|
|
3179
|
+
var zMin = track.elevation_min || +Infinity; // check and fix missing elevation data on last added point
|
|
3374
3180
|
|
|
3375
3181
|
if (!this.options.skipNullZCoords && i > 0) {
|
|
3376
3182
|
var prevZ = data[i - 1].z;
|
|
@@ -3394,14 +3200,12 @@
|
|
|
3394
3200
|
|
|
3395
3201
|
|
|
3396
3202
|
if (!isNaN(z)) {
|
|
3397
|
-
eleMax = eleMax < z ? z : eleMax;
|
|
3398
|
-
eleMin = eleMin > z ? z : eleMin;
|
|
3399
3203
|
this._lastValidZ = z;
|
|
3400
3204
|
}
|
|
3401
3205
|
|
|
3206
|
+
track.elevation_max = z > zMax ? z : zMax;
|
|
3207
|
+
track.elevation_min = z < zMin ? z : zMin;
|
|
3402
3208
|
data[i].z = z;
|
|
3403
|
-
track.elevation_max = eleMax;
|
|
3404
|
-
track.elevation_min = eleMin;
|
|
3405
3209
|
});
|
|
3406
3210
|
this.on("elechart_axis", function () {
|
|
3407
3211
|
this._chart._registerAxisGrid({
|
|
@@ -3413,13 +3217,10 @@
|
|
|
3413
3217
|
|
|
3414
3218
|
if (this.options.altitude != "summary") {
|
|
3415
3219
|
this.on("elechart_axis", function () {
|
|
3416
|
-
altitude.y = this._chart._y;
|
|
3417
|
-
altitude.label = this._yLabel;
|
|
3418
|
-
|
|
3419
3220
|
this._chart._registerAxisScale({
|
|
3420
3221
|
axis: "y",
|
|
3421
3222
|
position: "left",
|
|
3422
|
-
scale:
|
|
3223
|
+
scale: this._chart._y,
|
|
3423
3224
|
label: altitude.label,
|
|
3424
3225
|
labelX: -3,
|
|
3425
3226
|
labelY: -8,
|
|
@@ -3429,8 +3230,6 @@
|
|
|
3429
3230
|
this.on("elechart_init", function () {
|
|
3430
3231
|
var theme = this.options.theme.replace('-theme', '');
|
|
3431
3232
|
var color = Colors[theme] || {};
|
|
3432
|
-
var alpha = this.options.detached ? color.alpha || '0.8' : 1;
|
|
3433
|
-
var stroke = this.options.detached ? color.stroke : false;
|
|
3434
3233
|
|
|
3435
3234
|
this._chart._registerAreaPath({
|
|
3436
3235
|
name: 'altitude',
|
|
@@ -3438,21 +3237,21 @@
|
|
|
3438
3237
|
scaleX: 'distance',
|
|
3439
3238
|
scaleY: 'altitude',
|
|
3440
3239
|
color: color.area || theme,
|
|
3441
|
-
strokeColor: stroke
|
|
3240
|
+
strokeColor: this.options.detached ? color.stroke : '#000',
|
|
3442
3241
|
strokeOpacity: "1",
|
|
3443
|
-
fillOpacity: alpha,
|
|
3242
|
+
fillOpacity: this.options.detached ? color.alpha || '0.8' : 1,
|
|
3444
3243
|
preferCanvas: this.options.preferCanvas
|
|
3445
3244
|
});
|
|
3446
3245
|
});
|
|
3447
3246
|
}
|
|
3448
3247
|
|
|
3449
|
-
this.
|
|
3248
|
+
this._registerTooltip({
|
|
3450
3249
|
name: 'y',
|
|
3451
3250
|
chart: function chart(item) {
|
|
3452
|
-
return L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " +
|
|
3251
|
+
return L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label;
|
|
3453
3252
|
},
|
|
3454
3253
|
marker: function marker(item) {
|
|
3455
|
-
return d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " +
|
|
3254
|
+
return d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label;
|
|
3456
3255
|
}
|
|
3457
3256
|
});
|
|
3458
3257
|
|
|
@@ -3460,30 +3259,28 @@
|
|
|
3460
3259
|
"maxele": {
|
|
3461
3260
|
label: "Max Elevation: ",
|
|
3462
3261
|
value: function value(track) {
|
|
3463
|
-
return (track.elevation_max || 0).toFixed(2) + ' ' +
|
|
3262
|
+
return (track.elevation_max || 0).toFixed(2) + ' ' + altitude.label;
|
|
3464
3263
|
}
|
|
3465
3264
|
},
|
|
3466
3265
|
"minele": {
|
|
3467
3266
|
label: "Min Elevation: ",
|
|
3468
3267
|
value: function value(track) {
|
|
3469
|
-
return (track.elevation_min || 0).toFixed(2) + ' ' +
|
|
3268
|
+
return (track.elevation_min || 0).toFixed(2) + ' ' + altitude.label;
|
|
3470
3269
|
}
|
|
3471
3270
|
}
|
|
3472
3271
|
});
|
|
3473
3272
|
});
|
|
3474
3273
|
|
|
3475
3274
|
Elevation.addInitHook(function () {
|
|
3476
|
-
var _this2 = this;
|
|
3477
|
-
|
|
3478
3275
|
var opts = this.options;
|
|
3479
3276
|
var distance = {};
|
|
3480
3277
|
|
|
3481
|
-
if (
|
|
3482
|
-
|
|
3483
|
-
|
|
3278
|
+
if (opts.imperial) {
|
|
3279
|
+
opts.distanceFactor = this.__mileFactor;
|
|
3280
|
+
distance.label = "mi";
|
|
3484
3281
|
} else {
|
|
3485
|
-
|
|
3486
|
-
|
|
3282
|
+
opts.distanceFactor = opts.distanceFactor || 1;
|
|
3283
|
+
distance.label = opts.xLabel;
|
|
3487
3284
|
}
|
|
3488
3285
|
|
|
3489
3286
|
this.on("eledata_updated", function (e) {
|
|
@@ -3493,13 +3290,11 @@
|
|
|
3493
3290
|
var dist = track.distance || 0;
|
|
3494
3291
|
var curr = data[i].latlng;
|
|
3495
3292
|
var prev = i > 0 ? data[i - 1].latlng : curr;
|
|
3496
|
-
|
|
3497
|
-
var delta = curr.distanceTo(prev) * this._distanceFactor;
|
|
3498
|
-
|
|
3293
|
+
var delta = curr.distanceTo(prev) * opts.distanceFactor;
|
|
3499
3294
|
dist += Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
|
|
3500
3295
|
|
|
3501
|
-
data[i].dist = dist;
|
|
3502
3296
|
track.distance = dist;
|
|
3297
|
+
data[i].dist = dist;
|
|
3503
3298
|
});
|
|
3504
3299
|
this.on("elechart_axis", function () {
|
|
3505
3300
|
this._chart._registerAxisGrid({
|
|
@@ -3513,13 +3308,10 @@
|
|
|
3513
3308
|
this.on("elechart_axis", function () {
|
|
3514
3309
|
var _this = this;
|
|
3515
3310
|
|
|
3516
|
-
distance.x = this._chart._x;
|
|
3517
|
-
distance.label = this._chart._xLabel;
|
|
3518
|
-
|
|
3519
3311
|
this._chart._registerAxisScale({
|
|
3520
3312
|
axis: "x",
|
|
3521
3313
|
position: "bottom",
|
|
3522
|
-
scale:
|
|
3314
|
+
scale: this._chart._x,
|
|
3523
3315
|
label: distance.label,
|
|
3524
3316
|
labelY: 25,
|
|
3525
3317
|
labelX: function labelX() {
|
|
@@ -3530,10 +3322,10 @@
|
|
|
3530
3322
|
});
|
|
3531
3323
|
}
|
|
3532
3324
|
|
|
3533
|
-
this.
|
|
3325
|
+
this._registerTooltip({
|
|
3534
3326
|
name: 'x',
|
|
3535
3327
|
chart: function chart(item) {
|
|
3536
|
-
return L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " +
|
|
3328
|
+
return L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + distance.label;
|
|
3537
3329
|
}
|
|
3538
3330
|
});
|
|
3539
3331
|
|
|
@@ -3541,7 +3333,7 @@
|
|
|
3541
3333
|
"totlen": {
|
|
3542
3334
|
label: "Total Length: ",
|
|
3543
3335
|
value: function value(track) {
|
|
3544
|
-
return (track.distance || 0).toFixed(2) + ' ' +
|
|
3336
|
+
return (track.distance || 0).toFixed(2) + ' ' + distance.label;
|
|
3545
3337
|
}
|
|
3546
3338
|
}
|
|
3547
3339
|
});
|
|
@@ -3553,7 +3345,7 @@
|
|
|
3553
3345
|
var opts = this.options;
|
|
3554
3346
|
var time = {};
|
|
3555
3347
|
time.label = opts.timeLabel || 't';
|
|
3556
|
-
|
|
3348
|
+
opts.timeFactor = opts.timeFactor || 3600;
|
|
3557
3349
|
/**
|
|
3558
3350
|
* Common AVG speeds:
|
|
3559
3351
|
* ----------------------
|
|
@@ -3618,7 +3410,7 @@
|
|
|
3618
3410
|
e.point.meta = e.point.meta || {};
|
|
3619
3411
|
var delta = data[i].dist - data[i > 0 ? i - 1 : i].dist;
|
|
3620
3412
|
var speed = this._timeAVGSpeed;
|
|
3621
|
-
e.point.meta.time = new Date(i > 0 ? data[i - 1].time.getTime() + delta / speed *
|
|
3413
|
+
e.point.meta.time = new Date(i > 0 ? data[i - 1].time.getTime() + delta / speed * opts.timeFactor * 1000 : Date.now());
|
|
3622
3414
|
}
|
|
3623
3415
|
|
|
3624
3416
|
var time = e.point.meta.time; // Handle timezone offset
|
|
@@ -3631,13 +3423,13 @@
|
|
|
3631
3423
|
var prevT = i > 0 ? data[i - 1].time : currT;
|
|
3632
3424
|
var deltaT = Math.abs(currT - prevT);
|
|
3633
3425
|
var duration = (this.track_info.time || 0) + deltaT;
|
|
3426
|
+
this.track_info.time = duration;
|
|
3634
3427
|
data[i].time = time;
|
|
3635
3428
|
data[i].duration = duration;
|
|
3636
|
-
this.track_info.time = duration;
|
|
3637
3429
|
});
|
|
3638
3430
|
|
|
3639
3431
|
if (this.options.timestamps) {
|
|
3640
|
-
this.
|
|
3432
|
+
this._registerTooltip({
|
|
3641
3433
|
name: 'date',
|
|
3642
3434
|
chart: function chart(item) {
|
|
3643
3435
|
return L._("t: ") + _this.options.timeFormat(item.time);
|
|
@@ -3646,7 +3438,7 @@
|
|
|
3646
3438
|
}
|
|
3647
3439
|
|
|
3648
3440
|
if (this.options.time) {
|
|
3649
|
-
this.
|
|
3441
|
+
this._registerTooltip({
|
|
3650
3442
|
name: 'time',
|
|
3651
3443
|
chart: function chart(item) {
|
|
3652
3444
|
return L._("T: ") + formatTime(item.duration || 0);
|
|
@@ -3735,22 +3527,15 @@
|
|
|
3735
3527
|
} // Range of acceptable slope values.
|
|
3736
3528
|
|
|
3737
3529
|
|
|
3738
|
-
|
|
3739
|
-
var range = this.options.sRange;
|
|
3740
|
-
if (slope < range[0]) slope = range[0];else if (slope > range[1]) slope = range[1];
|
|
3741
|
-
}
|
|
3742
|
-
|
|
3743
|
-
slope = L.Util.formatNum(slope, 2);
|
|
3744
|
-
if (slope > sMax) sMax = slope;
|
|
3745
|
-
if (slope < sMin) sMin = slope;
|
|
3746
|
-
data[i].slope = slope;
|
|
3530
|
+
slope = clamp(slope, this.options.sRange);
|
|
3747
3531
|
track.ascent = tAsc;
|
|
3748
3532
|
track.descent = tDes;
|
|
3749
|
-
track.slope_max = sMax;
|
|
3750
|
-
track.slope_min = sMin;
|
|
3533
|
+
track.slope_max = slope > sMax ? slope : sMax;
|
|
3534
|
+
track.slope_min = slope < sMin ? slope : sMin;
|
|
3535
|
+
data[i].slope = L.Util.formatNum(slope, 2);
|
|
3751
3536
|
});
|
|
3752
3537
|
|
|
3753
|
-
this.
|
|
3538
|
+
this._registerTooltip({
|
|
3754
3539
|
name: 'slope',
|
|
3755
3540
|
chart: function chart(item) {
|
|
3756
3541
|
return L._("m: ") + item.slope + slope.label;
|
|
@@ -3764,13 +3549,13 @@
|
|
|
3764
3549
|
"ascent": {
|
|
3765
3550
|
label: "Total Ascent: ",
|
|
3766
3551
|
value: function value(track) {
|
|
3767
|
-
return Math.round(track.ascent || 0) + ' ' + _this.
|
|
3552
|
+
return Math.round(track.ascent || 0) + ' ' + (_this.options.imperial ? 'ft' : 'm');
|
|
3768
3553
|
}
|
|
3769
3554
|
},
|
|
3770
3555
|
"descent": {
|
|
3771
3556
|
label: "Total Descent: ",
|
|
3772
3557
|
value: function value(track) {
|
|
3773
|
-
return Math.round(track.descent || 0) + ' ' + _this.
|
|
3558
|
+
return Math.round(track.descent || 0) + ' ' + (_this.options.imperial ? 'ft' : 'm');
|
|
3774
3559
|
}
|
|
3775
3560
|
},
|
|
3776
3561
|
"minslope": {
|
|
@@ -3792,8 +3577,8 @@
|
|
|
3792
3577
|
if (!this.options.speed && !this.options.acceleration) return;
|
|
3793
3578
|
var opts = this.options;
|
|
3794
3579
|
var speed = {};
|
|
3795
|
-
speed.label = opts.speedLabel || L._(
|
|
3796
|
-
|
|
3580
|
+
speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
|
|
3581
|
+
opts.speedFactor = opts.speedFactor || 1;
|
|
3797
3582
|
|
|
3798
3583
|
if (this.options.speed && this.options.speed != "summary") {
|
|
3799
3584
|
this._registerAxisScale({
|
|
@@ -3840,7 +3625,7 @@
|
|
|
3840
3625
|
|
|
3841
3626
|
if (deltaT > 0) {
|
|
3842
3627
|
var delta = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
|
|
3843
|
-
speed = Math.abs(delta / deltaT *
|
|
3628
|
+
speed = Math.abs(delta / deltaT * opts.timeFactor) * opts.speedFactor;
|
|
3844
3629
|
} // Try to smooth "crazy" speed values.
|
|
3845
3630
|
|
|
3846
3631
|
|
|
@@ -3854,23 +3639,15 @@
|
|
|
3854
3639
|
} // Range of acceptable speed values.
|
|
3855
3640
|
|
|
3856
3641
|
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
speed = L.Util.formatNum(speed, 2);
|
|
3863
|
-
sMax = speed > sMax ? speed : sMax;
|
|
3864
|
-
sMin = speed < sMin ? speed : sMin;
|
|
3865
|
-
sAvg = (speed + sAvg) / 2.0;
|
|
3866
|
-
data[i].speed = speed;
|
|
3867
|
-
track.speed_max = sMax;
|
|
3868
|
-
track.speed_min = sMin;
|
|
3869
|
-
track.speed_avg = sAvg;
|
|
3642
|
+
speed = clamp(speed, this.options.speedRange);
|
|
3643
|
+
track.speed_max = speed > sMax ? speed : sMax;
|
|
3644
|
+
track.speed_min = speed < sMin ? speed : sMin;
|
|
3645
|
+
track.speed_avg = (speed + sAvg) / 2.0;
|
|
3646
|
+
data[i].speed = L.Util.formatNum(speed, 2);
|
|
3870
3647
|
});
|
|
3871
3648
|
|
|
3872
3649
|
if (this.options.speed) {
|
|
3873
|
-
this.
|
|
3650
|
+
this._registerTooltip({
|
|
3874
3651
|
name: 'speed',
|
|
3875
3652
|
chart: function chart(item) {
|
|
3876
3653
|
return L._('v: ') + item.speed + " " + speed.label;
|
|
@@ -3907,8 +3684,8 @@
|
|
|
3907
3684
|
if (!this.options.acceleration) return;
|
|
3908
3685
|
var opts = this.options;
|
|
3909
3686
|
var acceleration = {};
|
|
3910
|
-
acceleration.label = opts.accelerationLabel || L._(
|
|
3911
|
-
|
|
3687
|
+
acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
|
|
3688
|
+
opts.accelerationFactor = opts.accelerationFactor || 1;
|
|
3912
3689
|
|
|
3913
3690
|
if (this.options.acceleration != "summary") {
|
|
3914
3691
|
this._registerAxisScale({
|
|
@@ -3956,8 +3733,8 @@
|
|
|
3956
3733
|
if (deltaT > 0) {
|
|
3957
3734
|
var curr = data[i].speed;
|
|
3958
3735
|
var prev = i > 0 ? data[i - 1].speed : curr;
|
|
3959
|
-
var delta = (curr - prev) * (1000 /
|
|
3960
|
-
acceleration = Math.abs(delta / deltaT) *
|
|
3736
|
+
var delta = (curr - prev) * (1000 / opts.timeFactor);
|
|
3737
|
+
acceleration = Math.abs(delta / deltaT) * opts.accelerationFactor;
|
|
3961
3738
|
} // Try to smooth "crazy" acceleration values.
|
|
3962
3739
|
|
|
3963
3740
|
|
|
@@ -3971,22 +3748,14 @@
|
|
|
3971
3748
|
} // Range of acceptable acceleration values.
|
|
3972
3749
|
|
|
3973
3750
|
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
acceleration = L.Util.formatNum(acceleration, 2);
|
|
3980
|
-
if (acceleration > sMax) sMax = acceleration;
|
|
3981
|
-
if (acceleration < sMin) sMin = acceleration;
|
|
3982
|
-
sAvg = (acceleration + sAvg) / 2.0;
|
|
3983
|
-
data[i].acceleration = acceleration;
|
|
3984
|
-
track.acceleration_max = sMax;
|
|
3985
|
-
track.acceleration_min = sMin;
|
|
3986
|
-
track.acceleration_avg = sAvg;
|
|
3751
|
+
acceleration = clamp(acceleration, this.options.accelerationRange);
|
|
3752
|
+
track.acceleration_max = acceleration > sMax ? acceleration : sMax;
|
|
3753
|
+
track.acceleration_min = acceleration < sMin ? acceleration : sMin;
|
|
3754
|
+
track.acceleration_avg = (acceleration + sAvg) / 2.0;
|
|
3755
|
+
data[i].acceleration = L.Util.formatNum(acceleration, 2);
|
|
3987
3756
|
});
|
|
3988
3757
|
|
|
3989
|
-
this.
|
|
3758
|
+
this._registerTooltip({
|
|
3990
3759
|
name: 'acceleration',
|
|
3991
3760
|
chart: function chart(item) {
|
|
3992
3761
|
return L._("a: ") + item.acceleration + " " + acceleration.label;
|