ooxml-core 0.21.2 → 0.22.1

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 (85) hide show
  1. package/README.md +3 -4
  2. package/dist/automation/index.cjs +86 -22
  3. package/dist/automation/index.mjs +86 -22
  4. package/dist/chart/index.cjs +242 -0
  5. package/dist/chart/index.d.ts +5 -0
  6. package/dist/chart/index.d.ts.map +1 -1
  7. package/dist/chart/index.mjs +227 -1
  8. package/dist/chart/pie-best-fit.d.ts +51 -0
  9. package/dist/chart/pie-best-fit.d.ts.map +1 -0
  10. package/dist/chart/pie-label-collision.d.ts +48 -0
  11. package/dist/chart/pie-label-collision.d.ts.map +1 -0
  12. package/dist/chart/radar-geometry.d.ts +19 -0
  13. package/dist/chart/radar-geometry.d.ts.map +1 -0
  14. package/dist/chart/treemap-squarify.d.ts +31 -0
  15. package/dist/chart/treemap-squarify.d.ts.map +1 -0
  16. package/dist/chart/trendline-equation.d.ts +39 -0
  17. package/dist/chart/trendline-equation.d.ts.map +1 -0
  18. package/dist/collab/index.cjs +6 -1
  19. package/dist/collab/index.mjs +6 -1
  20. package/dist/color/contrast.d.ts +18 -0
  21. package/dist/color/contrast.d.ts.map +1 -0
  22. package/dist/color/index.cjs +33 -0
  23. package/dist/color/index.d.ts +2 -0
  24. package/dist/color/index.d.ts.map +1 -1
  25. package/dist/color/index.mjs +31 -1
  26. package/dist/color/unit-rgb.d.ts +21 -0
  27. package/dist/color/unit-rgb.d.ts.map +1 -0
  28. package/dist/docx/embedded.cjs +1 -1
  29. package/dist/docx/embedded.mjs +1 -1
  30. package/dist/docx/index.cjs +1 -1
  31. package/dist/docx/index.mjs +1 -1
  32. package/dist/docx/load/index.cjs +1 -1
  33. package/dist/docx/load/index.mjs +1 -1
  34. package/dist/geometry/align-distribute.d.ts +145 -0
  35. package/dist/geometry/align-distribute.d.ts.map +1 -0
  36. package/dist/geometry/index.cjs +318 -0
  37. package/dist/geometry/index.d.ts +2 -0
  38. package/dist/geometry/index.d.ts.map +1 -1
  39. package/dist/geometry/index.mjs +307 -1
  40. package/dist/geometry/snap-guides.d.ts +125 -0
  41. package/dist/geometry/snap-guides.d.ts.map +1 -0
  42. package/dist/index.cjs +665 -0
  43. package/dist/index.mjs +665 -0
  44. package/dist/pptx/automation/index.cjs +24 -1
  45. package/dist/pptx/automation/index.d.ts +3 -3
  46. package/dist/pptx/automation/index.mjs +24 -1
  47. package/dist/pptx/chunks/{index-JaNVJ6Tf.d.ts → index-D2y7ehZ5.d.ts} +3 -3
  48. package/dist/pptx/chunks/{index-JaNVJ6Tf.d.ts.map → index-D2y7ehZ5.d.ts.map} +1 -1
  49. package/dist/pptx/chunks/{index-DHdHU9Qr.d.ts → index-ucqKcqvI.d.ts} +10 -2
  50. package/dist/pptx/chunks/{index-DHdHU9Qr.d.ts.map → index-ucqKcqvI.d.ts.map} +1 -1
  51. package/dist/pptx/chunks/{text-operations-DUEhSW5Z.d.ts → text-operations-CR3pUJi-.d.ts} +14 -2
  52. package/dist/pptx/chunks/text-operations-CR3pUJi-.d.ts.map +1 -0
  53. package/dist/pptx/cli/index.cjs +23 -0
  54. package/dist/pptx/cli/index.d.ts +1 -1
  55. package/dist/pptx/cli/index.mjs +23 -0
  56. package/dist/pptx/converter/index.d.ts +1 -1
  57. package/dist/pptx/index.cjs +33 -3
  58. package/dist/pptx/index.d.ts +3 -3
  59. package/dist/pptx/index.mjs +33 -3
  60. package/dist/teams/index.cjs +7 -2
  61. package/dist/teams/index.mjs +7 -2
  62. package/dist/text/decimal-tab.d.ts +24 -0
  63. package/dist/text/decimal-tab.d.ts.map +1 -0
  64. package/dist/text/index.cjs +72 -0
  65. package/dist/text/index.d.ts +2 -0
  66. package/dist/text/index.d.ts.map +1 -1
  67. package/dist/text/index.mjs +68 -1
  68. package/dist/text/tab-leader.d.ts +36 -0
  69. package/dist/text/tab-leader.d.ts.map +1 -0
  70. package/dist/xlsx/edit/charts.d.ts.map +1 -1
  71. package/dist/xlsx/edit/clipboard-html-parse.d.ts.map +1 -1
  72. package/dist/xlsx/edit/fill-series.d.ts.map +1 -1
  73. package/dist/xlsx/index.cjs +85 -21
  74. package/dist/xlsx/index.mjs +85 -21
  75. package/dist/xlsx/load/csv.d.ts.map +1 -1
  76. package/dist/xlsx/load/index.cjs +17 -8
  77. package/dist/xlsx/load/index.mjs +17 -8
  78. package/dist/xlsx/numfmt/input-date.d.ts.map +1 -1
  79. package/dist/xlsx/ui/grid/cell-paint.d.ts.map +1 -1
  80. package/dist/xlsx/ui/index.cjs +86 -25
  81. package/dist/xlsx/ui/index.mjs +86 -25
  82. package/dist/xlsx/ui/selection.d.ts.map +1 -1
  83. package/dist/xlsx/write/drawing.d.ts.map +1 -1
  84. package/package.json +2 -2
  85. package/dist/pptx/chunks/text-operations-DUEhSW5Z.d.ts.map +0 -1
