@tangle-network/charts 0.15.0 → 0.15.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 (2) hide show
  1. package/dist/index.js +23 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2336,6 +2336,7 @@ function xTicks(xs, px, left, right, width, label, size = 12) {
2336
2336
  const [a, b] = span(x);
2337
2337
  if (a < 2 || b > width - 2) continue;
2338
2338
  const previous = kept.at(-1);
2339
+ if (previous !== void 0 && label(x) === label(previous)) continue;
2339
2340
  if (previous !== void 0 && a < span(previous)[1] + 10) {
2340
2341
  if (x !== xs.at(-1) || kept.length === 1) continue;
2341
2342
  kept.pop();
@@ -2460,7 +2461,7 @@ function pointMark(x, y, shape, r, p) {
2460
2461
  * Text beside a mark: the status glyph, `*` or `?`, the label and `×n`. Drawn to the right, or to the left when it
2461
2462
  * would cross `limit`; returns the markup and its width so a caller can skip it when the column has no room.
2462
2463
  */
2463
- function pointBadge(x, y, r, p, limit) {
2464
+ function pointBadge(x, y, r, p, limit, above = false) {
2464
2465
  const parts = [];
2465
2466
  if (p.glyph === "check") parts.push(["✓", "tgc-glyph-check"]);
2466
2467
  if (p.glyph === "cross") parts.push(["✕", "tgc-glyph-cross"]);
@@ -2473,9 +2474,13 @@ function pointBadge(x, y, r, p, limit) {
2473
2474
  width: 0
2474
2475
  };
2475
2476
  const width = textWidth(parts.map(([t]) => t).join(" "), 10, "mono");
2477
+ const spans = parts.map(([t, cls], i) => `<tspan class="${cls}">${i ? " " : ""}${esc(t)}</tspan>`).join("");
2478
+ if (above) return {
2479
+ svg: `<text class="tgc-point-badge" x="${Math.round(x * 100) / 100}" y="${Math.round((y - r - 5) * 100) / 100}" font-size="10" text-anchor="middle">${spans}</text>`,
2480
+ width
2481
+ };
2476
2482
  const left = x + r + 3 + width > limit;
2477
2483
  const tx = left ? x - r - 3 : x + r + 3;
2478
- const spans = parts.map(([t, cls], i) => `<tspan class="${cls}">${i ? " " : ""}${esc(t)}</tspan>`).join("");
2479
2484
  return {
2480
2485
  svg: `<text class="tgc-point-badge" x="${Math.round(tx * 100) / 100}" y="${Math.round((y + 3.5) * 100) / 100}" font-size="10"${left ? " text-anchor=\"end\"" : ""}>${spans}</text>`,
2481
2486
  width
@@ -2510,9 +2515,22 @@ function placeBadges(pending, marks, left, right) {
2510
2515
  y - 6,
2511
2516
  y + 6
2512
2517
  ];
2513
- if (!free(box)) continue;
2514
- placed.push(box);
2515
- out += badge.svg;
2518
+ const over = [
2519
+ x - badge.width / 2,
2520
+ x + badge.width / 2,
2521
+ y - r - 15,
2522
+ y - r - 3
2523
+ ];
2524
+ const at = free(box) ? {
2525
+ box,
2526
+ svg: badge.svg
2527
+ } : free(over) ? {
2528
+ box: over,
2529
+ svg: pointBadge(x, y, r, point, right, true).svg
2530
+ } : null;
2531
+ if (!at) continue;
2532
+ placed.push(at.box);
2533
+ out += at.svg;
2516
2534
  }
2517
2535
  return out;
2518
2536
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/charts",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Static SVG and HTML figures for benchmarks and operational timing. Draws from producer data and refuses what it cannot draw honestly.",
5
5
  "type": "module",
6
6
  "license": "MIT",