@raruto/leaflet-elevation 1.9.5 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/leaflet-elevation.css +52 -161
- package/dist/leaflet-elevation.js +1587 -3883
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.css +1 -1
- package/dist/leaflet-elevation.min.js +1 -3
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/checkered.png +0 -0
- package/libs/leaflet-gpxgroup.js +2 -2
- package/package.json +9 -11
- package/src/{chart.js → components/chart.js} +147 -144
- package/src/{components.js → components/d3.js} +43 -71
- package/src/{marker.js → components/marker.js} +11 -14
- package/src/{summary.js → components/summary.js} +4 -5
- package/src/control.js +421 -326
- package/src/handlers/acceleration.js +64 -0
- package/src/handlers/altitude.js +76 -0
- package/src/handlers/cadence.js +54 -0
- package/src/handlers/distance.js +45 -0
- package/src/handlers/heart.js +53 -0
- package/src/handlers/slope.js +79 -0
- package/src/handlers/speed.js +66 -0
- package/src/{time.js → handlers/time.js} +32 -54
- package/src/index.css +52 -161
- package/src/index.js +0 -24
- package/src/options.js +20 -28
- package/src/utils.js +74 -102
- package/src/acceleration.js +0 -113
- package/src/altitude.js +0 -119
- package/src/distance.js +0 -69
- package/src/slope.js +0 -129
- package/src/speed.js +0 -118
|
Binary file
|
package/libs/leaflet-gpxgroup.js
CHANGED
|
@@ -189,7 +189,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
|
|
192
|
-
this._elevation.
|
|
192
|
+
this._elevation.import(this._elevation.__LGEOMUTIL).then(() => {
|
|
193
193
|
route.addTo(this._layers);
|
|
194
194
|
|
|
195
195
|
route.eachLayer((layer) => this._onEachRouteLayer(route, layer));
|
|
@@ -279,7 +279,7 @@ L.GpxGroup = L.Class.extend({
|
|
|
279
279
|
|
|
280
280
|
if (route && route.isSelected()) {
|
|
281
281
|
if (!eleDiv) {
|
|
282
|
-
elevation.
|
|
282
|
+
elevation.addTo(this._map);
|
|
283
283
|
}
|
|
284
284
|
route.getLayers().forEach(function(layer) {
|
|
285
285
|
if (layer instanceof L.Polyline) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raruto/leaflet-elevation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A Leaflet plugin that allows to add elevation profiles using d3js",
|
|
5
5
|
"main": "dist/leaflet-elevation.min.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -45,24 +45,22 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/Raruto/leaflet-elevation#readme",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@babel/core": "^7.10.2",
|
|
49
|
-
"@babel/preset-env": "^7.10.2",
|
|
50
|
-
"@rollup/plugin-babel": "^5.0.3",
|
|
51
48
|
"postcss-copy": "^7.1.0",
|
|
52
|
-
"postcss-import": "^
|
|
53
|
-
"rollup": "^2.
|
|
49
|
+
"postcss-import": "^14.0.2",
|
|
50
|
+
"rollup": "^2.70.0",
|
|
54
51
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
55
52
|
"rollup-plugin-git-version": "^0.3.1",
|
|
56
53
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
57
|
-
"rollup-plugin-postcss": "^
|
|
54
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
58
55
|
"rollup-plugin-terser": "^7.0.2"
|
|
59
56
|
},
|
|
60
57
|
"peerDependencies": {
|
|
61
|
-
"leaflet": "^1.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
58
|
+
"leaflet": "^1.7.0",
|
|
59
|
+
"d3": "6.5.0",
|
|
60
|
+
"@tmcw/togeojson": "4.6.0"
|
|
64
61
|
},
|
|
65
62
|
"dependencies": {
|
|
66
|
-
"leaflet-i18n": "^0.3.1"
|
|
63
|
+
"leaflet-i18n": "^0.3.1",
|
|
64
|
+
"postcss": "^8.4.8"
|
|
67
65
|
}
|
|
68
66
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
1
|
+
import * as D3 from './d3.js';
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
|
+
|
|
5
|
+
export var Chart = L.Control.Elevation.Chart = L.Class.extend({
|
|
6
6
|
|
|
7
7
|
includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ export var Chart = L.Class.extend({
|
|
|
10
10
|
this.options = opts;
|
|
11
11
|
this.control = control;
|
|
12
12
|
|
|
13
|
-
this._data = [];
|
|
13
|
+
this._data = control._data || [];
|
|
14
14
|
|
|
15
15
|
// cache registered components
|
|
16
16
|
this._props = {
|
|
@@ -31,10 +31,13 @@ export var Chart = L.Class.extend({
|
|
|
31
31
|
this._brushEnabled = opts.dragging;
|
|
32
32
|
this._zoomEnabled = opts.zooming;
|
|
33
33
|
|
|
34
|
+
opts.xTicks = this._xTicks();
|
|
35
|
+
opts.yTicks = this._yTicks();
|
|
36
|
+
|
|
34
37
|
let chart = this._chart = D3.Chart(opts);
|
|
35
38
|
|
|
36
39
|
// SVG Container
|
|
37
|
-
|
|
40
|
+
this._container = chart.svg;
|
|
38
41
|
|
|
39
42
|
// Panes
|
|
40
43
|
this._grid = chart.pane('grid');
|
|
@@ -49,23 +52,23 @@ export var Chart = L.Class.extend({
|
|
|
49
52
|
this._initScale();
|
|
50
53
|
|
|
51
54
|
// Helpers
|
|
52
|
-
this._mask
|
|
55
|
+
this._mask = chart.get('mask');
|
|
53
56
|
this._context = chart.get('context');
|
|
54
57
|
this._brush = chart.get('brush');
|
|
55
58
|
|
|
56
|
-
this._zoom
|
|
57
|
-
this._drag
|
|
59
|
+
this._zoom = d3.zoom();
|
|
60
|
+
this._drag = d3.drag();
|
|
58
61
|
|
|
59
62
|
// Interactions
|
|
60
63
|
this._initInteractions();
|
|
61
64
|
|
|
62
65
|
// svg.on('resize', (e)=>console.log(e.detail));
|
|
63
66
|
|
|
64
|
-
// Handle multi-track segments
|
|
67
|
+
// Handle multi-track segments
|
|
65
68
|
this._maskGaps = [];
|
|
66
|
-
control.on('eletrack_added', (
|
|
67
|
-
this._maskGaps.push(
|
|
68
|
-
control.once('
|
|
69
|
+
control.on('eletrack_added', ({index}) => {
|
|
70
|
+
this._maskGaps.push(index);
|
|
71
|
+
control.once('elepoint_added', ({index}) => this._maskGaps.push(index));
|
|
69
72
|
});
|
|
70
73
|
|
|
71
74
|
},
|
|
@@ -76,6 +79,9 @@ export var Chart = L.Class.extend({
|
|
|
76
79
|
if (props.options) this.options = props.options;
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
this.options.xTicks = this._xTicks();
|
|
83
|
+
this.options.yTicks = this._yTicks();
|
|
84
|
+
|
|
79
85
|
this._updateScale();
|
|
80
86
|
this._updateArea();
|
|
81
87
|
this._updateAxis();
|
|
@@ -94,14 +100,13 @@ export var Chart = L.Class.extend({
|
|
|
94
100
|
this._hideDiagramIndicator()
|
|
95
101
|
this._area.selectAll('path').attr("d", "M0 0");
|
|
96
102
|
this._context.clearRect(0, 0, this._width(), this._height());
|
|
103
|
+
this._mask.selectAll(".gap").remove();
|
|
104
|
+
this._maskGaps = [];
|
|
97
105
|
|
|
98
106
|
// if (this._path) {
|
|
99
107
|
// this._x.domain([0, 1]);
|
|
100
108
|
// this._y.domain([0, 1]);
|
|
101
109
|
// }
|
|
102
|
-
|
|
103
|
-
this._maskGaps = [];
|
|
104
|
-
this._mask.selectAll(".gap").remove();
|
|
105
110
|
},
|
|
106
111
|
|
|
107
112
|
_drawPath: function(name) {
|
|
@@ -119,12 +124,10 @@ export var Chart = L.Class.extend({
|
|
|
119
124
|
)
|
|
120
125
|
);
|
|
121
126
|
|
|
122
|
-
if (path.classed('leaflet-hidden'))
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
this._area.append(() => path.node());
|
|
127
|
+
if (!path.classed('leaflet-hidden')) {
|
|
128
|
+
this.options.preferCanvas
|
|
129
|
+
? _.drawCanvas(this._context, path)
|
|
130
|
+
: _.append(this._area.node(), path.node());
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
|
|
@@ -142,29 +145,27 @@ export var Chart = L.Class.extend({
|
|
|
142
145
|
* Initialize "d3-brush".
|
|
143
146
|
*/
|
|
144
147
|
_initBrush: function(e) {
|
|
145
|
-
const brush = (
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
let start = this._findIndexForXCoord(extent[0]);
|
|
150
|
-
let end = this._findIndexForXCoord(extent[1]);
|
|
148
|
+
const brush = ({selection}) => {
|
|
149
|
+
if (selection && this._data.length) {
|
|
150
|
+
let start = this._findIndexForXCoord(selection[0]);
|
|
151
|
+
let end = this._findIndexForXCoord(selection[1]);
|
|
151
152
|
this.fire('dragged', { dragstart: this._data[start], dragend: this._data[end] });
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
const focus = (e) => {
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
if (this._data.length && (e.type != 'brush' /*|| e.sourceEvent*/)) {
|
|
158
|
+
let rect = this._chart.panes.brush.select('.overlay').node();
|
|
159
|
+
let coords = d3.pointers(e, rect)[0];
|
|
160
|
+
let xCoord = coords[0];
|
|
161
|
+
let item = this._data[this._findIndexForXCoord(xCoord)];
|
|
162
|
+
|
|
163
|
+
this.fire("mouse_move", { item: item, xCoord: xCoord });
|
|
164
|
+
}
|
|
164
165
|
};
|
|
165
166
|
|
|
166
167
|
this._brush
|
|
167
|
-
.filter((
|
|
168
|
+
.filter(({shiftKey, button}) => !shiftKey && !button && this._brushEnabled)
|
|
168
169
|
.on("end.update", brush)
|
|
169
170
|
.on("brush.update", focus);
|
|
170
171
|
|
|
@@ -184,11 +185,11 @@ export var Chart = L.Class.extend({
|
|
|
184
185
|
|
|
185
186
|
const zoom = this._zoom;
|
|
186
187
|
|
|
187
|
-
const onStart = (
|
|
188
|
-
if (
|
|
189
|
-
if (
|
|
188
|
+
const onStart = ({transform, sourceEvent}) => {
|
|
189
|
+
if (sourceEvent && sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing');
|
|
190
|
+
if (transform.k == 1 && transform.x == 0) {
|
|
190
191
|
this._container.classed('zoomed', true);
|
|
191
|
-
// Apply d3-zoom
|
|
192
|
+
// Apply d3-zoom and bind <mask>
|
|
192
193
|
if (this._mask) {
|
|
193
194
|
this._point.attr('mask', 'url(#' + this._mask.attr('id') + ')');
|
|
194
195
|
}
|
|
@@ -196,10 +197,10 @@ export var Chart = L.Class.extend({
|
|
|
196
197
|
this.zooming = true;
|
|
197
198
|
};
|
|
198
199
|
|
|
199
|
-
const onEnd = (
|
|
200
|
-
if (
|
|
200
|
+
const onEnd = ({transform}) => {
|
|
201
|
+
if (transform.k ==1 && transform.x == 0) {
|
|
201
202
|
this._container.classed('zoomed', false);
|
|
202
|
-
//
|
|
203
|
+
// Reset d3-zoom and remove <mask>
|
|
203
204
|
if (this._mask) {
|
|
204
205
|
this._point.attr('mask', null);
|
|
205
206
|
}
|
|
@@ -208,15 +209,15 @@ export var Chart = L.Class.extend({
|
|
|
208
209
|
svg.style('cursor', '');
|
|
209
210
|
};
|
|
210
211
|
|
|
211
|
-
const onZoom = (
|
|
212
|
+
const onZoom = ({transform, sourceEvent}) => {
|
|
212
213
|
// TODO: find a faster way to redraw the chart.
|
|
213
214
|
this.zooming = false;
|
|
214
215
|
this._updateScale(); // hacky way for restoring x scale when zooming out
|
|
215
216
|
this.zooming = true;
|
|
216
|
-
this._scales.distance = this._x =
|
|
217
|
-
if (this._scales.time) this._scales.time =
|
|
217
|
+
this._scales.distance = this._x = transform.rescaleX(this._x); // calculate x scale at zoom level
|
|
218
|
+
if (this._scales.time) this._scales.time = transform.rescaleX(this._scales.time); // calculate x scale at zoom level
|
|
218
219
|
this._resetDrag();
|
|
219
|
-
if (
|
|
220
|
+
if (sourceEvent && sourceEvent.type == "mousemove") {
|
|
220
221
|
this._hideDiagramIndicator();
|
|
221
222
|
}
|
|
222
223
|
this.fire('zoom');
|
|
@@ -232,7 +233,7 @@ export var Chart = L.Class.extend({
|
|
|
232
233
|
[margin.left, -Infinity],
|
|
233
234
|
[this._width() - margin.right, Infinity]
|
|
234
235
|
])
|
|
235
|
-
.filter((
|
|
236
|
+
.filter(({shiftKey, buttons}) => (shiftKey || buttons == 4) && this._zoomEnabled)
|
|
236
237
|
.on("start", onStart)
|
|
237
238
|
.on("end", onEnd)
|
|
238
239
|
.on("zoom", onZoom);
|
|
@@ -254,21 +255,17 @@ export var Chart = L.Class.extend({
|
|
|
254
255
|
* Toggle chart data on legend click
|
|
255
256
|
*/
|
|
256
257
|
_initLegend: function() {
|
|
257
|
-
this._container.on('legend_clicked', (
|
|
258
|
-
let { path, legend, name, enabled } =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this._updateArea();
|
|
270
|
-
|
|
271
|
-
this.fire("elepath_toggle", { path, name, legend, enabled })
|
|
258
|
+
this._container.on('legend_clicked', ({detail}) => {
|
|
259
|
+
let { path, legend, name, enabled } = detail;
|
|
260
|
+
if (path) {
|
|
261
|
+
let label = _.select('text', legend);
|
|
262
|
+
let rect = _.select('rect', legend);
|
|
263
|
+
_.toggleStyle(label, 'text-decoration-line', 'line-through', enabled);
|
|
264
|
+
_.toggleStyle(rect, 'fill-opacity', '0', enabled);
|
|
265
|
+
_.toggleClass(path, 'leaflet-hidden', enabled);
|
|
266
|
+
this._updateArea();
|
|
267
|
+
this.fire("elepath_toggle", { path, name, legend, enabled })
|
|
268
|
+
}
|
|
272
269
|
});
|
|
273
270
|
},
|
|
274
271
|
|
|
@@ -290,26 +287,25 @@ export var Chart = L.Class.extend({
|
|
|
290
287
|
};
|
|
291
288
|
|
|
292
289
|
const position = (e, d) => {
|
|
293
|
-
let yMax = this._height();
|
|
294
290
|
let yCoord = d3.pointers(e, this._area.node())[0][1];
|
|
295
|
-
let
|
|
296
|
-
let
|
|
297
|
-
let data = L.extend(this._ruler.data()[0], { y: y });
|
|
291
|
+
let yMax = this._height();
|
|
292
|
+
let y = _.clamp(yCoord, [0, yMax]);
|
|
298
293
|
|
|
299
294
|
this._ruler
|
|
300
|
-
.data([data])
|
|
295
|
+
.data([L.extend(this._ruler.data()[0], { y: y })])
|
|
301
296
|
.attr("transform", d => "translate(" + d.x + "," + d.y + ")")
|
|
302
297
|
.classed('active', y < yMax);
|
|
303
298
|
|
|
304
|
-
this._container
|
|
305
|
-
.
|
|
299
|
+
this._container
|
|
300
|
+
.select(".horizontal-drag-label")
|
|
301
|
+
.text(formatNum(this._y.invert(y)) + " " + (this.options.imperial ? 'ft' : 'm'));
|
|
306
302
|
|
|
307
303
|
this.fire('ruler_filter', { coords: yCoord < yMax && yCoord > 0 ? this._findCoordsForY(yCoord) : [] });
|
|
308
304
|
}
|
|
309
305
|
|
|
310
306
|
drag
|
|
311
|
-
|
|
312
|
-
|
|
307
|
+
.on("start end", label)
|
|
308
|
+
.on("drag", position);
|
|
313
309
|
|
|
314
310
|
this._ruler.call(drag);
|
|
315
311
|
|
|
@@ -353,18 +349,17 @@ export var Chart = L.Class.extend({
|
|
|
353
349
|
if (!props.yAttr) props.yAttr = opts.yAttr;
|
|
354
350
|
if (typeof props.preferCanvas === "undefined") props.preferCanvas = opts.preferCanvas;
|
|
355
351
|
|
|
356
|
-
let path = D3.Path(props);
|
|
357
|
-
|
|
358
352
|
// Save paths in memory for latter usage
|
|
359
|
-
this._paths[props.name] =
|
|
353
|
+
this._paths[props.name] = D3.Path(props);;
|
|
360
354
|
this._props.areas[props.name] = props;
|
|
361
355
|
|
|
362
356
|
if (opts.legend) {
|
|
363
357
|
this._props.legendItems[props.name] = {
|
|
364
|
-
name
|
|
365
|
-
label
|
|
366
|
-
color
|
|
367
|
-
|
|
358
|
+
name : props.name,
|
|
359
|
+
label : props.label,
|
|
360
|
+
color : props.color,
|
|
361
|
+
className: props.className,
|
|
362
|
+
path : this._paths[props.name]
|
|
368
363
|
};
|
|
369
364
|
}
|
|
370
365
|
|
|
@@ -405,12 +400,15 @@ export var Chart = L.Class.extend({
|
|
|
405
400
|
}
|
|
406
401
|
|
|
407
402
|
if (!props.ticks) {
|
|
408
|
-
if (props.axis == 'x') props.ticks =
|
|
409
|
-
else if (props.axis == 'y') props.ticks =
|
|
403
|
+
if (props.axis == 'x') props.ticks = this._xTicks.bind(this);
|
|
404
|
+
else if (props.axis == 'y') props.ticks = this._yTicks.bind(this);
|
|
410
405
|
}
|
|
411
406
|
|
|
412
407
|
this._props.axes[props.name] = props;
|
|
413
408
|
|
|
409
|
+
if (props.name == this.options.yScale) this._y = scale;
|
|
410
|
+
if (props.name == this.options.xScale) this._x = scale;
|
|
411
|
+
|
|
414
412
|
return scale;
|
|
415
413
|
},
|
|
416
414
|
|
|
@@ -420,16 +418,17 @@ export var Chart = L.Class.extend({
|
|
|
420
418
|
_registerCheckPoint: function(point) {
|
|
421
419
|
if (!this._data.length) return;
|
|
422
420
|
|
|
421
|
+
const {xAttr, yAttr} = this.options;
|
|
423
422
|
let item, x, y;
|
|
424
423
|
|
|
425
424
|
if (point.latlng) {
|
|
426
425
|
item = this._data[this._findIndexForLatLng(point.latlng)];
|
|
427
|
-
x = this._x(item
|
|
428
|
-
y = this._y(item
|
|
429
|
-
} else if (!isNaN(point
|
|
430
|
-
x = this._x(point
|
|
426
|
+
x = this._x(item[xAttr]);
|
|
427
|
+
y = this._y(item[yAttr]);
|
|
428
|
+
} else if (!isNaN(point[xAttr])) {
|
|
429
|
+
x = this._x(point[xAttr]);
|
|
431
430
|
item = this._data[this._findIndexForXCoord(x)]
|
|
432
|
-
y = this._y(item
|
|
431
|
+
y = this._y(item[yAttr]);
|
|
433
432
|
}
|
|
434
433
|
|
|
435
434
|
this._point.call(D3.CheckPoint({
|
|
@@ -442,57 +441,46 @@ export var Chart = L.Class.extend({
|
|
|
442
441
|
},
|
|
443
442
|
|
|
444
443
|
_registerTooltip: function(props) {
|
|
445
|
-
props.order = props.order ??
|
|
444
|
+
props.order = props.order ?? 1000;
|
|
446
445
|
this._props.tooltipItems[props.name] = props;
|
|
447
446
|
},
|
|
448
447
|
|
|
449
448
|
_updateArea: function() {
|
|
450
|
-
let paths = this._paths;
|
|
451
449
|
// Reset and update chart profiles
|
|
452
450
|
this._context.clearRect(0, 0, this._width(), this._height());
|
|
453
|
-
|
|
454
|
-
if (!paths[i].classed('leaflet-hidden')) {
|
|
455
|
-
this._drawPath(i);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
451
|
+
_.each(this._paths, (path, i) => !path.classed('leaflet-hidden') && this._drawPath(i));
|
|
458
452
|
},
|
|
459
453
|
|
|
460
454
|
_updateAxis: function() {
|
|
461
455
|
|
|
462
456
|
let opts = this.options;
|
|
463
457
|
|
|
464
|
-
|
|
465
|
-
this._grid.selectAll('g').remove();
|
|
466
|
-
this._axis.selectAll('g').remove();
|
|
467
|
-
|
|
468
|
-
let grids = this._props.grids;
|
|
469
|
-
let axes = this._props.axes;
|
|
470
|
-
let props, axis, grid;
|
|
471
|
-
|
|
472
|
-
let gridOpts = {
|
|
458
|
+
const gridOpts = {
|
|
473
459
|
width : this._width(),
|
|
474
460
|
height : this._height(),
|
|
475
461
|
tickFormat: "",
|
|
476
462
|
};
|
|
477
|
-
|
|
463
|
+
|
|
464
|
+
const axesOpts = {
|
|
478
465
|
width : this._width(),
|
|
479
466
|
height : this._height(),
|
|
480
467
|
};
|
|
481
468
|
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
469
|
+
// Reset grids
|
|
470
|
+
this._grid.selectAll('g').remove();
|
|
471
|
+
_.each(this._props.grids, (grid, i) => {
|
|
472
|
+
if (opts[i] !== false && opts[i] !== 'summary') {
|
|
473
|
+
this._grid.call(D3.Grid(L.extend({}, gridOpts, grid)))
|
|
474
|
+
}
|
|
475
|
+
});
|
|
488
476
|
|
|
489
|
-
//
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
477
|
+
// Rest axis
|
|
478
|
+
this._axis.selectAll('g').remove();
|
|
479
|
+
_.each(this._props.axes, (axis, i) => {
|
|
480
|
+
if (opts[i] !== false && opts[i] !== 'summary') {
|
|
481
|
+
this._axis.call(D3.Axis(L.extend({}, axesOpts, axis)));
|
|
482
|
+
}
|
|
483
|
+
});
|
|
496
484
|
|
|
497
485
|
// Adjust axis scale positions
|
|
498
486
|
this._axis
|
|
@@ -515,27 +503,26 @@ export var Chart = L.Class.extend({
|
|
|
515
503
|
},
|
|
516
504
|
|
|
517
505
|
_updateClipper: function() {
|
|
518
|
-
|
|
506
|
+
const { xAttr, margins } = this.options;
|
|
507
|
+
const data = this._data;
|
|
519
508
|
|
|
520
509
|
this._zoom
|
|
521
510
|
.scaleExtent([1, 10])
|
|
522
511
|
.extent([
|
|
523
|
-
[
|
|
524
|
-
[this._width() -
|
|
512
|
+
[margins.left, 0],
|
|
513
|
+
[this._width() - margins.right, this._height()]
|
|
525
514
|
])
|
|
526
515
|
.translateExtent([
|
|
527
|
-
[
|
|
528
|
-
[this._width() -
|
|
516
|
+
[margins.left, -Infinity],
|
|
517
|
+
[this._width() - margins.right, Infinity]
|
|
529
518
|
]);
|
|
530
519
|
|
|
531
|
-
// Apply svg mask on multi-track segments
|
|
520
|
+
// Apply svg mask on multi-track segments
|
|
532
521
|
this._mask.selectAll(".gap").remove()
|
|
533
522
|
this._maskGaps.forEach((d, i) => {
|
|
534
523
|
if(i >= this._maskGaps.length - 2) return;
|
|
535
|
-
let
|
|
536
|
-
let
|
|
537
|
-
let x1 = this._x(this._data[this._findIndexForLatLng(d1.latlng)].dist);
|
|
538
|
-
let x2 = this._x(this._data[this._findIndexForLatLng(d2.latlng)].dist);
|
|
524
|
+
let x1 = this._x(data[this._findIndexForLatLng(data[this._maskGaps[i]].latlng)][xAttr]);
|
|
525
|
+
let x2 = this._x(data[this._findIndexForLatLng(data[this._maskGaps[i + 1]].latlng)][xAttr]);
|
|
539
526
|
this._mask
|
|
540
527
|
.append("rect")
|
|
541
528
|
.attr("x", x1)
|
|
@@ -544,7 +531,7 @@ export var Chart = L.Class.extend({
|
|
|
544
531
|
.attr("height", this._height())
|
|
545
532
|
.attr('class', 'gap')
|
|
546
533
|
.attr('fill-opacity', '0.8')
|
|
547
|
-
.attr("fill", 'black'); //
|
|
534
|
+
.attr("fill", 'black'); // hide = black (mask)
|
|
548
535
|
});
|
|
549
536
|
},
|
|
550
537
|
|
|
@@ -552,27 +539,23 @@ export var Chart = L.Class.extend({
|
|
|
552
539
|
|
|
553
540
|
if (this.options.legend === false) return;
|
|
554
541
|
|
|
555
|
-
|
|
556
|
-
|
|
542
|
+
const legendOpts = {
|
|
543
|
+
width : this._width(),
|
|
544
|
+
height : this._height(),
|
|
545
|
+
margins: this.options.margins,
|
|
546
|
+
};
|
|
557
547
|
|
|
558
548
|
// Reset legend items
|
|
559
549
|
this._legend.selectAll('g').remove();
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
width : this._width(),
|
|
564
|
-
height : this._height(),
|
|
565
|
-
margins: this.options.margins,
|
|
566
|
-
}, legends[i])
|
|
567
|
-
)
|
|
568
|
-
this._legend.append("g").call(legend);
|
|
569
|
-
}
|
|
550
|
+
_.each(this._props.legendItems, (legend) => {
|
|
551
|
+
this._legend.append("g").call(D3.LegendItem(L.extend(legendOpts, legend)));
|
|
552
|
+
});
|
|
570
553
|
|
|
571
554
|
// Get legend items
|
|
572
555
|
let items = this._legend.selectAll('.legend-item');
|
|
573
556
|
|
|
574
557
|
// Calculate legend item positions
|
|
575
|
-
let n
|
|
558
|
+
let n = items.nodes().length;
|
|
576
559
|
let v = Array(Math.floor(n / 2)).fill(null).map((d, i) => (i + 1) * 2 - (1 - Math.sign(n % 2)));
|
|
577
560
|
let rev = v.slice().reverse().map((d) => -(d));
|
|
578
561
|
|
|
@@ -645,14 +628,18 @@ export var Chart = L.Class.extend({
|
|
|
645
628
|
* Calculates chart width.
|
|
646
629
|
*/
|
|
647
630
|
_width: function() {
|
|
648
|
-
|
|
631
|
+
if (this._chart) this._chart._width;
|
|
632
|
+
const { width, margins } = this.options;
|
|
633
|
+
return width - margins.left - margins.right;
|
|
649
634
|
},
|
|
650
635
|
|
|
651
636
|
/**
|
|
652
637
|
* Calculates chart height.
|
|
653
638
|
*/
|
|
654
639
|
_height: function() {
|
|
655
|
-
return this._chart._height;
|
|
640
|
+
if (this._chart) return this._chart._height;
|
|
641
|
+
const { height, margins } = this.options;
|
|
642
|
+
return height - margins.top - margins.bottom;
|
|
656
643
|
},
|
|
657
644
|
|
|
658
645
|
/*
|
|
@@ -664,7 +651,7 @@ export var Chart = L.Class.extend({
|
|
|
664
651
|
|
|
665
652
|
// save indexes of elevation values above the horizontal line
|
|
666
653
|
const list = data.reduce((array, item, index) => {
|
|
667
|
-
if (item.
|
|
654
|
+
if (item[this.options.yAttr] >= z) array.push(index);
|
|
668
655
|
return array;
|
|
669
656
|
}, []);
|
|
670
657
|
|
|
@@ -749,4 +736,20 @@ export var Chart = L.Class.extend({
|
|
|
749
736
|
_hideDiagramIndicator: function() {
|
|
750
737
|
this._tooltip.attr("display", 'none');
|
|
751
738
|
},
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Calculate chart xTicks
|
|
742
|
+
*/
|
|
743
|
+
_xTicks: function() {
|
|
744
|
+
if (this.__xTicks) this.__xTicks = this.options.xTicks;
|
|
745
|
+
return this.__xTicks || Math.round(this._width() / 75);
|
|
746
|
+
},
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Calculate chart yTicks
|
|
750
|
+
*/
|
|
751
|
+
_yTicks: function() {
|
|
752
|
+
if (this.__yTicks) this.__yTicks = this.options.yTicks;
|
|
753
|
+
return this.__yTicks || Math.round(this._height() / 30);
|
|
754
|
+
}
|
|
752
755
|
});
|