@crysound/crychart 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -6,12 +6,12 @@ CRYChart is a **frontend rendering library built by CRYSOUND for OpenTest**, wri
6
6
 
7
7
  Designed for OpenTest's data visualization needs, CRYChart provides streaming data rendering, interactive axes, cursors, and 2D and 3D charts. It uses WebGL2 for rendering, with a Canvas fallback.
8
8
 
9
- Version `1.0.4` keeps long Canvas2D waveform lines visible by drawing them in bounded batches.
9
+ Version `1.0.5` applies compact content-measured XY axis layout consistently across HTML and non-HTML text modes.
10
10
 
11
11
  ## Install in an application
12
12
 
13
13
  ```powershell
14
- pnpm add --save-exact @crysound/crychart@1.0.4 --registry=https://registry.npmjs.org/
14
+ pnpm add --save-exact @crysound/crychart@1.0.5 --registry=https://registry.npmjs.org/
15
15
  ```
16
16
 
17
17
  Commit the application's lockfile and use `pnpm install --frozen-lockfile` for repeatable installs. See the [npm usage guide](docs/npm-usage.md) for package entry points and migration from the old `crychart` name.
package/README.zh-CN.md CHANGED
@@ -6,12 +6,12 @@ CRYChart 是 **CRYSOUND 为 OpenTest 定制的前端渲染库**,基于 TypeScr
6
6
 
7
7
  CRYChart 面向 OpenTest 的数据可视化场景,提供流式数据绘制、交互坐标轴、游标、二维和三维图表。绘图使用 WebGL2,并提供 Canvas 回退。
8
8
 
9
- `1.0.4` 修复了 Canvas2D 绘制长波形时曲线消失的问题。
9
+ `1.0.5` 统一了二维图表在非 HTML 与 HTML 文本模式下的紧凑内容坐标轴布局,修复多通道场景下 Y 轴边距过宽的问题。
10
10
 
11
11
  ## 在应用中安装
12
12
 
13
13
  ```powershell
14
- pnpm add --save-exact @crysound/crychart@1.0.4 --registry=https://registry.npmjs.org/
14
+ pnpm add --save-exact @crysound/crychart@1.0.5 --registry=https://registry.npmjs.org/
15
15
  ```
16
16
 
17
17
  提交应用的锁文件,后续执行 `pnpm install --frozen-lockfile`。包入口和旧 `crychart` 包名的迁移方式见 [npm 使用说明](docs/npm-usage.md)。