@@ -380,17 +380,259 @@ function aggregateByCategory(values, rawCategories) {
380
380
  });
381
381
  }
382
382
 
383
+ // chart/treemap-squarify.ts
384
+ function worstAspectRatio(areas, side) {
385
+ const sum = areas.reduce((total, area) => total + area, 0);
386
+ const max = Math.max(...areas);
387
+ const min = Math.min(...areas);
388
+ const sideSq = side * side;
389
+ const sumSq = sum * sum;
390
+ return Math.max(sideSq * max / sumSq, sumSq / (sideSq * min));
391
+ }
392
+ function squarify(nodes, box) {
393
+ const sorted = [...nodes].sort((a, b) => b.weight - a.weight);
394
+ const total = sorted.reduce((sum, node) => sum + node.weight, 0);
395
+ const scale = total > 0 ? box.w * box.h / total : box.w * box.h / sorted.length;
396
+ const items = sorted.map((node) => ({ node, area: (total > 0 ? node.weight : 1) * scale }));
397
+ const result = [];
398
+ let rect = { ...box };
399
+ let remaining = items;
400
+ for (let first = remaining[0]; first !== void 0; first = remaining[0]) {
401
+ const side = Math.min(rect.w, rect.h);
402
+ let row = [first];
403
+ let rowAreas = [first.area];
404
+ let worst = worstAspectRatio(rowAreas, side);
405
+ let cursor = 1;
406
+ for (let next = remaining[cursor]; next !== void 0; next = remaining[cursor]) {
407
+ const candidateAreas = [...rowAreas, next.area];
408
+ const candidateWorst = worstAspectRatio(candidateAreas, side);
409
+ if (candidateWorst > worst) {
410
+ break;
411
+ }
412
+ row = [...row, next];
413
+ rowAreas = candidateAreas;
414
+ worst = candidateWorst;
415
+ cursor++;
416
+ }
417
+ const rowTotalArea = rowAreas.reduce((sum, area) => sum + area, 0);
418
+ const thickness = side > 0 ? rowTotalArea / side : 0;
419
+ const layoutVertically = rect.w >= rect.h;
420
+ let offset = layoutVertically ? rect.y : rect.x;
421
+ for (const item of row) {
422
+ const length = thickness > 0 ? item.area / thickness : 0;
423
+ if (layoutVertically) {
424
+ result.push([item.node, { x: rect.x, y: offset, w: thickness, h: length }]);
425
+ } else {
426
+ result.push([item.node, { x: offset, y: rect.y, w: length, h: thickness }]);
427
+ }
428
+ offset += length;
429
+ }
430
+ rect = layoutVertically ? { ...rect, x: rect.x + thickness, w: rect.w - thickness } : { ...rect, y: rect.y + thickness, h: rect.h - thickness };
431
+ remaining = remaining.slice(row.length);
432
+ }
433
+ return result;
434
+ }
435
+
436
+ // chart/trendline-equation.ts
437
+ var SIGNIFICANT_DIGITS = 4;
438
+ function formatTrendlineCoefficient(value) {
439
+ if (!Number.isFinite(value) || value === 0) {
440
+ return "0";
441
+ }
442
+ const rounded = Number(value.toPrecision(SIGNIFICANT_DIGITS));
443
+ return rounded === 0 ? "0" : String(rounded);
444
+ }
445
+ function signedTerm(value) {
446
+ return { sign: value < 0 ? "-" : "+", abs: formatTrendlineCoefficient(Math.abs(value)) };
447
+ }
448
+ function formatLinearEquation(slope, intercept) {
449
+ const { sign, abs } = signedTerm(intercept);
450
+ return `y = ${formatTrendlineCoefficient(slope)}x ${sign} ${abs}`;
451
+ }
452
+ function formatExponentialEquation(a, b) {
453
+ return `y = ${formatTrendlineCoefficient(a)} e^(${formatTrendlineCoefficient(b)}x)`;
454
+ }
455
+ function formatLogarithmicEquation(slope, intercept) {
456
+ const { sign, abs } = signedTerm(intercept);
457
+ return `y = ${formatTrendlineCoefficient(slope)}ln(x) ${sign} ${abs}`;
458
+ }
459
+ function formatPowerEquation(a, b) {
460
+ return `y = ${formatTrendlineCoefficient(a)}x^${formatTrendlineCoefficient(b)}`;
461
+ }
462
+ function formatPolynomialEquation(coeffsAscending) {
463
+ const order = coeffsAscending.length - 1;
464
+ let out = "y = ";
465
+ for (let power = order; power >= 0; power--) {
466
+ const coeff = coeffsAscending[power] ?? 0;
467
+ const { sign, abs } = signedTerm(coeff);
468
+ const variable = power === 0 ? "" : power === 1 ? "x" : `x^${power}`;
469
+ out += power === order ? `${sign === "-" ? "-" : ""}${abs}${variable}` : ` ${sign} ${abs}${variable}`;
470
+ }
471
+ return out;
472
+ }
473
+
474
+ // chart/radar-geometry.ts
475
+ function radarAngle(index, catCount) {
476
+ const n = Math.max(catCount, 1);
477
+ return Math.PI * 2 * index / n - Math.PI / 2;
478
+ }
479
+ function computeRadarPoints(values, maxVal, radius, cx, cy, catCount) {
480
+ const denom = maxVal > 0 ? maxVal : 1;
481
+ return values.slice(0, Math.max(catCount, 1)).map((val, i) => {
482
+ const angle = radarAngle(i, catCount), r = Math.abs(val) / denom * radius;
483
+ return { x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) };
484
+ });
485
+ }
486
+ function radarRingPoints(cx, cy, rr, catCount) {
487
+ const n = Math.max(catCount, 1);
488
+ return Array.from({ length: n }, (_, i) => {
489
+ const angle = radarAngle(i, n);
490
+ return `${(cx + rr * Math.cos(angle)).toFixed(2)},${(cy + rr * Math.sin(angle)).toFixed(2)}`;
491
+ }).join(" ");
492
+ }
493
+
494
+ // chart/pie-best-fit.ts
495
+ var PX_PER_PT = 4 / 3;
496
+ var BEST_FIT_RIM_INSET = 4 * PX_PER_PT;
497
+ var BEST_FIT_EDGE_TOLERANCE = 1.5 * PX_PER_PT;
498
+ var BEST_FIT_OUTSIDE_GAP = 2 * PX_PER_PT;
499
+ function farCorner(x, y, w, h) {
500
+ return Math.hypot(Math.abs(x) + w / 2, Math.abs(y) + h / 2);
501
+ }
502
+ function insideDistance(ux, uy, w, h, limit) {
503
+ if (farCorner(0, 0, w, h) > limit) {
504
+ return void 0;
505
+ }
506
+ let lo = 0;
507
+ let hi = limit;
508
+ for (let i = 0; i < 40; i++) {
509
+ const mid = (lo + hi) / 2;
510
+ if (farCorner(mid * ux, mid * uy, w, h) > limit) {
511
+ hi = mid;
512
+ } else {
513
+ lo = mid;
514
+ }
515
+ }
516
+ return lo;
517
+ }
518
+ function edgeOverhang(x, y, w, h, slice) {
519
+ let worst = Number.NEGATIVE_INFINITY;
520
+ const corners = [
521
+ [-w / 2, -h / 2],
522
+ [w / 2, -h / 2],
523
+ [-w / 2, h / 2],
524
+ [w / 2, h / 2]
525
+ ];
526
+ for (const [dx, dy] of corners) {
527
+ const px = x + dx;
528
+ const py = y + dy;
529
+ const fromStart = Math.cos(slice.startAngle) * py - Math.sin(slice.startAngle) * px;
530
+ const fromEnd = Math.sin(slice.endAngle) * px - Math.cos(slice.endAngle) * py;
531
+ worst = Math.max(worst, -fromStart, -fromEnd);
532
+ }
533
+ return worst;
534
+ }
535
+ function placeBestFitLabel(slice, w, h) {
536
+ const mid = (slice.startAngle + slice.endAngle) / 2;
537
+ const ux = Math.cos(mid);
538
+ const uy = Math.sin(mid);
539
+ const distance = insideDistance(ux, uy, w, h, slice.outerR - BEST_FIT_RIM_INSET);
540
+ if (distance !== void 0) {
541
+ const x = distance * ux;
542
+ const y = distance * uy;
543
+ const reflex = slice.endAngle - slice.startAngle >= Math.PI;
544
+ if (reflex || edgeOverhang(x, y, w, h, slice) <= BEST_FIT_EDGE_TOLERANCE) {
545
+ return { x: slice.cx + x, y: slice.cy + y, inside: true };
546
+ }
547
+ }
548
+ const extent = Math.abs(ux) * w / 2 + Math.abs(uy) * h / 2;
549
+ const outside = slice.outerR + BEST_FIT_OUTSIDE_GAP + extent;
550
+ return { x: slice.cx + outside * ux, y: slice.cy + outside * uy, inside: false };
551
+ }
552
+
553
+ // chart/pie-label-collision.ts
554
+ var LABEL_COLLISION_GAP = 2;
555
+ function boxDistanceToCentre(box, y, disc) {
556
+ const nearestX = Math.max(box.x - box.w / 2, Math.min(disc.cx, box.x + box.w / 2));
557
+ const nearestY = Math.max(y - box.h / 2, Math.min(disc.cy, y + box.h / 2));
558
+ return Math.hypot(nearestX - disc.cx, nearestY - disc.cy);
559
+ }
560
+ function clearOfDisc(box, y, disc) {
561
+ if (boxDistanceToCentre(box, y, disc) >= disc.r) {
562
+ return 0;
563
+ }
564
+ const sign = box.x >= disc.cx ? 1 : -1;
565
+ let dx = 0;
566
+ while (dx < disc.r * 2 && boxDistanceToCentre({ ...box, x: box.x + sign * dx }, y, disc) < disc.r) {
567
+ dx += 1;
568
+ }
569
+ return sign * dx;
570
+ }
571
+ function overlapsX(a, b) {
572
+ return Math.abs(a.x - b.x) < (a.w + b.w) / 2;
573
+ }
574
+ function sweepSide(boxes, minY, maxY) {
575
+ const sorted = [...boxes].sort((a, b) => a.y - b.y || a.id - b.id);
576
+ const ys = sorted.map((box) => box.y);
577
+ for (let i = 1; i < sorted.length; i++) {
578
+ const prev = sorted[i - 1];
579
+ const box = sorted[i];
580
+ if (overlapsX(prev, box)) {
581
+ ys[i] = Math.max(ys[i], ys[i - 1] + (prev.h + box.h) / 2 + LABEL_COLLISION_GAP);
582
+ }
583
+ }
584
+ for (let i = sorted.length - 1; i >= 0; i--) {
585
+ const box = sorted[i];
586
+ const limit = i === sorted.length - 1 ? maxY - box.h / 2 : ys[i + 1] - (box.h + sorted[i + 1].h) / 2 - LABEL_COLLISION_GAP;
587
+ if (ys[i] > limit) {
588
+ ys[i] = Math.max(limit, minY + box.h / 2);
589
+ }
590
+ }
591
+ return new Map(sorted.map((box, i) => [box.id, ys[i]]));
592
+ }
593
+ function nudgeOutsideLabels(boxes, disc, minY, maxY) {
594
+ const resolved = /* @__PURE__ */ new Map();
595
+ for (const side of [
596
+ boxes.filter((box) => box.x >= disc.cx),
597
+ boxes.filter((box) => box.x < disc.cx)
598
+ ]) {
599
+ for (const [id, y] of sweepSide(side, minY, maxY)) {
600
+ resolved.set(id, y);
601
+ }
602
+ }
603
+ return boxes.map((box) => {
604
+ const y = resolved.get(box.id) ?? box.y;
605
+ return { id: box.id, dx: y === box.y ? 0 : clearOfDisc(box, y, disc), dy: y - box.y };
606
+ });
607
+ }
608
+
609
+ exports.BEST_FIT_EDGE_TOLERANCE = BEST_FIT_EDGE_TOLERANCE;
610
+ exports.BEST_FIT_OUTSIDE_GAP = BEST_FIT_OUTSIDE_GAP;
611
+ exports.BEST_FIT_RIM_INSET = BEST_FIT_RIM_INSET;
612
+ exports.LABEL_COLLISION_GAP = LABEL_COLLISION_GAP;
383
613
  exports.aggregateByCategory = aggregateByCategory;
