@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.
Files changed (45) hide show
  1. package/README.md +8 -7
  2. package/dist/leaflet-elevation.css +51 -161
  3. package/dist/leaflet-elevation.js +1622 -3767
  4. package/dist/leaflet-elevation.js.map +1 -1
  5. package/dist/leaflet-elevation.min.css +1 -1
  6. package/dist/leaflet-elevation.min.js +1 -3
  7. package/dist/leaflet-elevation.min.js.map +1 -1
  8. package/images/checkered.png +0 -0
  9. package/libs/leaflet-distance-marker.js +17 -18
  10. package/libs/leaflet-distance-marker.min.js +1 -1
  11. package/libs/leaflet-gpxgroup.js +2 -2
  12. package/libs/leaflet-ruler.css +42 -0
  13. package/libs/leaflet-ruler.js +183 -0
  14. package/libs/leaflet-ruler.min.css +1 -0
  15. package/libs/leaflet-ruler.min.js +1 -0
  16. package/package.json +9 -11
  17. package/src/chart.js +156 -143
  18. package/src/components.js +55 -76
  19. package/src/control.js +503 -345
  20. package/src/handlers/acceleration.js +64 -0
  21. package/src/handlers/acceleration.min.js +1 -0
  22. package/src/handlers/altitude.js +76 -0
  23. package/src/handlers/altitude.min.js +1 -0
  24. package/src/handlers/cadence.js +54 -0
  25. package/src/handlers/distance.js +45 -0
  26. package/src/handlers/distance.min.js +1 -0
  27. package/src/handlers/heart.js +53 -0
  28. package/src/handlers/slope.js +79 -0
  29. package/src/handlers/slope.min.js +1 -0
  30. package/src/handlers/speed.js +66 -0
  31. package/src/handlers/speed.min.js +1 -0
  32. package/src/handlers/time.js +103 -0
  33. package/src/handlers/time.min.js +1 -0
  34. package/src/index.css +51 -161
  35. package/src/index.js +0 -24
  36. package/src/marker.js +11 -14
  37. package/src/options.js +20 -28
  38. package/src/summary.js +14 -4
  39. package/src/utils.js +74 -102
  40. package/src/acceleration.js +0 -108
  41. package/src/altitude.js +0 -120
  42. package/src/distance.js +0 -78
  43. package/src/slope.js +0 -113
  44. package/src/speed.js +0 -110
  45. package/src/time.js +0 -124
package/src/components.js CHANGED
@@ -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);
@@ -150,17 +141,21 @@ export const PositionMarker = ({
150
141
 
151
142
  let label;
152
143
 
153
- for (var i in labels) {
154
- label = text.select(".height-focus-" + labels[i].name);
144
+ Object
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);
155
149
 
156
- if (!label.size()) {
157
- label = text.append("svg:tspan")
158
- .attr("class", "height-focus-" + labels[i].name)
159
- .attr("dy", "1.5em");
160
- }
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
+ }
161
155
 
162
- label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
163
- }
156
+ label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
157
+
158
+ });
164
159
 
165
160
  text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
166
161
  text.selectAll('tspan').attr("x", xCoord + 5);
