@raruto/leaflet-elevation 1.7.5 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,6 +158,9 @@ _For a working example see one of the following demos:_
158
158
  // Toggle "leaflet-distance-markers" integration
159
159
  distanceMarkers: false,
160
160
 
161
+ // Display track datetimes: true || false
162
+ timestamps: false,
163
+
161
164
  // Display track waypoints: true || "markers" || "dots" || false
162
165
  waypoints: true,
163
166
 
@@ -171,11 +174,11 @@ _For a working example see one of the following demos:_
171
174
  }),
172
175
  },
173
176
 
174
- // Display waypoint labels: true || "markers" || "dots" || false
177
+ // Toggle waypoint labels: true || "markers" || "dots" || false
175
178
  wptLabels: true,
176
179
 
177
180
  // Render chart profiles as Canvas or SVG Paths
178
- preferCanvas: true
181
+ preferCanvas: true,
179
182
 
180
183
  };
181
184
 
@@ -690,12 +690,25 @@
690
690
  xCoord = _ref5$xCoord === void 0 ? 0 : _ref5$xCoord,
691
691
  _ref5$yCoord = _ref5.yCoord,
692
692
  yCoord = _ref5$yCoord === void 0 ? 0 : _ref5$yCoord,
693
- label = _ref5.label;
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;
694
697
  return function (text) {
695
698
  text.attr("class", theme + " height-focus-label").style("pointer-events", "none").attr("x", xCoord + 5).attr("y", yCoord);
696
- var y = text.select(".height-focus-y");
697
- if (!y.node()) y = text.append("svg:tspan");
698
- y.attr("class", "height-focus-y").text(label);
699
+ var label;
700
+
701
+ for (var i in labels) {
702
+ label = text.select(".height-focus-" + labels[i].name);
703
+
704
+ if (!label.size()) {
705
+ label = text.append("svg:tspan").attr("class", "height-focus-" + labels[i].name).attr("dy", "1.5em");
706
+ }
707
+
708
+ label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
709
+ }
710
+
711
+ text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em");
699
712
  text.selectAll('tspan').attr("x", xCoord + 5);
700
713
  return text;
701
714
  };
@@ -748,23 +761,17 @@
748
761
  var MouseFocusLabel = function MouseFocusLabel(_ref9) {
749
762
  var xCoord = _ref9.xCoord,
750
763
  yCoord = _ref9.yCoord,
751
- _ref9$labelX = _ref9.labelX,
752
- labelX = _ref9$labelX === void 0 ? "" : _ref9$labelX,
753
- _ref9$labelY = _ref9.labelY,
754
- labelY = _ref9$labelY === void 0 ? "" : _ref9$labelY,
755
- width = _ref9.width;
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;
756
769
  return function (g) {
757
770
  g.attr('class', 'mouse-focus-label');
758
771
  var rect = g.select(".mouse-focus-label-rect");
759
772
  var text = g.select(".mouse-focus-label-text");
760
- var y = text.select(".mouse-focus-label-y");
761
- var x = text.select(".mouse-focus-label-x");
762
773
  if (!rect.node()) rect = g.append("svg:rect");
763
- if (!text.node()) text = g.append("svg:text");
764
- if (!y.node()) y = text.append("svg:tspan");
765
- if (!x.node()) x = text.append("svg:tspan");
766
- y.text(labelY);
767
- x.text(labelX); // Sets focus-label-text position to the left / right of the mouse-focus-line
774
+ if (!text.node()) text = g.append("svg:text"); // Sets focus-label-text position to the left / right of the mouse-focus-line
768
775
 
769
776
  var xAlign = 0;
770
777
  var yAlign = 0;
@@ -783,8 +790,19 @@
783
790
  if (yCoord) yAlign = Math.max(yCoord - bbox.height, L.Browser.webkit ? 0 : -Infinity);
784
791
  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);
785
792
  text.attr("class", "mouse-focus-label-text").style("font-weight", "700").attr("y", yAlign);
786
- y.attr("class", "mouse-focus-label-y").attr("dy", "1em");
787
- x.attr("class", "mouse-focus-label-x").attr("dy", "2em");
793
+ var label;
794
+
795
+ for (var i in labels) {
796
+ label = text.select(".mouse-focus-label-" + labels[i].name);
797
+
798
+ if (!label.size()) {
799
+ label = text.append("svg:tspan", ".mouse-focus-label-x").attr("class", "mouse-focus-label-" + labels[i].name).attr("dy", "1.5em");
800
+ }
801
+
802
+ label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
803
+ }
804
+
805
+ text.select('tspan').attr("dy", "1em");
788
806
  text.selectAll('tspan').attr("x", xAlign);
789
807
  return g;
790
808
  };