384
614
  exports.axisTargetIntervals = axisTargetIntervals;
385
615
  exports.computeBoxStats = computeBoxStats;
386
616
  exports.computeHistogramBins = computeHistogramBins;
387
617
  exports.computeLinearRegression = computeLinearRegression;
388
618
  exports.computeRSquared = computeRSquared;
619
+ exports.computeRadarPoints = computeRadarPoints;
389
620
  exports.computeStackedSeriesPlots = computeStackedSeriesPlots;
390
621
  exports.fitPolynomial = fitPolynomial;
622
+ exports.formatExponentialEquation = formatExponentialEquation;
623
+ exports.formatLinearEquation = formatLinearEquation;
624
+ exports.formatLogarithmicEquation = formatLogarithmicEquation;
625
+ exports.formatPolynomialEquation = formatPolynomialEquation;
626
+ exports.formatPowerEquation = formatPowerEquation;
627
+ exports.formatTrendlineCoefficient = formatTrendlineCoefficient;
391
628
  exports.groupRowsByCategory = groupRowsByCategory;
392
629
  exports.niceAxisStep = niceAxisStep;
393
630
  exports.niceValueAxisBounds = niceValueAxisBounds;
631
+ exports.nudgeOutsideLabels = nudgeOutsideLabels;
632
+ exports.placeBestFitLabel = placeBestFitLabel;
633
+ exports.radarAngle = radarAngle;
634
+ exports.radarRingPoints = radarRingPoints;
394
635
  exports.resolveBlankDisplay = resolveBlankDisplay;
