@raruto/leaflet-elevation 1.9.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/leaflet-elevation.css +51 -161
- package/dist/leaflet-elevation.js +1622 -3767
- 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-distance-marker.js +17 -18
- package/libs/leaflet-distance-marker.min.js +1 -1
- package/libs/leaflet-gpxgroup.js +2 -2
- package/libs/leaflet-ruler.css +42 -0
- package/libs/leaflet-ruler.js +183 -0
- package/libs/leaflet-ruler.min.css +1 -0
- package/libs/leaflet-ruler.min.js +1 -0
- package/package.json +9 -11
- package/src/chart.js +156 -143
- package/src/components.js +55 -76
- package/src/control.js +503 -345
- package/src/handlers/acceleration.js +64 -0
- package/src/handlers/acceleration.min.js +1 -0
- package/src/handlers/altitude.js +76 -0
- package/src/handlers/altitude.min.js +1 -0
- package/src/handlers/cadence.js +54 -0
- package/src/handlers/distance.js +45 -0
- package/src/handlers/distance.min.js +1 -0
- package/src/handlers/heart.js +53 -0
- package/src/handlers/slope.js +79 -0
- package/src/handlers/slope.min.js +1 -0
- package/src/handlers/speed.js +66 -0
- package/src/handlers/speed.min.js +1 -0
- package/src/handlers/time.js +103 -0
- package/src/handlers/time.min.js +1 -0
- package/src/index.css +51 -161
- package/src/index.js +0 -24
- package/src/marker.js +11 -14
- package/src/options.js +20 -28
- package/src/summary.js +14 -4
- package/src/utils.js +74 -102
- package/src/acceleration.js +0 -108
- package/src/altitude.js +0 -120
- package/src/distance.js +0 -78
- package/src/slope.js +0 -113
- package/src/speed.js +0 -110
- package/src/time.js +0 -124
package/src/chart.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
1
|
+
import * as D3 from './components.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
|
|
|
@@ -344,34 +340,42 @@ export var Chart = L.Class.extend({
|
|
|
344
340
|
},
|
|
345
341
|
|
|
346
342
|
_registerAreaPath: function(props) {
|
|
343
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
344
|
+
else if (props.scale == 'x') props.scale = this._x;
|
|
345
|
+
|
|
347
346
|
let opts = this.options;
|
|
348
347
|
|
|
349
348
|
if (!props.xAttr) props.xAttr = opts.xAttr;
|
|
350
349
|
if (!props.yAttr) props.yAttr = opts.yAttr;
|
|
351
350
|
if (typeof props.preferCanvas === "undefined") props.preferCanvas = opts.preferCanvas;
|
|
352
351
|
|
|
353
|
-
let path = D3.Path(props);
|
|
354
|
-
|
|
355
352
|
// Save paths in memory for latter usage
|
|
356
|
-
this._paths[props.name] =
|
|
353
|
+
this._paths[props.name] = D3.Path(props);;
|
|
357
354
|
this._props.areas[props.name] = props;
|
|
358
355
|
|
|
359
356
|
if (opts.legend) {
|
|
360
357
|
this._props.legendItems[props.name] = {
|
|
361
|
-
name
|
|
362
|
-
label
|
|
363
|
-
color
|
|
364
|
-
|
|
358
|
+
name : props.name,
|
|
359
|
+
label : props.label,
|
|
360
|
+
color : props.color,
|
|
361
|
+
className: props.className,
|
|
362
|
+
path : this._paths[props.name]
|
|
365
363
|
};
|
|
366
364
|
}
|
|
367
365
|
|
|
368
366
|
},
|
|
369
367
|
|
|
370
368
|
_registerAxisGrid: function(props) {
|
|
369
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
370
|
+
else if(props.scale == 'x') props.scale = this._x;
|
|
371
|
+
|
|
371
372
|
this._props.grids[props.name || props.axis] = props;
|
|
372
373
|
},
|
|
373
374
|
|
|
374
375
|
_registerAxisScale: function(props) {
|
|
376
|
+
if (props.scale == 'y') props.scale = this._y;
|
|
377
|
+
else if(props.scale == 'x') props.scale = this._x;
|
|
378
|
+
|
|
375
379
|
let opts = this.options;
|
|
376
380
|
let scale = props.scale;
|
|
377
381
|
|
|
@@ -396,12 +400,15 @@ export var Chart = L.Class.extend({
|
|
|
396
400
|
}
|
|
397
401
|
|
|
398
402
|
if (!props.ticks) {
|
|
399
|
-
if (props.axis == 'x') props.ticks =
|
|
400
|
-
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);
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
this._props.axes[props.name] = props;
|
|
404
408
|
|
|
409
|
+
if (props.name == this.options.yScale) this._y = scale;
|
|
410
|
+
if (props.name == this.options.xScale) this._x = scale;
|
|
411
|
+
|
|
405
412
|
return scale;
|
|
406
413
|
},
|
|
407
414
|
|
|
@@ -411,16 +418,17 @@ export var Chart = L.Class.extend({
|
|
|
411
418
|
_registerCheckPoint: function(point) {
|
|
412
419
|
if (!this._data.length) return;
|
|
413
420
|
|
|
421
|
+
const {xAttr, yAttr} = this.options;
|
|
414
422
|
let item, x, y;
|
|
415
423
|
|
|
416
424
|
if (point.latlng) {
|
|
417
425
|
item = this._data[this._findIndexForLatLng(point.latlng)];
|
|
418
|
-
x = this._x(item
|
|
419
|
-
y = this._y(item
|
|
420
|
-
} else if (!isNaN(point
|
|
421
|
-
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]);
|
|
422
430
|
item = this._data[this._findIndexForXCoord(x)]
|
|
423
|
-
y = this._y(item
|
|
431
|
+
y = this._y(item[yAttr]);
|
|
424
432
|
}
|
|
425
433
|
|
|
426
434
|
this._point.call(D3.CheckPoint({
|
|
@@ -433,56 +441,46 @@ export var Chart = L.Class.extend({
|
|
|
433
441
|
},
|
|
434
442
|
|
|
435
443
|
_registerTooltip: function(props) {
|
|
444
|
+
props.order = props.order ?? 1000;
|
|
436
445
|
this._props.tooltipItems[props.name] = props;
|
|
437
446
|
},
|
|
438
447
|
|
|
439
448
|
_updateArea: function() {
|
|
440
|
-
let paths = this._paths;
|
|
441
449
|
// Reset and update chart profiles
|
|
442
450
|
this._context.clearRect(0, 0, this._width(), this._height());
|
|
443
|
-
|
|
444
|
-
if (!paths[i].classed('leaflet-hidden')) {
|
|
445
|
-
this._drawPath(i);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
451
|
+
_.each(this._paths, (path, i) => !path.classed('leaflet-hidden') && this._drawPath(i));
|
|
448
452
|
},
|
|
449
453
|
|
|
450
454
|
_updateAxis: function() {
|
|
451
455
|
|
|
452
456
|
let opts = this.options;
|
|
453
457
|
|
|
454
|
-
|
|
455
|
-
this._grid.selectAll('g').remove();
|
|
456
|
-
this._axis.selectAll('g').remove();
|
|
457
|
-
|
|
458
|
-
let grids = this._props.grids;
|
|
459
|
-
let axes = this._props.axes;
|
|
460
|
-
let props, axis, grid;
|
|
461
|
-
|
|
462
|
-
let gridOpts = {
|
|
458
|
+
const gridOpts = {
|
|
463
459
|
width : this._width(),
|
|
464
460
|
height : this._height(),
|
|
465
461
|
tickFormat: "",
|
|
466
462
|
};
|
|
467
|
-
|
|
463
|
+
|
|
464
|
+
const axesOpts = {
|
|
468
465
|
width : this._width(),
|
|
469
466
|
height : this._height(),
|
|
470
467
|
};
|
|
471
468
|
|
|
472
|
-
//
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
});
|
|
478
476
|
|
|
479
|
-
//
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
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
|
+
});
|
|
486
484
|
|
|
487
485
|
// Adjust axis scale positions
|
|
488
486
|
this._axis
|
|
@@ -505,27 +503,26 @@ export var Chart = L.Class.extend({
|
|
|
505
503
|
},
|
|
506
504
|
|
|
507
505
|
_updateClipper: function() {
|
|
508
|
-
|
|
506
|
+
const { xAttr, margins } = this.options;
|
|
507
|
+
const data = this._data;
|
|
509
508
|
|
|
510
509
|
this._zoom
|
|
511
510
|
.scaleExtent([1, 10])
|
|
512
511
|
.extent([
|
|
513
|
-
[
|
|
514
|
-
[this._width() -
|
|
512
|
+
[margins.left, 0],
|
|
513
|
+
[this._width() - margins.right, this._height()]
|
|
515
514
|
])
|
|
516
515
|
.translateExtent([
|
|
517
|
-
[
|
|
518
|
-
[this._width() -
|
|
516
|
+
[margins.left, -Infinity],
|
|
517
|
+
[this._width() - margins.right, Infinity]
|
|
519
518
|
]);
|
|
520
519
|
|
|
521
|
-
// Apply svg mask on multi-track segments
|
|
520
|
+
// Apply svg mask on multi-track segments
|
|
522
521
|
this._mask.selectAll(".gap").remove()
|
|
523
522
|
this._maskGaps.forEach((d, i) => {
|
|
524
523
|
if(i >= this._maskGaps.length - 2) return;
|
|
525
|
-
let
|
|
526
|
-
let
|
|
527
|
-
let x1 = this._x(this._data[this._findIndexForLatLng(d1.latlng)].dist);
|
|
528
|
-
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]);
|
|
529
526
|
this._mask
|
|
530
527
|
.append("rect")
|
|
531
528
|
.attr("x", x1)
|
|
@@ -534,7 +531,7 @@ export var Chart = L.Class.extend({
|
|
|
534
531
|
.attr("height", this._height())
|
|
535
532
|
.attr('class', 'gap')
|
|
536
533
|
.attr('fill-opacity', '0.8')
|
|
537
|
-
.attr("fill", 'black'); //
|
|
534
|
+
.attr("fill", 'black'); // hide = black (mask)
|
|
538
535
|
});
|
|
539
536
|
},
|
|
540
537
|
|
|
@@ -542,27 +539,23 @@ export var Chart = L.Class.extend({
|
|
|
542
539
|
|
|
543
540
|
if (this.options.legend === false) return;
|
|
544
541
|
|
|
545
|
-
|
|
546
|
-
|
|
542
|
+
const legendOpts = {
|
|
543
|
+
width : this._width(),
|
|
544
|
+
height : this._height(),
|
|
545
|
+
margins: this.options.margins,
|
|
546
|
+
};
|
|
547
547
|
|
|
548
548
|
// Reset legend items
|
|
549
549
|
this._legend.selectAll('g').remove();
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
width : this._width(),
|
|
554
|
-
height : this._height(),
|
|
555
|
-
margins: this.options.margins,
|
|
556
|
-
}, legends[i])
|
|
557
|
-
)
|
|
558
|
-
this._legend.append("g").call(legend);
|
|
559
|
-
}
|
|
550
|
+
_.each(this._props.legendItems, (legend) => {
|
|
551
|
+
this._legend.append("g").call(D3.LegendItem(L.extend(legendOpts, legend)));
|
|
552
|
+
});
|
|
560
553
|
|
|
561
554
|
// Get legend items
|
|
562
555
|
let items = this._legend.selectAll('.legend-item');
|
|
563
556
|
|
|
564
557
|
// Calculate legend item positions
|
|
565
|
-
let n
|
|
558
|
+
let n = items.nodes().length;
|
|
566
559
|
let v = Array(Math.floor(n / 2)).fill(null).map((d, i) => (i + 1) * 2 - (1 - Math.sign(n % 2)));
|
|
567
560
|
let rev = v.slice().reverse().map((d) => -(d));
|
|
568
561
|
|
|
@@ -635,14 +628,18 @@ export var Chart = L.Class.extend({
|
|
|
635
628
|
* Calculates chart width.
|
|
636
629
|
*/
|
|
637
630
|
_width: function() {
|
|
638
|
-
|
|
631
|
+
if (this._chart) this._chart._width;
|
|
632
|
+
const { width, margins } = this.options;
|
|
633
|
+
return width - margins.left - margins.right;
|
|
639
634
|
},
|
|
640
635
|
|
|
641
636
|
/**
|
|
642
637
|
* Calculates chart height.
|
|
643
638
|
*/
|
|
644
639
|
_height: function() {
|
|
645
|
-
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;
|
|
646
643
|
},
|
|
647
644
|
|
|
648
645
|
/*
|
|
@@ -654,7 +651,7 @@ export var Chart = L.Class.extend({
|
|
|
654
651
|
|
|
655
652
|
// save indexes of elevation values above the horizontal line
|
|
656
653
|
const list = data.reduce((array, item, index) => {
|
|
657
|
-
if (item.
|
|
654
|
+
if (item[this.options.yAttr] >= z) array.push(index);
|
|
658
655
|
return array;
|
|
659
656
|
}, []);
|
|
660
657
|
|
|
@@ -739,4 +736,20 @@ export var Chart = L.Class.extend({
|
|
|
739
736
|
_hideDiagramIndicator: function() {
|
|
740
737
|
this._tooltip.attr("display", 'none');
|
|
741
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
|
+
}
|
|
742
755
|
});
|