@@ -938,8 +956,9 @@
938
956
  yCoord: 0,
939
957
  height: _height,
940
958
  width: _width,
941
- labelX: "",
942
- labelY: ""
959
+ labels: {} // labelX: "",
960
+ // labelY: "",
961
+
943
962
  })); // Add the brushing
944
963
 
945
964
  var brush = d3.brushX().on('start.cursor end.cursor brush.cursor', function () {
@@ -1807,28 +1826,9 @@
1807
1826
  yCoord: yCoordinate,
1808
1827
  height: this._height(),
1809
1828
  width: this._width(),
1810
- labelX: d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + this._xLabel,
1811
- labelY: d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + this._yLabel
1812
- })); // this._focuslabel.selectAll('tspan').data(Object.values(this._focuslabels));
1813
-
1814
-
1815
- var labels = this._props.focusLabels;
1816
-
1817
- var tooltip = this._focuslabel.select('text');
1818
-
1819
- var label;
1820
-
1821
- for (var i in labels) {
1822
- label = tooltip.select(".mouse-focus-label-" + labels[i].name);
1823
-
1824
- if (!label.size()) {
1825
- label = tooltip.append("svg:tspan", ".mouse-focus-label-x").attr("class", "mouse-focus-label-" + labels[i].name).attr("dy", "1.5em");
1826
- }
1827
-
1828
- label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
1829
-
1830
- this._focuslabel.select('.mouse-focus-label-x').attr("dy", "1.5em");
1831
- }
1829
+ labels: this._props.focusLabels,
1830
+ item: item
1831
+ }));
1832
1832
  },
1833
1833
  _hideDiagramIndicator: function _hideDiagramIndicator() {
1834
1834
  this._focusG.attr("display", 'none');
@@ -1931,24 +1931,9 @@
1931
1931
  theme: opts.theme,
1932
1932
  xCoord: point.x,
1933
1933
  yCoord: normalizedY,
1934
- label: d3.format("." + opts.decimalsY + "f")(point[opts.yAttr]) + " " + this._yLabel
1934
+ labels: this._focuslabels,
1935
+ item: point
1935
1936
  }));
1936
-
1937
- var labels = this._focuslabels;
1938
- var tooltip = this._focuslabel;
1939
- var label;
1940
-
1941
- for (var i in labels) {
1942
- label = tooltip.select(".height-focus-" + labels[i].name);
1943
-
1944
- if (!label.size()) {
1945
- label = tooltip.append("svg:tspan").attr("class", "height-focus-" + labels[i].name).attr("dy", "1.5em");
1946
- }
1947
-
1948
- label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(props.item));
1949
-
1950
- this._focuslabel.select('.height-focus-y').attr("dy", "-1.5em");
1951
- }
1952
1937
  } else if (this.options.marker == 'position-marker') {
1953
1938
  removeClass(this._marker.getElement(), 'leaflet-hidden');
1954
1939
 
@@ -2084,6 +2069,7 @@
2084
2069
  time: false,
2085
2070
  timeFactor: 3600,
2086
2071
  timeFormat: false,
2072
+ timestamps: false,
2087
2073
  sDeltaMax: undefined,
2088
2074
  sInterpolation: "curveStepAfter",
2089
2075
  sRange: undefined,
@@ -3037,7 +3023,8 @@
3037
3023
  * Hacky way for handling chart resize. Deletes it and redraw chart.
3038
3024
  */
3039
3025
  _resizeChart: function _resizeChart() {
3040
- // prevent displaying chart on resize if hidden
3026
+ if (!this._container) return; // prevent displaying chart on resize if hidden
3027
+
3041
3028
  if (style(this._container, "display") == "none") return;
3042
3029
  var opts = this.options;
3043
3030
 
@@ -3141,7 +3128,7 @@
3141
3128
  _updateChart: function _updateChart() {
3142
3129
  if (
3143
3130
  /*!this._data.length ||*/
3144
- !this._container) return;
3131
+ !this._chart || !this._container) return;
3145
3132
 
3146
3133
  this._fireEvt("elechart_axis");
3147
3134
 
@@ -3339,7 +3326,7 @@
3339
3326
  if (options.stroke && options.weight !== 0) {
3340
3327
  var oldVal = ctx.globalCompositeOperation || 'source-over';
3341
3328
  ctx.globalCompositeOperation = 'destination-over';
3342
- ctx.strokeStyle = '#FFF';
3329
+ ctx.strokeStyle = color.outline || '#FFF';
3343
3330
  ctx.lineWidth = options.weight * 1.75;
3344
3331
  ctx.stroke();
3345
3332
  ctx.globalCompositeOperation = oldVal;
@@ -3363,74 +3350,6 @@
3363
3350
  });
3364
3351
  });
