@raruto/leaflet-elevation 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/leaflet-elevation.css +0 -1
- package/dist/leaflet-elevation.js +98 -57
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +2 -2
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/package.json +1 -1
- package/src/chart.js +36 -3
- package/src/components.js +5 -5
- package/src/control.js +2 -1
- package/src/index.css +0 -1
|
@@ -949,10 +949,11 @@
|
|
|
949
949
|
legend: g.append('g').attr("class", "legend")
|
|
950
950
|
}; // SVG Paths
|
|
951
951
|
|
|
952
|
-
var
|
|
953
|
-
var
|
|
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
|
|
954
955
|
|
|
955
|
-
var foreignObject = panes.area.append('svg:foreignObject');
|
|
956
|
+
var foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
|
|
956
957
|
var canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
|
|
957
958
|
var context = canvas.node().getContext('2d'); // Add tooltip
|
|
958
959
|
|
|
@@ -976,7 +977,7 @@
|
|
|
976
977
|
};
|
|
977
978
|
|
|
978
979
|
var utils = {
|
|
979
|
-
|
|
980
|
+
mask: mask,
|
|
980
981
|
canvas: canvas,
|
|
981
982
|
context: context,
|
|
982
983
|
brush: brush
|
|
@@ -1007,7 +1008,7 @@
|
|
|
1007
1008
|
canvas.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
1008
1009
|
}
|
|
1009
1010
|
|
|
1010
|
-
|
|
1011
|
+
maskRect.attr("x", 0).attr("y", 0).attr("width", _width).attr("height", _height);
|
|
1011
1012
|
foreignObject.attr('width', _width).attr('height', _height);
|
|
1012
1013
|
canvas.attr('width', _width).attr('height', _height);
|
|
1013
1014
|
|
|
@@ -1073,6 +1074,8 @@
|
|
|
1073
1074
|
var Chart$1 = L.Class.extend({
|
|
1074
1075
|
includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
|
|
1075
1076
|
initialize: function initialize(opts, control) {
|
|
1077
|
+
var _this = this;
|
|
1078
|
+
|
|
1076
1079
|
this.options = opts;
|
|
1077
1080
|
this.control = control;
|
|
1078
1081
|
this._data = []; // cache registered components
|
|
@@ -1107,14 +1110,24 @@
|
|
|
1107
1110
|
this._initScale(); // Helpers
|
|
1108
1111
|
|
|
1109
1112
|
|
|
1110
|
-
this.
|
|
1113
|
+
this._mask = chart.get('mask');
|
|
1111
1114
|
this._context = chart.get('context');
|
|
1112
1115
|
this._brush = chart.get('brush');
|
|
1113
1116
|
this._zoom = d3.zoom();
|
|
1114
1117
|
this._drag = d3.drag(); // Interactions
|
|
1115
1118
|
|
|
1116
1119
|
this._initInteractions(); // svg.on('resize', (e)=>console.log(e.detail));
|
|
1120
|
+
// Handle multi-track segments (BETA)
|
|
1121
|
+
|
|
1117
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
|
+
});
|
|
1118
1131
|
},
|
|
1119
1132
|
update: function update(props) {
|
|
1120
1133
|
if (props) {
|
|
@@ -1135,11 +1148,11 @@
|
|
|
1135
1148
|
return this;
|
|
1136
1149
|
},
|
|
1137
1150
|
render: function render() {
|
|
1138
|
-
var
|
|
1151
|
+
var _this2 = this;
|
|
1139
1152
|
|
|
1140
1153
|
return function (container) {
|
|
1141
1154
|
return container.append(function () {
|
|
1142
|
-
return
|
|
1155
|
+
return _this2._container.node();
|
|
1143
1156
|
});
|
|
1144
1157
|
};
|
|
1145
1158
|
},
|
|
@@ -1191,43 +1204,43 @@
|
|
|
1191
1204
|
* Initialize "d3-brush".
|
|
1192
1205
|
*/
|
|
1193
1206
|
_initBrush: function _initBrush(e) {
|
|
1194
|
-
var
|
|
1207
|
+
var _this3 = this;
|
|
1195
1208
|
|
|
1196
1209
|
var brush = function brush(e) {
|
|
1197
|
-
if (!
|
|
1210
|
+
if (!_this3._data.length) return;
|
|
1198
1211
|
var extent = e.selection;
|
|
1199
1212
|
|
|
1200
1213
|
if (extent) {
|
|
1201
|
-
var start =
|
|
1214
|
+
var start = _this3._findIndexForXCoord(extent[0]);
|
|
1202
1215
|
|
|
1203
|
-
var end =
|
|
1216
|
+
var end = _this3._findIndexForXCoord(extent[1]);
|
|
1204
1217
|
|
|
1205
|
-
|
|
1206
|
-
dragstart:
|
|
1207
|
-
dragend:
|
|
1218
|
+
_this3.fire('dragged', {
|
|
1219
|
+
dragstart: _this3._data[start],
|
|
1220
|
+
dragend: _this3._data[end]
|
|
1208
1221
|
});
|
|
1209
1222
|
}
|
|
1210
1223
|
};
|
|
1211
1224
|
|
|
1212
1225
|
var focus = function focus(e) {
|
|
1213
|
-
if (!
|
|
1226
|
+
if (!_this3._data.length) return;
|
|
1214
1227
|
if (e.type == 'brush' && !e.sourceEvent) return;
|
|
1215
1228
|
|
|
1216
|
-
var rect =
|
|
1229
|
+
var rect = _this3._chart.panes.brush.select('.overlay').node();
|
|
1217
1230
|
|
|
1218
1231
|
var coords = d3.pointers(e, rect)[0];
|
|
1219
1232
|
var xCoord = coords[0];
|
|
1220
1233
|
|
|
1221
|
-
var item =
|
|
1234
|
+
var item = _this3._data[_this3._findIndexForXCoord(xCoord)];
|
|
1222
1235
|
|
|
1223
|
-
|
|
1236
|
+
_this3.fire("mouse_move", {
|
|
1224
1237
|
item: item,
|
|
1225
1238
|
xCoord: xCoord
|
|
1226
1239
|
});
|
|
1227
1240
|
};
|
|
1228
1241
|
|
|
1229
1242
|
this._brush.filter(function (e) {
|
|
1230
|
-
return
|
|
1243
|
+
return _this3._brushEnabled && !e.shiftKey && !e.button;
|
|
1231
1244
|
}).on("end.update", brush).on("brush.update", focus);
|
|
1232
1245
|
|
|
1233
1246
|
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);
|
|
@@ -1237,7 +1250,7 @@
|
|
|
1237
1250
|
* Initialize "d3-zoom"
|
|
1238
1251
|
*/
|
|
1239
1252
|
_initClipper: function _initClipper() {
|
|
1240
|
-
var
|
|
1253
|
+
var _this4 = this;
|
|
1241
1254
|
|
|
1242
1255
|
var svg = this._container;
|
|
1243
1256
|
var margin = this.options.margins;
|
|
@@ -1247,42 +1260,52 @@
|
|
|
1247
1260
|
if (e.sourceEvent && e.sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing');
|
|
1248
1261
|
|
|
1249
1262
|
if (e.transform.k == 1 && e.transform.x == 0) {
|
|
1250
|
-
|
|
1263
|
+
_this4._container.classed('zoomed', true); // Apply d3-zoom (bind <clipPath> mask)
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
if (_this4._mask) {
|
|
1267
|
+
_this4._point.attr('mask', 'url(#' + _this4._mask.attr('id') + ')');
|
|
1268
|
+
}
|
|
1251
1269
|
}
|
|
1252
1270
|
|
|
1253
|
-
|
|
1271
|
+
_this4.zooming = true;
|
|
1254
1272
|
};
|
|
1255
1273
|
|
|
1256
1274
|
var onEnd = function onEnd(e) {
|
|
1257
1275
|
if (e.transform.k == 1 && e.transform.x == 0) {
|
|
1258
|
-
|
|
1276
|
+
_this4._container.classed('zoomed', false); // Apply d3-zoom (bind <clipPath> mask)
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
if (_this4._mask) {
|
|
1280
|
+
_this4._point.attr('mask', null);
|
|
1281
|
+
}
|
|
1259
1282
|
}
|
|
1260
1283
|
|
|
1261
|
-
|
|
1284
|
+
_this4.zooming = false;
|
|
1262
1285
|
svg.style('cursor', '');
|
|
1263
1286
|
};
|
|
1264
1287
|
|
|
1265
1288
|
var onZoom = function onZoom(e) {
|
|
1266
1289
|
// TODO: find a faster way to redraw the chart.
|
|
1267
|
-
|
|
1290
|
+
_this4.zooming = false;
|
|
1268
1291
|
|
|
1269
|
-
|
|
1292
|
+
_this4._updateScale(); // hacky way for restoring x scale when zooming out
|
|
1270
1293
|
|
|
1271
1294
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1295
|
+
_this4.zooming = true;
|
|
1296
|
+
_this4._scales.distance = _this4._x = e.transform.rescaleX(_this4._x); // calculate x scale at zoom level
|
|
1274
1297
|
|
|
1275
|
-
|
|
1298
|
+
_this4._resetDrag();
|
|
1276
1299
|
|
|
1277
1300
|
if (e.sourceEvent && e.sourceEvent.type == "mousemove") {
|
|
1278
|
-
|
|
1301
|
+
_this4._hideDiagramIndicator();
|
|
1279
1302
|
}
|
|
1280
1303
|
|
|
1281
|
-
|
|
1304
|
+
_this4.fire('zoom');
|
|
1282
1305
|
};
|
|
1283
1306
|
|
|
1284
1307
|
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) {
|
|
1285
|
-
return
|
|
1308
|
+
return _this4._zoomEnabled && (e.shiftKey || e.buttons == 4);
|
|
1286
1309
|
}).on("start", onStart).on("end", onEnd).on("zoom", onZoom);
|
|
1287
1310
|
svg.call(zoom); // add zoom functionality to "svg" group
|
|
1288
1311
|
// d3.select("body").on("keydown.grabzoom keyup.grabzoom", (e) => svg.style('cursor', e.shiftKey ? 'move' : ''));
|
|
@@ -1301,7 +1324,7 @@
|
|
|
1301
1324
|
* Toggle chart data on legend click
|
|
1302
1325
|
*/
|
|
1303
1326
|
_initLegend: function _initLegend() {
|
|
1304
|
-
var
|
|
1327
|
+
var _this5 = this;
|
|
1305
1328
|
|
|
1306
1329
|
this._container.on('legend_clicked', function (e) {
|
|
1307
1330
|
var _e$detail = e.detail,
|
|
@@ -1321,9 +1344,9 @@
|
|
|
1321
1344
|
|
|
1322
1345
|
toggleClass(path, 'leaflet-hidden', enabled);
|
|
1323
1346
|
|
|
1324
|
-
|
|
1347
|
+
_this5._updateArea();
|
|
1325
1348
|
|
|
1326
|
-
|
|
1349
|
+
_this5.fire("elepath_toggle", {
|
|
1327
1350
|
path: path,
|
|
1328
1351
|
name: name,
|
|
1329
1352
|
legend: legend,
|
|
@@ -1336,7 +1359,7 @@
|
|
|
1336
1359
|
* Initialize "ruler".
|
|
1337
1360
|
*/
|
|
1338
1361
|
_initRuler: function _initRuler() {
|
|
1339
|
-
var
|
|
1362
|
+
var _this6 = this;
|
|
1340
1363
|
|
|
1341
1364
|
if (!this.options.ruler) return; // const yMax = this._height();
|
|
1342
1365
|
|
|
@@ -1344,35 +1367,35 @@
|
|
|
1344
1367
|
var drag = this._drag;
|
|
1345
1368
|
|
|
1346
1369
|
var label = function label(e, d) {
|
|
1347
|
-
var yMax =
|
|
1370
|
+
var yMax = _this6._height();
|
|
1348
1371
|
|
|
1349
|
-
var y =
|
|
1372
|
+
var y = _this6._ruler.data()[0].y;
|
|
1350
1373
|
|
|
1351
|
-
if (y >= yMax || y <= 0)
|
|
1374
|
+
if (y >= yMax || y <= 0) _this6._ruler.select(".horizontal-drag-label").text('');
|
|
1352
1375
|
|
|
1353
|
-
|
|
1376
|
+
_this6._hideDiagramIndicator();
|
|
1354
1377
|
};
|
|
1355
1378
|
|
|
1356
1379
|
var position = function position(e, d) {
|
|
1357
|
-
var yMax =
|
|
1380
|
+
var yMax = _this6._height();
|
|
1358
1381
|
|
|
1359
|
-
var yCoord = d3.pointers(e,
|
|
1382
|
+
var yCoord = d3.pointers(e, _this6._area.node())[0][1];
|
|
1360
1383
|
var y = yCoord > 0 ? yCoord < yMax ? yCoord : yMax : 0;
|
|
1361
1384
|
|
|
1362
|
-
var z =
|
|
1385
|
+
var z = _this6._y.invert(y);
|
|
1363
1386
|
|
|
1364
|
-
var data = L.extend(
|
|
1387
|
+
var data = L.extend(_this6._ruler.data()[0], {
|
|
1365
1388
|
y: y
|
|
1366
1389
|
});
|
|
1367
1390
|
|
|
1368
|
-
|
|
1391
|
+
_this6._ruler.data([data]).attr("transform", function (d) {
|
|
1369
1392
|
return "translate(" + d.x + "," + d.y + ")";
|
|
1370
1393
|
}).classed('active', y < yMax);
|
|
1371
1394
|
|
|
1372
|
-
|
|
1395
|
+
_this6._container.select(".horizontal-drag-label").text(formatNum(z) + " " + (_this6.options.imperial ? 'ft' : 'm'));
|
|
1373
1396
|
|
|
1374
|
-
|
|
1375
|
-
coords: yCoord < yMax && yCoord > 0 ?
|
|
1397
|
+
_this6.fire('ruler_filter', {
|
|
1398
|
+
coords: yCoord < yMax && yCoord > 0 ? _this6._findCoordsForY(yCoord) : []
|
|
1376
1399
|
});
|
|
1377
1400
|
};
|
|
1378
1401
|
|
|
@@ -1545,12 +1568,30 @@
|
|
|
1545
1568
|
});
|
|
1546
1569
|
},
|
|
1547
1570
|
_updateClipper: function _updateClipper() {
|
|
1571
|
+
var _this7 = this;
|
|
1572
|
+
|
|
1548
1573
|
var margin = this.options.margins;
|
|
1549
1574
|
|
|
1550
|
-
this._zoom.scaleExtent([1, 10]).extent([[margin.left, 0], [this._width() - margin.right, this._height()]]).translateExtent([[margin.left, -Infinity], [this._width() - margin.right, Infinity]]);
|
|
1575
|
+
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)
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
this._mask.selectAll(".gap").remove();
|
|
1579
|
+
|
|
1580
|
+
this._maskGaps.forEach(function (d, i) {
|
|
1581
|
+
if (i >= _this7._maskGaps.length - 2) return;
|
|
1582
|
+
var d1 = _this7._data[_this7._maskGaps[i]];
|
|
1583
|
+
var d2 = _this7._data[_this7._maskGaps[i + 1]];
|
|
1584
|
+
|
|
1585
|
+
var x1 = _this7._x(_this7._data[_this7._findIndexForLatLng(d1.latlng)].dist);
|
|
1586
|
+
|
|
1587
|
+
var x2 = _this7._x(_this7._data[_this7._findIndexForLatLng(d2.latlng)].dist);
|
|
1588
|
+
|
|
1589
|
+
_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
|
|
1590
|
+
|
|
1591
|
+
});
|
|
1551
1592
|
},
|
|
1552
1593
|
_updateLegend: function _updateLegend() {
|
|
1553
|
-
var
|
|
1594
|
+
var _this8 = this;
|
|
1554
1595
|
|
|
1555
1596
|
if (this.options.legend === false) return;
|
|
1556
1597
|
var legends = this._props.legendItems;
|
|
@@ -1606,21 +1647,21 @@
|
|
|
1606
1647
|
var legend = d3.select(n[i]);
|
|
1607
1648
|
var rect = legend.select('rect');
|
|
1608
1649
|
var name = legend.attr('data-name');
|
|
1609
|
-
var path =
|
|
1650
|
+
var path = _this8._paths[name];
|
|
1610
1651
|
var tx = v[i] * 55;
|
|
1611
1652
|
var ty = xAxesB * 2;
|
|
1612
1653
|
legend // Adjust legend item positions
|
|
1613
1654
|
.attr("transform", "translate(" + tx + ", " + ty + ")"); // Set initial state (disabled controls)
|
|
1614
1655
|
|
|
1615
|
-
if (name in
|
|
1656
|
+
if (name in _this8.options && _this8.options[name] == 'disabled') {
|
|
1616
1657
|
path.classed('leaflet-hidden', true);
|
|
1617
1658
|
legend.select('text').style('text-decoration-line', 'line-through');
|
|
1618
1659
|
legend.select('rect').style('fill-opacity', '0');
|
|
1619
1660
|
} // Apply d3-zoom (bind <clipPath> mask)
|
|
1620
1661
|
|
|
1621
1662
|
|
|
1622
|
-
if (
|
|
1623
|
-
path.attr('
|
|
1663
|
+
if (_this8._mask) {
|
|
1664
|
+
path.attr('mask', 'url(#' + _this8._mask.attr('id') + ')');
|
|
1624
1665
|
}
|
|
1625
1666
|
});
|
|
1626
1667
|
},
|
|
@@ -1689,10 +1730,10 @@
|
|
|
1689
1730
|
* Finds a data entry for a given x-coordinate of the diagram
|
|
1690
1731
|
*/
|
|
1691
1732
|
_findIndexForXCoord: function _findIndexForXCoord(x) {
|
|
1692
|
-
var
|
|
1733
|
+
var _this9 = this;
|
|
1693
1734
|
|
|
1694
1735
|
return d3.bisector(function (d) {
|
|
1695
|
-
return d[
|
|
1736
|
+
return d[_this9.options.xAttr];
|
|
1696
1737
|
}).left(this._data || [0, 1], this._x.invert(x));
|
|
1697
1738
|
},
|
|
1698
1739
|
|