@raruto/leaflet-elevation 1.9.6 → 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/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);
@@ -151,20 +142,20 @@ export const PositionMarker = ({
151
142
  let label;
152
143
 
153
144
  Object
154
- .keys(labels)
155
- .sort((a, b) => labels[a].order - labels[b].order) // TODO: any performance issues?
156
- .forEach((i)=> {
157
- label = text.select(".height-focus-" + labels[i].name);
158
-
159
- if (!label.size()) {
160
- label = text.append("svg:tspan")
161
- .attr("class", "height-focus-" + labels[i].name)
162
- .attr("dy", "1.5em");
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
- label.text(typeof labels[i].value !== "function" ? labels[i].value : labels[i].value(item));
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 _width = width - margins.left - margins.right;
498
- const _height = height - margins.top - margins.bottom;
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: _height, width : _width, labels: {} }));
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 _width = width - margins.left - margins.right;
558
- const _height = height - margins.top - margins.bottom;
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
- .attr("width", width)
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
- .attr("x", 0)
574
- .attr("y", 0)
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: _height, width: _width }));
565
+ panes.ruler.call(Ruler({ height: h, width: w }));
588
566
  }
589
567
 
590
- panes.brush.call(brush.extent( [ [0,0], [_width, _height] ] ));
568
+ panes.brush.call(brush.extent( [ [0,0], [w, h] ] ));
591
569
  panes.brush.select(".overlay").attr('cursor', null);
592
570
 
593
- chart._width = _width;
594
- chart._height = _height;
571
+ chart._width = w;
572
+ chart._height = h;
595
573
 
596
- chart.svg.dispatch('resize', { detail: { width: _width, height: _height } } );
574
+ chart.svg.dispatch('resize', { detail: { width: w, height: h } } );
597
575
 
598
576
  };
599
577
 
600
- chart.pane = (name) => {
601
- if (!panes[name]) {
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