3365
3352
 
3366
- Elevation.addInitHook(function () {
3367
- var _this2 = this;
3368
-
3369
- var opts = this.options;
3370
- var distance = {};
3371
-
3372
- if (this.options.imperial) {
3373
- this._distanceFactor = this.__mileFactor;
3374
- this._xLabel = "mi";
3375
- } else {
3376
- this._distanceFactor = opts.distanceFactor;
3377
- this._xLabel = opts.xLabel;
3378
- }
3379
-
3380
- this.on("eledata_updated", function (e) {
3381
- var data = this._data;
3382
- var i = e.index;
3383
- var track = this.track_info;
3384
- var dist = track.distance || 0;
3385
- var curr = data[i].latlng;
3386
- var prev = i > 0 ? data[i - 1].latlng : curr;
3387
-
3388
- var delta = curr.distanceTo(prev) * this._distanceFactor;
3389
-
3390
- dist += Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
3391
-
3392
- data[i].dist = dist;
3393
- track.distance = dist;
3394
- });
3395
- this.on("elechart_axis", function () {
3396
- this._chart._registerAxisGrid({
3397
- axis: "x",
3398
- position: "bottom",
3399
- scale: this._chart._x
3400
- });
3401
- });
3402
-
3403
- if (this.options.distance != "summary") {
3404
- this.on("elechart_axis", function () {
3405
- var _this = this;
3406
-
3407
- distance.x = this._chart._x;
3408
- distance.label = this._chart._xLabel;
3409
-
3410
- this._chart._registerAxisScale({
3411
- axis: "x",
3412
- position: "bottom",
3413
- scale: distance.x,
3414
- label: distance.label,
3415
- labelY: 25,
3416
- labelX: function labelX() {
3417
- return _this._width() + 6;
3418
- },
3419
- name: "distance"
3420
- });
3421
- });
3422
- }
3423
-
3424
- this._registerSummary({
3425
- "totlen": {
3426
- label: "Total Length: ",
3427
- value: function value(track) {
3428
- return (track.distance || 0).toFixed(2) + ' ' + _this2._xLabel;
3429
- }
3430
- }
3431
- });
3432
- });
3433
-
3434
3353
  Elevation.addInitHook(function () {
3435
3354
  var _this = this;
3436
3355
 
@@ -3527,6 +3446,16 @@
3527
3446
  });
3528
3447
  }
3529
3448
 
3449
+ this._registerFocusLabel({
3450
+ name: 'y',
3451
+ chart: function chart(item) {
3452
+ return L._("y: ") + d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + _this._yLabel;
3453
+ },
3454
+ marker: function marker(item) {
3455
+ return d3.format("." + opts.decimalsY + "f")(item[opts.yAttr]) + " " + _this._yLabel;
3456
+ }
3457
+ });
3458
+
3530
3459
  this._registerSummary({
3531
3460
  "maxele": {
3532
3461
  label: "Max Elevation: ",
@@ -3543,6 +3472,81 @@
3543
3472
  });
3544
3473
  });
3545
3474
 