package/dist/crychart.cjs CHANGED
@@ -19934,7 +19934,6 @@ function fitEllipsoid3D(input, options = {}) {
19934
19934
  // src/axis-canvas.ts
19935
19935
  var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
19936
19936
  var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
19937
- var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
19938
19937
  var lineBoxHeight = (font2) => font2.getSize() * 0.8;
19939
19938
  function lineBoxBaseline(metrics2, font2) {
19940
19939
  const size = font2.getSize();
@@ -19950,7 +19949,7 @@ function textMetrics(ctx, text, font2, cache) {
19950
19949
  }
19951
19950
  let measured;
19952
19951
  try {
19953
- measured = ctx?.measureText(text);
19952
+ measured = ctx?.measureText?.(text);
19954
19953
  } finally {
19955
19954
  if (ctx) {
19956
19955
  if (previous !== void 0) ctx.font = previous;
@@ -19995,10 +19994,13 @@ function measuredTickLayout(axis, ctx, axisSizePixels = axis.getPixelLength(), c
19995
19994
  return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
19996
19995
  });
19997
19996
  }
19998
- function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
19997
+ function metrics(axis, ctx, cache, theme, resolveFont) {
19999
19998
  const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
20000
19999
  const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
20001
- const titleOnly = !strategy.visible && titleVisible && !axis.annotations.some((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
20000
+ const liveCustomTicks = axis.annotations.filter((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
20001
+ const hasCustomTicks = liveCustomTicks.length > 0;
20002
+ const strokeThickness = (axis.stroke?.getThickness?.() ?? 0) > 0 && color(axis.stroke?.getFillStyle?.(), ColorRGBA(0, 0, 0, 0)).a > 0 ? axis.stroke.getThickness() : 0;
20003
+ const titleOnly = !strategy.visible && titleVisible && !hasCustomTicks;
20002
20004
  const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
20003
20005
  const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
20004
20006
  const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
@@ -20008,36 +20010,39 @@ function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
20008
20010
  const fill = resolvedTickFill(axis, level, style, theme);
20009
20011
  return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
20010
20012
  });
20011
- const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
20013
+ const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly || !strategy.visible && !hasCustomTicks ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
20012
20014
  const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
20013
- const customLabels = visibleLevels.some(({ level, style, visible }) => visible && (typeof style.formatter === "function" || typeof (level === "major" ? strategy.getMajorFormattingFunction() : strategy.getMinorFormattingFunction()) === "function")) || strategy.getFormattingOffset() !== void 0 || strategy.customMajor !== void 0 || strategy.customMinor !== void 0 || strategy.hasDateTimeFormatting?.() === true;
20014
- const interval = axis.getInterval(), longDefault = !horizontal && strategy.kind === "numeric" && !customLabels && [interval.start, interval.end].some((value) => formatNumeric(value, interval).length * labelFont.getSize() * 0.6 + 17 > 54);
20015
- const changedLayout = contentLayout || titleOnly || margin2 > 0 || visibleLevels.some(({ font: font2, visible }) => visible && !isDefaultFont(font2)) || !isDefaultFont(titleFont) || axis.titleRotation !== void 0 || tickLength > 7 || customLabels || longDefault || strategy.kind === "datetime";
20016
- if (!changedLayout) return { measured: false, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: horizontal ? 44 : 54, labelOffset: horizontal ? axis.opposite ? 10 : 20 : 9, titleOffset: horizontal ? axis.opposite ? 32 : 43 : 48, tickLength, labelWidth: 0, labelAscent: 9, labelDescent: 3, titleWidth: 0, titleAscent: 9, titleDescent: 3, rotation };
20017
20015
  const layout = measuredTickLayout(axis, ctx, void 0, cache, theme, resolveFont), labels = visibleLevels.flatMap(({ level, font: font2, visible }) => visible ? (layout[level] ?? []).filter((t) => t.label.length).map((t) => textMetrics(ctx, t.label, font2, cache)) : []);
20018
- const labelWidth = Math.max(0, ...labels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...labels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...labels.map((m) => m.descent));
20019
- const title = textMetrics(ctx, titleText, titleFont, cache);
20020
- if (contentLayout && axis.titleRotation === void 0) {
20021
- const gutter = 7, labelOffset2 = tickLength + gutter;
20022
- const labelBand = horizontal ? Math.max(0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
20023
- const labelOuter2 = labels.length > 0 ? labelOffset2 + labelBand : tickLength;
20024
- const titleHalf = lineBoxHeight(titleFont) / 2, titleOffset2 = labelOuter2 + (labels.length > 0 ? margin2 : 0) + titleHalf;
20016
+ const customTickLabels = liveCustomTicks.map((annotation) => {
20017
+ const formatted = typeof annotation.textFormatter === "function" ? String(annotation.textFormatter(annotation.value)) : String(annotation.text ?? "");
20018
+ return formatted.length > 0 ? textMetrics(ctx, formatted, labelFont, cache) : void 0;
20019
+ }).filter((m) => !!m);
20020
+ const allLabels = [...labels, ...customTickLabels], hasLabels = allLabels.length > 0;
20021
+ const labelWidth = Math.max(0, ...allLabels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...allLabels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...allLabels.map((m) => m.descent));
20022
+ const title = titleVisible ? textMetrics(ctx, titleText, titleFont, cache) : { width: 0, ascent: titleFont.getSize() * 0.75, descent: titleFont.getSize() * 0.25, baseline: lineBoxBaseline(void 0, titleFont) };
20023
+ if (axis.titleRotation === void 0) {
20024
+ const gutter = 7, labelOffset2 = hasLabels || hasCustomTicks ? tickLength + gutter : 0;
20025
+ const labelBand = horizontal ? Math.max(customTickLabels.length > 0 ? lineBoxHeight(labelFont) : 0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
20026
+ const labelOuter2 = hasLabels ? labelOffset2 + labelBand : hasCustomTicks ? labelOffset2 : tickLength;
20027
+ const titleHalf = lineBoxHeight(titleFont) / 2;
20028
+ const titleBase = labelOuter2 > 0 ? labelOuter2 + (hasLabels ? margin2 : 0) : (strokeThickness > 0 ? strokeThickness / 2 : 0) + gutter;
20029
+ const titleOffset2 = titleBase + titleHalf;
20025
20030
  const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
20026
- return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: extent2 > 0 ? extent2 + gutter : 0, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
20031
+ const laneSize2 = extent2 > 0 ? extent2 + gutter : strokeThickness > 0 ? Math.ceil(strokeThickness) : 0;
20032
+ return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: laneSize2, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
20027
20033
  }
20028
20034
  const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
20029
- const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + (contentLayout ? 5 : 2));
20030
- const labelOuter = titleOnly ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
20035
+ const labelOffset = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + 5);
20036
+ const labelOuter = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
20031
20037
  const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
20032
20038
  const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
20033
- const defaultTitleOffset = horizontal ? axis.opposite ? 32 : 43 : 48;
20034
- const titleOffset = contentLayout ? labelOuter + margin2 + titleInner + 2 : changedLayout ? Math.max(defaultTitleOffset + margin2, labelOuter + margin2 + titleInner + 5) : defaultTitleOffset;
20035
- const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength);
20036
- const baseline = horizontal ? 44 : 54, laneSize = contentLayout ? Math.ceil(extent + (horizontal ? 2 : 0)) : changedLayout ? Math.max(baseline, Math.ceil(extent + 8)) : baseline;
20039
+ const titleOffset = labelOuter + (hasLabels ? margin2 : 0) + titleInner + (labelOuter > 0 ? 2 : 5);
20040
+ const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength, strokeThickness);
20041
+ const laneSize = extent > 0 ? Math.ceil(extent + (horizontal ? 2 : 4)) : 0;
20037
20042
  return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize, labelOffset, titleOffset, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation };
20038
20043
  }
20039
- function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentLayout = false) {
20040
- const result2 = { extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map(), ...contentLayout ? { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 } } : {} };
20044
+ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont) {
20045
+ const result2 = { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 }, extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map() };
20041
20046
  const textCache = /* @__PURE__ */ new Map();
