expressive-charts 0.4.0 → 0.5.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/testing.cjs CHANGED
@@ -754,7 +754,7 @@ function pathData(segments, closed = false) {
754
754
  }
755
755
  // src/core/geometry/walk.ts
756
756
  const clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
757
- const NONE = Object.freeze([]);
757
+ const NONE = /* @__PURE__ */ Object.freeze([]);
758
758
  function createWalk(segments, gaps = NONE) {
759
759
  const first = segments[0];
760
760
  const last = segments[segments.length - 1];
@@ -951,7 +951,7 @@ function checkCount(n, multiple) {
951
951
  }
952
952
  }
953
953
  // src/core/geometry/describe/mark.ts
954
- function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, segments }) {
954
+ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, nearbyLabels, segments }) {
955
955
  return {
956
956
  key,
957
957
  ...series === void 0 ? {} : { series },
@@ -968,6 +968,7 @@ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot
968
968
  center,
969
969
  pivot,
970
970
  ...labelBounds === void 0 ? {} : { labelBounds },
971
+ ...nearbyLabels === void 0 ? {} : { nearbyLabels },
971
972
  ...segments === void 0 ? {} : { segments }
972
973
  };
973
974
  }
@@ -975,15 +976,15 @@ function finite(builder, field, value) {
975
976
  if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
976
977
  return value;
977
978
  }
978
- function labelBoxes(builder, boxes) {
979
+ function labelBoxes(builder, boxes, field = "labelBounds") {
979
980
  if (!boxes) return boxes;
980
981
  for (let i = 0; i < boxes.length; i++) {
981
982
  const { x, y, width, height } = boxes[i];
982
983
  if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
983
- finite(builder, `labelBounds[${i}].x`, x);
984
- finite(builder, `labelBounds[${i}].y`, y);
985
- size(builder, `labelBounds[${i}].width`, width);
986
- size(builder, `labelBounds[${i}].height`, height);
984
+ finite(builder, `${field}[${i}].x`, x);
985
+ finite(builder, `${field}[${i}].y`, y);
986
+ size(builder, `${field}[${i}].width`, width);
987
+ size(builder, `${field}[${i}].height`, height);
987
988
  }
988
989
  return boxes;
989
990
  }
@@ -1022,7 +1023,8 @@ function describeArc(spec) {
1022
1023
  bounds: boundsOf(sides.flat().flatMap(extremes)),
1023
1024
  center: walk.point(.5),
1024
1025
  pivot: center,
1025
- labelBounds: labelBoxes("arc", spec.labelBounds)
1026
+ labelBounds: labelBoxes("arc", spec.labelBounds),
1027
+ nearbyLabels: labelBoxes("arc", spec.nearbyLabels, "nearbyLabels")
1026
1028
  });
1027
1029
  }
1028
1030
  // src/core/geometry/describe/bar.ts
@@ -1042,6 +1044,7 @@ function describeBar(spec) {
1042
1044
  const radius = size("bar", "radius", spec.radius ?? 0);
1043
1045
  const gap = size("bar", "gap", spec.gap ?? 0);
1044
1046
  const labelBounds = labelBoxes("bar", spec.labelBounds);
1047
+ const nearbyLabels = labelBoxes("bar", spec.nearbyLabels, "nearbyLabels");
1045
1048
  const horizontal = baseline === "left" || baseline === "right";
1046
1049
  const length = horizontal ? width : height;
1047
1050
  const thickness = horizontal ? height : width;
@@ -1106,6 +1109,7 @@ function describeBar(spec) {
1106
1109
  height
1107
1110
  },
1108
1111
  labelBounds,
1112
+ nearbyLabels,
1109
1113
  segments
1110
1114
  });
1111
1115
  }
@@ -1160,7 +1164,8 @@ function describeLine(spec) {
1160
1164
  },
1161
1165
  center: walk.point(.5),
1162
1166
  pivot: first,
1163
- labelBounds: labelBoxes("line", spec.labelBounds)
1167
+ labelBounds: labelBoxes("line", spec.labelBounds),
1168
+ nearbyLabels: labelBoxes("line", spec.nearbyLabels, "nearbyLabels")
1164
1169
  });
1165
1170
  }
1166
1171
  function gapsAt(breaks, segments) {
@@ -1208,7 +1213,8 @@ function describePoint(spec) {
1208
1213
  },
1209
1214
  center,
1210
1215
  pivot: center,
1211
- labelBounds: labelBoxes("point", spec.labelBounds)
1216
+ labelBounds: labelBoxes("point", spec.labelBounds),
1217
+ nearbyLabels: labelBoxes("point", spec.nearbyLabels, "nearbyLabels")
1212
1218
  });
1213
1219
  }
1214
1220
  // src/core/geometry/flatten.ts
@@ -1285,9 +1291,8 @@ function flattenPath(commands) {
1285
1291
  return subpaths;
1286
1292
  }
1287
1293
  function bezier(...p) {
1288
- const bend = (a, b, c) => Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
1289
1294
  const cubic = p.length === 4;
1290
- const n = pieces(1, cubic ? 6 * Math.max(bend(p[0], p[1], p[2]), bend(p[1], p[2], p[3])) : 2 * bend(p[0], p[1], p[2]));
1295
+ const n = cubic ? cubicPieces(p[0], p[1], p[2], p[3]) : pieces(1, 2 * bend(p[0], p[1], p[2]));
1291
1296
  const points = [p[0]];
1292
1297
  for (let k = 1; k < n; k++) {
1293
1298
  const t = k / n;
@@ -1311,6 +1316,12 @@ function bezier(...p) {
1311
1316
  points.push(p[p.length - 1]);
1312
1317
  return points;
1313
1318
  }
1319
+ function cubicPieces(p0, p1, p2, p3) {
1320
+ return pieces(1, 6 * Math.max(bend(p0, p1, p2), bend(p1, p2, p3)));
1321
+ }
1322
+ function bend(a, b, c) {
1323
+ return Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
1324
+ }
1314
1325
  function pieces(span, second) {
1315
1326
  const n = Math.ceil(span * Math.sqrt(second / (8 * FLAT)));
1316
1327
  return Number.isFinite(n) ? Math.min(MAX_PIECES, Math.max(1, n)) : MAX_PIECES;
@@ -1597,6 +1608,7 @@ function describeShape(spec) {
1597
1608
  length
1598
1609
  ].every(Number.isFinite)) throw new RangeError(`describe.shape: d must stay finite${m ? " once moved by matrix" : ""}, got ${show$1(d)}.`);
1599
1610
  const labelBounds = labelBoxes("shape", spec.labelBounds);
1611
+ const nearbyLabels = labelBoxes("shape", spec.nearbyLabels, "nearbyLabels");
1600
1612
  if (subpaths.every(closes) && length > 0) {
1601
1613
  const center = {
1602
1614
  x: box.x + box.width / 2,
@@ -1611,7 +1623,8 @@ function describeShape(spec) {
1611
1623
  bounds: box,
1612
1624
  center,
1613
1625
  pivot: center,
1614
- labelBounds
1626
+ labelBounds,
1627
+ nearbyLabels
1615
1628
  });
1616
1629
  }
1617
1630
  const { segments, gaps } = joined(subpaths);
@@ -1631,7 +1644,8 @@ function describeShape(spec) {
1631
1644
  },
1632
1645
  center: walk.point(.5),
1633
1646
  pivot: walk.start,
1634
- labelBounds
1647
+ labelBounds,
1648
+ nearbyLabels
1635
1649
  });
1636
1650
  }
1637
1651
  const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;