3475
+ Elevation.addInitHook(function () {
3476
+ var _this2 = this;
3477
+
3478
+ var opts = this.options;
3479
+ var distance = {};
3480
+
3481
+ if (this.options.imperial) {
3482
+ this._distanceFactor = this.__mileFactor;
3483
+ this._xLabel = "mi";
3484
+ } else {
3485
+ this._distanceFactor = opts.distanceFactor;
3486
+ this._xLabel = opts.xLabel;
3487
+ }
3488
+
3489
+ this.on("eledata_updated", function (e) {
3490
+ var data = this._data;
3491
+ var i = e.index;
3492
+ var track = this.track_info;
3493
+ var dist = track.distance || 0;
3494
+ var curr = data[i].latlng;
3495
+ var prev = i > 0 ? data[i - 1].latlng : curr;
3496
+
3497
+ var delta = curr.distanceTo(prev) * this._distanceFactor;
3498
+
3499
+ dist += Math.round(delta / 1000 * 100000) / 100000; // handles floating points calc
3500
+
3501
+ data[i].dist = dist;
3502
+ track.distance = dist;
3503
+ });
3504
+ this.on("elechart_axis", function () {
3505
+ this._chart._registerAxisGrid({
3506
+ axis: "x",
3507
+ position: "bottom",
3508
+ scale: this._chart._x
3509
+ });
3510
+ });
3511
+
3512
+ if (this.options.distance != "summary") {
3513
+ this.on("elechart_axis", function () {
3514
+ var _this = this;
3515
+
3516
+ distance.x = this._chart._x;
3517
+ distance.label = this._chart._xLabel;
3518
+
3519
+ this._chart._registerAxisScale({
3520
+ axis: "x",
3521
+ position: "bottom",
3522
+ scale: distance.x,
3523
+ label: distance.label,
3524
+ labelY: 25,
3525
+ labelX: function labelX() {
3526
+ return _this._width() + 6;
3527
+ },
3528
+ name: "distance"
3529
+ });
3530
+ });
3531
+ }
3532
+
3533
+ this._registerFocusLabel({
3534
+ name: 'x',
3535
+ chart: function chart(item) {
3536
+ return L._("x: ") + d3.format("." + opts.decimalsX + "f")(item[opts.xAttr]) + " " + _this2._xLabel;
3537
+ }
3538
+ });
3539
+
3540
+ this._registerSummary({
3541
+ "totlen": {
3542
+ label: "Total Length: ",
3543
+ value: function value(track) {
3544
+ return (track.distance || 0).toFixed(2) + ' ' + _this2._xLabel;
3545
+ }
3546
+ }
3547
+ });
3548
+ });
3549
+
3546
3550
  Elevation.addInitHook(function () {
3547
3551
  var _this = this;
3548
3552
 
@@ -3632,11 +3636,20 @@
3632
3636
  this.track_info.time = duration;
3633
3637
  });
3634
3638
 
3639
+ if (this.options.timestamps) {
3640
+ this._registerFocusLabel({
3641
+ name: 'date',
3642
+ chart: function chart(item) {
3643
+ return L._("t: ") + _this.options.timeFormat(item.time);
3644
+ }
3645
+ });
3646
+ }
3647
+
3635
3648
  if (this.options.time) {
3636
3649
  this._registerFocusLabel({
3637
3650
  name: 'time',
3638
3651
  chart: function chart(item) {
3639
- return _this.options.timeFormat(item.time);
3652
+ return L._("T: ") + formatTime(item.duration || 0);
3640
3653
  }
3641
3654
  });
3642
3655
 
@@ -3740,7 +3753,7 @@
3740
3753
  this._registerFocusLabel({
3741
3754
  name: 'slope',
3742
3755
  chart: function chart(item) {
3743
- return item.slope + slope.label;
3756
+ return L._("m: ") + item.slope + slope.label;
3744
3757
  },
3745
3758
  marker: function marker(item) {
3746
3759
  return Math.round(item.slope) + slope.label;
@@ -3860,7 +3873,7 @@
3860
3873
  this._registerFocusLabel({
3861
3874
  name: 'speed',
3862
3875
  chart: function chart(item) {
3863
- return item.speed + " " + speed.label;
3876
+ return L._('v: ') + item.speed + " " + speed.label;
3864
3877
  },
3865
3878
  marker: function marker(item) {
3866
3879
  return Math.round(item.speed) + " " + speed.label;
@@ -3976,7 +3989,7 @@
3976
3989
  this._registerFocusLabel({
3977
3990
  name: 'acceleration',
3978
3991
  chart: function chart(item) {
3979
- return item.acceleration + " " + acceleration.label;
3992
+ return L._("a: ") + item.acceleration + " " + acceleration.label;
3980
3993
  },
3981
3994
  marker: function marker(item) {
3982
3995
  return Math.round(item.acceleration) + " " + acceleration.label;
@@ -4043,6 +4056,19 @@
4043
4056
  Elevation.Utils = _;
4044
4057
  Elevation.Components = D3;
4045
4058
  Elevation.Chart = Chart$1;
4059
+ /* Temporary fix for empty values evaluated as false (leaflet-i18n v0.3.1) */
4060
+
4061
+ (function () {
4062
+ var proto = L.i18n.bind({});
4063
+
4064
+ L.i18n = L._ = function (string, data) {
4065
+ if (L.locale && L.locales[L.locale] && L.locales[L.locale][string] == "") {
4066
+ L.locales[L.locale][string] = "\u200B";
4067
+ }
4068
+
4069
+ return proto.call(null, string, data);
4070
+ };
4071
+ })();
4046
4072
 
4047
4073
  L.control.elevation = function (options) {
4048
4074
  return new Elevation(options);