20042
20047
  for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
20043
20048
  const groups = /* @__PURE__ */ new Map();
@@ -20048,14 +20053,14 @@ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentL
20048
20053
  }
20049
20054
  let offset = 0, lane = 0;
20050
20055
  for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
20051
- const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont, contentLayout)]), size = Math.max(contentLayout ? 0 : horizontal ? 44 : 54, ...values.map(([, m]) => m.laneSize));
20056
+ const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
20052
20057
  for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
20053
20058
  offset += size;
20054
20059
  lane++;
20055
20060
  }
20056
20061
  const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
20057
20062
  result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
20058
- if (result2.contentMargins) result2.contentMargins[side] = offset;
20063
+ result2.contentMargins[side] = offset;
20059
20064
  }
20060
20065
  return result2;
20061
20066
  }
@@ -21421,7 +21426,7 @@ var ChartXY = class {
21421
21426
  this.prepareCustomTickPlacementLengths(axesX, axesY);
21422
21427
  const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
21423
21428
  const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
21424
- this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont, !!this.cssTextFonts) : void 0;
21429
+ this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
21425
21430
  const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
21426
21431
  const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
21427
21432
  if (this.kind === "polar") {
@@ -23374,6 +23379,7 @@ var Chart3D = class extends ChartXY {
23374
23379
  this.coordsAxis.z = this.axesZ[0];
23375
23380
  if (this.renderer?.gl && this.canvas)
23376
23381
  this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
23382
+ this.layout();
23377
23383
  this.invalidate();
23378
23384
  }
23379
23385
  /** Project full XYZ axis coordinates with the existing original GPU camera
@@ -25162,7 +25168,7 @@ function cryChart(_options = {}) {
25162
25168
  getChartCount: () => owned2.size
25163
25169
  };
25164
25170
  }
25165
- var version = "1.0.4";
25171
+ var version = "1.0.5";
25166
25172
  var Dashboard = class {
25167
25173
  root;
25168
25174
  cells = /* @__PURE__ */ new Map();
@@ -19934,7 +19934,6 @@ void main() {
19934
19934
  // src/axis-canvas.ts
19935
19935
  var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
19936
19936
  var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
19937
- var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
19938
19937
  var lineBoxHeight = (font2) => font2.getSize() * 0.8;
19939
19938
  function lineBoxBaseline(metrics2, font2) {
19940
19939
  const size = font2.getSize();
@@ -19950,7 +19949,7 @@ void main() {
19950
19949
  }
19951
19950
  let measured;
19952
19951
  try {
19953
- measured = ctx?.measureText(text);
19952
+ measured = ctx?.measureText?.(text);
19954
19953
  } finally {
19955
19954
  if (ctx) {
19956
19955
  if (previous !== void 0) ctx.font = previous;
@@ -19995,10 +19994,13 @@ void main() {
19995
19994
  return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
19996
19995
  });
19997
19996
  }
19998
- function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
19997
+ function metrics(axis, ctx, cache, theme, resolveFont) {
19999
19998
  const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
20000
19999
  const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
20001
- const titleOnly = !strategy.visible && titleVisible && !axis.annotations.some((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
20000
+ const liveCustomTicks = axis.annotations.filter((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
20001
+ const hasCustomTicks = liveCustomTicks.length > 0;
20002
+ const strokeThickness = (axis.stroke?.getThickness?.() ?? 0) > 0 && color(axis.stroke?.getFillStyle?.(), ColorRGBA(0, 0, 0, 0)).a > 0 ? axis.stroke.getThickness() : 0;
20003
+ const titleOnly = !strategy.visible && titleVisible && !hasCustomTicks;
20002
20004
  const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
20003
20005
  const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
20004
20006
  const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
@@ -20008,36 +20010,39 @@ void main() {
20008
20010
  const fill = resolvedTickFill(axis, level, style, theme);
20009
20011
  return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
20010
20012
  });
20011
- const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
20013
+ const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly || !strategy.visible && !hasCustomTicks ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
20012
20014
  const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
20013
- const customLabels = visibleLevels.some(({ level, style, visible }) => visible && (typeof style.formatter === "function" || typeof (level === "major" ? strategy.getMajorFormattingFunction() : strategy.getMinorFormattingFunction()) === "function")) || strategy.getFormattingOffset() !== void 0 || strategy.customMajor !== void 0 || strategy.customMinor !== void 0 || strategy.hasDateTimeFormatting?.() === true;
20014
- const interval = axis.getInterval(), longDefault = !horizontal && strategy.kind === "numeric" && !customLabels && [interval.start, interval.end].some((value) => formatNumeric(value, interval).length * labelFont.getSize() * 0.6 + 17 > 54);
20015
- const changedLayout = contentLayout || titleOnly || margin2 > 0 || visibleLevels.some(({ font: font2, visible }) => visible && !isDefaultFont(font2)) || !isDefaultFont(titleFont) || axis.titleRotation !== void 0 || tickLength > 7 || customLabels || longDefault || strategy.kind === "datetime";
20016
- if (!changedLayout) return { measured: false, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: horizontal ? 44 : 54, labelOffset: horizontal ? axis.opposite ? 10 : 20 : 9, titleOffset: horizontal ? axis.opposite ? 32 : 43 : 48, tickLength, labelWidth: 0, labelAscent: 9, labelDescent: 3, titleWidth: 0, titleAscent: 9, titleDescent: 3, rotation };
20017
20015
  const layout = measuredTickLayout(axis, ctx, void 0, cache, theme, resolveFont), labels = visibleLevels.flatMap(({ level, font: font2, visible }) => visible ? (layout[level] ?? []).filter((t) => t.label.length).map((t) => textMetrics(ctx, t.label, font2, cache)) : []);
20018
- const labelWidth = Math.max(0, ...labels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...labels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...labels.map((m) => m.descent));
20019
- const title = textMetrics(ctx, titleText, titleFont, cache);
20020
- if (contentLayout && axis.titleRotation === void 0) {
20021
- const gutter = 7, labelOffset2 = tickLength + gutter;
20022
- const labelBand = horizontal ? Math.max(0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
20023
- const labelOuter2 = labels.length > 0 ? labelOffset2 + labelBand : tickLength;
20024
- const titleHalf = lineBoxHeight(titleFont) / 2, titleOffset2 = labelOuter2 + (labels.length > 0 ? margin2 : 0) + titleHalf;
20016
+ const customTickLabels = liveCustomTicks.map((annotation) => {
20017
+ const formatted = typeof annotation.textFormatter === "function" ? String(annotation.textFormatter(annotation.value)) : String(annotation.text ?? "");
20018
+ return formatted.length > 0 ? textMetrics(ctx, formatted, labelFont, cache) : void 0;
20019
+ }).filter((m) => !!m);
20020
+ const allLabels = [...labels, ...customTickLabels], hasLabels = allLabels.length > 0;
20021
+ const labelWidth = Math.max(0, ...allLabels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...allLabels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...allLabels.map((m) => m.descent));
20022
+ const title = titleVisible ? textMetrics(ctx, titleText, titleFont, cache) : { width: 0, ascent: titleFont.getSize() * 0.75, descent: titleFont.getSize() * 0.25, baseline: lineBoxBaseline(void 0, titleFont) };
20023
+ if (axis.titleRotation === void 0) {
20024
+ const gutter = 7, labelOffset2 = hasLabels || hasCustomTicks ? tickLength + gutter : 0;
20025
+ const labelBand = horizontal ? Math.max(customTickLabels.length > 0 ? lineBoxHeight(labelFont) : 0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
20026
+ const labelOuter2 = hasLabels ? labelOffset2 + labelBand : hasCustomTicks ? labelOffset2 : tickLength;
20027
+ const titleHalf = lineBoxHeight(titleFont) / 2;
20028
+ const titleBase = labelOuter2 > 0 ? labelOuter2 + (hasLabels ? margin2 : 0) : (strokeThickness > 0 ? strokeThickness / 2 : 0) + gutter;
20029
+ const titleOffset2 = titleBase + titleHalf;
20025
20030
  const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
20026
- return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: extent2 > 0 ? extent2 + gutter : 0, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
20031
+ const laneSize2 = extent2 > 0 ? extent2 + gutter : strokeThickness > 0 ? Math.ceil(strokeThickness) : 0;
20032
+ return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: laneSize2, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
20027
20033
  }
20028
20034
  const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
20029
- const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + (contentLayout ? 5 : 2));
20030
- const labelOuter = titleOnly ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
20035
+ const labelOffset = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + 5);
20036
+ const labelOuter = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
20031
20037
  const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
20032
20038
  const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
20033
- const defaultTitleOffset = horizontal ? axis.opposite ? 32 : 43 : 48;
20034
- const titleOffset = contentLayout ? labelOuter + margin2 + titleInner + 2 : changedLayout ? Math.max(defaultTitleOffset + margin2, labelOuter + margin2 + titleInner + 5) : defaultTitleOffset;
20035
- const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength);
20036
- const baseline = horizontal ? 44 : 54, laneSize = contentLayout ? Math.ceil(extent + (horizontal ? 2 : 0)) : changedLayout ? Math.max(baseline, Math.ceil(extent + 8)) : baseline;
20039
+ const titleOffset = labelOuter + (hasLabels ? margin2 : 0) + titleInner + (labelOuter > 0 ? 2 : 5);
20040
+ const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength, strokeThickness);
20041
+ const laneSize = extent > 0 ? Math.ceil(extent + (horizontal ? 2 : 4)) : 0;
20037
20042
  return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize, labelOffset, titleOffset, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation };
20038
20043
  }
20039
- function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentLayout = false) {
20040
- const result2 = { extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map(), ...contentLayout ? { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 } } : {} };
20044
+ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont) {
20045
+ const result2 = { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 }, extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map() };
20041
20046
  const textCache = /* @__PURE__ */ new Map();
20042
20047
  for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
20043
20048
  const groups = /* @__PURE__ */ new Map();
@@ -20048,14 +20053,14 @@ void main() {
20048
20053
  }
20049
20054
  let offset = 0, lane = 0;
20050
20055
  for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
20051
- const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont, contentLayout)]), size = Math.max(contentLayout ? 0 : horizontal ? 44 : 54, ...values.map(([, m]) => m.laneSize));
20056
+ const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
20052
20057
  for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