@@ -176,7 +171,8 @@ export const LegendItem = ({
176
171
  height,
177
172
  margins = {},
178
173
  color,
179
- path
174
+ path,
175
+ className = ''
180
176
  }) => {
181
177
  return g => {
182
178
  g
@@ -202,7 +198,8 @@ export const LegendItem = ({
202
198
  .attr("fill", color)
203
199
  .attr("stroke", "#000")
204
200
  .attr("stroke-opacity", "0.5")
205
- .attr("fill-opacity", "0.25");
201
+ .attr("fill-opacity", "0.25")
202
+ .attr("class", className);
206
203
 
207
204
  g.append('svg:text')
208
205
  .text(L._(label || name))
@@ -274,17 +271,20 @@ export const Tooltip = ({
274
271
 
275
272
  let label;
276
273
 
277
- for (let i in labels) {
278
- label = text.select(".mouse-focus-label-" + labels[i].name);
274
+ Object
275
+ .keys(labels)
276
+ .sort((a, b) => labels[a].order - labels[b].order) // TODO: any performance issues?
277
+ .forEach((i)=> {
278
+ label = text.select(".mouse-focus-label-" + labels[i].name);
279
279
 
280
- if (!label.size()) {
281
- label = text.append("svg:tspan", ".mouse-focus-label-x")
282
- .attr("class", "mouse-focus-label-" + labels[i].name)
283
- .attr("dy", "1.5em");
284
- }
280
+ if (!label.size()) {
281
+ label = text.append("svg:tspan", ".mouse-focus-label-x")
282
+ .attr("class", "mouse-focus-label-" + labels[i].name /*+ " " + "order-" + labels[i].order*/)
283
+ .attr("dy", "1.5em");
284
+ }
285
285
 
286
- label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
287
- }
286
+ label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
287
+ });
288
288
 
289
289
  text.select('tspan').attr("dy", "1em");
290
290
  text.selectAll('tspan').attr("x", xAlign);
@@ -437,8 +437,7 @@ export const Domain = ({
437
437
  forceBounds,
438
438
  scale
439
439
  }) => function(data) {
440
- attr = attr || name;
441
- if (scale && scale.attr) attr = scale.attr;
440
+ attr = (scale && scale.attr) || attr || name;
442
441
  let domain = data && data.length ? d3.extent(data, d => d[attr]) : [0, 1];
443
442
  if (typeof min !== "undefined" && (min < domain[0] || forceBounds)) {
444
443
  domain[0] = min;
@@ -487,8 +486,8 @@ export const Chart = ({
487
486
  ruler,
488
487
  }) => {
489
488
 
490
- const _width = width - margins.left - margins.right;
491
- const _height = height - margins.top - margins.bottom;
489
+ const w = width - margins.left - margins.right;
490
+ const h = height - margins.top - margins.bottom;
492
491
 
493
492
  // SVG Container
494
493
  const svg = d3.create("svg:svg").attr("class", "background");
@@ -507,16 +506,16 @@ export const Chart = ({
507
506
  };
508
507
 
509
508
  // SVG Paths
510
- const mask = panes.area.append("svg:mask").attr("id", 'elevation-clipper').attr('fill-opacity', 1);
511
- 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
512
511
 
513
512
  // Canvas Paths
514
- const foreignObject = panes.area.append('svg:foreignObject').attr('mask', 'url(#' + mask.attr('id') + ')');
515
- 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');
516
515
  const context = canvas.node().getContext('2d');
517
516
 
518
517
  // Add tooltip
519
- panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height: _height, width : _width, labels: {} }));
518
+ panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height: h, width : w, labels: {} }));
520
519
 
521
520
  // Add the brushing
522
521
  let brush = d3.brushX().on('start.cursor end.cursor brush.cursor', () => panes.brush.select(".overlay").attr('cursor', null));
@@ -547,57 +546,37 @@ export const Chart = ({
547
546
  ruler,
548
547
  }) => {
549
548
 
550
- const _width = width - margins.left - margins.right;
551
- const _height = height - margins.top - margins.bottom;
552
-
553
- svg.attr("viewBox", `0 0 ${width} ${height}`)
554
- .attr("width", width)
555
- .attr("height", height);
549
+ const w = width - margins.left - margins.right;
550
+ const h = height - margins.top - margins.bottom;
556
551
 
557
- 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 + ")");
558
554
 
559
555
  // Partially fix: https://github.com/Raruto/leaflet-elevation/issues/123
560
556
  if(/Mac|iPod|iPhone|iPad/.test(navigator.platform) && /AppleWebkit/i.test(navigator.userAgent)) {
561
- canvas
562
- .style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
557
+ canvas .style("transform", "translate(" + margins.left + "px," + margins.top + "px)");
563
558
  }
564
559
 
565
- maskRect
566
- .attr("x", 0)
567
- .attr("y", 0)
568
- .attr("width", _width)
569
- .attr("height", _height);
570
-
571
- foreignObject
572
- .attr('width', _width)
573
- .attr('height', _height);
574
-
575
- canvas
576
- .attr('width', _width)
577
- .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);
578
563
 
579
564
  if (ruler) {
580
- panes.ruler.call(Ruler({ height: _height, width: _width }));
565
+ panes.ruler.call(Ruler({ height: h, width: w }));
581
566
  }
582
567
 
583
- panes.brush.call(brush.extent( [ [0,0], [_width, _height] ] ));
568
+ panes.brush.call(brush.extent( [ [0,0], [w, h] ] ));
584
569
  panes.brush.select(".overlay").attr('cursor', null);
585
570
 
586
- chart._width = _width;
587
- chart._height = _height;
571
+ chart._width = w;
572
+ chart._height = h;
588
573
 
589
- chart.svg.dispatch('resize', { detail: { width: _width, height: _height } } );
574
+ chart.svg.dispatch('resize', { detail: { width: w, height: h } } );
590
575
 
591
576
  };
592
577
 
593
- chart.pane = (name) => {
594
- if (!panes[name]) {
595
- panes[name] = g.append('g').attr("class", name);
596
- }
597
- return panes[name];
598
- }
599
-
600
- 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];
601
580
 
602
581
  chart._resize({ width, height, margins});
603
582