vvplot 0.4.4 → 0.4.5

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.
@@ -1818,7 +1818,7 @@ class AsisNumber extends Number {
1818
1818
  AsisNumber.#cache.set(n, this);
1819
1819
  }
1820
1820
  }
1821
- class Asis extends String {
1821
+ class Asis {
1822
1822
  static #cache = /* @__PURE__ */ new Map();
1823
1823
  constructor(value) {
1824
1824
  if (typeof value === "string" || value instanceof String) {
@@ -1862,7 +1862,7 @@ class EnumLevel extends Array {
1862
1862
  static from(x2) {
1863
1863
  if (x2 instanceof this) return x2;
1864
1864
  if (x2[Symbol.iterator]) {
1865
- let lvl = unique(Array.from(x2).filter((x3) => !(x3 instanceof Asis)).map((x3) => String(x3))).sort((a, b) => compare(a, b, { numeric: true }));
1865
+ let lvl = unique(Array.from(x2).filter((x3) => !(x3 instanceof Asis) && x3 != null).map((x3) => String(x3))).sort((a, b) => compare(a, b, { numeric: true }));
1866
1866
  return new this(...lvl);
1867
1867
  } else if (typeof x2 === "object") {
1868
1868
  let lvl = Object.keys(x2).map((x3) => String(x3)).sort((a, b) => compare(x2[a], x2[b]));
@@ -1916,6 +1916,9 @@ class EnumLevel extends Array {
1916
1916
  function is_continuous(x2) {
1917
1917
  return typeof x2 === "number" || x2 instanceof Number || x2 instanceof Date;
1918
1918
  }
1919
+ function is_categorical(v) {
1920
+ return typeof v === "string" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "object" && v !== null && typeof v.valueOf() !== "number" && typeof v.valueOf() !== "bigint";
1921
+ }
1919
1922
  function plus$1(a, b = 0) {
1920
1923
  if (b == 0 || a == null) return a;
1921
1924
  if (a instanceof Date) return new a.constructor(+a + b);
@@ -2507,7 +2510,7 @@ const boxplot$1 = {
2507
2510
  y2,
2508
2511
  ds.outliers ?? [],
2509
2512
  xnudge
2510
- ), $xmin = psum$a(ds.xmin, xnudge), $xmax = psum$a(ds.xmax, xnudge);
2513
+ ), $xmin = psum$a(ds.min, xnudge), $xmax = psum$a(ds.max, xnudge);
2511
2514
  return {
2512
2515
  y: y2,
2513
2516
  ymin,
@@ -2807,8 +2810,8 @@ const boxplot = Object.assign(function(data, {}) {
2807
2810
  let missingAes = ["x", "y"].filter((a) => data[a] == null);
2808
2811
  if (missingAes.length > 0)
2809
2812
  throw new Error(`Missing aesthetics for "StatBoxplot": "${missingAes.join('", "')}"`);
2810
- let isXdiscrete = data.x.some((x2) => typeof x2 !== "number");
2811
- let isYdiscrete = data.y.some((y2) => typeof y2 !== "number");
2813
+ let isXdiscrete = data.x.some(is_categorical);
2814
+ let isYdiscrete = data.y.some(is_categorical);
2812
2815
  if (isXdiscrete && isYdiscrete)
2813
2816
  throw new Error(`Both "x" and "y" are discrete, "StatBoxplot" requires one continuous and one discrete aesthetic`);
2814
2817
  if (!isXdiscrete && !isYdiscrete)
@@ -6792,9 +6795,6 @@ function object_map(obj, expr) {
6792
6795
  if (obj == null) return {};
6793
6796
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, expr(k, v)]));
6794
6797
  }
6795
- function is_categorical(v) {
6796
- return typeof v === "string" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "object" && v !== null && typeof v.valueOf() !== "number" && typeof v.valueOf() !== "bigint";
6797
- }
6798
6798
  class GLayer {
6799
6799
  /**
6800
6800
  * Create a graphic layer from schema
@@ -14977,7 +14977,6 @@ const _sfc_main$11 = {
14977
14977
  pointermove(e) {
14978
14978
  emit("pointermove", e, getPosition(e));
14979
14979
  },
14980
- pointerdown: axisMovePointerdown,
14981
14980
  wheel: axisWheel
14982
14981
  };
14983
14982
  return (_ctx, _cache) => {
@@ -15015,27 +15014,26 @@ const _sfc_main$11 = {
15015
15014
  height: 10,
15016
15015
  y: -5
15017
15016
  }, toHandlers(axisVOn, true), {
15017
+ onPointerdown: axisMovePointerdown,
15018
15018
  cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
15019
15019
  }), null, 16, _hoisted_4$3)
15020
15020
  ]),
15021
15021
  _cache[4] || (_cache[4] = createTextVNode()),
15022
15022
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$2, [
15023
- createElementVNode("rect", {
15023
+ createElementVNode("rect", mergeProps({
15024
15024
  width: 20,
15025
15025
  height: 10,
15026
15026
  y: -5,
15027
- style: { "cursor": "ew-resize" },
15028
- onPointerdown: axisRescaleLeftPointerdown
15029
- }, null, 32),
15027
+ style: { "cursor": "ew-resize" }
15028
+ }, toHandlers(axisVOn, true), { onPointerdown: axisRescaleLeftPointerdown }), null, 16),
15030
15029
  _cache[0] || (_cache[0] = createTextVNode()),
15031
- createElementVNode("rect", {
15030
+ createElementVNode("rect", mergeProps({
15032
15031
  width: 20,
15033
15032
  height: 10,
15034
15033
  y: -5,
15035
15034
  x: width.value - 20,
15036
- style: { "cursor": "ew-resize" },
15037
- onPointerdown: axisRescaleRightPointerdown
15038
- }, null, 40, _hoisted_6$2)
15035
+ style: { "cursor": "ew-resize" }
15036
+ }, toHandlers(axisVOn, true), { onPointerdown: axisRescaleRightPointerdown }), null, 16, _hoisted_6$2)
15039
15037
  ])) : createCommentVNode("", true),
15040
15038
  _cache[5] || (_cache[5] = createTextVNode()),
15041
15039
  axisTitle.value.text ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
@@ -15404,7 +15402,6 @@ const _sfc_main$10 = {
15404
15402
  pointermove(e) {
15405
15403
  emit("pointermove", e, getPosition(e));
15406
15404
  },
15407
- pointerdown: axisMovePointerdown,
15408
15405
  wheel: axisWheel
15409
15406
  };
15410
15407
  return (_ctx, _cache) => {
@@ -15442,27 +15439,26 @@ const _sfc_main$10 = {
15442
15439
  height: height.value,
15443
15440
  x: -5
15444
15441
  }, toHandlers(axisVOn, true), {
15442
+ onPointerdown: axisMovePointerdown,
15445
15443
  cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
15446
15444
  }), null, 16, _hoisted_4$2)
15447
15445
  ]),
15448
15446
  _cache[4] || (_cache[4] = createTextVNode()),
15449
15447
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$1, [
15450
- createElementVNode("rect", {
15448
+ createElementVNode("rect", mergeProps({
15451
15449
  width: 10,
15452
15450
  height: 20,
15453
15451
  x: -5,
15454
- style: { "cursor": "ns-resize" },
15455
- onPointerdown: axisRescaleTopPointerdown
15456
- }, null, 32),
15452
+ style: { "cursor": "ns-resize" }
15453
+ }, toHandlers(axisVOn, true), { onPointerdown: axisRescaleTopPointerdown }), null, 16),
15457
15454
  _cache[0] || (_cache[0] = createTextVNode()),
15458
- createElementVNode("rect", {
15455
+ createElementVNode("rect", mergeProps({
15459
15456
  width: 10,
15460
15457
  height: 20,
15461
15458
  x: -5,
15462
15459
  y: height.value - 20,
15463
- style: { "cursor": "ns-resize" },
15464
- onPointerdown: axisRescaleBottomPointerdown
15465
- }, null, 40, _hoisted_6$1)
15460
+ style: { "cursor": "ns-resize" }
15461
+ }, toHandlers(axisVOn, true), { onPointerdown: axisRescaleBottomPointerdown }), null, 16, _hoisted_6$1)
15466
15462
  ])) : createCommentVNode("", true),
15467
15463
  _cache[5] || (_cache[5] = createTextVNode()),
15468
15464
  axisTitle.value.text ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
@@ -15944,14 +15940,14 @@ const _sfc_main$W = {
15944
15940
  } of group) {
15945
15941
  let dx = Math.sqrt(C / (A * C - B * B)), dy = Math.sqrt(A / (A * C - B * B));
15946
15942
  const { h: ch, v: cv } = __props.coord2pos({ x: cx, y: cy });
15947
- let { hmin, hmax, vmin, vmax } = __props.coord2pos({ xmin: cx - dx, xmax: cx + dx, ymin: cy - dy, ymax: cy + dy });
15948
- let scaleX = (hmax - hmin) / (2 * dx), scaleY = (vmax - vmin) / (2 * dy);
15943
+ let { h: h1, v: v1 } = __props.coord2pos({ x: cx - dx, y: cy - dy }), { h: h2, v: v2 } = __props.coord2pos({ x: cx + dx, y: cy + dy });
15944
+ let scaleX = (h2 - h1) / (2 * dx), scaleY = (v2 - v1) / (2 * dy);
15949
15945
  A /= scaleX * scaleX;
15950
15946
  B /= scaleX * scaleY;
15951
15947
  C /= scaleY * scaleY;
15952
15948
  const tr = A + C, det = A * C - B * B;
15953
15949
  const disc = Math.sqrt(Math.max(0, tr * tr / 4 - det));
15954
- let rx2 = 1 / Math.sqrt(tr / 2 + disc), ry = 1 / Math.sqrt(tr / 2 - disc), angle2 = -Math.atan2(2 * B, A - C) / 2;
15950
+ let rx2 = 1 / Math.sqrt(tr / 2 + disc), ry = 1 / Math.sqrt(tr / 2 - disc), angle2 = Math.atan2(2 * B, A - C) / 2;
15955
15951
  const path2d = new Path2D();
15956
15952
  path2d.ellipse(ch + translateX, cv + translateY, rx2, ry, angle2, 0, 2 * Math.PI);
15957
15953
  _path_data.set(path2d, $raw);
@@ -17252,9 +17248,9 @@ const _sfc_main$H = {
17252
17248
  }) => {
17253
17249
  let dx = Math.sqrt(C / (A * C - B * B)), dy = Math.sqrt(A / (A * C - B * B));
17254
17250
  const { h: ch, v: cv } = __props.coord2pos({ x: cx, y: cy });
17255
- let { hmin, hmax, vmin, vmax } = __props.coord2pos({ xmin: cx - dx, xmax: cx + dx, ymin: cy - dy, ymax: cy + dy });
17256
- if (hmax < xlim_min || hmin > xlim_max || vmax < ylim_min || vmin > ylim_max) return null;
17257
- let scaleX = (hmax - hmin) / (2 * dx), scaleY = (vmax - vmin) / (2 * dy);
17251
+ let { h: h1, v: v1 } = __props.coord2pos({ x: cx - dx, y: cy - dy }), { h: h2, v: v2 } = __props.coord2pos({ x: cx + dx, y: cy + dy });
17252
+ if (h1 < xlim_min && h2 < xlim_min || h2 > xlim_max && h1 > xlim_max || v1 < ylim_min && v2 < ylim_min || v2 > ylim_max && v1 > ylim_max) return null;
17253
+ let scaleX = (h2 - h1) / (2 * dx), scaleY = (v2 - v1) / (2 * dy);
17258
17254
  A /= scaleX * scaleX;
17259
17255
  B /= scaleX * scaleY;
17260
17256
  C /= scaleY * scaleY;
@@ -17265,7 +17261,7 @@ const _sfc_main$H = {
17265
17261
  cy: cv,
17266
17262
  rx: 1 / Math.sqrt(tr / 2 + disc) || 0,
17267
17263
  ry: 1 / Math.sqrt(tr / 2 - disc) || 0,
17268
- angle: -Math.atan2(2 * B, A - C) / 2 * 180 / Math.PI || 0,
17264
+ angle: Math.atan2(2 * B, A - C) / 2 * 180 / Math.PI || 0,
17269
17265
  fill,
17270
17266
  color: color2,
17271
17267
  linetype,
@@ -17494,6 +17490,8 @@ const _sfc_main$E = {
17494
17490
  alpha: alpha2,
17495
17491
  "translate-x": translateX = 0,
17496
17492
  "translate-y": translateY = 0,
17493
+ "anchor-x": anchorX,
17494
+ "anchor-y": anchorY = 0.5,
17497
17495
  "font-family": fontFamily = "sans-serif",
17498
17496
  "text-align": textAlign = "start",
17499
17497
  inset = 0,
@@ -17507,140 +17505,72 @@ const _sfc_main$E = {
17507
17505
  if (x1 < xlim_min && x22 < xlim_min || x1 > xlim_max && x22 > xlim_max || y1 < ylim_min && y22 < ylim_min || y1 > ylim_max && y22 > ylim_max) return null;
17508
17506
  let radian = Math.atan2(y22 - y1, x22 - x1);
17509
17507
  let vbind = {
17510
- color: color2 || null,
17511
- fill: color2 || null,
17512
- "fill-opacity": alpha2 == 1 ? null : alpha2,
17513
- "font-size": size * 4,
17514
- stroke: stroke || null,
17515
- "stroke-width": linewidth,
17516
- "stroke-dasharray": parseLinetype(linetype).join(" ") || null,
17517
- "stroke-opacity": alpha2 == 1 ? null : alpha2,
17518
- "font-family": fontFamily,
17508
+ text: String(label),
17509
+ title: String(title ?? label),
17510
+ color: color2,
17511
+ alpha: alpha2,
17512
+ size,
17513
+ stroke,
17514
+ linewidth,
17515
+ linetype,
17516
+ fontFamily,
17519
17517
  class: className,
17520
17518
  style
17521
17519
  };
17522
17520
  let von = Object.fromEntries(
17523
17521
  events.map((evt) => [evt, (e) => emit(evt, Object.assign(e, { _vhandled: true }), __props.getCoord(e), $raw)])
17524
17522
  );
17525
- let tx, ty, content = parseMarkdownInline(String(label));
17523
+ let tx, ty;
17526
17524
  switch (textAlign) {
17527
17525
  case "stretch":
17528
17526
  tx = (x1 + x22) / 2;
17529
17527
  ty = (y1 + y22) / 2;
17530
- vbind["text-anchor"] = "middle";
17528
+ anchorX = 0.5;
17531
17529
  vbind.textLength = Math.hypot(x22 - x1 || 0, y22 - y1 || 0);
17532
- vbind.lengthAdjust = "spacingAndGlyphs";
17533
17530
  break;
17534
17531
  case "center":
17535
17532
  tx = (x1 + x22) / 2;
17536
17533
  ty = (y1 + y22) / 2;
17537
- vbind["text-anchor"] = "middle";
17534
+ anchorX ??= 0.5;
17538
17535
  break;
17539
17536
  case "pre":
17540
17537
  tx = x1;
17541
17538
  ty = y1;
17542
17539
  translateX -= Math.cos(radian) * inset;
17543
17540
  translateY -= Math.sin(radian) * inset;
17544
- vbind["text-anchor"] = "end";
17541
+ anchorX ??= 1;
17545
17542
  break;
17546
17543
  case "end":
17547
17544
  tx = x22;
17548
17545
  ty = y22;
17549
17546
  translateX -= Math.cos(radian) * inset;
17550
17547
  translateY -= Math.sin(radian) * inset;
17551
- vbind["text-anchor"] = "end";
17548
+ anchorX ??= 1;
17552
17549
  break;
17553
17550
  case "post":
17554
17551
  tx = x22;
17555
17552
  ty = y22;
17556
17553
  translateX += Math.cos(radian) * inset;
17557
17554
  translateY += Math.sin(radian) * inset;
17558
- vbind["text-anchor"] = "start";
17555
+ anchorX ??= 0;
17559
17556
  break;
17560
17557
  default:
17561
17558
  tx = x1;
17562
17559
  ty = y1;
17563
17560
  translateX += Math.cos(radian) * inset;
17564
17561
  translateY += Math.sin(radian) * inset;
17565
- vbind["text-anchor"] = "start";
17562
+ anchorX ??= 0;
17566
17563
  }
17567
- let transform = [];
17568
- if (translateX || translateY) transform.push(`translate(${translateX}, ${translateY})`);
17569
- if (radian) transform.push(`rotate(${radian * 180 / Math.PI})`);
17570
- Object.assign(vbind, {
17571
- x: tx,
17572
- y: ty,
17573
- "dominant-baseline": "central",
17574
- "transform-origin": `${tx} ${ty}`,
17575
- transform: transform.join(" ") || null
17576
- });
17577
- return [vbind, von, content, String(title ?? String(label).replace(/\x01|\x02/g, ""))];
17564
+ Object.assign(vbind, { x: tx, y: ty, translateX, translateY, anchorX, anchorY, angle: radian * 180 / Math.PI });
17565
+ return [vbind, von];
17578
17566
  }).filter((x2) => x2 != null));
17579
17567
  });
17580
- const parser = new Parser();
17581
- function parseMarkdownInline(markdown2) {
17582
- const walker = parser.parse(markdown2).walker();
17583
- const fragments = [];
17584
- let stack2 = [], scales = [1], offset = 0;
17585
- let ev;
17586
- while (ev = walker.next()) {
17587
- let { node: { type, literal }, entering } = ev;
17588
- let scale = scales.at(-1);
17589
- if (entering) {
17590
- if (type === "text" || type === "code") {
17591
- const vbind = Object.assign({
17592
- dy: str_c(offset || null, "em")
17593
- }, ...stack2, {
17594
- "font-family": type === "code" ? "monospace" : null,
17595
- "font-size": scale === 1 ? null : `${scale}em`
17596
- });
17597
- offset = 0;
17598
- fragments.push({ text: literal, vbind });
17599
- } else if (type === "strong") {
17600
- stack2.push({ "font-weight": "bold" });
17601
- } else if (type === "emph") {
17602
- stack2.push({ "font-style": "italic" });
17603
- } else if (type === "softbreak" || type === "paragraph") {
17604
- fragments.push({ text: " " });
17605
- } else if (type === "html_inline") {
17606
- const tag2 = literal;
17607
- if (tag2.includes("color=")) {
17608
- const fill = tag2.match(/color=(['"])(.*?)\1/i)?.[2] ?? tag2.match(/color=(\S*)/)?.[1];
17609
- if (fill) stack2.push({ fill });
17610
- } else if (tag2.includes("</font>")) {
17611
- stack2.pop();
17612
- } else if (tag2.includes("<sup>")) {
17613
- offset -= 0.4 * scale;
17614
- scales.push(scale * 0.7);
17615
- } else if (tag2.includes("</sup>")) {
17616
- offset += 0.4 * scales.at(-1);
17617
- scales.pop();
17618
- } else if (tag2.includes("<sub>")) {
17619
- offset += 0.25 * scale;
17620
- scales.push(scale * 0.7);
17621
- } else if (tag2.includes("</sub>")) {
17622
- offset -= 0.25 * scales.at(-1);
17623
- scales.pop();
17624
- }
17625
- }
17626
- } else {
17627
- if (["strong", "emph"].includes(type)) stack2.pop();
17628
- }
17629
- }
17630
- return fragments;
17631
- }
17632
17568
  return (_ctx, _cache) => {
17633
17569
  return openBlock(), createElementBlock("g", null, [
17634
17570
  (openBlock(true), createElementBlock(Fragment, null, renderList(binds.value, (group) => {
17635
17571
  return openBlock(), createElementBlock("g", mergeProps({ ref_for: true }, { class: __props.groupClass, style: __props.groupStyle }), [
17636
- (openBlock(true), createElementBlock(Fragment, null, renderList(group, ([vbind, von, textFragments, title]) => {
17637
- return openBlock(), createElementBlock("text", mergeProps({ ref_for: true }, vbind, toHandlers(von, true)), [
17638
- createElementVNode("title", null, toDisplayString(title), 1),
17639
- _cache[0] || (_cache[0] = createTextVNode()),
17640
- (openBlock(true), createElementBlock(Fragment, null, renderList(textFragments, (tspan) => {
17641
- return openBlock(), createElementBlock("tspan", mergeProps({ ref_for: true }, tspan.vbind), toDisplayString(tspan.text), 17);
17642
- }), 256))
17643
- ], 16);
17572
+ (openBlock(true), createElementBlock(Fragment, null, renderList(group, ([vbind, von]) => {
17573
+ return openBlock(), createBlock(_sfc_main$12, mergeProps({ ref_for: true }, vbind, toHandlers(von)), null, 16);
17644
17574
  }), 256))
17645
17575
  ], 16);
17646
17576
  }), 256))