20053
20058
  offset += size;
20054
20059
  lane++;
20055
20060
  }
20056
20061
  const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
20057
20062
  result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
20058
- if (result2.contentMargins) result2.contentMargins[side] = offset;
20063
+ result2.contentMargins[side] = offset;
20059
20064
  }
20060
20065
  return result2;
20061
20066
  }
@@ -21421,7 +21426,7 @@ void main() {
21421
21426
  this.prepareCustomTickPlacementLengths(axesX, axesY);
21422
21427
  const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
21423
21428
  const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
21424
- this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont, !!this.cssTextFonts) : void 0;
21429
+ this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
21425
21430
  const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
21426
21431
  const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
21427
21432
  if (this.kind === "polar") {
@@ -23374,6 +23379,7 @@ void main() {
23374
23379
  this.coordsAxis.z = this.axesZ[0];
23375
23380
  if (this.renderer?.gl && this.canvas)
23376
23381
  this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
23382
+ this.layout();
23377
23383
  this.invalidate();
23378
23384
  }
23379
23385
  /** Project full XYZ axis coordinates with the existing original GPU camera
@@ -25162,7 +25168,7 @@ ${sample.position[0].toFixed(4)}, ${sample.position[1].toFixed(4)}`, contains: (
25162
25168
  getChartCount: () => owned2.size
25163
25169
  };
25164
25170
  }
25165
- var version = "1.0.4";
25171
+ var version = "1.0.5";
25166
25172
  var Dashboard = class {
25167
25173
  root;
25168
25174
  cells = /* @__PURE__ */ new Map();
package/dist/crychart.js CHANGED
@@ -19750,7 +19750,6 @@ function fitEllipsoid3D(input, options = {}) {
19750
19750
  // src/axis-canvas.ts
19751
19751
  var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
19752
19752
  var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
19753
- var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
19754
19753
  var lineBoxHeight = (font2) => font2.getSize() * 0.8;
19755
19754
  function lineBoxBaseline(metrics2, font2) {
19756
19755
  const size = font2.getSize();
@@ -19766,7 +19765,7 @@ function textMetrics(ctx, text, font2, cache) {
19766
19765
  }
19767
19766
  let measured;
19768
19767
  try {
19769
- measured = ctx?.measureText(text);
19768
+ measured = ctx?.measureText?.(text);
19770
19769
  } finally {
19771
19770
  if (ctx) {
19772
19771
  if (previous !== void 0) ctx.font = previous;
@@ -19811,10 +19810,13 @@ function measuredTickLayout(axis, ctx, axisSizePixels = axis.getPixelLength(), c
19811
19810
  return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
19812
19811
  });
19813
19812
  }
19814
- function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
19813
+ function metrics(axis, ctx, cache, theme, resolveFont) {
19815
19814
  const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
19816
19815
  const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
19817
- const titleOnly = !strategy.visible && titleVisible && !axis.annotations.some((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
19816
+ const liveCustomTicks = axis.annotations.filter((annotation) => annotation.kind === "tick" && annotation.visible && !annotation.disposed);
19817
+ const hasCustomTicks = liveCustomTicks.length > 0;
19818
+ const strokeThickness = (axis.stroke?.getThickness?.() ?? 0) > 0 && color(axis.stroke?.getFillStyle?.(), ColorRGBA(0, 0, 0, 0)).a > 0 ? axis.stroke.getThickness() : 0;
19819
+ const titleOnly = !strategy.visible && titleVisible && !hasCustomTicks;
19818
19820
  const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
19819
19821
  const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
19820
19822
  const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
@@ -19824,36 +19826,39 @@ function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
19824
19826
  const fill = resolvedTickFill(axis, level, style, theme);
19825
19827
  return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
19826
19828
  });
19827
- const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
19829
+ const margin2 = axis.getMarginAfterTicks(), tickLength = titleOnly || !strategy.visible && !hasCustomTicks ? 0 : Math.max(0, ...visibleLevels.map(({ style }) => style.getTickStyle()?.getThickness?.() > 0 ? style.getTickLength() : 0));
19828
19830
  const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
19829
- const customLabels = visibleLevels.some(({ level, style, visible }) => visible && (typeof style.formatter === "function" || typeof (level === "major" ? strategy.getMajorFormattingFunction() : strategy.getMinorFormattingFunction()) === "function")) || strategy.getFormattingOffset() !== void 0 || strategy.customMajor !== void 0 || strategy.customMinor !== void 0 || strategy.hasDateTimeFormatting?.() === true;
19830
- const interval = axis.getInterval(), longDefault = !horizontal && strategy.kind === "numeric" && !customLabels && [interval.start, interval.end].some((value) => formatNumeric(value, interval).length * labelFont.getSize() * 0.6 + 17 > 54);
19831
- const changedLayout = contentLayout || titleOnly || margin2 > 0 || visibleLevels.some(({ font: font2, visible }) => visible && !isDefaultFont(font2)) || !isDefaultFont(titleFont) || axis.titleRotation !== void 0 || tickLength > 7 || customLabels || longDefault || strategy.kind === "datetime";
19832
- if (!changedLayout) return { measured: false, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: horizontal ? 44 : 54, labelOffset: horizontal ? axis.opposite ? 10 : 20 : 9, titleOffset: horizontal ? axis.opposite ? 32 : 43 : 48, tickLength, labelWidth: 0, labelAscent: 9, labelDescent: 3, titleWidth: 0, titleAscent: 9, titleDescent: 3, rotation };
19833
19831
  const layout = measuredTickLayout(axis, ctx, void 0, cache, theme, resolveFont), labels = visibleLevels.flatMap(({ level, font: font2, visible }) => visible ? (layout[level] ?? []).filter((t) => t.label.length).map((t) => textMetrics(ctx, t.label, font2, cache)) : []);
19834
- const labelWidth = Math.max(0, ...labels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...labels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...labels.map((m) => m.descent));
19835
- const title = textMetrics(ctx, titleText, titleFont, cache);
19836
- if (contentLayout && axis.titleRotation === void 0) {
19837
- const gutter = 7, labelOffset2 = tickLength + gutter;
19838
- const labelBand = horizontal ? Math.max(0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
19839
- const labelOuter2 = labels.length > 0 ? labelOffset2 + labelBand : tickLength;
19840
- const titleHalf = lineBoxHeight(titleFont) / 2, titleOffset2 = labelOuter2 + (labels.length > 0 ? margin2 : 0) + titleHalf;
19832
+ const customTickLabels = liveCustomTicks.map((annotation) => {
19833
+ const formatted = typeof annotation.textFormatter === "function" ? String(annotation.textFormatter(annotation.value)) : String(annotation.text ?? "");
19834
+ return formatted.length > 0 ? textMetrics(ctx, formatted, labelFont, cache) : void 0;
19835
+ }).filter((m) => !!m);
19836
+ const allLabels = [...labels, ...customTickLabels], hasLabels = allLabels.length > 0;
19837
+ const labelWidth = Math.max(0, ...allLabels.map((m) => m.width)), labelAscent = Math.max(labelFont.getSize() * 0.75, ...allLabels.map((m) => m.ascent)), labelDescent = Math.max(labelFont.getSize() * 0.25, ...allLabels.map((m) => m.descent));
19838
+ const title = titleVisible ? textMetrics(ctx, titleText, titleFont, cache) : { width: 0, ascent: titleFont.getSize() * 0.75, descent: titleFont.getSize() * 0.25, baseline: lineBoxBaseline(void 0, titleFont) };
19839
+ if (axis.titleRotation === void 0) {
19840
+ const gutter = 7, labelOffset2 = hasLabels || hasCustomTicks ? tickLength + gutter : 0;
19841
+ const labelBand = horizontal ? Math.max(customTickLabels.length > 0 ? lineBoxHeight(labelFont) : 0, ...visibleLevels.filter((level) => level.visible).map((level) => lineBoxHeight(level.font))) : labelWidth;
19842
+ const labelOuter2 = hasLabels ? labelOffset2 + labelBand : hasCustomTicks ? labelOffset2 : tickLength;
19843
+ const titleHalf = lineBoxHeight(titleFont) / 2;
19844
+ const titleBase = labelOuter2 > 0 ? labelOuter2 + (hasLabels ? margin2 : 0) : (strokeThickness > 0 ? strokeThickness / 2 : 0) + gutter;
19845
+ const titleOffset2 = titleBase + titleHalf;
19841
19846
  const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
19842
- return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: extent2 > 0 ? extent2 + gutter : 0, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
19847
+ const laneSize2 = extent2 > 0 ? extent2 + gutter : strokeThickness > 0 ? Math.ceil(strokeThickness) : 0;
19848
+ return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize: laneSize2, labelOffset: labelOffset2, titleOffset: titleOffset2, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation, lineBoxTitleBaseline: title.baseline };
19843
19849
  }
19844
19850
  const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
19845
- const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + (contentLayout ? 5 : 2));
19846
- const labelOuter = titleOnly ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
19851
+ const labelOffset = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength + 5);
19852
+ const labelOuter = titleOnly || !hasLabels && !hasCustomTicks ? 0 : horizontal ? labelOffset + (axis.opposite ? labelAscent : labelDescent) : labelOffset + labelWidth;
19847
19853
  const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
19848
19854
  const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
19849
- const defaultTitleOffset = horizontal ? axis.opposite ? 32 : 43 : 48;
19850
- const titleOffset = contentLayout ? labelOuter + margin2 + titleInner + 2 : changedLayout ? Math.max(defaultTitleOffset + margin2, labelOuter + margin2 + titleInner + 5) : defaultTitleOffset;
19851
- const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength);
19852
- const baseline = horizontal ? 44 : 54, laneSize = contentLayout ? Math.ceil(extent + (horizontal ? 2 : 0)) : changedLayout ? Math.max(baseline, Math.ceil(extent + 8)) : baseline;
19855
+ const titleOffset = labelOuter + (hasLabels ? margin2 : 0) + titleInner + (labelOuter > 0 ? 2 : 5);
19856
+ const extent = Math.max(labelOuter, titleVisible ? titleOffset + titleOuter : 0, tickLength, strokeThickness);
19857
+ const laneSize = extent > 0 ? Math.ceil(extent + (horizontal ? 2 : 4)) : 0;
19853
19858
  return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize, labelOffset, titleOffset, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation };
19854
19859
  }
