@vanduo-oss/vd3-cbun 1.4.1 → 1.4.2

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.
@@ -129,9 +129,22 @@ function normalizeMargin(value, fallback = DEFAULT_MARGIN) {
129
129
  left: Number(value?.left ?? fallback.left)
130
130
  };
131
131
  }
132
+ function dataTableContribution(target) {
133
+ if (!isElement(target) || typeof target.querySelectorAll !== "function") return 0;
134
+ let total = 0;
135
+ target.querySelectorAll(".vd-chart-data-table:not(.vd-chart-sr-only)").forEach((table) => {
136
+ const style = typeof getComputedStyle === "function" ? getComputedStyle(table) : null;
137
+ const marginTop = style ? parseFloat(style.marginTop) || 0 : 0;
138
+ const marginBottom = style ? parseFloat(style.marginBottom) || 0 : 0;
139
+ total += (table.offsetHeight || 0) + marginTop + marginBottom;
140
+ });
141
+ return total;
142
+ }
132
143
  function measureTarget(target, options) {
133
144
  const width = Number(options.width) || Math.round(target.clientWidth) || DEFAULT_WIDTH;
134
- const height = Number(options.height) || Math.round(target.clientHeight) || DEFAULT_HEIGHT;
145
+ const targetHeight = Math.round(Number(target.clientHeight));
146
+ const availableHeight = Math.max(0, targetHeight - dataTableContribution(target));
147
+ const height = Number(options.height) || (targetHeight > 0 ? availableHeight : DEFAULT_HEIGHT);
135
148
  return {
136
149
  width: Math.max(160, width),
137
150
  height: Math.max(140, height)
@@ -1413,12 +1426,22 @@ function renderMultiLineChart(instance, mode) {
1413
1426
  }
1414
1427
  });
1415
1428
  setupKeyboardNavigation(svg, markGroup);
1416
- const uniqueX = unique(allRows.map((r) => r.x));
1417
- const tableRows = uniqueX.map((xVal) => {
1429
+ const xKey = (value) => String(xInfo.mapValue(value));
1430
+ const uniqueX = /* @__PURE__ */ new Map();
1431
+ for (const row of allRows) {
1432
+ const key = xKey(row.x);
1433
+ if (!uniqueX.has(key)) uniqueX.set(key, row.x);
1434
+ }
1435
+ const seriesValues = seriesList.map((s) => {
1436
+ const byX = /* @__PURE__ */ new Map();
1437
+ for (const row of s.rows) byX.set(xKey(row.x), row.y);
1438
+ return byX;
1439
+ });
1440
+ const tableRows = [...uniqueX.entries()].map(([key, xVal]) => {
1418
1441
  const rowCells = [formatCategory(xVal)];
1419
- seriesList.forEach((s) => {
1420
- const match = s.rows.find((r) => r.x === xVal);
1421
- rowCells.push(match && isFiniteNumber(match.y) ? formatNumber(match.y) : "");
1442
+ seriesValues.forEach((byX) => {
1443
+ const y = byX.get(key);
1444
+ rowCells.push(isFiniteNumber(y) ? formatNumber(y) : "");
1422
1445
  });
1423
1446
  return rowCells;
1424
1447
  });
@@ -1700,7 +1723,11 @@ var ChartInstance = class {
1700
1723
  }
1701
1724
  render() {
1702
1725
  if (this.destroyed) return this;
1726
+ const tableHeight = dataTableContribution(this.target);
1703
1727
  this.renderer(this);
1728
+ if (!Number(this.options.height) && dataTableContribution(this.target) !== tableHeight) {
1729
+ this.renderer(this);
1730
+ }
1704
1731
  return this;
1705
1732
  }
1706
1733
  update(nextOptions = {}) {
@@ -1714,11 +1741,12 @@ var ChartInstance = class {
1714
1741
  setupResizeObserver() {
1715
1742
  if (this.options.responsive === false || !hasWindow() || typeof ResizeObserver === "undefined")
1716
1743
  return;
1744
+ const chartHeight = () => Math.max(0, this.target.clientHeight - dataTableContribution(this.target));
1717
1745
  let lastWidth = this.target.clientWidth;
1718
- let lastHeight = this.target.clientHeight;
1746
+ let lastHeight = chartHeight();
1719
1747
  this.resizeObserver = new ResizeObserver(() => {
1720
1748
  const width = this.target.clientWidth;
1721
- const height = this.target.clientHeight;
1749
+ const height = chartHeight();
1722
1750
  if (width === lastWidth && height === lastHeight) return;
1723
1751
  lastWidth = width;
1724
1752
  lastHeight = height;
@@ -1836,7 +1864,9 @@ var CHART_PROPS = {
1836
1864
  // Accessible data table: `true` (sr-only, default) / `false` / `'visible'`.
1837
1865
  dataTable: { type: [Boolean, String], default: void 0 },
1838
1866
  // Override the SVG `aria-roledescription` (defaults to `${kind} chart`).
1839
- ariaRoleDescription: { type: String, default: void 0 }
1867
+ ariaRoleDescription: { type: String, default: void 0 },
1868
+ // Avoid colliding with the standard root `role` fallthrough attribute.
1869
+ svgRole: { type: String, default: void 0 }
1840
1870
  };
1841
1871
  function optionsFrom(target, props, emit) {
1842
1872
  return {
@@ -1872,6 +1902,7 @@ function optionsFrom(target, props, emit) {
1872
1902
  yAxis: props.yAxis,
1873
1903
  dataTable: props.dataTable,
1874
1904
  ariaRoleDescription: props.ariaRoleDescription,
1905
+ role: props.svgRole,
1875
1906
  // Forward the core's mark-click callbacks as the Vue emit family. Passing
1876
1907
  // all three unconditionally is safe: the core only fires the callback
1877
1908
  // relevant to the rendered chart type (bars → onBarClick, points →
@@ -1930,7 +1961,10 @@ var VdChart = defineComponent({
1930
1961
  props.xFormat,
1931
1962
  props.yFormat,
1932
1963
  props.xAxis,
1933
- props.yAxis
1964
+ props.yAxis,
1965
+ props.dataTable,
1966
+ props.ariaRoleDescription,
1967
+ props.svgRole
1934
1968
  ],
1935
1969
  () => {
1936
1970
  if (!instance) return;