@raruto/leaflet-elevation 1.7.6 → 1.8.2

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.
@@ -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
- * Generate download data event.
378
+ * Convert SVG Path into Path2D and then update canvas
395
379
  */
396
380
 
397
- function saveFile(dataURI, fileName) {
398
- var a = create('a', '', {
399
- href: dataURI,
400
- target: '_new',
401
- download: fileName || "",
402
- style: "display:none;"
403
- });
404
- var b = document.body;
405
- b.appendChild(a);
406
- a.click();
407
- b.removeChild(a);
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
- * Wait for element visible before execute function.
400
+ * Limit a number between min / max values
411
401
  */
412
402
 
413
- function waitHolder(elem) {
414
- return new Promise(function (resolve, reject) {
415
- var ticking = false;
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
- waitHolder: waitHolder,
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 HeightFocusLine = function HeightFocusLine(_ref4) {
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 (line) {
684
- return line.attr("class", theme + " height-focus line").attr("x1", xCoord).attr("x2", xCoord).attr("y1", yCoord).attr("y2", length);
685
- };
686
- };
687
- var HeightFocusLabel = function HeightFocusLabel(_ref5) {
688
- var theme = _ref5.theme,
689
- _ref5$xCoord = _ref5.xCoord,
690
- xCoord = _ref5$xCoord === void 0 ? 0 : _ref5$xCoord,
691
- _ref5$yCoord = _ref5.yCoord,
692
- yCoord = _ref5$yCoord === void 0 ? 0 : _ref5$yCoord,
693
- _ref5$labels = _ref5.labels,
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 text;
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(_ref7) {
727
- var name = _ref7.name,
728
- label = _ref7.label,
729
- width = _ref7.width,
730
- height = _ref7.height,
731
- _ref7$margins = _ref7.margins,
732
- margins = _ref7$margins === void 0 ? {} : _ref7$margins,
733
- color = _ref7.color,
734
- path = _ref7.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 svg.dispatch("legend_clicked", {
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 MouseFocusLine = function MouseFocusLine(_ref8) {
754
- var _ref8$xCoord = _ref8.xCoord,
755
- xCoord = _ref8$xCoord === void 0 ? 0 : _ref8$xCoord,
756
- height = _ref8.height;
757
- return function (line) {
758
- return line.attr('class', 'mouse-focus-line').attr('x2', xCoord).attr('y2', 0).attr('x1', xCoord).attr('y1', height);
759
- };
760
- };
761
- var MouseFocusLabel = function MouseFocusLabel(_ref9) {
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.attr('class', 'mouse-focus-label');
771
- var rect = g.select(".mouse-focus-label-rect");
772
- var text = g.select(".mouse-focus-label-text");
773
- if (!rect.node()) rect = g.append("svg:rect");
774
- if (!text.node()) text = g.append("svg:text"); // Sets focus-label-text position to the left / right of the mouse-focus-line
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(_ref10) {
811
- var height = _ref10.height,
812
- width = _ref10.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 Domain = function Domain(_ref11) {
860
- var min = _ref11.min,
861
- max = _ref11.max,
862
- attr = _ref11.attr,
863
- name = _ref11.name,
864
- forceBounds = _ref11.forceBounds,
865
- scale = _ref11.scale;
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(_ref12) {
885
- var axis = _ref12.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(_ref13) {
891
- var data = _ref13.data,
892
- attr = _ref13.attr,
893
- min = _ref13.min,
894
- max = _ref13.max,
895
- forceBounds = _ref13.forceBounds,
896
- range = _ref13.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(_ref14) {
905
- var _ref14$data = _ref14.data,
906
- data = _ref14$data === void 0 ? [0, 1] : _ref14$data,
907
- scale = _ref14.scale,
908
- x = _ref14.x,
909
- attr = _ref14.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(_ref15) {
915
- var width = _ref15.width,
916
- height = _ref15.height,
917
- _ref15$margins = _ref15.margins,
918
- margins = _ref15$margins === void 0 ? {} : _ref15$margins,
919
- ruler = _ref15.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
 
@@ -937,32 +949,24 @@
937
949
  legend: g.append('g').attr("class", "legend")
938
950
  }; // SVG Paths
939
951
 
940
- var clipPath = panes.area.append("svg:clipPath").attr("id", 'elevation-clipper');
941
- var clipRect = clipPath.append("svg:rect"); // Canvas Paths
952
+ var mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
953
+ var maskRect = mask.append("svg:rect").attr('class', 'zoom').attr('fill', 'white'); // white = transparent
954
+ // Canvas Paths
942
955
 
943
- var foreignObject = panes.area.append('svg:foreignObject');
956
+ var foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
944
957
  var canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
945
- var context = canvas.node().getContext('2d'); // Mouse Focus
958
+ var context = canvas.node().getContext('2d'); // Add tooltip
946
959
 
947
- var dragG = panes.ruler;
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({
960
+ panes.tooltip.call(Tooltip({
955
961
  xCoord: 0,
956
962
  yCoord: 0,
957
963
  height: _height,
958
964
  width: _width,
959
- labels: {} // labelX: "",
960
- // labelY: "",
961
-
965
+ labels: {}
962
966
  })); // Add the brushing
963
967
 
964
968
  var brush = d3.brushX().on('start.cursor end.cursor brush.cursor', function () {
965
- return brushG.select(".overlay").attr('cursor', null);
969
+ return panes.brush.select(".overlay").attr('cursor', null);
966
970
  }); // Scales
967
971
 
968
972
  var scale = function scale(opts) {
@@ -973,11 +977,9 @@
973
977
  };
974
978
 
975
979
  var utils = {
976
- clipPath: clipPath,
980
+ mask: mask,
977
981
  canvas: canvas,
978
982
  context: context,
979
- dragG: dragG,
980
- focusG: focusG,
981
983
  brush: brush
982
984
  };
983
985
  var chart = {
@@ -988,12 +990,12 @@
988
990
  scale: scale
989
991
  }; // Resize
990
992
 
991
- chart._resize = function (_ref16) {
992
- var width = _ref16.width,
993
- height = _ref16.height,
994
- _ref16$margins = _ref16.margins,
995
- margins = _ref16$margins === void 0 ? {} : _ref16$margins,
996
- ruler = _ref16.ruler;
993
+ chart._resize = function (_ref14) {
994
+ var width = _ref14.width,
995
+ height = _ref14.height,
996
+ _ref14$margins = _ref14.margins,
997
+ margins = _ref14$margins === void 0 ? {} : _ref14$margins,
998
+ ruler = _ref14.ruler;
997
999
 
998
1000
  var _width = width - margins.left - margins.right;
999
1001
 
@@ -1006,19 +1008,19 @@
1006
1008
  canvas.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
1007
1009
  }
1008
1010
 
1009
- clipRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
1011
+ maskRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
1010
1012
  foreignObject.attr('width', _width).attr('height', _height);
1011
1013
  canvas.attr('width', _width).attr('height', _height);
1012
1014
 
1013
1015
  if (ruler) {
1014
- dragG.call(Ruler({
1016
+ panes.ruler.call(Ruler({
1015
1017
  height: _height,
1016
1018
  width: _width
1017
1019
  }));
1018
1020
  }
1019
1021
 
1020
- brushG.call(brush.extent([[0, 0], [_width, _height]]));
1021
- brushG.select(".overlay").attr('cursor', null);
1022
+ panes.brush.call(brush.extent([[0, 0], [_width, _height]]));
1023
+ panes.brush.select(".overlay").attr('cursor', null);
1022
1024
  chart._width = _width;
1023
1025
  chart._height = _height;
1024
1026
  chart.svg.dispatch('resize', {
@@ -1057,13 +1059,11 @@
1057
1059
  Path: Path,
1058
1060
  Axis: Axis,
1059
1061
  Grid: Grid,
1060
- HeightFocusLine: HeightFocusLine,
1061
- HeightFocusLabel: HeightFocusLabel,
1062
- HeightFocusMarker: HeightFocusMarker,
1062
+ PositionMarker: PositionMarker,
1063
1063
  LegendItem: LegendItem,
1064
- MouseFocusLine: MouseFocusLine,
1065
- MouseFocusLabel: MouseFocusLabel,
1064
+ Tooltip: Tooltip,
1066
1065
  Ruler: Ruler,
1066
+ CheckPoint: CheckPoint,
1067
1067
  Domain: Domain,
1068
1068
  Range: Range,
1069
1069
  Scale: Scale,
@@ -1074,6 +1074,8 @@
1074
1074
  var Chart$1 = L.Class.extend({
1075
1075
  includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
1076
1076
  initialize: function initialize(opts, control) {
1077
+ var _this = this;
1078
+
1077
1079
  this.options = opts;
1078
1080
  this.control = control;
1079
1081
  this._data = []; // cache registered components
@@ -1085,7 +1087,7 @@
1085
1087
  grids: {},
1086
1088
  axes: {},
1087
1089
  legendItems: {},
1088
- focusLabels: {}
1090
+ tooltipItems: {}
1089
1091
  };
1090
1092
  this._scales = {};
1091
1093
  this._domains = {};
@@ -1093,15 +1095,6 @@
1093
1095
  this._paths = {};
1094
1096
  this._brushEnabled = opts.dragging;
1095
1097
  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
1098
  var chart = this._chart = Chart(opts); // SVG Container
1106
1099
 
1107
1100
  var svg = this._container = chart.svg; // Panes
@@ -1110,25 +1103,31 @@
1110
1103
  this._area = chart.pane('area');
1111
1104
  this._point = chart.pane('point');
1112
1105
  this._axis = chart.pane('axis');
1113
- this._legend = chart.pane('legend'); // Scales
1106
+ this._legend = chart.pane('legend');
1107
+ this._tooltip = chart.pane('tooltip');
1108
+ this._ruler = chart.pane('ruler'); // Scales
1114
1109
 
1115
1110
  this._initScale(); // Helpers
1116
1111
 
1117
1112
 
1118
- this._clipPath = chart.get('clipPath');
1119
- this._canvas = chart.get('canvas');
1113
+ this._mask = chart.get('mask');
1120
1114
  this._context = chart.get('context');
1121
- this._dragG = chart.get('dragG');
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');
1115
+ this._brush = chart.get('brush');
1127
1116
  this._zoom = d3.zoom();
1128
1117
  this._drag = d3.drag(); // Interactions
1129
1118
 
1130
1119
  this._initInteractions(); // svg.on('resize', (e)=>console.log(e.detail));
1120
+ // Handle multi-track segments (BETA)
1121
+
1131
1122
 
1123
+ this._maskGaps = [];
1124
+ control.on('eletrack_added', function (e) {
1125
+ _this._maskGaps.push(e.index);
1126
+
1127
+ control.once('eledata_updated', function (e) {
1128
+ return _this._maskGaps.push(e.index);
1129
+ });
1130
+ });
1132
1131
  },
1133
1132
  update: function update(props) {
1134
1133
  if (props) {
@@ -1149,11 +1148,11 @@
1149
1148
  return this;
1150
1149
  },
1151
1150
  render: function render() {
1152
- var _this = this;
1151
+ var _this2 = this;
1153
1152
 
1154
1153
  return function (container) {
1155
1154
  return container.append(function () {
1156
- return _this._container.node();
1155
+ return _this2._container.node();
1157
1156
  });
1158
1157
  };
1159
1158
  },
@@ -1164,52 +1163,32 @@
1164
1163
 
1165
1164
  this._area.selectAll('path').attr("d", "M0 0");
1166
1165
 
1167
- this._context.clearRect(0, 0, this._width(), this._height());
1166
+ this._context.clearRect(0, 0, this._width(), this._height()); // if (this._path) {
1167
+ // this._x.domain([0, 1]);
1168
+ // this._y.domain([0, 1]);
1169
+ // }
1170
+
1168
1171
 
1169
- if (this._path) ;
1172
+ this._maskGaps = [];
1173
+
1174
+ this._mask.selectAll(".gap").remove();
1170
1175
  },
1171
1176
  _drawPath: function _drawPath(name) {
1172
- var opts = this.options;
1173
- var ctx = this._context;
1174
1177
  var path = this._paths[name];
1175
1178
  var area = this._props.areas[name];
1176
- var node = path.node();
1177
- var scaleX = this._scales[area.scaleX];
1178
- var scaleY = this._scales[area.scaleY];
1179
- area = L.extend({}, area, {
1179
+ path.datum(this._data).attr("d", Area(L.extend({}, area, {
1180
1180
  width: this._width(),
1181
1181
  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));
1182
+ scaleX: this._scales[area.scaleX],
1183
+ scaleY: this._scales[area.scaleY]
1184
+ })));
1191
1185
  if (path.classed('leaflet-hidden')) return;
1192
1186
 
1193
- if (opts.preferCanvas) {
1194
- path.classed('canvas-path', true);
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();
1187
+ if (this.options.preferCanvas) {
1188
+ drawCanvas(this._context, path);
1210
1189
  } else {
1211
1190
  this._area.append(function () {
1212
- return node;
1191
+ return path.node();
1213
1192
  });
1214
1193
  }
1215
1194
  },
@@ -1229,43 +1208,43 @@
1229
1208
  * Initialize "d3-brush".
1230
1209
  */
1231
1210
  _initBrush: function _initBrush(e) {
1232
- var _this2 = this;
1211
+ var _this3 = this;
1233
1212
 
1234
1213
  var brush = function brush(e) {
1235
- if (!_this2._data.length) return;
1214
+ if (!_this3._data.length) return;
1236
1215
  var extent = e.selection;
1237
1216
 
1238
1217
  if (extent) {
1239
- var start = _this2._findIndexForXCoord(extent[0]);
1218
+ var start = _this3._findIndexForXCoord(extent[0]);
1240
1219
 
1241
- var end = _this2._findIndexForXCoord(extent[1]);
1220
+ var end = _this3._findIndexForXCoord(extent[1]);
1242
1221
 
1243
- _this2.fire('dragged', {
1244
- dragstart: _this2._data[start],
1245
- dragend: _this2._data[end]
1222
+ _this3.fire('dragged', {
1223
+ dragstart: _this3._data[start],
1224
+ dragend: _this3._data[end]
1246
1225
  });
1247
1226
  }
1248
1227
  };
1249
1228
 
1250
1229
  var focus = function focus(e) {
1251
- if (!_this2._data.length) return;
1230
+ if (!_this3._data.length) return;
1252
1231
  if (e.type == 'brush' && !e.sourceEvent) return;
1253
1232
 
1254
- var rect = _this2._chart.panes.brush.select('.overlay').node();
1233
+ var rect = _this3._chart.panes.brush.select('.overlay').node();
1255
1234
 
1256
1235
  var coords = d3.pointers(e, rect)[0];
1257
1236
  var xCoord = coords[0];
1258
1237
 
1259
- var item = _this2._data[_this2._findIndexForXCoord(xCoord)];
1238
+ var item = _this3._data[_this3._findIndexForXCoord(xCoord)];
1260
1239
 
1261
- _this2.fire("mouse_move", {
1240
+ _this3.fire("mouse_move", {
1262
1241
  item: item,
1263
1242
  xCoord: xCoord
1264
1243
  });
1265
1244
  };
1266
1245
 
1267
1246
  this._brush.filter(function (e) {
1268
- return _this2._brushEnabled && !e.shiftKey && !e.button;
1247
+ return _this3._brushEnabled && !e.shiftKey && !e.button;
1269
1248
  }).on("end.update", brush).on("brush.update", focus);
1270
1249
 
1271
1250
  this._chart.panes.brush.on("mouseenter.focus touchstart.focus", this.fire.bind(this, "mouse_enter")).on("mouseout.focus touchend.focus", this.fire.bind(this, "mouse_out")).on("mousemove.focus touchmove.focus", focus);
@@ -1275,7 +1254,7 @@
1275
1254
  * Initialize "d3-zoom"
1276
1255
  */
1277
1256
  _initClipper: function _initClipper() {
1278
- var _this3 = this;
1257
+ var _this4 = this;
1279
1258
 
1280
1259
  var svg = this._container;
1281
1260
  var margin = this.options.margins;
@@ -1285,42 +1264,52 @@
1285
1264
  if (e.sourceEvent && e.sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing');
1286
1265
 
1287
1266
  if (e.transform.k == 1 && e.transform.x == 0) {
1288
- _this3._container.classed('zoomed', true);
1267
+ _this4._container.classed('zoomed', true); // Apply d3-zoom (bind <clipPath> mask)
1268
+
1269
+
1270
+ if (_this4._mask) {
1271
+ _this4._point.attr('mask', 'url(#' + _this4._mask.attr('id') + ')');
1272
+ }
1289
1273
  }
1290
1274
 
1291
- _this3.zooming = true;
1275
+ _this4.zooming = true;
1292
1276
  };
1293
1277
 
1294
1278
  var onEnd = function onEnd(e) {
1295
1279
  if (e.transform.k == 1 && e.transform.x == 0) {
1296
- _this3._container.classed('zoomed', false);
1280
+ _this4._container.classed('zoomed', false); // Apply d3-zoom (bind <clipPath> mask)
1281
+
1282
+
1283
+ if (_this4._mask) {
1284
+ _this4._point.attr('mask', null);
1285
+ }
1297
1286
  }
1298
1287
 
1299
- _this3.zooming = false;
1288
+ _this4.zooming = false;
1300
1289
  svg.style('cursor', '');
1301
1290
  };
1302
1291
 
1303
1292
  var onZoom = function onZoom(e) {
1304
1293
  // TODO: find a faster way to redraw the chart.
1305
- _this3.zooming = false;
1294
+ _this4.zooming = false;
1306
1295
 
1307
- _this3._updateScale(); // hacky way for restoring x scale when zooming out
1296
+ _this4._updateScale(); // hacky way for restoring x scale when zooming out
1308
1297
 
1309
1298
 
1310
- _this3.zooming = true;
1311
- _this3._scales.distance = _this3._x = e.transform.rescaleX(_this3._x); // calculate x scale at zoom level
1299
+ _this4.zooming = true;
1300
+ _this4._scales.distance = _this4._x = e.transform.rescaleX(_this4._x); // calculate x scale at zoom level
1312
1301
 
1313
- _this3._resetDrag();
1302
+ _this4._resetDrag();
1314
1303
 
1315
1304
  if (e.sourceEvent && e.sourceEvent.type == "mousemove") {
1316
- _this3._hideDiagramIndicator();
1305
+ _this4._hideDiagramIndicator();
1317
1306
  }
1318
1307
 
1319
- _this3.fire('zoom');
1308
+ _this4.fire('zoom');
1320
1309
  };
1321
1310
 
1322
1311
  zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]).filter(function (e) {
1323
- return _this3._zoomEnabled && (e.shiftKey || e.buttons == 4);
1312
+ return _this4._zoomEnabled && (e.shiftKey || e.buttons == 4);
1324
1313
  }).on("start", onStart).on("end", onEnd).on("zoom", onZoom);
1325
1314
  svg.call(zoom); // add zoom functionality to "svg" group
1326
1315
  // d3.select("body").on("keydown.grabzoom keyup.grabzoom", (e) => svg.style('cursor', e.shiftKey ? 'move' : ''));
@@ -1339,7 +1328,7 @@
1339
1328
  * Toggle chart data on legend click
1340
1329
  */
1341
1330
  _initLegend: function _initLegend() {
1342
- var _this4 = this;
1331
+ var _this5 = this;
1343
1332
 
1344
1333
  this._container.on('legend_clicked', function (e) {
1345
1334
  var _e$detail = e.detail,
@@ -1359,9 +1348,9 @@
1359
1348
 
1360
1349
  toggleClass(path, 'leaflet-hidden', enabled);
1361
1350
 
1362
- _this4._updateArea();
1351
+ _this5._updateArea();
1363
1352
 
1364
- _this4.fire("elepath_toggle", {
1353
+ _this5.fire("elepath_toggle", {
1365
1354
  path: path,
1366
1355
  name: name,
1367
1356
  legend: legend,
@@ -1374,7 +1363,7 @@
1374
1363
  * Initialize "ruler".
1375
1364
  */
1376
1365
  _initRuler: function _initRuler() {
1377
- var _this5 = this;
1366
+ var _this6 = this;
1378
1367
 
1379
1368
  if (!this.options.ruler) return; // const yMax = this._height();
1380
1369
 
@@ -1382,41 +1371,41 @@
1382
1371
  var drag = this._drag;
1383
1372
 
1384
1373
  var label = function label(e, d) {
1385
- var yMax = _this5._height();
1374
+ var yMax = _this6._height();
1386
1375
 
1387
- var y = _this5._dragG.data()[0].y;
1376
+ var y = _this6._ruler.data()[0].y;
1388
1377
 
1389
- if (y >= yMax || y <= 0) _this5._dragG.select(".horizontal-drag-label").text('');
1378
+ if (y >= yMax || y <= 0) _this6._ruler.select(".horizontal-drag-label").text('');
1390
1379
 
1391
- _this5._hideDiagramIndicator();
1380
+ _this6._hideDiagramIndicator();
1392
1381
  };
1393
1382
 
1394
1383
  var position = function position(e, d) {
1395
- var yMax = _this5._height();
1384
+ var yMax = _this6._height();
1396
1385
 
1397
- var yCoord = d3.pointers(e, _this5._area.node())[0][1];
1386
+ var yCoord = d3.pointers(e, _this6._area.node())[0][1];
1398
1387
  var y = yCoord > 0 ? yCoord < yMax ? yCoord : yMax : 0;
1399
1388
 
1400
- var z = _this5._y.invert(y);
1389
+ var z = _this6._y.invert(y);
1401
1390
 
1402
- var data = L.extend(_this5._dragG.data()[0], {
1391
+ var data = L.extend(_this6._ruler.data()[0], {
1403
1392
  y: y
1404
1393
  });
1405
1394
 
1406
- _this5._dragG.data([data]).attr("transform", function (d) {
1395
+ _this6._ruler.data([data]).attr("transform", function (d) {
1407
1396
  return "translate(" + d.x + "," + d.y + ")";
1408
1397
  }).classed('active', y < yMax);
1409
1398
 
1410
- _this5._container.select(".horizontal-drag-label").text(formatNum(z) + " " + _this5._yLabel);
1399
+ _this6._container.select(".horizontal-drag-label").text(formatNum(z) + " " + (_this6.options.imperial ? 'ft' : 'm'));
1411
1400
 
1412
- _this5.fire('ruler_filter', {
1413
- coords: yCoord < yMax && yCoord > 0 ? _this5._findCoordsForY(yCoord) : []
1401
+ _this6.fire('ruler_filter', {
1402
+ coords: yCoord < yMax && yCoord > 0 ? _this6._findCoordsForY(yCoord) : []
1414
1403
  });
1415
1404
  };
1416
1405
 
1417
1406
  drag.on("start end", label).on("drag", position);
1418
1407
 
1419
- this._dragG.call(drag);
1408
+ this._ruler.call(drag);
1420
1409
  },
1421
1410
 
1422
1411
  /**
@@ -1495,7 +1484,7 @@
1495
1484
  },
1496
1485
 
1497
1486
  /**
1498
- * Add a waypoint of interest over the chart
1487
+ * Add a point of interest over the chart
1499
1488
  */
1500
1489
  _registerCheckPoint: function _registerCheckPoint(point) {
1501
1490
  if (!this._data.length) return;
@@ -1509,49 +1498,18 @@
1509
1498
  x = this._x(point.dist);
1510
1499
  item = this._data[this._findIndexForXCoord(x)];
1511
1500
  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
1501
  }
1524
1502
 
1525
- point.item.datum({
1526
- pos: point.position,
1503
+ this._point.call(CheckPoint({
1504
+ point: point,
1505
+ width: this._width(),
1506
+ height: this._height(),
1527
1507
  x: x,
1528
1508
  y: y
1529
- }).attr("class", function (d) {
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
- }
1509
+ }));
1552
1510
  },
1553
- _registerFocusLabel: function _registerFocusLabel(props) {
1554
- this._props.focusLabels[props.name] = props;
1511
+ _registerTooltip: function _registerTooltip(props) {
1512
+ this._props.tooltipItems[props.name] = props;
1555
1513
  },
1556
1514
  _updateArea: function _updateArea() {
1557
1515
  var paths = this._paths; // Reset and update chart profiles
@@ -1614,14 +1572,32 @@
1614
1572
  });
1615
1573
  },
1616
1574
  _updateClipper: function _updateClipper() {
1575
+ var _this7 = this;
1576
+
1617
1577
  var margin = this.options.margins;
1618
1578
 
1619
- this._zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]);
1579
+ this._zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]); // Apply svg mask on multi-track segments (BETA)
1580
+
1581
+
1582
+ this._mask.selectAll(".gap").remove();
1583
+
1584
+ this._maskGaps.forEach(function (d, i) {
1585
+ if (i >= _this7._maskGaps.length - 2) return;
1586
+ var d1 = _this7._data[_this7._maskGaps[i]];
1587
+ var d2 = _this7._data[_this7._maskGaps[i + 1]];
1588
+
1589
+ var x1 = _this7._x(_this7._data[_this7._findIndexForLatLng(d1.latlng)].dist);
1590
+
1591
+ var x2 = _this7._x(_this7._data[_this7._findIndexForLatLng(d2.latlng)].dist);
1592
+
1593
+ _this7._mask.append("rect").attr("x", x1).attr("y", 0).attr("width", x2 - x1).attr("height", _this7._height()).attr('class', 'gap').attr('fill-opacity', '0.8').attr("fill", 'black'); // black = hide
1594
+
1595
+ });
1620
1596
  },
1621
1597
  _updateLegend: function _updateLegend() {
1622
- var _this6 = this;
1598
+ var _this8 = this;
1623
1599
 
1624
- if (this.options.legend == false) return;
1600
+ if (this.options.legend === false) return;
1625
1601
  var legends = this._props.legendItems;
1626
1602
  var legend; // Reset legend items
1627
1603
 
@@ -1675,21 +1651,21 @@
1675
1651
  var legend = d3.select(n[i]);
1676
1652
  var rect = legend.select('rect');
1677
1653
  var name = legend.attr('data-name');
1678
- var path = _this6._paths[name];
1654
+ var path = _this8._paths[name];
1679
1655
  var tx = v[i] * 55;
1680
1656
  var ty = xAxesB * 2;
1681
1657
  legend // Adjust legend item positions
1682
1658
  .attr("transform", "translate(" + tx + ", " + ty + ")"); // Set initial state (disabled controls)
1683
1659
 
1684
- if (name in _this6.options && _this6.options[name] == 'disabled') {
1660
+ if (name in _this8.options && _this8.options[name] == 'disabled') {
1685
1661
  path.classed('leaflet-hidden', true);
1686
1662
  legend.select('text').style('text-decoration-line', 'line-through');
1687
1663
  legend.select('rect').style('fill-opacity', '0');
1688
1664
  } // Apply d3-zoom (bind <clipPath> mask)
1689
1665
 
1690
1666
 
1691
- if (_this6._clipPath) {
1692
- path.attr('clip-path', 'url(#' + _this6._clipPath.attr('id') + ')');
1667
+ if (_this8._mask) {
1668
+ path.attr('mask', 'url(#' + _this8._mask.attr('id') + ')');
1693
1669
  }
1694
1670
  });
1695
1671
  },
@@ -1698,13 +1674,9 @@
1698
1674
  x: this._x,
1699
1675
  y: this._y
1700
1676
  };
1701
- var opts = this.options;
1702
- var scales = this._scales;
1703
- var d = this._domains;
1704
- var r = this._ranges;
1705
1677
 
1706
- for (var i in scales) {
1707
- scales[i].domain(d[i](this._data)).range(r[i](this._width(), this._height()));
1678
+ for (var i in this._scales) {
1679
+ this._scales[i].domain(this._domains[i](this._data)).range(this._ranges[i](this._width(), this._height()));
1708
1680
  }
1709
1681
 
1710
1682
  return {
@@ -1762,10 +1734,10 @@
1762
1734
  * Finds a data entry for a given x-coordinate of the diagram
1763
1735
  */
1764
1736
  _findIndexForXCoord: function _findIndexForXCoord(x) {
1765
- var _this7 = this;
1737
+ var _this9 = this;
1766
1738
 
1767
1739
  return d3.bisector(function (d) {
1768
- return d[_this7.options.xAttr];
1740
+ return d[_this9.options.xAttr];
1769
1741
  }).left(this._data || [0, 1], this._x.invert(x));
1770
1742
  },
1771
1743
 
@@ -1810,28 +1782,17 @@
1810
1782
  * Display distance and altitude level ("focus-rect").
1811
1783
  */
1812
1784
  _showDiagramIndicator: function _showDiagramIndicator(item, xCoordinate) {
1813
- var opts = this.options;
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({
1785
+ this._tooltip.attr("display", null).call(Tooltip({
1825
1786
  xCoord: xCoordinate,
1826
- yCoord: yCoordinate,
1787
+ yCoord: this._y(item[this.options.yAttr]),
1827
1788
  height: this._height(),
1828
1789
  width: this._width(),
1829
- labels: this._props.focusLabels,
1790
+ labels: this._props.tooltipItems,
1830
1791
  item: item
1831
1792
  }));
1832
1793
  },
1833
1794
  _hideDiagramIndicator: function _hideDiagramIndicator() {
1834
- this._focusG.attr("display", 'none');
1795
+ this._tooltip.attr("display", 'none');
1835
1796
  }
1836
1797
  });
1837
1798
 
@@ -1839,51 +1800,40 @@
1839
1800
  initialize: function initialize(options) {
1840
1801
  this.options = options;
1841
1802
 
1842
- if (this.options.imperial) {
1843
- this._xLabel = "mi";
1844
- this._yLabel = "ft";
1845
- } else {
1846
- this._xLabel = this.options.xLabel;
1847
- this._yLabel = this.options.yLabel;
1848
- }
1849
-
1850
- if (this.options.marker == 'elevation-line') {
1851
- // this._container = d3.create("g").attr("class", "height-focus-group");
1852
- this._focusline = d3.create('svg:line');
1853
- this._focusmarker = d3.create("svg:circle");
1854
- this._focuslabel = d3.create("svg:text");
1855
- } else if (this.options.marker == 'position-marker') {
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
- });
1803
+ switch (this.options.marker) {
1804
+ case 'elevation-line':
1805
+ // this._container = d3.create("g").attr("class", "height-focus-group");
1806
+ this._container = d3.select(map.getPane('elevationPane')).select("svg > g").attr("class", "height-focus-group");
1807
+ break;
1808
+
1809
+ case 'position-marker':
1810
+ // this._marker = L.circleMarker([0, 0], { pane: 'overlayPane', radius: 6, fillColor: '#fff', fillOpacity:1, color: '#000', weight:1, interactive: false });
1811
+ this._marker = L.marker([0, 0], {
1812
+ icon: this.options.markerIcon,
1813
+ zIndexOffset: 1000000,
1814
+ interactive: false
1815
+ });
1816
+ break;
1862
1817
  }
1863
1818
 
1864
- this._focuslabels = {};
1819
+ this._labels = {};
1865
1820
  return this;
1866
1821
  },
1867
1822
  addTo: function addTo(map) {
1868
- var _this = this;
1869
-
1870
1823
  this._map = map;
1871
1824
 
1872
- if (this.options.marker == 'elevation-line') {
1873
- var g = this._container = d3.select(map.getPane('elevationPane')).select("svg > g").attr("class", "height-focus-group");
1874
- g.append(function () {
1875
- return _this._focusline.node();
1876
- });
1877
- g.append(function () {
1878
- return _this._focusmarker.node();
1879
- });
1880
- g.append(function () {
1881
- return _this._focuslabel.node();
1882
- });
1883
- } else if (this.options.marker == 'position-marker') {
1884
- this._marker.addTo(map, {
1885
- pane: 'overlayPane'
1886
- });
1825
+ switch (this.options.marker) {
1826
+ case 'elevation-line':
1827
+ this._container.call(PositionMarker({}));
1828
+
1829
+ break;
1830
+
1831
+ case 'position-marker':
1832
+ this._marker.addTo(map, {
1833
+ pane: 'overlayPane'
1834
+ });
1835
+
1836
+ break;
1887
1837
  }
1888
1838
 
1889
1839
  return this;
@@ -1897,47 +1847,34 @@
1897
1847
  if (!props) return;
1898
1848
  if (props.options) this.options = props.options;
1899
1849
  if (!this._map) this.addTo(props.map);
1900
- var opts = this.options;
1901
- var map = this._map;
1902
1850
  this._latlng = props.item.latlng;
1903
- var pos = map.latLngToLayerPoint(this._latlng);
1904
1851
 
1905
- if (map._rotate) {
1906
- pos = map.rotatedPointToMapPanePoint(pos);
1907
- }
1852
+ switch (this.options.marker) {
1853
+ case 'elevation-line':
1854
+ var point = this._map.latLngToLayerPoint(this._latlng);
1908
1855
 
1909
- var point = L.extend({}, props.item, pos);
1856
+ point = L.extend({}, props.item, this._map._rotate ? this._map.rotatedPointToMapPanePoint(point) : point);
1910
1857
 
1911
- if (this.options.marker == 'elevation-line') {
1912
- var normalizedAlt = this._height() / props.maxElevation * point.z;
1913
- var normalizedY = point.y - normalizedAlt;
1858
+ this._container.classed("leaflet-hidden", false);
1914
1859
 
1915
- this._container.classed("leaflet-hidden", false);
1860
+ this._container.call(PositionMarker({
1861
+ theme: this.options.theme,
1862
+ xCoord: point.x,
1863
+ yCoord: point.y,
1864
+ length: point.y - this._height() / props.maxElevation * point.z,
1865
+ // normalized Y
1866
+ labels: this._labels,
1867
+ item: point
1868
+ }));
1916
1869
 
1917
- this._focusmarker.call(HeightFocusMarker({
1918
- theme: opts.theme,
1919
- xCoord: point.x,
1920
- yCoord: point.y
1921
- }));
1870
+ break;
1922
1871
 
1923
- this._focusline.call(HeightFocusLine({
1924
- theme: opts.theme,
1925
- xCoord: point.x,
1926
- yCoord: point.y,
1927
- length: normalizedY
1928
- }));
1872
+ case 'position-marker':
1873
+ removeClass(this._marker.getElement(), 'leaflet-hidden');
1929
1874
 
1930
- this._focuslabel.call(HeightFocusLabel({
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');
1875
+ this._marker.setLatLng(this._latlng);
1939
1876
 
1940
- this._marker.setLatLng(this._latlng);
1877
+ break;
1941
1878
  }
1942
1879
  },
1943
1880
 
@@ -1947,10 +1884,15 @@
1947
1884
  remove: function remove() {
1948
1885
  this._props = null;
1949
1886
 
1950
- if (this.options.marker == 'elevation-line') {
1951
- if (this._container) this._container.classed("leaflet-hidden", true);
1952
- } else if (this.options.marker == 'position-marker') {
1953
- addClass(this._marker.getElement(), 'leaflet-hidden');
1887
+ switch (this.options.marker) {
1888
+ case 'elevation-line':
1889
+ this._container && this._container.classed("leaflet-hidden", true);
1890
+ break;
1891
+
1892
+ case 'position-marker':
1893
+ addClass(this._marker.getElement(), 'leaflet-hidden');
1894
+
1895
+ break;
1954
1896
  }
1955
1897
  },
1956
1898
  getLatLng: function getLatLng() {
@@ -1964,8 +1906,8 @@
1964
1906
  var opts = this.options;
1965
1907
  return opts.height - opts.margins.top - opts.margins.bottom;
1966
1908
  },
1967
- _registerFocusLabel: function _registerFocusLabel(props) {
1968
- this._focuslabels[props.name] = props;
1909
+ _registerTooltip: function _registerTooltip(props) {
1910
+ this._labels[props.name] = props;
1969
1911
  }
1970
1912
  });
1971
1913
 
@@ -2010,7 +1952,6 @@
2010
1952
  collapsed: false,
2011
1953
  detached: true,
2012
1954
  distance: true,
2013
- distanceFactor: 1,
2014
1955
  distanceMarkers: false,
2015
1956
  decimalsX: 2,
2016
1957
  decimalsY: 0,
@@ -2020,15 +1961,10 @@
2020
1961
  followMarker: true,
2021
1962
  forceAxisBounds: false,
2022
1963
  height: 200,
2023
- heightFactor: 1,
2024
1964
  imperial: false,
2025
1965
  interpolation: "curveLinear",
2026
1966
  lazyLoadJS: true,
2027
1967
  legend: true,
2028
- loadData: {
2029
- defer: false,
2030
- lazy: false
2031
- },
2032
1968
  margins: {
2033
1969
  top: 30,
2034
1970
  right: 30,
@@ -2042,7 +1978,6 @@
2042
1978
  iconSize: [32, 32],
2043
1979
  iconAnchor: [16, 16]
2044
1980
  }),
2045
- placeholder: false,
2046
1981
  position: "topright",
2047
1982
  polyline: {
2048
1983
  className: 'elevation-polyline',
@@ -2061,7 +1996,6 @@
2061
1996
  ruler: true,
2062
1997
  skipNullZCoords: false,
2063
1998
  theme: "lightblue-theme",
2064
- responsive: true,
2065
1999
  summary: 'inline',
2066
2000
  slope: false,
2067
2001
  speed: false,
@@ -2105,7 +2039,7 @@
2105
2039
  __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@4.3.0/dist/togeojson.umd.js',
2106
2040
  __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js',
2107
2041
  __LALMOSTOVER: 'https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js',
2108
- __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.7.5/libs/leaflet-distance-marker.min.js',
2042
+ __LDISTANCEM: 'https://unpkg.com/@raruto/leaflet-elevation@1.8.2/libs/leaflet-distance-marker.min.js',
2109
2043
 
2110
2044
  /*
2111
2045
  * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
@@ -2113,11 +2047,11 @@
2113
2047
  addData: function addData(d, layer) {
2114
2048
  var _this = this;
2115
2049
 
2116
- if (typeof layer === "undefined" && d.on) {
2117
- layer = d;
2118
- }
2050
+ this.lazyLoad(this.__D3).then(function () {
2051
+ if (typeof layer === "undefined" && d.on) {
2052
+ layer = d;
2053
+ }
2119
2054
 
2120
- Elevation._d3LazyLoader = lazyLoader(this.__D3, (typeof d3 === "undefined" ? "undefined" : _typeof(d3)) !== 'object' || !this.options.lazyLoadJS, Elevation._d3LazyLoader).then(function () {
2121
2055
  _this._addData(d);
2122
2056
 
2123
2057
  _this._addLayer(layer);
@@ -2212,20 +2146,6 @@
2212
2146
  this._chart._brushEnabled = true;
2213
2147
  },
2214
2148
 
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
2149
  /**
2230
2150
  * Disable chart zooming.
2231
2151
  */
@@ -2260,7 +2180,7 @@
2260
2180
  * Get default zoom level when "followMarker" is true.
2261
2181
  */
2262
2182
  getZFollow: function getZFollow() {
2263
- return this._zFollow;
2183
+ return this.options.zFollow;
2264
2184
  },
2265
2185
 
2266
2186
  /**
@@ -2280,50 +2200,29 @@
2280
2200
  this._markedSegments = L.polyline([]);
2281
2201
  this._chartEnabled = true, this.track_info = {};
2282
2202
  this.options = deepMerge({}, this.options, options);
2283
- this._zFollow = this.options.zFollow;
2284
2203
  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
2204
  if (this.options.legend) this.options.margins.bottom += 30;
2287
2205
  if (this.options.theme) this.options.polylineSegments.className += ' ' + this.options.theme;
2206
+ if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons;
2288
2207
 
2289
- this._markedSegments.setStyle(this.options.polylineSegments); // this._resizeChart = _.debounce(this._resizeChart, 300, this);
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
- // }
2295
-
2208
+ this._markedSegments.setStyle(this.options.polylineSegments); // Leaflet canvas renderer colors
2296
2209
 
2297
- if (this.options.wptIcons === true) this.options.wptIcons = Options.wptIcons; // Leaflet canvas renderer colors
2298
2210
 
2299
2211
  L.extend(Colors, this.options.colors || {});
2300
2212
  },
2301
2213
 
2302
2214
  /**
2303
- * Alias for loadData
2304
- */
2305
- load: function load(data, opts) {
2306
- this.loadData(data, opts);
2307
- },
2308
-
2309
- /**
2310
- * Alias for addTo
2215
+ * Javascript scripts downloader (lazy loader)
2311
2216
  */
2312
- loadChart: function loadChart(map) {
2313
- this.addTo(map);
2217
+ lazyLoad: function lazyLoad$1(src) {
2218
+ return lazyLoad(src, this);
2314
2219
  },
2315
2220
 
2316
2221
  /**
2317
2222
  * Load elevation data (GPX, GeoJSON or KML).
2318
2223
  */
2319
- loadData: function loadData(data, opts) {
2320
- opts = L.extend({}, this.options.loadData, opts);
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)) {
2224
+ load: function load(data) {
2225
+ if (isXMLDoc(data)) {
2327
2226
  this.loadXML(data);
2328
2227
  } else if (isJSONDoc(data)) {
2329
2228
  this.loadGeoJSON(data);
@@ -2332,16 +2231,6 @@
2332
2231
  }
2333
2232
  },
2334
2233
 
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
2234
  /**
2346
2235
  * Load data from a remote url.
2347
2236
  */
@@ -2353,10 +2242,7 @@
2353
2242
  }).then(function (data) {
2354
2243
  _this3._downloadURL = url; // TODO: handle multiple urls?
2355
2244
 
2356
- _this3.loadData(data, {
2357
- lazy: false,
2358
- defer: false
2359
- });
2245
+ _this3.load(data);
2360
2246
  }).catch(function (err) {
2361
2247
  return console.warn(err);
2362
2248
  });
@@ -2369,20 +2255,13 @@
2369
2255
  GeoJSONLoader(data, this);
2370
2256
  },
2371
2257
 
2372
- /**
2373
- * Alias for loadXML
2374
- */
2375
- loadGPX: function loadGPX(data) {
2376
- this.loadXML(data);
2377
- },
2378
-
2379
2258
  /**
2380
2259
  * Load raw XML data.
2381
2260
  */
2382
2261
  loadXML: function loadXML(data) {
2383
2262
  var _this4 = this;
2384
2263
 
2385
- Elevation._togeojsonLazyLoader = lazyLoader(this.__TOGEOJSON, typeof toGeoJSON !== 'function' || !this.options.lazyLoadJS, Elevation._togeojsonLazyLoader).then(function () {
2264
+ this.lazyLoad(this.__TOGEOJSON).then(function () {
2386
2265
  var xml = new DOMParser().parseFromString(data, "text/xml");
2387
2266
  var type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"
2388
2267
 
@@ -2403,32 +2282,12 @@
2403
2282
  });
2404
2283
  },
2405
2284
 
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
2285
  /**
2427
2286
  * Create container DOM element and related event listeners.
2428
2287
  * Called on control.addTo(map).
2429
2288
  */
2430
2289
  onAdd: function onAdd(map) {
2431
- var _this6 = this;
2290
+ var _this5 = this;
2432
2291
 
2433
2292
  this._map = map;
2434
2293
 
@@ -2438,37 +2297,28 @@
2438
2297
  addClass(container, 'leaflet-control');
2439
2298
  }
2440
2299
 
2441
- if (this.options.placeholder && !this._data.length) {
2442
- this.placeholder = create('img', 'elevation-placeholder', typeof this.options.placeholder === 'string' ? {
2443
- src: this.options.placeholder,
2444
- alt: ''
2445
- } : this.options.placeholder);
2446
-
2447
- insert(container, this.placeholder, 'afterbegin');
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);
2300
+ this.lazyLoad(this.__D3).then(function () {
2301
+ _this5._initButton(container);
2452
2302
 
2453
- _this6._initChart(container);
2303
+ _this5._initChart(container);
2454
2304
 
2455
- _this6._initSummary(container);
2305
+ _this5._initSummary(container);
2456
2306
 
2457
- _this6._initMarker(map);
2307
+ _this5._initMarker(map);
2458
2308
 
2459
- _this6._initLayer(map);
2309
+ _this5._initLayer(map);
2460
2310
 
2461
- map.on('zoom viewreset zoomanim', _this6._hideMarker, _this6).on('resize', _this6._resetView, _this6).on('resize', _this6._resizeChart, _this6).on('rotate', _this6._rotateMarker, _this6).on('mousedown', _this6._resetDrag, _this6);
2311
+ 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
2312
 
2463
- on(map.getContainer(), 'mousewheel', _this6._resetDrag, _this6);
2313
+ on(map.getContainer(), 'mousewheel', _this5._resetDrag, _this5);
2464
2314
 
2465
- on(map.getContainer(), 'touchstart', _this6._resetDrag, _this6);
2315
+ on(map.getContainer(), 'touchstart', _this5._resetDrag, _this5);
2466
2316
 
2467
- _this6.on('eledata_added eledata_loaded', _this6._updateChart, _this6).on('eledata_added eledata_loaded', _this6._updateSummary, _this6);
2317
+ _this5.on('eledata_added eledata_loaded', _this5._updateChart, _this5).on('eledata_added eledata_loaded', _this5._updateSummary, _this5);
2468
2318
 
2469
- _this6._updateChart();
2319
+ _this5._updateChart();
2470
2320
 
2471
- _this6._updateSummary();
2321
+ _this5._updateSummary();
2472
2322
  });
2473
2323
  return container;
2474
2324
  },
@@ -2499,7 +2349,7 @@
2499
2349
  * Set default zoom level when "followMarker" is true.
2500
2350
  */
2501
2351
  setZFollow: function setZFollow(zoom) {
2502
- this._zFollow = zoom;
2352
+ this.options.zFollow = zoom;
2503
2353
  },
2504
2354
 
2505
2355
  /**
@@ -2513,7 +2363,7 @@
2513
2363
  * Parsing data either from GPX or GeoJSON and update the diagram data
2514
2364
  */
2515
2365
  _addData: function _addData(d) {
2516
- var _this7 = this;
2366
+ var _this6 = this;
2517
2367
 
2518
2368
  if (!d) {
2519
2369
  return;
@@ -2530,7 +2380,7 @@
2530
2380
 
2531
2381
  case 'MultiLineString':
2532
2382
  each(geom.coordinates, function (coords) {
2533
- return _this7._addGeoJSONData(coords);
2383
+ return _this6._addGeoJSONData(coords);
2534
2384
  });
2535
2385
 
2536
2386
  break;
@@ -2542,7 +2392,7 @@
2542
2392
 
2543
2393
  if (d.type === "FeatureCollection") {
2544
2394
  each(d.features, function (feature) {
2545
- return _this7._addData(feature);
2395
+ return _this6._addData(feature);
2546
2396
  });
2547
2397
  }
2548
2398
 
@@ -2555,14 +2405,14 @@
2555
2405
  * Parsing of GeoJSON data lines and their elevation in z-coordinate
2556
2406
  */
2557
2407
  _addGeoJSONData: function _addGeoJSONData(coords) {
2558
- var _this8 = this;
2408
+ var _this7 = this;
2559
2409
 
2560
2410
  each(coords, function (point) {
2561
- _this8._addPoint(point[1], point[0], point[2]);
2411
+ _this7._addPoint(point[1], point[0], point[2]);
2562
2412
 
2563
- _this8._fireEvt("elepoint_added", {
2413
+ _this7._fireEvt("elepoint_added", {
2564
2414
  point: point,
2565
- index: _this8._data.length - 1
2415
+ index: _this7._data.length - 1
2566
2416
  });
2567
2417
  });
2568
2418
 
@@ -2576,14 +2426,16 @@
2576
2426
  * Parsing function for GPX data and their elevation in z-coordinate
2577
2427
  */
2578
2428
  _addGPXData: function _addGPXData(coords) {
2579
- var _this9 = this;
2429
+ var _this8 = this;
2580
2430
 
2581
2431
  each(coords, function (point) {
2582
- _this9._addPoint(point.lat, point.lng, typeof point.alt !== "undefined" ? point.alt : point.meta.ele);
2432
+ var _point$alt;
2433
+
2434
+ _this8._addPoint(point.lat, point.lng, (_point$alt = point.alt) !== null && _point$alt !== void 0 ? _point$alt : point.meta.ele);
2583
2435
 
2584
- _this9._fireEvt("elepoint_added", {
2436
+ _this8._fireEvt("elepoint_added", {
2585
2437
  point: point,
2586
- index: _this9._data.length - 1
2438
+ index: _this8._data.length - 1
2587
2439
  });
2588
2440
  });
2589
2441
 
@@ -2704,21 +2556,19 @@
2704
2556
  opts.xTicks = this._xTicks();
2705
2557
  opts.yTicks = this._yTicks();
2706
2558
 
2707
- if (opts.responsive) {
2708
- if (opts.detached) {
2709
- var _this$eleDiv = this.eleDiv,
2710
- offsetWidth = _this$eleDiv.offsetWidth,
2711
- offsetHeight = _this$eleDiv.offsetHeight;
2712
- if (offsetWidth > 0) opts.width = offsetWidth;
2713
- if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
2714
- } else {
2715
- var _this$_map$getContain = this._map.getContainer(),
2716
- clientWidth = _this$_map$getContain.clientWidth;
2559
+ if (opts.detached) {
2560
+ var _this$eleDiv = this.eleDiv,
2561
+ offsetWidth = _this$eleDiv.offsetWidth,
2562
+ offsetHeight = _this$eleDiv.offsetHeight;
2563
+ if (offsetWidth > 0) opts.width = offsetWidth;
2564
+ if (offsetHeight > 20) opts.height = offsetHeight - 20; // 20 = horizontal scrollbar size.
2565
+ } else {
2566
+ var _this$_map$getContain = this._map.getContainer(),
2567
+ clientWidth = _this$_map$getContain.clientWidth;
2717
2568
 
2718
- opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
2719
- this._container.style.maxWidth = opts._maxWidth + 'px';
2720
- if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
2721
- }
2569
+ opts._maxWidth = opts._maxWidth > opts.width ? opts._maxWidth : opts.width;
2570
+ this._container.style.maxWidth = opts._maxWidth + 'px';
2571
+ if (opts._maxWidth > clientWidth) opts.width = clientWidth - 30;
2722
2572
  }
2723
2573
 
2724
2574
  var chart = this._chart = new Chart$1(opts, this);
@@ -2734,17 +2584,17 @@
2734
2584
  this._fireEvt("elechart_init");
2735
2585
  },
2736
2586
  _initLayer: function _initLayer() {
2737
- var _this10 = this;
2587
+ var _this9 = this;
2738
2588
 
2739
2589
  this._layers.on('layeradd layerremove', function (e) {
2740
2590
  var layer = e.layer;
2741
2591
  var node = layer.getElement && layer.getElement();
2742
2592
 
2743
- toggleClass(node, _this10.options.polyline.className + ' ' + _this10.options.theme, e.type == 'layeradd');
2593
+ toggleClass(node, _this9.options.polyline.className + ' ' + _this9.options.theme, e.type == 'layeradd');
2744
2594
 
2745
- toggleEvent(layer, "mousemove", _this10._mousemoveLayerHandler.bind(_this10), e.type == 'layeradd');
2595
+ toggleEvent(layer, "mousemove", _this9._mousemoveLayerHandler.bind(_this9), e.type == 'layeradd');
2746
2596
 
2747
- toggleEvent(layer, "mouseout", _this10._mouseoutHandler.bind(_this10), e.type == 'layeradd');
2597
+ toggleEvent(layer, "mouseout", _this9._mouseoutHandler.bind(_this9), e.type == 'layeradd');
2748
2598
  });
2749
2599
  },
2750
2600
  _initMarker: function _initMarker(map) {
@@ -2775,7 +2625,7 @@
2775
2625
  container.setAttribute('aria-haspopup', true);
2776
2626
 
2777
2627
  if (!this.options.detached) {
2778
- L.DomEvent.disableClickPropagation(container); //.disableScrollPropagation(container);
2628
+ L.DomEvent.disableClickPropagation(container).disableScrollPropagation(container);
2779
2629
  }
2780
2630
 
2781
2631
  if (L.Browser.mobile) {
@@ -2918,10 +2768,10 @@
2918
2768
  * Add a waypoint marker to the diagram
2919
2769
  */
2920
2770
  _registerCheckPoint: function _registerCheckPoint(props) {
2921
- var _this11 = this;
2771
+ var _this10 = this;
2922
2772
 
2923
2773
  this.on("elechart_updated", function () {
2924
- return _this11._chart._registerCheckPoint(props);
2774
+ return _this10._chart._registerCheckPoint(props);
2925
2775
  });
2926
2776
  },
2927
2777
 
@@ -2929,10 +2779,10 @@
2929
2779
  * Add chart profile to diagram
2930
2780
  */
2931
2781
  _registerAreaPath: function _registerAreaPath(props) {
2932
- var _this12 = this;
2782
+ var _this11 = this;
2933
2783
 
2934
2784
  this.on("elechart_init", function () {
2935
- return _this12._chart._registerAreaPath(props);
2785
+ return _this11._chart._registerAreaPath(props);
2936
2786
  });
2937
2787
  },
2938
2788
 
@@ -2940,10 +2790,10 @@
2940
2790
  * Add chart grid to diagram
2941
2791
  */
2942
2792
  _registerAxisGrid: function _registerAxisGrid(props) {
2943
- var _this13 = this;
2793
+ var _this12 = this;
2944
2794
 
2945
2795
  this.on("elechart_axis", function () {
2946
- return _this13._chart._registerAxisGrid(props);
2796
+ return _this12._chart._registerAxisGrid(props);
2947
2797
  });
2948
2798
  },
2949
2799
 
@@ -2951,25 +2801,25 @@
2951
2801
  * Add chart axis to diagram
2952
2802
  */
2953
2803
  _registerAxisScale: function _registerAxisScale(props) {
2954
- var _this14 = this;
2804
+ var _this13 = this;
2955
2805
 
2956
2806
  this.on("elechart_axis", function () {
2957
- return _this14._chart._registerAxisScale(props);
2807
+ return _this13._chart._registerAxisScale(props);
2958
2808
  });
2959
2809
  },
2960
2810
 
2961
2811
  /**
2962
2812
  * Add chart or marker tooltip info
2963
2813
  */
2964
- _registerFocusLabel: function _registerFocusLabel(props) {
2965
- var _this15 = this;
2814
+ _registerTooltip: function _registerTooltip(props) {
2815
+ var _this14 = this;
2966
2816
 
2967
2817
  if (props.chart) {
2968
2818
  var label = L.extend({}, props, {
2969
2819
  value: props.chart
2970
2820
  });
2971
2821
  this.on("elechart_init", function () {
2972
- return _this15._chart._registerFocusLabel(label);
2822
+ return _this14._chart._registerTooltip(label);
2973
2823
  });
2974
2824
  }
2975
2825
 
@@ -2979,7 +2829,7 @@
2979
2829
  });
2980
2830
 
2981
2831
  this.on("elechart_marker", function () {
2982
- return _this15._marker._registerFocusLabel(_label);
2832
+ return _this14._marker._registerTooltip(_label);
2983
2833
  });
2984
2834
  }
2985
2835
  },
@@ -2988,10 +2838,10 @@
2988
2838
  * Add summary info to diagram
2989
2839
  */
2990
2840
  _registerSummary: function _registerSummary(props) {
2991
- var _this16 = this;
2841
+ var _this15 = this;
2992
2842
 
2993
2843
  this.on('elechart_summary', function () {
2994
- return _this16._summary._registerSummary(props);
2844
+ return _this15._summary._registerSummary(props);
2995
2845
  });
2996
2846
  },
2997
2847
 
@@ -3027,31 +2877,28 @@
3027
2877
 
3028
2878
  if (style(this._container, "display") == "none") return;
3029
2879
  var opts = this.options;
2880
+ var newWidth;
3030
2881
 
3031
- if (opts.responsive) {
3032
- var newWidth;
3033
-
3034
- if (opts.detached) {
3035
- newWidth = (this.eleDiv || this._container).offsetWidth;
3036
- } else {
3037
- var _this$_map$getContain2 = this._map.getContainer(),
3038
- clientWidth = _this$_map$getContain2.clientWidth;
2882
+ if (opts.detached) {
2883
+ newWidth = (this.eleDiv || this._container).offsetWidth;
2884
+ } else {
2885
+ var _this$_map$getContain2 = this._map.getContainer(),
2886
+ clientWidth = _this$_map$getContain2.clientWidth;
3039
2887
 
3040
- newWidth = opts._maxWidth > clientWidth ? clientWidth - 30 : opts._maxWidth;
3041
- }
2888
+ newWidth = opts._maxWidth > clientWidth ? clientWidth - 30 : opts._maxWidth;
2889
+ }
3042
2890
 
3043
- if (newWidth) {
3044
- var chart = this._chart;
3045
- opts.width = newWidth;
2891
+ if (newWidth) {
2892
+ var chart = this._chart;
2893
+ opts.width = newWidth;
3046
2894
 
3047
- if (chart && chart._chart) {
3048
- chart._chart._resize(opts);
2895
+ if (chart && chart._chart) {
2896
+ chart._chart._resize(opts);
3049
2897
 
3050
- opts.xTicks = this._xTicks();
3051
- opts.yTicks = this._yTicks();
2898
+ opts.xTicks = this._xTicks();
2899
+ opts.yTicks = this._yTicks();
3052
2900
 
3053
- this._updateChart();
3054
- }
2901
+ this._updateChart();
3055
2902
  }
3056
2903
  }
3057
2904
 
@@ -3080,10 +2927,10 @@
3080
2927
 
3081
2928
  var zoom = this._map.getZoom();
3082
2929
 
3083
- if ("number" === typeof this._zFollow) {
3084
- if (zoom < this._zFollow) zoom = this._zFollow;
2930
+ var z = this.options.zFollow;
3085
2931
 
3086
- this._map.setView(item.latlng, zoom, {
2932
+ if (typeof z === "number") {
2933
+ this._map.setView(item.latlng, zoom < z ? z : zoom, {
3087
2934
  animate: true,
3088
2935
  duration: 0.25
3089
2936
  });
@@ -3099,7 +2946,7 @@
3099
2946
  * Toggle chart data on legend click
3100
2947
  */
3101
2948
  _toggleChartHandler: function _toggleChartHandler(e) {
3102
- var _this17 = this;
2949
+ var _this16 = this;
3103
2950
 
3104
2951
  var path = e.path,
3105
2952
  name = e.name,
@@ -3109,7 +2956,7 @@
3109
2956
  this._layers.eachLayer(function (layer) {
3110
2957
  var node = layer.getElement && layer.getElement();
3111
2958
 
3112
- toggleClass(node, _this17.options.polyline.className + ' ' + _this17.options.theme, _this17._chartEnabled);
2959
+ toggleClass(node, _this16.options.polyline.className + ' ' + _this16.options.theme, _this16._chartEnabled);
3113
2960
  }); // toggle option value (eg. altitude = { 'disabled' || 'disabled' })
3114
2961
 
3115
2962
 
@@ -3149,23 +2996,23 @@
3149
2996
  * Update the position/height indicator marker drawn onto the map
3150
2997
  */
3151
2998
  _updateMarker: function _updateMarker(item) {
3152
- if (!this._marker) return;
3153
-
3154
- this._marker.update({
3155
- map: this._map,
3156
- item: item,
3157
- maxElevation: this.track_info.elevation_max || 0,
3158
- options: this.options
3159
- });
2999
+ if (this._marker) {
3000
+ this._marker.update({
3001
+ map: this._map,
3002
+ item: item,
3003
+ maxElevation: this.track_info.elevation_max || 0,
3004
+ options: this.options
3005
+ });
3006
+ }
3160
3007
  },
3161
3008
 
3162
3009
  /**
3163
3010
  * Fix marker rotation on rotated maps
3164
3011
  */
3165
3012
  _rotateMarker: function _rotateMarker() {
3166
- if (!this._marker) return;
3167
-
3168
- this._marker.update();
3013
+ if (this._marker) {
3014
+ this._marker.update();
3015
+ }
3169
3016
  },
3170
3017
 
3171
3018
  /**
@@ -3183,7 +3030,7 @@
3183
3030
  * Update chart summary.
3184
3031
  */
3185
3032
  _updateSummary: function _updateSummary() {
3186
- var _this18 = this;
3033
+ var _this17 = this;
3187
3034
 
3188
3035
  this._summary.reset();
3189
3036
 
@@ -3198,9 +3045,9 @@
3198
3045
  select('.download a', this.summaryDiv).onclick = function (e) {
3199
3046
  e.preventDefault();
3200
3047
 
3201
- _this18._fireEvt('eletrack_download', {
3202
- downloadLink: _this18.options.downloadLink,
3203
- confirm: saveFile.bind(_this18, _this18._downloadURL)
3048
+ _this17._fireEvt('eletrack_download', {
3049
+ downloadLink: _this17.options.downloadLink,
3050
+ confirm: saveFile.bind(_this17, _this17._downloadURL)
3204
3051
  });
3205
3052
  };
3206
3053
  }
@@ -3236,6 +3083,12 @@
3236
3083
  */
3237
3084
 
3238
3085
  Elevation.addInitHook(function () {
3086
+ // Alias deprecated functions
3087
+ this.enableDragging = this.enableBrush;
3088
+ this.disableDragging = this.disableBrush;
3089
+ this.loadChart = this.addTo;
3090
+ this.loadData = this.load;
3091
+ this.loadGPX = this.loadXML;
3239
3092
  this.on('waypoint_added', function (e) {
3240
3093
  var p = e.point,
3241
3094
  pop = p._popup;
@@ -3264,7 +3117,7 @@
3264
3117
  }
3265
3118
  });
3266
3119
  this.on('eledata_loaded', function (e) {
3267
- var _this19 = this;
3120
+ var _this18 = this;
3268
3121
 
3269
3122
  var map = this._map;
3270
3123
  var layer = e.layer;
@@ -3275,37 +3128,37 @@
3275
3128
  }
3276
3129
 
3277
3130
  map.once('layeradd', function (e) {
3278
- return _this19.options.autofitBounds && _this19.fitBounds(layer.getBounds());
3131
+ return _this18.options.autofitBounds && _this18.fitBounds(layer.getBounds());
3279
3132
  });
3280
3133
 
3281
3134
  if (L.Browser.mobile) {
3282
3135
  if (this.options.polyline) layer.addTo(map);
3283
3136
  } else {
3284
3137
  // leaflet-geometryutil
3285
- Elevation._geomutilLazyLoader = lazyLoader(this.__LGEOMUTIL, typeof L.GeometryUtil !== 'function' || !this.options.lazyLoadJS, Elevation._geomutilLazyLoader).then(function () {
3138
+ this.lazyLoad(this.__LGEOMUTIL).then(function () {
3286
3139
  // leaflet-almostover
3287
- if (_this19.options.almostOver) {
3288
- Elevation._almostoverLazyLoader = lazyLoader(_this19.__LALMOSTOVER, typeof L.Handler.AlmostOver !== 'function' || !_this19.options.lazyLoadJS, Elevation._almostoverLazyLoader).then(function () {
3140
+ if (_this18.options.almostOver) {
3141
+ _this18.lazyLoad(_this18.__LALMOSTOVER).then(function () {
3289
3142
  map.addHandler('almostOver', L.Handler.AlmostOver);
3290
3143
 
3291
3144
  if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) {
3292
3145
  map.almostOver.addLayer(layer);
3293
3146
  map.on('almost:move', function (e) {
3294
- return _this19._mousemoveLayerHandler(e);
3147
+ return _this18._mousemoveLayerHandler(e);
3295
3148
  }).on('almost:out', function (e) {
3296
- return _this19._mouseoutHandler(e);
3149
+ return _this18._mouseoutHandler(e);
3297
3150
  });
3298
3151
  }
3299
3152
  });
3300
3153
  } // leaflet-distance-markers
3301
3154
 
3302
3155
 
3303
- if (_this19.options.distanceMarkers) {
3304
- Elevation._distanceMarkersLazyLoader = lazyLoader(_this19.__LDISTANCEM, typeof L.DistanceMarkers !== 'function' || !_this19.options.lazyLoadJS, Elevation._distanceMarkersLazyLoader).then(function () {
3305
- return _this19.options.polyline && layer.addTo(map);
3156
+ if (_this18.options.distanceMarkers) {
3157
+ _this18.lazyLoad(_this18.__LDISTANCEM).then(function () {
3158
+ return _this18.options.polyline && layer.addTo(map);
3306
3159
  });
3307
3160
  } else {
3308
- if (_this19.options.polyline) layer.addTo(map);
3161
+ if (_this18.options.polyline) layer.addTo(map);
3309
3162
  }
3310
3163
  });
3311
3164
  }
@@ -3351,26 +3204,24 @@
3351
3204
  });
3352
3205
 
3353
3206
  Elevation.addInitHook(function () {
3354
- var _this = this;
3355
-
3356
3207
  var opts = this.options;
3357
3208
  var altitude = {};
3358
3209
 
3359
3210
  if (opts.imperial) {
3360
- this._heightFactor = this.__footFactor;
3361
- this._yLabel = "ft";
3211
+ opts.altitudeFactor = this.__footFactor;
3212
+ altitude.label = "ft";
3362
3213
  } else {
3363
- this._heightFactor = opts.heightFactor;
3364
- this._yLabel = opts.yLabel;
3214
+ opts.altitudeFactor = opts.heightFactor || opts.altitudeFactor || 1;
3215
+ altitude.label = opts.yLabel;
3365
3216
  }
3366
3217
 
3367
3218
  this.on("eledata_updated", function (e) {
3368
3219
  var data = this._data;
3369
3220
  var i = e.index;
3370
- var z = data[i].z * this._heightFactor;
3221
+ var z = data[i].z * opts.altitudeFactor;
3371
3222
  var track = this.track_info;
3372
- var eleMax = track.elevation_max || -Infinity;
3373
- var eleMin = track.elevation_min || +Infinity; // check and fix missing elevation data on last added point
3223
+ var zMax = track.elevation_max || -Infinity;
3224
+ var zMin = track.elevation_min || +Infinity; // check and fix missing elevation data on last added point
3374
3225
 
3375
3226
  if (!this.options.skipNullZCoords && i > 0) {
3376
3227
  var prevZ = data[i - 1].z;
@@ -3394,14 +3245,12 @@
3394
3245
 
3395
3246
 
3396
3247
  if (!isNaN(z)) {
3397
- eleMax = eleMax < z ? z : eleMax;
3398
- eleMin = eleMin > z ? z : eleMin;
3399
3248
  this._lastValidZ = z;
3400
3249
  }
3401
3250
 
3251
+ track.elevation_max = z > zMax ? z : zMax;
3252
+ track.elevation_min = z < zMin ? z : zMin;
3402
3253
  data[i].z = z;
3403
- track.elevation_max = eleMax;
3404
- track.elevation_min = eleMin;
3405
3254
  });
3406
3255
  this.on("elechart_axis", function () {
3407
3256
  this._chart._registerAxisGrid({
@@ -3413,13 +3262,10 @@
3413
3262
 
3414
3263
  if (this.options.altitude != "summary") {
3415
3264
  this.on("elechart_axis", function () {
3416
- altitude.y = this._chart._y;
3417
- altitude.label = this._yLabel;
3418
-
3419
3265
  this._chart._registerAxisScale({
3420
3266
  axis: "y",
3421
3267
  position: "left",
3422
- scale: altitude.y,
3268
+ scale: this._chart._y,
3423
3269
  label: altitude.label,
3424
3270
  labelX: -3,
3425
3271
  labelY: -8,
@@ -3429,8 +3275,6 @@
3429
3275
  this.on("elechart_init", function () {
3430
3276
  var theme = this.options.theme.replace('-theme', '');
3431
3277
  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
3278
 
3435
3279
  this._chart._registerAreaPath({
3436
3280
  name: 'altitude',
@@ -3438,21 +3282,21 @@
3438
3282
  scaleX: 'distance',
3439
3283
  scaleY: 'altitude',
3440
3284
  color: color.area || theme,
3441
- strokeColor: stroke || '#000',
3285
+ strokeColor: this.options.detached ? color.stroke : '#000',
3442
3286
  strokeOpacity: "1",
3443
- fillOpacity: alpha,
3287
+ fillOpacity: this.options.detached ? color.alpha || '0.8' : 1,
3444
3288
  preferCanvas: this.options.preferCanvas
3445
3289
  });
3446
3290
  });
3447
3291
  }
3448
3292
 
3449
- this._registerFocusLabel({
3293
+ this._registerTooltip({
3450
3294
  name: 'y',
3451
3295
  chart: function chart(item) {
3452
- return L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + _this._yLabel;
3296
+ return L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label;
3453
3297
  },
3454
3298
  marker: function marker(item) {
3455
- return d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + _this._yLabel;
3299
+ return d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + altitude.label;
3456
3300
  }
3457
3301
  });
3458
3302
 
@@ -3460,30 +3304,28 @@
3460
3304
  "maxele": {
3461
3305
  label: "Max Elevation: ",
3462
3306
  value: function value(track) {
3463
- return (track.elevation_max || 0).toFixed(2) + '&nbsp;' + _this._yLabel;
3307
+ return (track.elevation_max || 0).toFixed(2) + '&nbsp;' + altitude.label;
3464
3308
  }
3465
3309
  },
3466
3310
  "minele": {
3467
3311
  label: "Min Elevation: ",
3468
3312
  value: function value(track) {
3469
- return (track.elevation_min || 0).toFixed(2) + '&nbsp;' + _this._yLabel;
3313
+ return (track.elevation_min || 0).toFixed(2) + '&nbsp;' + altitude.label;
3470
3314
  }
3471
3315
  }
3472
3316
  });
3473
3317
  });
3474
3318
 
3475
3319
  Elevation.addInitHook(function () {
3476
- var _this2 = this;
3477
-
3478
3320
  var opts = this.options;
3479
3321
  var distance = {};
3480
3322
 
3481
- if (this.options.imperial) {
3482
- this._distanceFactor = this.__mileFactor;
3483
- this._xLabel = "mi";
3323
+ if (opts.imperial) {
3324
+ opts.distanceFactor = this.__mileFactor;
3325
+ distance.label = "mi";
3484
3326
  } else {
3485
- this._distanceFactor = opts.distanceFactor;
3486
- this._xLabel = opts.xLabel;
3327
+ opts.distanceFactor = opts.distanceFactor || 1;
3328
+ distance.label = opts.xLabel;
3487
3329
  }
3488
3330
 
3489
3331
  this.on("eledata_updated", function (e) {
@@ -3493,13 +3335,11 @@
3493
3335
  var dist = track.distance || 0;
3494
3336
  var curr = data[i].latlng;
3495
3337
  var prev = i > 0 ? data[i - 1].latlng : curr;
3496
-
3497
- var delta = curr.distanceTo(prev) * this._distanceFactor;
3498
-
3338
+ var delta = curr.distanceTo(prev) * opts.distanceFactor;
3499
3339
  dist += Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
3500
3340
 
3501
- data[i].dist = dist;
3502
3341
  track.distance = dist;
3342
+ data[i].dist = dist;
3503
3343
  });
3504
3344
  this.on("elechart_axis", function () {
3505
3345
  this._chart._registerAxisGrid({
@@ -3513,13 +3353,10 @@
3513
3353
  this.on("elechart_axis", function () {
3514
3354
  var _this = this;
3515
3355
 
3516
- distance.x = this._chart._x;
3517
- distance.label = this._chart._xLabel;
3518
-
3519
3356
  this._chart._registerAxisScale({
3520
3357
  axis: "x",
3521
3358
  position: "bottom",
3522
- scale: distance.x,
3359
+ scale: this._chart._x,
3523
3360
  label: distance.label,
3524
3361
  labelY: 25,
3525
3362
  labelX: function labelX() {
@@ -3530,10 +3367,10 @@
3530
3367
  });
3531
3368
  }
3532
3369
 
3533
- this._registerFocusLabel({
3370
+ this._registerTooltip({
3534
3371
  name: 'x',
3535
3372
  chart: function chart(item) {
3536
- return L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + _this2._xLabel;
3373
+ return L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + distance.label;
3537
3374
  }
3538
3375
  });
3539
3376
 
@@ -3541,7 +3378,7 @@
3541
3378
  "totlen": {
3542
3379
  label: "Total Length: ",
3543
3380
  value: function value(track) {
3544
- return (track.distance || 0).toFixed(2) + '&nbsp;' + _this2._xLabel;
3381
+ return (track.distance || 0).toFixed(2) + '&nbsp;' + distance.label;
3545
3382
  }
3546
3383
  }
3547
3384
  });
@@ -3553,7 +3390,7 @@
3553
3390
  var opts = this.options;
3554
3391
  var time = {};
3555
3392
  time.label = opts.timeLabel || 't';
3556
- this._timeFactor = opts.timeFactor;
3393
+ opts.timeFactor = opts.timeFactor || 3600;
3557
3394
  /**
3558
3395
  * Common AVG speeds:
3559
3396
  * ----------------------
@@ -3618,7 +3455,7 @@
3618
3455
  e.point.meta = e.point.meta || {};
3619
3456
  var delta = data[i].dist - data[i > 0 ? i - 1 : i].dist;
3620
3457
  var speed = this._timeAVGSpeed;
3621
- e.point.meta.time = new Date(i > 0 ? data[i - 1].time.getTime() + delta / speed * this._timeFactor * 1000 : Date.now());
3458
+ e.point.meta.time = new Date(i > 0 ? data[i - 1].time.getTime() + delta / speed * opts.timeFactor * 1000 : Date.now());
3622
3459
  }
3623
3460
 
3624
3461
  var time = e.point.meta.time; // Handle timezone offset
@@ -3631,13 +3468,13 @@
3631
3468
  var prevT = i > 0 ? data[i - 1].time : currT;
3632
3469
  var deltaT = Math.abs(currT - prevT);
3633
3470
  var duration = (this.track_info.time || 0) + deltaT;
3471
+ this.track_info.time = duration;
3634
3472
  data[i].time = time;
3635
3473
  data[i].duration = duration;
3636
- this.track_info.time = duration;
3637
3474
  });
3638
3475
 
3639
3476
  if (this.options.timestamps) {
3640
- this._registerFocusLabel({
3477
+ this._registerTooltip({
3641
3478
  name: 'date',
3642
3479
  chart: function chart(item) {
3643
3480
  return L._("t: ") + _this.options.timeFormat(item.time);
@@ -3646,7 +3483,7 @@
3646
3483
  }
3647
3484
 
3648
3485
  if (this.options.time) {
3649
- this._registerFocusLabel({
3486
+ this._registerTooltip({
3650
3487
  name: 'time',
3651
3488
  chart: function chart(item) {
3652
3489
  return L._("T: ") + formatTime(item.duration || 0);
@@ -3735,22 +3572,15 @@
3735
3572
  } // Range of acceptable slope values.
3736
3573
 
3737
3574
 
3738
- if (this.options.sRange) {
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;
3575
+ slope = clamp(slope, this.options.sRange);
3747
3576
  track.ascent = tAsc;
3748
3577
  track.descent = tDes;
3749
- track.slope_max = sMax;
3750
- track.slope_min = sMin;
3578
+ track.slope_max = slope > sMax ? slope : sMax;
3579
+ track.slope_min = slope < sMin ? slope : sMin;
3580
+ data[i].slope = L.Util.formatNum(slope, 2);
3751
3581
  });
3752
3582
 
3753
- this._registerFocusLabel({
3583
+ this._registerTooltip({
3754
3584
  name: 'slope',
3755
3585
  chart: function chart(item) {
3756
3586
  return L._("m: ") + item.slope + slope.label;
@@ -3764,13 +3594,13 @@
3764
3594
  "ascent": {
3765
3595
  label: "Total Ascent: ",
3766
3596
  value: function value(track) {
3767
- return Math.round(track.ascent || 0) + '&nbsp;' + _this._yLabel;
3597
+ return Math.round(track.ascent || 0) + '&nbsp;' + (_this.options.imperial ? 'ft' : 'm');
3768
3598
  }
3769
3599
  },
3770
3600
  "descent": {
3771
3601
  label: "Total Descent: ",
3772
3602
  value: function value(track) {
3773
- return Math.round(track.descent || 0) + '&nbsp;' + _this._yLabel;
3603
+ return Math.round(track.descent || 0) + '&nbsp;' + (_this.options.imperial ? 'ft' : 'm');
3774
3604
  }
3775
3605
  },
3776
3606
  "minslope": {
@@ -3792,8 +3622,8 @@
3792
3622
  if (!this.options.speed && !this.options.acceleration) return;
3793
3623
  var opts = this.options;
3794
3624
  var speed = {};
3795
- speed.label = opts.speedLabel || L._(this.options.imperial ? 'mph' : 'km/h');
3796
- this._speedFactor = opts.speedFactor || 1;
3625
+ speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
3626
+ opts.speedFactor = opts.speedFactor || 1;
3797
3627
 
3798
3628
  if (this.options.speed && this.options.speed != "summary") {
3799
3629
  this._registerAxisScale({
@@ -3840,7 +3670,7 @@
3840
3670
 
3841
3671
  if (deltaT > 0) {
3842
3672
  var delta = (data[i].dist - data[i > 0 ? i - 1 : i].dist) * 1000;
3843
- speed = Math.abs(delta / deltaT * this._timeFactor) * this._speedFactor;
3673
+ speed = Math.abs(delta / deltaT * opts.timeFactor) * opts.speedFactor;
3844
3674
  } // Try to smooth "crazy" speed values.
3845
3675
 
3846
3676
 
@@ -3854,23 +3684,15 @@
3854
3684
  } // Range of acceptable speed values.
3855
3685
 
3856
3686
 
3857
- if (this.options.speedRange) {
3858
- var range = this.options.speedRange;
3859
- if (speed < range[0]) speed = range[0];else if (speed > range[1]) speed = range[1];
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;
3687
+ speed = clamp(speed, this.options.speedRange);
3688
+ track.speed_max = speed > sMax ? speed : sMax;
3689
+ track.speed_min = speed < sMin ? speed : sMin;
3690
+ track.speed_avg = (speed + sAvg) / 2.0;
3691
+ data[i].speed = L.Util.formatNum(speed, 2);
3870
3692
  });
3871
3693
 
3872
3694
  if (this.options.speed) {
3873
- this._registerFocusLabel({
3695
+ this._registerTooltip({
3874
3696
  name: 'speed',
3875
3697
  chart: function chart(item) {
3876
3698
  return L._('v: ') + item.speed + " " + speed.label;
@@ -3907,8 +3729,8 @@
3907
3729
  if (!this.options.acceleration) return;
3908
3730
  var opts = this.options;
3909
3731
  var acceleration = {};
3910
- acceleration.label = opts.accelerationLabel || L._(this.options.imperial ? 'ft/s²' : 'm/s²');
3911
- this._accelerationFactor = opts.accelerationFactor || 1;
3732
+ acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
3733
+ opts.accelerationFactor = opts.accelerationFactor || 1;
3912
3734
 
3913
3735
  if (this.options.acceleration != "summary") {
3914
3736
  this._registerAxisScale({
@@ -3956,8 +3778,8 @@
3956
3778
  if (deltaT > 0) {
3957
3779
  var curr = data[i].speed;
3958
3780
  var prev = i > 0 ? data[i - 1].speed : curr;
3959
- var delta = (curr - prev) * (1000 / this._timeFactor);
3960
- acceleration = Math.abs(delta / deltaT) * this._accelerationFactor;
3781
+ var delta = (curr - prev) * (1000 / opts.timeFactor);
3782
+ acceleration = Math.abs(delta / deltaT) * opts.accelerationFactor;
3961
3783
  } // Try to smooth "crazy" acceleration values.
3962
3784
 
3963
3785
 
@@ -3971,22 +3793,14 @@
3971
3793
  } // Range of acceptable acceleration values.
3972
3794
 
3973
3795
 
3974
- if (this.options.accelerationRange) {
3975
- var range = this.options.accelerationRange;
3976
- if (acceleration < range[0]) acceleration = range[0];else if (acceleration > range[1]) acceleration = range[1];
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;
3796
+ acceleration = clamp(acceleration, this.options.accelerationRange);
3797
+ track.acceleration_max = acceleration > sMax ? acceleration : sMax;
3798
+ track.acceleration_min = acceleration < sMin ? acceleration : sMin;
3799
+ track.acceleration_avg = (acceleration + sAvg) / 2.0;
3800
+ data[i].acceleration = L.Util.formatNum(acceleration, 2);
3987
3801
  });
3988
3802
 
3989
- this._registerFocusLabel({
3803
+ this._registerTooltip({
3990
3804
  name: 'acceleration',
3991
3805
  chart: function chart(item) {
3992
3806
  return L._("a: ") + item.acceleration + " " + acceleration.label;