19855
- function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentLayout = false) {
19856
- const result2 = { extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map(), ...contentLayout ? { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 } } : {} };
19860
+ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont) {
19861
+ const result2 = { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 }, extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map() };
19857
19862
  const textCache = /* @__PURE__ */ new Map();
19858
19863
  for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
19859
19864
  const groups = /* @__PURE__ */ new Map();
@@ -19864,14 +19869,14 @@ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentL
19864
19869
  }
19865
19870
  let offset = 0, lane = 0;
19866
19871
  for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
19867
- const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont, contentLayout)]), size = Math.max(contentLayout ? 0 : horizontal ? 44 : 54, ...values.map(([, m]) => m.laneSize));
19872
+ const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
19868
19873
  for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
19869
19874
  offset += size;
19870
19875
  lane++;
19871
19876
  }
19872
19877
  const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
19873
19878
  result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
19874
- if (result2.contentMargins) result2.contentMargins[side] = offset;
19879
+ result2.contentMargins[side] = offset;
19875
19880
  }
19876
19881
  return result2;
19877
19882
  }
@@ -21237,7 +21242,7 @@ var ChartXY = class {
21237
21242
  this.prepareCustomTickPlacementLengths(axesX, axesY);
21238
21243
  const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
21239
21244
  const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
21240
- this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont, !!this.cssTextFonts) : void 0;
21245
+ this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
21241
21246
  const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
