@hpcc-js/tree 2.25.0 → 2.31.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/dist/index.es6.js CHANGED
@@ -2,8 +2,8 @@ import { ITree } from '@hpcc-js/api';
2
2
  import { rgb, d3Event, interpolateZoom, SVGWidget, select, SVGZoomWidget, Utility, PropertyExt, Platform, max as max$1, Palette, HTMLWidget, scaleLinear, scaleSqrt, interpolate } from '@hpcc-js/common';
3
3
 
4
4
  var PKG_NAME = "@hpcc-js/tree";
5
- var PKG_VERSION = "2.25.0";
6
- var BUILD_VERSION = "2.76.0";
5
+ var PKG_VERSION = "2.31.0";
6
+ var BUILD_VERSION = "2.88.0";
7
7
 
8
8
  /*! *****************************************************************************
9
9
  Copyright (c) Microsoft Corporation.
@@ -326,83 +326,92 @@ Node.prototype = hierarchy.prototype = {
326
326
  copy: node_copy
327
327
  };
328
328
 
329
- function Node$1(value) {
330
- this._ = value;
331
- this.next = null;
332
- }
329
+ var slice = Array.prototype.slice;
333
330
 
334
331
  function shuffle(array) {
335
- var i,
336
- n = (array = array.slice()).length,
337
- head = null,
338
- node = head;
339
-
340
- while (n) {
341
- var next = new Node$1(array[n - 1]);
342
- if (node) node = node.next = next;
343
- else node = head = next;
344
- array[i] = array[--n];
332
+ var m = array.length,
333
+ t,
334
+ i;
335
+
336
+ while (m) {
337
+ i = Math.random() * m-- | 0;
338
+ t = array[m];
339
+ array[m] = array[i];
340
+ array[i] = t;
345
341
  }
346
342
 
347
- return {
348
- head: head,
349
- tail: node
350
- };
343
+ return array;
351
344
  }
352
345
 
353
346
  function enclose(circles) {
354
- return encloseN(shuffle(circles), []);
355
- }
347
+ var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
348
+
349
+ while (i < n) {
350
+ p = circles[i];
351
+ if (e && enclosesWeak(e, p)) ++i;
352
+ else e = encloseBasis(B = extendBasis(B, p)), i = 0;
353
+ }
356
354
 
357
- function encloses(a, b) {
358
- var dx = b.x - a.x,
359
- dy = b.y - a.y,
360
- dr = a.r - b.r;
361
- return dr * dr + 1e-6 > dx * dx + dy * dy;
355
+ return e;
362
356
  }
363
357
 
364
- // Returns the smallest circle that contains circles L and intersects circles B.
365
- function encloseN(L, B) {
366
- var circle,
367
- l0 = null,
368
- l1 = L.head,
369
- l2,
370
- p1;
358
+ function extendBasis(B, p) {
359
+ var i, j;
371
360
 
372
- switch (B.length) {
373
- case 1: circle = enclose1(B[0]); break;
374
- case 2: circle = enclose2(B[0], B[1]); break;
375
- case 3: circle = enclose3(B[0], B[1], B[2]); break;
361
+ if (enclosesWeakAll(p, B)) return [p];
362
+
363
+ // If we get here then B must have at least one element.
364
+ for (i = 0; i < B.length; ++i) {
365
+ if (enclosesNot(p, B[i])
366
+ && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
367
+ return [B[i], p];
368
+ }
376
369
  }
377
370
 
378
- while (l1) {
379
- p1 = l1._, l2 = l1.next;
380
- if (!circle || !encloses(circle, p1)) {
371
+ // If we get here then B must have at least two elements.
372
+ for (i = 0; i < B.length - 1; ++i) {
373
+ for (j = i + 1; j < B.length; ++j) {
374
+ if (enclosesNot(encloseBasis2(B[i], B[j]), p)
375
+ && enclosesNot(encloseBasis2(B[i], p), B[j])
376
+ && enclosesNot(encloseBasis2(B[j], p), B[i])
377
+ && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
378
+ return [B[i], B[j], p];
379
+ }
380
+ }
381
+ }
381
382
 
382
- // Temporarily truncate L before l1.
383
- if (l0) L.tail = l0, l0.next = null;
384
- else L.head = L.tail = null;
383
+ // If we get here then something is very wrong.
384
+ throw new Error;
385
+ }
385
386
 
386
- B.push(p1);
387
- circle = encloseN(L, B); // Note: reorders L!
388
- B.pop();
387
+ function enclosesNot(a, b) {
388
+ var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
389
+ return dr < 0 || dr * dr < dx * dx + dy * dy;
390
+ }
389
391
 
390
- // Move l1 to the front of L and reconnect the truncated list L.
391
- if (L.head) l1.next = L.head, L.head = l1;
392
- else l1.next = null, L.head = L.tail = l1;
393
- l0 = L.tail, l0.next = l2;
392
+ function enclosesWeak(a, b) {
393
+ var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
394
+ return dr > 0 && dr * dr > dx * dx + dy * dy;
395
+ }
394
396
 
395
- } else {
396
- l0 = l1;
397
+ function enclosesWeakAll(a, B) {
398
+ for (var i = 0; i < B.length; ++i) {
399
+ if (!enclosesWeak(a, B[i])) {
400
+ return false;
397
401
  }
398
- l1 = l2;
399
402
  }
403
+ return true;
404
+ }
400
405
 
401
- L.tail = l0;
402
- return circle;
406
+ function encloseBasis(B) {
407
+ switch (B.length) {
408
+ case 1: return encloseBasis1(B[0]);
409
+ case 2: return encloseBasis2(B[0], B[1]);
410
+ case 3: return encloseBasis3(B[0], B[1], B[2]);
411
+ }
403
412
  }
404
413
 
405
- function enclose1(a) {
414
+ function encloseBasis1(a) {
406
415
  return {
407
416
  x: a.x,
408
417
  y: a.y,
@@ -410,7 +419,7 @@ function enclose1(a) {
410
419
  };
411
420
  }
412
421
 
413
- function enclose2(a, b) {
422
+ function encloseBasis2(a, b) {
414
423
  var x1 = a.x, y1 = a.y, r1 = a.r,
415
424
  x2 = b.x, y2 = b.y, r2 = b.r,
416
425
  x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
@@ -422,70 +431,74 @@ function enclose2(a, b) {
422
431
  };
423
432
  }
424
433
 
425
- function enclose3(a, b, c) {
434
+ function encloseBasis3(a, b, c) {
426
435
  var x1 = a.x, y1 = a.y, r1 = a.r,
427
436
  x2 = b.x, y2 = b.y, r2 = b.r,
428
437
  x3 = c.x, y3 = c.y, r3 = c.r,
429
- a2 = 2 * (x1 - x2),
430
- b2 = 2 * (y1 - y2),
431
- c2 = 2 * (r2 - r1),
432
- d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
433
- a3 = 2 * (x1 - x3),
434
- b3 = 2 * (y1 - y3),
435
- c3 = 2 * (r3 - r1),
436
- d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
438
+ a2 = x1 - x2,
439
+ a3 = x1 - x3,
440
+ b2 = y1 - y2,
441
+ b3 = y1 - y3,
442
+ c2 = r2 - r1,
443
+ c3 = r3 - r1,
444
+ d1 = x1 * x1 + y1 * y1 - r1 * r1,
445
+ d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
446
+ d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
437
447
  ab = a3 * b2 - a2 * b3,
438
- xa = (b2 * d3 - b3 * d2) / ab - x1,
448
+ xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
439
449
  xb = (b3 * c2 - b2 * c3) / ab,
440
- ya = (a3 * d2 - a2 * d3) / ab - y1,
450
+ ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
441
451
  yb = (a2 * c3 - a3 * c2) / ab,
442
452
  A = xb * xb + yb * yb - 1,
443
- B = 2 * (xa * xb + ya * yb + r1),
453
+ B = 2 * (r1 + xa * xb + ya * yb),
444
454
  C = xa * xa + ya * ya - r1 * r1,
445
- r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
455
+ r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
446
456
  return {
447
- x: xa + xb * r + x1,
448
- y: ya + yb * r + y1,
457
+ x: x1 + xa + xb * r,
458
+ y: y1 + ya + yb * r,
449
459
  r: r
450
460
  };
451
461
  }
452
462
 
453
- function place(a, b, c) {
454
- var ax = a.x,
455
- ay = a.y,
456
- da = b.r + c.r,
457
- db = a.r + c.r,
458
- dx = b.x - ax,
459
- dy = b.y - ay,
460
- dc = dx * dx + dy * dy;
461
- if (dc) {
462
- var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
463
- y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
464
- c.x = ax + x * dx + y * dy;
465
- c.y = ay + x * dy - y * dx;
463
+ function place(b, a, c) {
464
+ var dx = b.x - a.x, x, a2,
465
+ dy = b.y - a.y, y, b2,
466
+ d2 = dx * dx + dy * dy;
467
+ if (d2) {
468
+ a2 = a.r + c.r, a2 *= a2;
469
+ b2 = b.r + c.r, b2 *= b2;
470
+ if (a2 > b2) {
471
+ x = (d2 + b2 - a2) / (2 * d2);
472
+ y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
473
+ c.x = b.x - x * dx - y * dy;
474
+ c.y = b.y - x * dy + y * dx;
475
+ } else {
476
+ x = (d2 + a2 - b2) / (2 * d2);
477
+ y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
478
+ c.x = a.x + x * dx - y * dy;
479
+ c.y = a.y + x * dy + y * dx;
480
+ }
466
481
  } else {
467
- c.x = ax + db;
468
- c.y = ay;
482
+ c.x = a.x + c.r;
483
+ c.y = a.y;
469
484
  }
470
485
  }
471
486
 
472
487
  function intersects(a, b) {
473
- var dx = b.x - a.x,
474
- dy = b.y - a.y,
475
- dr = a.r + b.r;
476
- return dr * dr - 1e-6 > dx * dx + dy * dy;
488
+ var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
489
+ return dr > 0 && dr * dr > dx * dx + dy * dy;
477
490
  }
478
491
 
479
- function distance2(node, x, y) {
492
+ function score(node) {
480
493
  var a = node._,
481
494
  b = node.next._,
482
495
  ab = a.r + b.r,
483
- dx = (a.x * b.r + b.x * a.r) / ab - x,
484
- dy = (a.y * b.r + b.y * a.r) / ab - y;
496
+ dx = (a.x * b.r + b.x * a.r) / ab,
497
+ dy = (a.y * b.r + b.y * a.r) / ab;
485
498
  return dx * dx + dy * dy;
486
499
  }
487
500
 
488
- function Node$2(circle) {
501
+ function Node$1(circle) {
489
502
  this._ = circle;
490
503
  this.next = null;
491
504
  this.previous = null;
@@ -494,7 +507,7 @@ function Node$2(circle) {
494
507
  function packEnclose(circles) {
495
508
  if (!(n = circles.length)) return 0;
496
509
 
497
- var a, b, c, n;
510
+ var a, b, c, n, aa, ca, i, j, k, sj, sk;
498
511
 
499
512
  // Place the first circle.
500
513
  a = circles[0], a.x = 0, a.y = 0;
@@ -507,24 +520,15 @@ function packEnclose(circles) {
507
520
  // Place the third circle.
508
521
  place(b, a, c = circles[2]);
509
522
 
510
- // Initialize the weighted centroid.
511
- var aa = a.r * a.r,
512
- ba = b.r * b.r,
513
- ca = c.r * c.r,
514
- oa = aa + ba + ca,
515
- ox = aa * a.x + ba * b.x + ca * c.x,
516
- oy = aa * a.y + ba * b.y + ca * c.y,
517
- cx, cy, i, j, k, sj, sk;
518
-
519
523
  // Initialize the front-chain using the first three circles a, b and c.
520
- a = new Node$2(a), b = new Node$2(b), c = new Node$2(c);
524
+ a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
521
525
  a.next = c.previous = b;
522
526
  b.next = a.previous = c;
523
527
  c.next = b.previous = a;
524
528
 
525
529
  // Attempt to place each remaining circle…
526
530
  pack: for (i = 3; i < n; ++i) {
527
- place(a._, b._, c = circles[i]), c = new Node$2(c);
531
+ place(a._, b._, c = circles[i]), c = new Node$1(c);
528
532
 
529
533
  // Find the closest intersecting circle on the front-chain, if any.
530
534
  // “Closeness” is determined by linear distance along the front-chain.
@@ -549,15 +553,10 @@ function packEnclose(circles) {
549
553
  // Success! Insert the new circle c between a and b.
550
554
  c.previous = a, c.next = b, a.next = b.previous = b = c;
551
555
 
552
- // Update the weighted centroid.
553
- oa += ca = c._.r * c._.r;
554
- ox += ca * c._.x;
555
- oy += ca * c._.y;
556
-
557
556
  // Compute the new closest circle pair to the centroid.
558
- aa = distance2(a, cx = ox / oa, cy = oy / oa);
557
+ aa = score(a);
559
558
  while ((c = c.next) !== b) {
560
- if ((ca = distance2(c, cx, cy)) < aa) {
559
+ if ((ca = score(c)) < aa) {
561
560
  a = c, aa = ca;
562
561
  }
563
562
  }
@@ -2117,7 +2116,7 @@ Path.prototype = path.prototype = {
2117
2116
  }
2118
2117
  },
2119
2118
  arc: function(x, y, r, a0, a1, ccw) {
2120
- x = +x, y = +y, r = +r;
2119
+ x = +x, y = +y, r = +r, ccw = !!ccw;
2121
2120
  var dx = r * Math.cos(a0),
2122
2121
  dy = r * Math.sin(a0),
2123
2122
  x0 = x + dx,
@@ -2212,7 +2211,9 @@ function arcPadAngle(d) {
2212
2211
  function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
2213
2212
  var x10 = x1 - x0, y10 = y1 - y0,
2214
2213
  x32 = x3 - x2, y32 = y3 - y2,
2215
- t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
2214
+ t = y32 * x10 - x32 * y10;
2215
+ if (t * t < epsilon$1) return;
2216
+ t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
2216
2217
  return [x0 + t * x10, y0 + t * y10];
2217
2218
  }
2218
2219
 
@@ -2333,12 +2334,12 @@ function d3Arc() {
2333
2334
  var x11 = r1 * cos(a11),
2334
2335
  y11 = r1 * sin(a11),
2335
2336
  x00 = r0 * cos(a00),
2336
- y00 = r0 * sin(a00);
2337
+ y00 = r0 * sin(a00),
2338
+ oc;
2337
2339
 
2338
2340
  // Restrict the corner radius according to the sector angle.
2339
- if (da < pi$1) {
2340
- var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
2341
- ax = x01 - oc[0],
2341
+ if (da < pi$1 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
2342
+ var ax = x01 - oc[0],
2342
2343
  ay = y01 - oc[1],
2343
2344
  bx = x11 - oc[0],
2344
2345
  by = y11 - oc[1],
@@ -2445,103 +2446,6 @@ function d3Arc() {
2445
2446
  return arc;
2446
2447
  }
2447
2448
 
2448
- function sign(x) {
2449
- return x < 0 ? -1 : 1;
2450
- }
2451
-
2452
- // Calculate the slopes of the tangents (Hermite-type interpolation) based on
2453
- // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
2454
- // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
2455
- // NOV(II), P. 443, 1990.
2456
- function slope3(that, x2, y2) {
2457
- var h0 = that._x1 - that._x0,
2458
- h1 = x2 - that._x1,
2459
- s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
2460
- s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
2461
- p = (s0 * h1 + s1 * h0) / (h0 + h1);
2462
- return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
2463
- }
2464
-
2465
- // Calculate a one-sided slope.
2466
- function slope2(that, t) {
2467
- var h = that._x1 - that._x0;
2468
- return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
2469
- }
2470
-
2471
- // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
2472
- // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
2473
- // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
2474
- function point(that, t0, t1) {
2475
- var x0 = that._x0,
2476
- y0 = that._y0,
2477
- x1 = that._x1,
2478
- y1 = that._y1,
2479
- dx = (x1 - x0) / 3;
2480
- that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
2481
- }
2482
-
2483
- function MonotoneX(context) {
2484
- this._context = context;
2485
- }
2486
-
2487
- MonotoneX.prototype = {
2488
- areaStart: function() {
2489
- this._line = 0;
2490
- },
2491
- areaEnd: function() {
2492
- this._line = NaN;
2493
- },
2494
- lineStart: function() {
2495
- this._x0 = this._x1 =
2496
- this._y0 = this._y1 =
2497
- this._t0 = NaN;
2498
- this._point = 0;
2499
- },
2500
- lineEnd: function() {
2501
- switch (this._point) {
2502
- case 2: this._context.lineTo(this._x1, this._y1); break;
2503
- case 3: point(this, this._t0, slope2(this, this._t0)); break;
2504
- }
2505
- if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
2506
- this._line = 1 - this._line;
2507
- },
2508
- point: function(x, y) {
2509
- var t1 = NaN;
2510
-
2511
- x = +x, y = +y;
2512
- if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
2513
- switch (this._point) {
2514
- case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
2515
- case 1: this._point = 2; break;
2516
- case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
2517
- default: point(this, this._t0, t1 = slope3(this, x, y)); break;
2518
- }
2519
-
2520
- this._x0 = this._x1, this._x1 = x;
2521
- this._y0 = this._y1, this._y1 = y;
2522
- this._t0 = t1;
2523
- }
2524
- };
2525
-
2526
- function MonotoneY(context) {
2527
- this._context = new ReflectContext(context);
2528
- }
2529
-
2530
- (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
2531
- MonotoneX.prototype.point.call(this, y, x);
2532
- };
2533
-
2534
- function ReflectContext(context) {
2535
- this._context = context;
2536
- }
2537
-
2538
- ReflectContext.prototype = {
2539
- moveTo: function(x, y) { this._context.moveTo(y, x); },
2540
- closePath: function() { this._context.closePath(); },
2541
- lineTo: function(x, y) { this._context.lineTo(y, x); },
2542
- bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
2543
- };
2544
-
2545
2449
  var css_248z$3 = ".tree_Sunburst path{stroke:#fff;stroke-width:.5px;fill-rule:evenodd}";
2546
2450
  styleInject(css_248z$3);
2547
2451