@raruto/leaflet-elevation 1.7.6 → 1.8.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
@@ -106,33 +106,45 @@ export const Grid = (props) => {
106
106
  return Axis(props);
107
107
  };
108
108
 
109
- export const HeightFocusLine = ({
109
+ export const PositionMarker = ({
110
110
  theme,
111
111
  xCoord = 0,
112
112
  yCoord = 0,
113
+ labels = {},
114
+ item = {},
113
115
  length = 0,
114
116
  }) => {
115
- return line => line
116
- .attr("class", theme + " height-focus line")
117
- .attr("x1", xCoord)
118
- .attr("x2", xCoord)
119
- .attr("y1", yCoord)
120
- .attr("y2", length);
121
- };
117
+ return g => {
118
+
119
+ let line = g.select('.height-focus.line');
120
+ let circle = g.select('.height-focus.circle-lower');
121
+ let text = g.select('.height-focus-label');
122
+
123
+ if (!line.node()) line = g.append('svg:line');
124
+ if (!circle.node()) circle = g.append('svg:circle');
125
+ if (!text.node()) text = g.append('svg:text');
126
+
127
+ if (isNaN(xCoord) || isNaN(yCoord)) return g;
128
+
129
+ circle
130
+ .attr("class", theme + " height-focus circle-lower")
131
+ .attr("transform", "translate(" + xCoord + "," + yCoord + ")")
132
+ .attr("r", 6)
133
+ .attr("cx", 0)
134
+ .attr("cy", 0);
135
+
136
+ line
137
+ .attr("class", theme + " height-focus line")
138
+ .attr("x1", xCoord)
139
+ .attr("x2", xCoord)
140
+ .attr("y1", yCoord)
141
+ .attr("y2", length);
122
142
 
123
- export const HeightFocusLabel = ({
124
- theme,
125
- xCoord = 0,
126
- yCoord = 0,
127
- labels = {},
128
- item = {}
129
- }) => {
130
- return text => {
131
143
  text
132
144
  .attr("class", theme + " height-focus-label")
133
145
  .style("pointer-events", "none")
134
146
  .attr("x", xCoord + 5)
135
- .attr("y", yCoord);
147
+ .attr("y", length);
136
148
 
137
149
  let label;
138
150
 
@@ -151,21 +163,8 @@ export const HeightFocusLabel = ({
151
163
  text.select('tspan').attr("dy", text.selectAll('tspan').size() > 1 ? "-1.5em" : "0em" );
152
164
  text.selectAll('tspan').attr("x", xCoord + 5);
153
165
 
154
- return text;
155
- };
156
- };
157
-
158
- export const HeightFocusMarker = ({
159
- theme,
160
- xCoord = 0,
161
- yCoord = 0,
162
- }) => {
163
- return circle => circle
164
- .attr("class", theme + " height-focus circle-lower")
165
- .attr("transform", "translate(" + xCoord + "," + yCoord + ")")
166
- .attr("r", 6)
167
- .attr("cx", 0)
168
- .attr("cy", 0);
166
+ return g;
167
+ }
169
168
  };
170
169
 
171
170
  export const LegendItem = ({
@@ -182,16 +181,16 @@ export const LegendItem = ({
182
181
  .attr("class", "legend-item legend-" + name.toLowerCase())
183
182
  .attr("data-name", name);
184
183
 
185
- const svg = d3.select(g.node().ownerSVGElement || g);
186
-
187
- g.on('click.legend', () => svg.dispatch("legend_clicked", {
188
- detail: {
189
- path: path.node(),
190
- name: name,
191
- legend: g.node(),
192
- enabled: !path.classed('leaflet-hidden'),
193
- }
194
- }));
184
+ g.on('click.legend', () => d3.select(g.node().ownerSVGElement || g)
185
+ .dispatch("legend_clicked", {
186
+ detail: {
187
+ path: path.node(),
188
+ name: name,
189
+ legend: g.node(),
190
+ enabled: !path.classed('leaflet-hidden'),
191
+ }
192
+ })
193
+ );
195
194
 
196
195
  g.append("svg:rect")
197
196
  .attr("x", (width / 2) - 50)
@@ -216,34 +215,27 @@ export const LegendItem = ({
216
215
  }
217
216
  };
218
217
 
219
- export const MouseFocusLine = ({
220
- xCoord = 0,
221
- height,
222
- }) => {
223
- return line => line
224
- .attr('class', 'mouse-focus-line')
225
- .attr('x2', xCoord)
226
- .attr('y2', 0)
227
- .attr('x1', xCoord)
228
- .attr('y1', height);
229
- };
230
-
231
- export const MouseFocusLabel = ({
218
+ export const Tooltip = ({
232
219
  xCoord,
233
220
  yCoord,
234
221
  width,
222
+ height,
235
223
  labels = {},
236
224
  item = {},
237
225
  }) => {
238
226
  return g => {
239
227
 
240
- g.attr('class', 'mouse-focus-label');
228
+ let line = g.select('.mouse-focus-line');
229
+ let box = g.select('.mouse-focus-label');
241
230
 
242
- let rect = g.select(".mouse-focus-label-rect");
243
- let text = g.select(".mouse-focus-label-text");
231
+ if (!line.node()) line = g.append('svg:line');
232
+ if (!box.node()) box = g.append("g");
244
233
 
245
- if (!rect.node()) rect = g.append("svg:rect");
246
- if (!text.node()) text = g.append("svg:text");
234
+ let rect = box.select(".mouse-focus-label-rect");
235
+ let text = box.select(".mouse-focus-label-text");
236
+
237
+ if (!rect.node()) rect = box.append("svg:rect");
238
+ if (!text.node()) text = box.append("svg:text");
247
239
 
248
240
  // Sets focus-label-text position to the left / right of the mouse-focus-line
249
241
  let xAlign = 0;
@@ -254,6 +246,16 @@ export const MouseFocusLabel = ({
254
246
  if (xCoord) xAlign = xCoord + (xCoord < width / 2 ? 10 : -bbox.width - 10);
255
247
  if (yCoord) yAlign = Math.max(yCoord - bbox.height, L.Browser.webkit ? 0 : -Infinity);
256
248
 
249
+ line
250
+ .attr('class', 'mouse-focus-line')
251
+ .attr('x2', xCoord)
252
+ .attr('y2', 0)
253
+ .attr('x1', xCoord)
254
+ .attr('y1', height);
255
+
256
+ box
257
+ .attr('class', 'mouse-focus-label');
258
+
257
259
  rect
258
260
  .attr("class", "mouse-focus-label-rect")
259
261
  .attr("x", xAlign - 5)
@@ -262,6 +264,7 @@ export const MouseFocusLabel = ({
262
264
  .attr("height", bbox.height + 10)
263
265
  .attr("rx", 3)
264
266
  .attr("ry", 3);
267
+
265
268
  text
266
269
  .attr("class", "mouse-focus-label-text")
267
270
  .style("font-weight", "700")
@@ -269,7 +272,7 @@ export const MouseFocusLabel = ({
269
272
 
270
273
  let label;
271
274
 
272
- for (var i in labels) {
275
+ for (let i in labels) {
273
276
  label = text.select(".mouse-focus-label-" + labels[i].name);
274
277
 
275
278
  if (!label.size()) {
@@ -365,6 +368,65 @@ export const Ruler = ({
365
368
  }
366
369
  };
367
370
 
371
+ export const CheckPoint = ({
372
+ point,
373
+ height,
374
+ width,
375
+ x,
376
+ y
377
+ }) => {
378
+ return g => {
379
+
380
+ if (isNaN(x) || isNaN(y)) return g;
381
+
382
+ if (!point.item || !point.item.property('isConnected')) {
383
+ point.position = point.position || "bottom";
384
+
385
+ point.item = g.append('g');
386
+
387
+ point.item.append("svg:line")
388
+ .attr("y1", 0)
389
+ .attr("x1", 0)
390
+ .attr("style","stroke: rgb(51, 51, 51); stroke-width: 0.5; stroke-dasharray: 2, 2;");
391
+
392
+ point.item
393
+ .append("svg:circle")
394
+ .attr("class", " height-focus circle-lower")
395
+ .attr("r", 3);
396
+
397
+ if (point.label) {
398
+ point.item.append("svg:text")
399
+ .attr("dx", "4px")
400
+ .attr("dy", "-4px");
401
+ }
402
+ }
403
+
404
+ point.item
405
+ .datum({
406
+ pos: point.position,
407
+ x: x,
408
+ y: y
409
+ })
410
+ .attr("class", d => "point " + d.pos)
411
+ .attr("transform", d => "translate(" + d.x + "," + d.y + ")");
412
+
413
+ point.item.select('line')
414
+ .datum({
415
+ y2: ({'top': -y, 'bottom': height - y})[point.position],
416
+ x2: ({'left': -x, 'right': width - x})[point.position] || 0
417
+ })
418
+ .attr("y2", d => d.y2)
419
+ .attr("x2", d => d.x2)
420
+
421
+ if (point.label) {
422
+ point.item.select('text')
423
+ .text(point.label);
424
+ }
425
+
426
+ return g;
427
+ }
428
+ };
429
+
368
430
  export const Domain = ({
369
431
  min,
370
432
  max,
@@ -451,45 +513,19 @@ export const Chart = ({
451
513
  const canvas = foreignObject.append('xhtml:canvas').attr('class', 'canvas-plot');
452
514
  const context = canvas.node().getContext('2d');
453
515
 
454
- // Mouse Focus
455
- const dragG = panes.ruler;
456
- const focusG = panes.tooltip;
457
- const brushG = panes.brush;
458
-
459
- focusG.append('svg:line')
460
- .call(
461
- MouseFocusLine({
462
- xCoord: 0,
463
- height: _height
464
- })
465
- );
466
-
467
- focusG.append("g")
468
- .call(
469
- MouseFocusLabel({
470
- xCoord: 0,
471
- yCoord: 0,
472
- height: _height,
473
- width : _width,
474
- labels: {}
475
- // labelX: "",
476
- // labelY: "",
477
- })
478
- );
479
-
516
+ // Add tooltip
517
+ panes.tooltip.call(Tooltip({ xCoord: 0, yCoord: 0, height: _height, width : _width, labels: {} }));
480
518
 
481
519
  // Add the brushing
482
- let brush = d3.brushX().on('start.cursor end.cursor brush.cursor', () => brushG.select(".overlay").attr('cursor', null));
520
+ let brush = d3.brushX().on('start.cursor end.cursor brush.cursor', () => panes.brush.select(".overlay").attr('cursor', null));
483
521
 
484
522
  // Scales
485
- const scale = (opts) => ({ x: Scale(opts.x), y: Scale(opts.y)});
523
+ const scale = (opts) => ({ x: Scale(opts.x), y: Scale(opts.y)});
486
524
 
487
525
  let utils = {
488
526
  clipPath,
489
527
  canvas,
490
528
  context,
491
- dragG,
492
- focusG,
493
529
  brush,
494
530
  };
495
531
 
@@ -539,11 +575,11 @@ export const Chart = ({
539
575
  .attr('height', _height);
540
576
 
541
577
  if (ruler) {
542
- dragG .call(Ruler({ height: _height, width: _width }));
578
+ panes.ruler.call(Ruler({ height: _height, width: _width }));
543
579
  }
544
580
 
545
- brushG.call(brush.extent( [ [0,0], [_width, _height] ] ));
546
- brushG.select(".overlay").attr('cursor', null);
581
+ panes.brush.call(brush.extent( [ [0,0], [_width, _height] ] ));
582
+ panes.brush.select(".overlay").attr('cursor', null);
547
583
 
548
584
  chart._width = _width;
549
585
  chart._height = _height;