21242
21247
  const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
21243
21248
  if (this.kind === "polar") {
@@ -23190,6 +23195,7 @@ var Chart3D = class extends ChartXY {
23190
23195
  this.coordsAxis.z = this.axesZ[0];
23191
23196
  if (this.renderer?.gl && this.canvas)
23192
23197
  this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
23198
+ this.layout();
23193
23199
  this.invalidate();
23194
23200
  }
23195
23201
  /** Project full XYZ axis coordinates with the existing original GPU camera
@@ -24978,7 +24984,7 @@ function cryChart(_options = {}) {
24978
24984
  getChartCount: () => owned2.size
24979
24985
  };
24980
24986
  }
24981
- var version = "1.0.4";
24987
+ var version = "1.0.5";
24982
24988
  var Dashboard = class {
24983
24989
  root;
24984
24990
  cells = /* @__PURE__ */ new Map();
@@ -65,8 +65,8 @@ export interface AxisCanvasTheme {
65
65
  export declare function measureChartTitleContent(ctx: CanvasRenderingContext2D | undefined, text: string, font: FontSettings, dpr?: number): number;
66
66
  type TickLevel = 'great' | 'major' | 'minor';
67
67
  export declare function resolvedTickFill(axis: Axis, level: TickLevel, style: TickStyle, theme?: AxisCanvasTheme, forDrawing?: boolean): any;
68
- /** Additional space only; callers retain their existing default 44/54px lanes. */
69
- export declare function measureAxisCanvasLayout(ctx: CanvasRenderingContext2D | undefined, axesX: readonly Axis[], axesY: readonly Axis[], theme?: AxisCanvasTheme, resolveFont?: (font: FontSettings) => FontSettings, contentLayout?: boolean): AxisCanvasLayout;
68
+ /** Measure compact content-based axis lanes for XY charts regardless of textRenderer. */
69
+ export declare function measureAxisCanvasLayout(ctx: CanvasRenderingContext2D | undefined, axesX: readonly Axis[], axesY: readonly Axis[], theme?: AxisCanvasTheme, resolveFont?: (font: FontSettings) => FontSettings): AxisCanvasLayout;
70
70
  export declare function axisCanvasLaneOffset(layout: AxisCanvasLayout, axis: Axis): number;
71
71
  /** Keep the actual ink inside the physical axis range, without changing text.
72
72
  * A label wider than that range cannot fit: align its nearer end and retain
@@ -51,7 +51,7 @@ export declare function cryChart(_options?: Record<string, unknown>): {
51
51
  /** Live charts owned by this context; disposed charts are released immediately. */
52
52
  getChartCount: () => number;
53
53
  };
54
- export declare const version = "1.0.4";
54
+ export declare const version = "1.0.5";
55
55
  export declare class Dashboard {
56
56
  readonly root: HTMLDivElement;
57
57
  private cells;
package/docs/npm-usage.md CHANGED
@@ -3,7 +3,7 @@
3
3
  在应用目录安装固定版本:
4
4
 
5
5
  ```powershell
6
- pnpm add --save-exact @crysound/crychart@1.0.4 --registry=https://registry.npmjs.org/
6
+ pnpm add --save-exact @crysound/crychart@1.0.5 --registry=https://registry.npmjs.org/
7
7
  ```
8
8
 
9
9
  ES 模块和 TypeScript 使用相同入口:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crysound/crychart",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "CRYChart chart engine with streaming data, interactive axes and WebGL rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/crychart.cjs",