395
636
  exports.scottBinCount = scottBinCount;
637
+ exports.squarify = squarify;
396
638
  exports.visibleRuns = visibleRuns;
@@ -5,4 +5,9 @@ export * from './blank-display.js';
5
5
  export * from './stacked-series.js';
6
6
  export * from './axis-nice.js';
7
7
  export * from './histogram-binning.js';
8
+ export * from './treemap-squarify.js';
9
+ export * from './trendline-equation.js';
10
+ export * from './radar-geometry.js';
11
+ export * from './pie-best-fit.js';
12
+ export * from './pie-label-collision.js';
8
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../chart/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../chart/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC"}
@@ -378,4 +378,230 @@ function aggregateByCategory(values, rawCategories) {
378
378
  });
379
379
  }
380
380
 
381
- export { aggregateByCategory, axisTargetIntervals, computeBoxStats, computeHistogramBins, computeLinearRegression, computeRSquared, computeStackedSeriesPlots, fitPolynomial, groupRowsByCategory, niceAxisStep, niceValueAxisBounds, resolveBlankDisplay, scottBinCount, visibleRuns };
381
+ // chart/treemap-squarify.ts
382
+ function worstAspectRatio(areas, side) {
383
+ const sum = areas.reduce((total, area) => total + area, 0);
384
+ const max = Math.max(...areas);
385
+ const min = Math.min(...areas);
386
+ const sideSq = side * side;
387
+ const sumSq = sum * sum;
388
+ return Math.max(sideSq * max / sumSq, sumSq / (sideSq * min));
389
+ }
390
+ function squarify(nodes, box) {
391
+ const sorted = [...nodes].sort((a, b) => b.weight - a.weight);
392
+ const total = sorted.reduce((sum, node) => sum + node.weight, 0);
393
+ const scale = total > 0 ? box.w * box.h / total : box.w * box.h / sorted.length;
394
+ const items = sorted.map((node) => ({ node, area: (total > 0 ? node.weight : 1) * scale }));
395
+ const result = [];
396
+ let rect = { ...box };
397
+ let remaining = items;
398
+ for (let first = remaining[0]; first !== void 0; first = remaining[0]) {
399
+ const side = Math.min(rect.w, rect.h);
400
+ let row = [first];
401
+ let rowAreas = [first.area];
402
+ let worst = worstAspectRatio(rowAreas, side);
403
+ let cursor = 1;
404
+ for (let next = remaining[cursor]; next !== void 0; next = remaining[cursor]) {
405
+ const candidateAreas = [...rowAreas, next.area];
406
+ const candidateWorst = worstAspectRatio(candidateAreas, side);
407
+ if (candidateWorst > worst) {
408
+ break;
409
+ }
410
+ row = [...row, next];
411
+ rowAreas = candidateAreas;
412
+ worst = candidateWorst;
413
+ cursor++;
414
+ }
415
+ const rowTotalArea = rowAreas.reduce((sum, area) => sum + area, 0);
416
+ const thickness = side > 0 ? rowTotalArea / side : 0;
417
+ const layoutVertically = rect.w >= rect.h;
418
+ let offset = layoutVertically ? rect.y : rect.x;
419
+ for (const item of row) {
420
+ const length = thickness > 0 ? item.area / thickness : 0;
421
+ if (layoutVertically) {
422
+ result.push([item.node, { x: rect.x, y: offset, w: thickness, h: length }]);
423
+ } else {
424
+ result.push([item.node, { x: offset, y: rect.y, w: length, h: thickness }]);
425
+ }
426
+ offset += length;
427
+ }
428
+ rect = layoutVertically ? { ...rect, x: rect.x + thickness, w: rect.w - thickness } : { ...rect, y: rect.y + thickness, h: rect.h - thickness };
429
+ remaining = remaining.slice(row.length);
430
+ }
431
+ return result;
432
+ }
433
+
434
+ // chart/trendline-equation.ts
435
+ var SIGNIFICANT_DIGITS = 4;
436
+ function formatTrendlineCoefficient(value) {
437
+ if (!Number.isFinite(value) || value === 0) {
438
+ return "0";
439
+ }
440
+ const rounded = Number(value.toPrecision(SIGNIFICANT_DIGITS));
441
+ return rounded === 0 ? "0" : String(rounded);
442
+ }
443
+ function signedTerm(value) {
444
+ return { sign: value < 0 ? "-" : "+", abs: formatTrendlineCoefficient(Math.abs(value)) };
445
+ }
446
+ function formatLinearEquation(slope, intercept) {
447
+ const { sign, abs } = signedTerm(intercept);
448
+ return `y = ${formatTrendlineCoefficient(slope)}x ${sign} ${abs}`;
449
+ }
450
+ function formatExponentialEquation(a, b) {
451
+ return `y = ${formatTrendlineCoefficient(a)} e^(${formatTrendlineCoefficient(b)}x)`;
452
+ }
453
+ function formatLogarithmicEquation(slope, intercept) {
454
+ const { sign, abs } = signedTerm(intercept);
455
+ return `y = ${formatTrendlineCoefficient(slope)}ln(x) ${sign} ${abs}`;
456
+ }
457
+ function formatPowerEquation(a, b) {
458
+ return `y = ${formatTrendlineCoefficient(a)}x^${formatTrendlineCoefficient(b)}`;
459
+ }
460
+ function formatPolynomialEquation(coeffsAscending) {
461
+ const order = coeffsAscending.length - 1;
462
+ let out = "y = ";
463
+ for (let power = order; power >= 0; power--) {
464
+ const coeff = coeffsAscending[power] ?? 0;
465
+ const { sign, abs } = signedTerm(coeff);
466
+ const variable = power === 0 ? "" : power === 1 ? "x" : `x^${power}`;
467
+ out += power === order ? `${sign === "-" ? "-" : ""}${abs}${variable}` : ` ${sign} ${abs}${variable}`;
468
+ }
469
+ return out;
470
+ }
471
+
472
+ // chart/radar-geometry.ts
473
+ function radarAngle(index, catCount) {
474
+ const n = Math.max(catCount, 1);
475
+ return Math.PI * 2 * index / n - Math.PI / 2;
476
+ }
477
+ function computeRadarPoints(values, maxVal, radius, cx, cy, catCount) {
478
+ const denom = maxVal > 0 ? maxVal : 1;
479
+ return values.slice(0, Math.max(catCount, 1)).map((val, i) => {
480
+ const angle = radarAngle(i, catCount), r = Math.abs(val) / denom * radius;
481
+ return { x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) };
482
+ });
483
+ }
484
+ function radarRingPoints(cx, cy, rr, catCount) {
485
+ const n = Math.max(catCount, 1);
486
+ return Array.from({ length: n }, (_, i) => {
487
+ const angle = radarAngle(i, n);
488
+ return `${(cx + rr * Math.cos(angle)).toFixed(2)},${(cy + rr * Math.sin(angle)).toFixed(2)}`;
489
+ }).join(" ");
490
+ }
491
+
492
+ // chart/pie-best-fit.ts
493
+ var PX_PER_PT = 4 / 3;
494
+ var BEST_FIT_RIM_INSET = 4 * PX_PER_PT;
495
+ var BEST_FIT_EDGE_TOLERANCE = 1.5 * PX_PER_PT;
496
+ var BEST_FIT_OUTSIDE_GAP = 2 * PX_PER_PT;
497
+ function farCorner(x, y, w, h) {
498
+ return Math.hypot(Math.abs(x) + w / 2, Math.abs(y) + h / 2);
499
+ }
500
+ function insideDistance(ux, uy, w, h, limit) {
501
+ if (farCorner(0, 0, w, h) > limit) {
502
+ return void 0;
503
+ }
504
+ let lo = 0;
505
+ let hi = limit;
506
+ for (let i = 0; i < 40; i++) {
507
+ const mid = (lo + hi) / 2;
508
+ if (farCorner(mid * ux, mid * uy, w, h) > limit) {
509
+ hi = mid;
510
+ } else {
511
+ lo = mid;
512
+ }
513
+ }
514
+ return lo;
515
+ }
516
+ function edgeOverhang(x, y, w, h, slice) {
517
+ let worst = Number.NEGATIVE_INFINITY;
518
+ const corners = [
519
+ [-w / 2, -h / 2],
520
+ [w / 2, -h / 2],
521
+ [-w / 2, h / 2],
522
+ [w / 2, h / 2]
523
+ ];
524
+ for (const [dx, dy] of corners) {
525
+ const px = x + dx;
526
+ const py = y + dy;
527
+ const fromStart = Math.cos(slice.startAngle) * py - Math.sin(slice.startAngle) * px;
528
+ const fromEnd = Math.sin(slice.endAngle) * px - Math.cos(slice.endAngle) * py;
529
+ worst = Math.max(worst, -fromStart, -fromEnd);
530
+ }
531
+ return worst;
532
+ }
533
+ function placeBestFitLabel(slice, w, h) {
534
+ const mid = (slice.startAngle + slice.endAngle) / 2;
535
+ const ux = Math.cos(mid);
536
+ const uy = Math.sin(mid);
537
+ const distance = insideDistance(ux, uy, w, h, slice.outerR - BEST_FIT_RIM_INSET);
538
+ if (distance !== void 0) {
539
+ const x = distance * ux;
540
+ const y = distance * uy;
541
+ const reflex = slice.endAngle - slice.startAngle >= Math.PI;
542
+ if (reflex || edgeOverhang(x, y, w, h, slice) <= BEST_FIT_EDGE_TOLERANCE) {
543
+ return { x: slice.cx + x, y: slice.cy + y, inside: true };
544
+ }
545
+ }
546
+ const extent = Math.abs(ux) * w / 2 + Math.abs(uy) * h / 2;
547
+ const outside = slice.outerR + BEST_FIT_OUTSIDE_GAP + extent;
548
+ return { x: slice.cx + outside * ux, y: slice.cy + outside * uy, inside: false };
549
+ }
550
+
551
+ // chart/pie-label-collision.ts
552
+ var LABEL_COLLISION_GAP = 2;
553
+ function boxDistanceToCentre(box, y, disc) {
554
+ const nearestX = Math.max(box.x - box.w / 2, Math.min(disc.cx, box.x + box.w / 2));
555
+ const nearestY = Math.max(y - box.h / 2, Math.min(disc.cy, y + box.h / 2));
556
+ return Math.hypot(nearestX - disc.cx, nearestY - disc.cy);
557
+ }
558
+ function clearOfDisc(box, y, disc) {
559
+ if (boxDistanceToCentre(box, y, disc) >= disc.r) {
560
+ return 0;
561
+ }
562
+ const sign = box.x >= disc.cx ? 1 : -1;
563
+ let dx = 0;
564
+ while (dx < disc.r * 2 && boxDistanceToCentre({ ...box, x: box.x + sign * dx }, y, disc) < disc.r) {
565
+ dx += 1;
566
+ }
567
+ return sign * dx;
568
+ }
569
+ function overlapsX(a, b) {
570
+ return Math.abs(a.x - b.x) < (a.w + b.w) / 2;
571
+ }
572
+ function sweepSide(boxes, minY, maxY) {
573
+ const sorted = [...boxes].sort((a, b) => a.y - b.y || a.id - b.id);
574
+ const ys = sorted.map((box) => box.y);
575
+ for (let i = 1; i < sorted.length; i++) {
576
+ const prev = sorted[i - 1];
577
+ const box = sorted[i];
578
+ if (overlapsX(prev, box)) {
579
+ ys[i] = Math.max(ys[i], ys[i - 1] + (prev.h + box.h) / 2 + LABEL_COLLISION_GAP);
580
+ }
581
+ }
582
+ for (let i = sorted.length - 1; i >= 0; i--) {
583
+ const box = sorted[i];
584
+ const limit = i === sorted.length - 1 ? maxY - box.h / 2 : ys[i + 1] - (box.h + sorted[i + 1].h) / 2 - LABEL_COLLISION_GAP;
585
+ if (ys[i] > limit) {
586
+ ys[i] = Math.max(limit, minY + box.h / 2);
587
+ }
588
+ }
589
+ return new Map(sorted.map((box, i) => [box.id, ys[i]]));
590
+ }
591
+ function nudgeOutsideLabels(boxes, disc, minY, maxY) {
592
+ const resolved = /* @__PURE__ */ new Map();
593
+ for (const side of [
594
+ boxes.filter((box) => box.x >= disc.cx),
595
+ boxes.filter((box) => box.x < disc.cx)
596
+ ]) {
597
+ for (const [id, y] of sweepSide(side, minY, maxY)) {
598
+ resolved.set(id, y);
599
+ }
600
+ }
601
+ return boxes.map((box) => {
602
+ const y = resolved.get(box.id) ?? box.y;
603
+ return { id: box.id, dx: y === box.y ? 0 : clearOfDisc(box, y, disc), dy: y - box.y };
604
+ });
605
+ }
606
+
607
+ export { BEST_FIT_EDGE_TOLERANCE, BEST_FIT_OUTSIDE_GAP, BEST_FIT_RIM_INSET, LABEL_COLLISION_GAP, aggregateByCategory, axisTargetIntervals, computeBoxStats, computeHistogramBins, computeLinearRegression, computeRSquared, computeRadarPoints, computeStackedSeriesPlots, fitPolynomial, formatExponentialEquation, formatLinearEquation, formatLogarithmicEquation, formatPolynomialEquation, formatPowerEquation, formatTrendlineCoefficient, groupRowsByCategory, niceAxisStep, niceValueAxisBounds, nudgeOutsideLabels, placeBestFitLabel, radarAngle, radarRingPoints, resolveBlankDisplay, scottBinCount, squarify, visibleRuns };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Where PowerPoint puts a pie data label at `c:dLblPos val="bestFit"`.
3
+ *
4
+ * COM ground truth (`chart-pie-best-fit.pptx`: eight pies of different slice
5
+ * sizes, boxed 12pt labels, measured from `Slide.Export` pixels at two pie
6
+ * sizes, R = 89.6pt and 190.3pt):
7
+ *
8
+ * - A label that fits inside its slice sits INSIDE it, on the slice's
9
+ * mid-angle, pushed out until the box corner farthest from the centre is
10
+ * 4pt inside the rim. The 4pt is the same for both pie sizes, so it is a
11
+ * fixed inset, not a fraction of the radius. (The renderer used to put
12
+ * every such label at 0.7 of the radius, well short of PowerPoint's.)
13
+ * - "Fits" means that box, so placed, stays inside the slice's two edges:
14
+ * PowerPoint tolerates about 1.5pt of overhang (a 10% slice with a
15
+ * two-line label is on the boundary: one of three stays inside).
16
+ * - A label that does not fit goes OUTSIDE, on the mid-angle, with the box
17
+ * side facing the pie 2pt beyond the rim. PowerPoint then nudges outside
18
+ * labels apart when they collide and draws leader lines to the nudged
19
+ * ones; that pass is `chart-pie-label-collision` (an approximation).
20
+ *
21
+ * All lengths are in the chart's px space (1pt = 4/3px).
22
+ *
23
+ * @module chart/pie-best-fit
24
+ */
25
+ /** COM: the farthest box corner of an inside label sits this far inside the rim. */
26
+ export declare const BEST_FIT_RIM_INSET: number;
27
+ /** COM: how far a box may overhang a slice edge and still count as inside. */
28
+ export declare const BEST_FIT_EDGE_TOLERANCE: number;
29
+ /** COM: the gap between the rim and an outside label's box. */
30
+ export declare const BEST_FIT_OUTSIDE_GAP: number;
31
+ /** A slice as the placement needs it: centre, radius and its two edge angles. */
32
+ export interface BestFitSlice {
33
+ cx: number;
34
+ cy: number;
35
+ outerR: number;
36
+ /** Radians, SVG convention (0 = 3 o'clock, clockwise positive). */
37
+ startAngle: number;
38
+ endAngle: number;
39
+ }
40
+ /** Where the label box's centre goes, and whether that is inside the slice. */
41
+ export interface BestFitPlacement {
42
+ x: number;
43
+ y: number;
44
+ inside: boolean;
45
+ }
46
+ /**
47
+ * Place a `w x h` label box for a slice at `bestFit` (see the module doc).
48
+ * A slice of half the pie or more always has room, so its label stays inside.
49
+ */
50
+ export declare function placeBestFitLabel(slice: BestFitSlice, w: number, h: number): BestFitPlacement;
51
+ //# sourceMappingURL=pie-best-fit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-best-fit.d.ts","sourceRoot":"","sources":["../../chart/pie-best-fit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,QAAgB,CAAC;AAChD,8EAA8E;AAC9E,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AACvD,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,QAAgB,CAAC;AAElD,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,OAAO,CAAC;CAChB;AAsDD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAiB7F"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * chart-pie-label-collision.ts: nudge colliding OUTSIDE pie labels apart.
3
+ *
4
+ * At `c:dLblPos val="bestFit"` PowerPoint puts a label that does not fit in its
5
+ * slice outside the rim; when two such labels overlap it moves them apart
6
+ * (vertically, within their own side of the pie) and draws a leader line to
7
+ * each one it moved. This module is the pure geometry half: it takes the
8
+ * outside label boxes and returns how far each one moves. The caller decides
9
+ * what to draw (a moved label gets a leader line; see `chart-pie-labels`).
10
+ *
11
+ * The algorithm is a per-side sweep: labels on the right (or left) of the pie
12
+ * are sorted top to bottom, each is pushed below the previous one when they
13
+ * overlap, and if the stack then runs past the bottom bound it is shifted back
14
+ * up. Constants are not COM-measured; the gap is one line of breathing room.
15
+ *
16
+ * @module chart/pie-label-collision
17
+ */
18
+ /** Minimum vertical gap (px) kept between two nudged labels. */
19
+ export declare const LABEL_COLLISION_GAP = 2;
20
+ /** One outside label box: its centre and size, keyed by an opaque id. */
21
+ export interface OutsideLabelBox {
22
+ id: number;
23
+ /** Box centre, in the same space as `pieCx`. */
24
+ x: number;
25
+ y: number;
26
+ w: number;
27
+ h: number;
28
+ }
29
+ /** How far one label moves (`dx`/`dy` are 0 when it stays put). */
30
+ export interface LabelNudge {
31
+ id: number;
32
+ dx: number;
33
+ dy: number;
34
+ }
35
+ /** The pie disc a nudged label must never be pushed into. */
36
+ export interface PieDisc {
37
+ cx: number;
38
+ cy: number;
39
+ r: number;
40
+ }
41
+ /**
42
+ * Compute the vertical nudges that separate overlapping outside labels.
43
+ * `disc` splits the labels into a left and a right column and keeps every
44
+ * nudged label outside the pie; `minY`/`maxY` bound the drawing area. Labels
45
+ * that do not collide get `dx: 0, dy: 0`.
46
+ */
47
+ export declare function nudgeOutsideLabels(boxes: ReadonlyArray<OutsideLabelBox>, disc: PieDisc, minY: number, maxY: number): LabelNudge[];
48
+ //# sourceMappingURL=pie-label-collision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-label-collision.d.ts","sourceRoot":"","sources":["../../chart/pie-label-collision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,mEAAmE;AACnE,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACX;AAED,6DAA6D;AAC7D,MAAM,WAAW,OAAO;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;CACV;AA+DD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EACrC,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,UAAU,EAAE,CAcd"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * chart-radar-geometry.ts: radar (spider) chart polar-coordinate geometry,
3
+ * split out of `chart-view-model-points.ts` to keep that file within the
4
+ * repo's ~300-LOC limit. Re-exported from there (and from `chart-view-model.ts`)
5
+ * so the public import surface is unchanged.
6
+ *
7
+ * @module chart/radar-geometry
8
+ */
9
+ /** Angle (radians) of the i-th radar spoke; 0 points up (-90°), clockwise. */
10
+ export declare function radarAngle(index: number, catCount: number): number;
11
+ export interface RadarPoint {
12
+ x: number;
13
+ y: number;
14
+ }
15
+ /** Project a series' values onto radar (polar) coordinates around (cx, cy). */
16
+ export declare function computeRadarPoints(values: ReadonlyArray<number>, maxVal: number, radius: number, cx: number, cy: number, catCount: number): RadarPoint[];
17
+ /** Points string for a radar gridline ring at radius `rr`. */
18
+ export declare function radarRingPoints(cx: number, cy: number, rr: number, catCount: number): string;
19
+ //# sourceMappingURL=radar-geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radar-geometry.d.ts","sourceRoot":"","sources":["../../chart/radar-geometry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,GACd,UAAU,EAAE,CAOd;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM5F"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Squarified treemap layout algorithm, generic over any weighted node.
3
+ * Split out of `chart-treemap-hierarchy.ts` (which supplies the node/box
4
+ * shapes and drives the recursive render) to keep each file under the
5
+ * repo's ~300-LOC budget.
6
+ *
7
+ * @module chart/treemap-squarify
8
+ */
9
+ export interface TreemapBox {
10
+ x: number;
11
+ y: number;
12
+ w: number;
13
+ h: number;
14
+ }
15
+ interface WeightedNode {
16
+ weight: number;
17
+ }
18
+ /**
19
+ * Squarified treemap layout (Bruls, Huizing & van Wijk): repeatedly lays out
20
+ * the widest possible "row" of items along the box's shorter side, adding
21
+ * items to the row only while doing so keeps improving (or not worsening)
22
+ * that row's worst aspect ratio, so cells stay close to square instead of
23
+ * degenerating into thin slivers the way a plain alternating slice-and-dice
24
+ * split does. COM-verified against charts-com.pptx slide 28 (chartEx3.xml):
25
+ * PowerPoint's own treemap mixes row and column splits within the SAME
26
+ * parent region (e.g. a tall cell beside a further row/column split), which
27
+ * a single alternating dimension split can never reproduce.
28
+ */
29
+ export declare function squarify<TNode extends WeightedNode>(nodes: readonly TNode[], box: TreemapBox): Array<[TNode, TreemapBox]>;
30
+ export {};
31
+ //# sourceMappingURL=treemap-squarify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treemap-squarify.d.ts","sourceRoot":"","sources":["../../chart/treemap-squarify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,UAAU,YAAY;IACrB,MAAM,EAAE,MAAM,CAAC;CACf;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,YAAY,EAClD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,GAAG,EAAE,UAAU,GACb,KAAK,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAkD5B"}