@raruto/leaflet-elevation 1.9.6 → 2.0.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.
- package/README.md +7 -5
- package/dist/leaflet-elevation.css +52 -161
- package/dist/leaflet-elevation.js +1550 -3884
- 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 +97 -92
- package/libs/leaflet-distance-marker.min.js +1 -1
- 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 +492 -434
- package/src/handlers/acceleration.js +64 -0
- package/src/handlers/altitude.js +79 -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} +31 -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
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export const Colors = {
|
|
2
|
-
'lightblue': { area: '#3366CC', alpha: 0.45, stroke: '#3366CC' },
|
|
3
|
-
'magenta' : { area: '#FF005E' },
|
|
4
|
-
'yellow' : { area: '#FF0' },
|
|
5
|
-
'purple' : { area: '#732C7B' },
|
|
6
|
-
'steelblue': { area: '#4682B4' },
|
|
7
|
-
'red' : { area: '#F00' },
|
|
8
|
-
'lime' : { area: '#9CC222', line: '#566B13' }
|
|
9
|
-
};
|
|
10
|
-
|
|
11
1
|
export const Area = ({
|
|
12
2
|
width,
|
|
13
3
|
height,
|
|
@@ -30,10 +20,11 @@ export const Path = ({
|
|
|
30
20
|
strokeColor,
|
|
31
21
|
strokeOpacity,
|
|
32
22
|
fillOpacity,
|
|
23
|
+
className = ''
|
|
33
24
|
}) => {
|
|
34
25
|
let path = d3.create('svg:path')
|
|
35
26
|
|
|
36
|
-
if (name) path.classed(name, true);
|
|
27
|
+
if (name) path.classed(name + ' ' + className, true);
|
|
37
28
|
|
|
38
29
|
path.style("pointer-events", "none");
|
|
39
30
|
|
|
@@ -76,7 +67,7 @@ export const Axis = ({
|
|
|
76
67
|
|
|
77
68
|
let axisScale = d3["axis" + position.replace(/\b\w/g, l => l.toUpperCase())]()
|
|
78
69
|
.scale(scale)
|
|
79
|
-
.ticks(ticks)
|
|
70
|
+
.ticks(typeof ticks === 'function' ? ticks() : ticks)
|
|
80
71
|
.tickPadding(tickPadding)
|
|
81
72
|
.tickSize(tickSize)
|
|
82
73
|
.tickFormat(tickFormat);
|
|
@@ -151,20 +142,20 @@ export const PositionMarker = ({
|
|
|
151
142
|
let label;
|
|
152
143
|
|
|
153
144
|
Object
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
145
|
+
.keys(labels)
|
|
146
|
+
.sort((a, b) => labels[a].order - labels[b].order) // TODO: any performance issues?
|
|
147
|
+
.forEach((i)=> {
|
|
148
|
+
label = text.select(".height-focus-" + labels[i].name);
|
|
149
|
+
|
|
150
|
+
if (!label.size()) {
|
|
151
|
+
label = text.append("svg:tspan")
|
|
152
|
+
.attr("class", "height-focus-" + labels[i].name /*+ " " + "order-" + labels[i].order*/)
|
|
153
|
+
.attr("dy", "1.5em");
|
|
154
|
+
}
|
|
164
155
|
|
|
165
|
-
|
|
156
|
+
label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
|
|
166
157
|
|
|
167
|
-
|
|
158
|
+
});
|
|
168
159
|
|
|
169
160
|
text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
|
|
170
161
|
text.selectAll('tspan').attr("x", xCoord + 5);
|
|
@@ -180,7 +171,8 @@ export const LegendItem = ({
|
|
|
180
171
|
height,
|
|
181
172
|
margins = {},
|
|
182
173
|
color,
|
|
183
|
-
path
|
|
174
|
+
path,
|
|
175
|
+
className = ''
|
|
184
176
|
}) => {
|
|
185
177
|
return g => {
|
|
186
178
|
g
|
|
@@ -206,7 +198,8 @@ export const LegendItem = ({
|
|
|
206
198
|
.attr("fill", color)
|
|
207
199
|
.attr("stroke", "#000")
|
|
208
200
|
.attr("stroke-opacity", "0.5")
|
|
209
|
-
.attr("fill-opacity", "0.25")
|
|
201
|
+
.attr("fill-opacity", "0.25")
|
|
202
|
+
.attr("class", className);
|
|
210
203
|
|
|
211
204
|
g.append('svg:text')
|
|
212
205
|
.text(L._(label || name))
|
|
@@ -286,7 +279,7 @@ export const Tooltip = ({
|
|
|
286
279
|
|
|
287
280
|
if (!label.size()) {
|
|
288
281
|
label = text.append("svg:tspan", ".mouse-focus-label-x")
|
|
289
|
-
.attr("class", "mouse-focus-label-" + labels[i].name)
|
|
282
|
+
.attr("class", "mouse-focus-label-" + labels[i].name /*+ " " + "order-" + labels[i].order*/)
|
|
290
283
|
.attr("dy", "1.5em");
|
|
291
284
|
}
|
|
292
285
|
|
|
@@ -444,8 +437,7 @@ export const Domain = ({
|
|
|
444
437
|
forceBounds,
|
|
445
438
|
scale
|
|
446
439
|
}) => function(data) {
|
|
447
|
-
attr = attr || name;
|
|
448
|
-
if (scale && scale.attr) attr = scale.attr;
|
|
440
|
+
attr = (scale && scale.attr) || attr || name;
|
|
449
441
|
let domain = data && data.length ? d3.extent(data, d => d[attr]) : [0, 1];
|
|
450
442
|
if (typeof min !== "undefined" && (min < domain[0] || forceBounds)) {
|
|
451
443
|
domain[0] = min;
|
|
@@ -494,8 +486,8 @@ export const Chart = ({
|
|
|
494
486
|
ruler,
|
|
495
487
|
}) => {
|
|
496
488
|
|
|
497
|
-
const
|
|
498
|
-
const
|
|
489
|
+
const w = width - margins.left - margins.right;
|
|
490
|
+
const h = height - margins.top - margins.bottom;
|
|
499
491
|
|
|
500
492
|
// SVG Container
|
|
501
493
|
const svg = d3.create("svg:svg").attr("class", "background");
|
|
@@ -514,16 +506,16 @@ export const Chart = ({
|
|
|
514
506
|
};
|
|
515
507
|
|
|
516
508
|
// SVG Paths
|
|
517
|
-
const mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
|
|
518
|
-
const maskRect = mask.append("svg:rect").attr('class', 'zoom').attr('fill', 'white'); // white = transparent
|
|
509
|
+
const mask = panes.area .append("svg:mask") .attr("id", 'elevation-clipper').attr('fill-opacity', 1);
|
|
510
|
+
const maskRect = mask .append("svg:rect") .attr('class', 'zoom') .attr('fill', 'white'); // white = transparent
|
|
519
511
|
|
|
520
512
|
// Canvas Paths
|
|
521
|
-
const foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
|
|
522
|
-
const canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
|
|
513
|
+
const foreignObject = panes.area .append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
|
|
514
|
+
const canvas = foreignObject.append('xhtml:canvas') .attr('class', 'canvas-plot');
|
|
523
515
|
const context = canvas.node().getContext('2d');
|
|
524
516
|
|
|
525
517
|
// Add tooltip
|
|
526
|
-
panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height:
|
|
518
|
+
panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height: h, width : w, labels: {} }));
|
|
527
519
|
|
|
528
520
|
// Add the brushing
|
|
529
521
|
let brush = d3.brushX().on('start.cursor end.cursor brush.cursor', () => panes.brush.select(".overlay").attr('cursor', null));
|
|
@@ -554,57 +546,37 @@ export const Chart = ({
|
|
|
554
546
|
ruler,
|
|
555
547
|
}) => {
|
|
556
548
|
|
|
557
|
-
const
|
|
558
|
-
const
|
|
549
|
+
const w = width - margins.left - margins.right;
|
|
550
|
+
const h = height - margins.top - margins.bottom;
|
|
559
551
|
|
|
560
|
-
svg.attr("viewBox", `0 0 ${width} ${height}`)
|
|
561
|
-
|
|
562
|
-
.attr("height", height);
|
|
563
|
-
|
|
564
|
-
g.attr("transform", "translate(" + margins.left + "," + margins.top + ")");
|
|
552
|
+
svg .attr("width", width).attr("height", height).attr("viewBox", `0 0 ${width} ${height}`);
|
|
553
|
+
g .attr("transform", "translate(" + margins.left + "," + margins.top + ")");
|
|
565
554
|
|
|
566
555
|
// Partially fix: https://github.com/Raruto/leaflet-elevation/issues/123
|
|
567
556
|
if(/Mac|iPod|iPhone|iPad/.test(navigator.platform) && /AppleWebkit/i.test(navigator.userAgent)) {
|
|
568
|
-
canvas
|
|
569
|
-
.style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
557
|
+
canvas .style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
|
|
570
558
|
}
|
|
571
559
|
|
|
572
|
-
maskRect
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
.attr("width", _width)
|
|
576
|
-
.attr("height", _height);
|
|
577
|
-
|
|
578
|
-
foreignObject
|
|
579
|
-
.attr('width', _width)
|
|
580
|
-
.attr('height', _height);
|
|
581
|
-
|
|
582
|
-
canvas
|
|
583
|
-
.attr('width', _width)
|
|
584
|
-
.attr('height', _height);
|
|
560
|
+
maskRect .attr("width", w).attr("height", h).attr("x", 0).attr("y", 0);
|
|
561
|
+
foreignObject.attr('width', w).attr('height', h);
|
|
562
|
+
canvas .attr('width', w).attr('height', h);
|
|
585
563
|
|
|
586
564
|
if (ruler) {
|
|
587
|
-
panes.ruler.call(Ruler({ height:
|
|
565
|
+
panes.ruler.call(Ruler({ height: h, width: w }));
|
|
588
566
|
}
|
|
589
567
|
|
|
590
|
-
panes.brush.call(brush.extent( [ [0,0], [
|
|
568
|
+
panes.brush.call(brush.extent( [ [0,0], [w, h] ] ));
|
|
591
569
|
panes.brush.select(".overlay").attr('cursor', null);
|
|
592
570
|
|
|
593
|
-
chart._width =
|
|
594
|
-
chart._height =
|
|
571
|
+
chart._width = w;
|
|
572
|
+
chart._height = h;
|
|
595
573
|
|
|
596
|
-
chart.svg.dispatch('resize', { detail: { width:
|
|
574
|
+
chart.svg.dispatch('resize', { detail: { width: w, height: h } } );
|
|
597
575
|
|
|
598
576
|
};
|
|
599
577
|
|
|
600
|
-
chart.pane = (name) =>
|
|
601
|
-
|
|
602
|
-
panes[name] = g.append('g').attr("class", name);
|
|
603
|
-
}
|
|
604
|
-
return panes[name];
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
chart.get = (name) => utils[name];
|
|
578
|
+
chart.pane = (name) => (panes[name] || (panes[name] = g.append('g').attr("class", name)));
|
|
579
|
+
chart.get = (name) => utils[name];
|
|
608
580
|
|
|
609
581
|
chart._resize({ width, height, margins});
|
|
610
582
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as D3 from './d3.js';
|
|
2
|
+
|
|
3
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
4
|
|
|
5
5
|
export var Marker = L.Class.extend({
|
|
6
6
|
|
|
7
|
-
initialize: function(options) {
|
|
7
|
+
initialize: function(options, control) {
|
|
8
8
|
this.options = options;
|
|
9
|
+
this.control = control
|
|
9
10
|
|
|
10
11
|
switch(this.options.marker) {
|
|
11
12
|
case 'elevation-line':
|
|
@@ -51,14 +52,18 @@ export var Marker = L.Class.extend({
|
|
|
51
52
|
let point = this._map.latLngToLayerPoint(this._latlng);
|
|
52
53
|
point = L.extend({}, props.item, this._map._rotate ? this._map.rotatedPointToMapPanePoint(point) : point);
|
|
53
54
|
|
|
55
|
+
let yMax = (this.control._height() / props.yCoordMax * point[this.options.yAttr]);
|
|
56
|
+
|
|
57
|
+
if(!isFinite(yMax) || isNaN(yMax)) yMax = 0;
|
|
58
|
+
|
|
54
59
|
this._container.classed("leaflet-hidden", false);
|
|
55
60
|
this._container.call(D3.PositionMarker({
|
|
56
61
|
theme : this.options.theme,
|
|
57
62
|
xCoord: point.x,
|
|
58
63
|
yCoord: point.y,
|
|
59
|
-
length: point.y -
|
|
64
|
+
length: point.y - yMax, // normalized Y
|
|
60
65
|
labels: this._labels,
|
|
61
|
-
item: point
|
|
66
|
+
item: point,
|
|
62
67
|
}));
|
|
63
68
|
}
|
|
64
69
|
break;
|
|
@@ -84,14 +89,6 @@ export var Marker = L.Class.extend({
|
|
|
84
89
|
return this._latlng;
|
|
85
90
|
},
|
|
86
91
|
|
|
87
|
-
/**
|
|
88
|
-
* Calculates chart height.
|
|
89
|
-
*/
|
|
90
|
-
_height: function() {
|
|
91
|
-
let opts = this.options;
|
|
92
|
-
return opts.height - opts.margins.top - opts.margins.bottom;
|
|
93
|
-
},
|
|
94
|
-
|
|
95
92
|
_registerTooltip: function(props) {
|
|
96
93
|
this._labels[props.name] = props;
|
|
97
94
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as _ from './utils';
|
|
3
|
-
import * as D3 from './components';
|
|
1
|
+
const _ = L.Control.Elevation.Utils;
|
|
4
2
|
|
|
5
3
|
export var Summary = L.Class.extend({
|
|
6
4
|
initialize: function(opts, control) {
|
|
@@ -30,13 +28,14 @@ export var Summary = L.Class.extend({
|
|
|
30
28
|
.keys(this.labels)
|
|
31
29
|
.sort((a, b) => this.labels[a].order - this.labels[b].order) // TODO: any performance issues?
|
|
32
30
|
.forEach((i)=> {
|
|
33
|
-
|
|
31
|
+
let value = typeof this.labels[i].value !== "function" ? this.labels[i].value : this.labels[i].value(this.control.track_info, this.labels[i].unit || '');
|
|
32
|
+
this.append(i /*+ " order-" + this.labels[i].order*/, L._(this.labels[i].label), value, this.labels[i].order);
|
|
34
33
|
});
|
|
35
34
|
},
|
|
36
35
|
|
|
37
36
|
_registerSummary: function(data) {
|
|
38
37
|
for (let i in data) {
|
|
39
|
-
data[i].order = data[i].order ??
|
|
38
|
+
data[i].order = data[i].order ?? 1000;
|
|
40
39
|
this.labels[i] = data[i];
|
|
41
40
|
}
|
|
42
41
|
}
|