@crysound/crychart 1.0.3 → 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 +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/crychart.cjs +59 -33
- package/dist/crychart.global.js +59 -33
- package/dist/crychart.js +59 -33
- package/dist/types/axis-canvas.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/docs/npm-usage.md +1 -1
- package/package.json +1 -1
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
@@ -16529,6 +16529,7 @@ void main(){
|
|
|
16529
16529
|
if(u_dashCount>0){float phase=mod(mix(v_dashPhase.x,v_dashPhase.y,rawT),u_dashPeriod);for(int i=0;i<16;i++){if(i>=u_dashCount)break;if(phase<u_dash[i]){if(i%2==1)discard;break;}phase-=u_dash[i];}}
|
|
16530
16530
|
}
|
|
16531
16531
|
}`;
|
|
16532
|
+
var canvasStrokePointLimit = 8192;
|
|
16532
16533
|
var DataRenderer = class {
|
|
16533
16534
|
constructor(canvas, options = {}) {
|
|
16534
16535
|
this.canvas = canvas;
|
|
@@ -17178,6 +17179,7 @@ var DataRenderer = class {
|
|
|
17178
17179
|
ctx.lineWidth = p.thickness;
|
|
17179
17180
|
ctx.setLineDash(p.mode === "line" ? [...p.dashPattern ?? []] : []);
|
|
17180
17181
|
const first = p.drawFirst ?? 0, end = first + (p.drawCount ?? p.count);
|
|
17182
|
+
const batchSolidLine = p.mode === "line" && !p.colors && !p.dashPattern?.length && a === 1 && Number.isFinite(p.thickness) && p.thickness > 0 && end - first > canvasStrokePointLimit;
|
|
17181
17183
|
if (pointOutline) for (let i = first; i < end; i++) {
|
|
17182
17184
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width;
|
|
17183
17185
|
const y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17200,6 +17202,7 @@ var DataRenderer = class {
|
|
|
17200
17202
|
}
|
|
17201
17203
|
ctx.beginPath();
|
|
17202
17204
|
let pen = false;
|
|
17205
|
+
let pathPoints = 0;
|
|
17203
17206
|
let previousX = 0, previousY = 0, arcLength = 0;
|
|
17204
17207
|
for (let i = first; i < end; i++) {
|
|
17205
17208
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width, y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17258,10 +17261,27 @@ var DataRenderer = class {
|
|
|
17258
17261
|
previousX = x;
|
|
17259
17262
|
previousY = y;
|
|
17260
17263
|
pen = true;
|
|
17261
|
-
} else
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
|
|
17264
|
+
} else {
|
|
17265
|
+
if (batchSolidLine && pathPoints === canvasStrokePointLimit - 1) {
|
|
17266
|
+
const midX = previousX / 2 + x / 2;
|
|
17267
|
+
const midY = previousY / 2 + y / 2;
|
|
17268
|
+
if (pen) ctx.lineTo(midX, midY);
|
|
17269
|
+
ctx.stroke();
|
|
17270
|
+
this.stats.drawCalls++;
|
|
17271
|
+
ctx.beginPath();
|
|
17272
|
+
if (pen) ctx.moveTo(midX, midY);
|
|
17273
|
+
pathPoints = pen ? 1 : 0;
|
|
17274
|
+
}
|
|
17275
|
+
if (pen) ctx.lineTo(x, y);
|
|
17276
|
+
else {
|
|
17277
|
+
ctx.moveTo(x, y);
|
|
17278
|
+
pen = true;
|
|
17279
|
+
}
|
|
17280
|
+
if (batchSolidLine) {
|
|
17281
|
+
previousX = x;
|
|
17282
|
+
previousY = y;
|
|
17283
|
+
pathPoints++;
|
|
17284
|
+
}
|
|
17265
17285
|
}
|
|
17266
17286
|
}
|
|
17267
17287
|
if (!p.colors) {
|
|
@@ -19914,7 +19934,6 @@ function fitEllipsoid3D(input, options = {}) {
|
|
|
19914
19934
|
// src/axis-canvas.ts
|
|
19915
19935
|
var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
|
|
19916
19936
|
var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
|
|
19917
|
-
var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
|
|
19918
19937
|
var lineBoxHeight = (font2) => font2.getSize() * 0.8;
|
|
19919
19938
|
function lineBoxBaseline(metrics2, font2) {
|
|
19920
19939
|
const size = font2.getSize();
|
|
@@ -19930,7 +19949,7 @@ function textMetrics(ctx, text, font2, cache) {
|
|
|
19930
19949
|
}
|
|
19931
19950
|
let measured;
|
|
19932
19951
|
try {
|
|
19933
|
-
measured = ctx?.measureText(text);
|
|
19952
|
+
measured = ctx?.measureText?.(text);
|
|
19934
19953
|
} finally {
|
|
19935
19954
|
if (ctx) {
|
|
19936
19955
|
if (previous !== void 0) ctx.font = previous;
|
|
@@ -19975,10 +19994,13 @@ function measuredTickLayout(axis, ctx, axisSizePixels = axis.getPixelLength(), c
|
|
|
19975
19994
|
return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
|
|
19976
19995
|
});
|
|
19977
19996
|
}
|
|
19978
|
-
function metrics(axis, ctx, cache, theme, resolveFont
|
|
19997
|
+
function metrics(axis, ctx, cache, theme, resolveFont) {
|
|
19979
19998
|
const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
|
|
19980
19999
|
const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
|
|
19981
|
-
const
|
|
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;
|
|
19982
20004
|
const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
|
|
19983
20005
|
const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
|
|
19984
20006
|
const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
|
|
@@ -19988,36 +20010,39 @@ function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
|
|
|
19988
20010
|
const fill = resolvedTickFill(axis, level, style, theme);
|
|
19989
20011
|
return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
|
|
19990
20012
|
});
|
|
19991
|
-
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));
|
|
19992
20014
|
const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
|
|
19993
|
-
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;
|
|
19994
|
-
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);
|
|
19995
|
-
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";
|
|
19996
|
-
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 };
|
|
19997
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)) : []);
|
|
19998
|
-
const
|
|
19999
|
-
|
|
20000
|
-
|
|
20001
|
-
|
|
20002
|
-
|
|
20003
|
-
|
|
20004
|
-
|
|
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;
|
|
20005
20030
|
const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
|
|
20006
|
-
|
|
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 };
|
|
20007
20033
|
}
|
|
20008
20034
|
const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
|
|
20009
|
-
const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength +
|
|
20010
|
-
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;
|
|
20011
20037
|
const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
|
|
20012
20038
|
const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
|
|
20013
|
-
const
|
|
20014
|
-
const
|
|
20015
|
-
const
|
|
20016
|
-
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;
|
|
20017
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 };
|
|
20018
20043
|
}
|
|
20019
|
-
function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont
|
|
20020
|
-
const result2 = {
|
|
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() };
|
|
20021
20046
|
const textCache = /* @__PURE__ */ new Map();
|
|
20022
20047
|
for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
|
|
20023
20048
|
const groups = /* @__PURE__ */ new Map();
|
|
@@ -20028,14 +20053,14 @@ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentL
|
|
|
20028
20053
|
}
|
|
20029
20054
|
let offset = 0, lane = 0;
|
|
20030
20055
|
for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
|
|
20031
|
-
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont
|
|
20056
|
+
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
|
|
20032
20057
|
for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
|
|
20033
20058
|
offset += size;
|
|
20034
20059
|
lane++;
|
|
20035
20060
|
}
|
|
20036
20061
|
const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
|
|
20037
20062
|
result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
|
|
20038
|
-
|
|
20063
|
+
result2.contentMargins[side] = offset;
|
|
20039
20064
|
}
|
|
20040
20065
|
return result2;
|
|
20041
20066
|
}
|
|
@@ -21401,7 +21426,7 @@ var ChartXY = class {
|
|
|
21401
21426
|
this.prepareCustomTickPlacementLengths(axesX, axesY);
|
|
21402
21427
|
const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21403
21428
|
const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21404
|
-
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont
|
|
21429
|
+
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
|
|
21405
21430
|
const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21406
21431
|
const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21407
21432
|
if (this.kind === "polar") {
|
|
@@ -23354,6 +23379,7 @@ var Chart3D = class extends ChartXY {
|
|
|
23354
23379
|
this.coordsAxis.z = this.axesZ[0];
|
|
23355
23380
|
if (this.renderer?.gl && this.canvas)
|
|
23356
23381
|
this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
|
|
23382
|
+
this.layout();
|
|
23357
23383
|
this.invalidate();
|
|
23358
23384
|
}
|
|
23359
23385
|
/** Project full XYZ axis coordinates with the existing original GPU camera
|
|
@@ -25142,7 +25168,7 @@ function cryChart(_options = {}) {
|
|
|
25142
25168
|
getChartCount: () => owned2.size
|
|
25143
25169
|
};
|
|
25144
25170
|
}
|
|
25145
|
-
var version = "1.0.
|
|
25171
|
+
var version = "1.0.5";
|
|
25146
25172
|
var Dashboard = class {
|
|
25147
25173
|
root;
|
|
25148
25174
|
cells = /* @__PURE__ */ new Map();
|
package/dist/crychart.global.js
CHANGED
|
@@ -16529,6 +16529,7 @@ void main(){
|
|
|
16529
16529
|
if(u_dashCount>0){float phase=mod(mix(v_dashPhase.x,v_dashPhase.y,rawT),u_dashPeriod);for(int i=0;i<16;i++){if(i>=u_dashCount)break;if(phase<u_dash[i]){if(i%2==1)discard;break;}phase-=u_dash[i];}}
|
|
16530
16530
|
}
|
|
16531
16531
|
}`;
|
|
16532
|
+
var canvasStrokePointLimit = 8192;
|
|
16532
16533
|
var DataRenderer = class {
|
|
16533
16534
|
constructor(canvas, options = {}) {
|
|
16534
16535
|
this.canvas = canvas;
|
|
@@ -17178,6 +17179,7 @@ void main(){
|
|
|
17178
17179
|
ctx.lineWidth = p.thickness;
|
|
17179
17180
|
ctx.setLineDash(p.mode === "line" ? [...p.dashPattern ?? []] : []);
|
|
17180
17181
|
const first = p.drawFirst ?? 0, end = first + (p.drawCount ?? p.count);
|
|
17182
|
+
const batchSolidLine = p.mode === "line" && !p.colors && !p.dashPattern?.length && a === 1 && Number.isFinite(p.thickness) && p.thickness > 0 && end - first > canvasStrokePointLimit;
|
|
17181
17183
|
if (pointOutline) for (let i = first; i < end; i++) {
|
|
17182
17184
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width;
|
|
17183
17185
|
const y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17200,6 +17202,7 @@ void main(){
|
|
|
17200
17202
|
}
|
|
17201
17203
|
ctx.beginPath();
|
|
17202
17204
|
let pen = false;
|
|
17205
|
+
let pathPoints = 0;
|
|
17203
17206
|
let previousX = 0, previousY = 0, arcLength = 0;
|
|
17204
17207
|
for (let i = first; i < end; i++) {
|
|
17205
17208
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width, y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17258,10 +17261,27 @@ void main(){
|
|
|
17258
17261
|
previousX = x;
|
|
17259
17262
|
previousY = y;
|
|
17260
17263
|
pen = true;
|
|
17261
|
-
} else
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
|
|
17264
|
+
} else {
|
|
17265
|
+
if (batchSolidLine && pathPoints === canvasStrokePointLimit - 1) {
|
|
17266
|
+
const midX = previousX / 2 + x / 2;
|
|
17267
|
+
const midY = previousY / 2 + y / 2;
|
|
17268
|
+
if (pen) ctx.lineTo(midX, midY);
|
|
17269
|
+
ctx.stroke();
|
|
17270
|
+
this.stats.drawCalls++;
|
|
17271
|
+
ctx.beginPath();
|
|
17272
|
+
if (pen) ctx.moveTo(midX, midY);
|
|
17273
|
+
pathPoints = pen ? 1 : 0;
|
|
17274
|
+
}
|
|
17275
|
+
if (pen) ctx.lineTo(x, y);
|
|
17276
|
+
else {
|
|
17277
|
+
ctx.moveTo(x, y);
|
|
17278
|
+
pen = true;
|
|
17279
|
+
}
|
|
17280
|
+
if (batchSolidLine) {
|
|
17281
|
+
previousX = x;
|
|
17282
|
+
previousY = y;
|
|
17283
|
+
pathPoints++;
|
|
17284
|
+
}
|
|
17265
17285
|
}
|
|
17266
17286
|
}
|
|
17267
17287
|
if (!p.colors) {
|
|
@@ -19914,7 +19934,6 @@ void main() {
|
|
|
19914
19934
|
// src/axis-canvas.ts
|
|
19915
19935
|
var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
|
|
19916
19936
|
var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
|
|
19917
|
-
var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
|
|
19918
19937
|
var lineBoxHeight = (font2) => font2.getSize() * 0.8;
|
|
19919
19938
|
function lineBoxBaseline(metrics2, font2) {
|
|
19920
19939
|
const size = font2.getSize();
|
|
@@ -19930,7 +19949,7 @@ void main() {
|
|
|
19930
19949
|
}
|
|
19931
19950
|
let measured;
|
|
19932
19951
|
try {
|
|
19933
|
-
measured = ctx?.measureText(text);
|
|
19952
|
+
measured = ctx?.measureText?.(text);
|
|
19934
19953
|
} finally {
|
|
19935
19954
|
if (ctx) {
|
|
19936
19955
|
if (previous !== void 0) ctx.font = previous;
|
|
@@ -19975,10 +19994,13 @@ void main() {
|
|
|
19975
19994
|
return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
|
|
19976
19995
|
});
|
|
19977
19996
|
}
|
|
19978
|
-
function metrics(axis, ctx, cache, theme, resolveFont
|
|
19997
|
+
function metrics(axis, ctx, cache, theme, resolveFont) {
|
|
19979
19998
|
const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
|
|
19980
19999
|
const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
|
|
19981
|
-
const
|
|
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;
|
|
19982
20004
|
const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
|
|
19983
20005
|
const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
|
|
19984
20006
|
const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
|
|
@@ -19988,36 +20010,39 @@ void main() {
|
|
|
19988
20010
|
const fill = resolvedTickFill(axis, level, style, theme);
|
|
19989
20011
|
return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
|
|
19990
20012
|
});
|
|
19991
|
-
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));
|
|
19992
20014
|
const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
|
|
19993
|
-
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;
|
|
19994
|
-
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);
|
|
19995
|
-
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";
|
|
19996
|
-
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 };
|
|
19997
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)) : []);
|
|
19998
|
-
const
|
|
19999
|
-
|
|
20000
|
-
|
|
20001
|
-
|
|
20002
|
-
|
|
20003
|
-
|
|
20004
|
-
|
|
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;
|
|
20005
20030
|
const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
|
|
20006
|
-
|
|
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 };
|
|
20007
20033
|
}
|
|
20008
20034
|
const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
|
|
20009
|
-
const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength +
|
|
20010
|
-
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;
|
|
20011
20037
|
const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
|
|
20012
20038
|
const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
|
|
20013
|
-
const
|
|
20014
|
-
const
|
|
20015
|
-
const
|
|
20016
|
-
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;
|
|
20017
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 };
|
|
20018
20043
|
}
|
|
20019
|
-
function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont
|
|
20020
|
-
const result2 = {
|
|
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() };
|
|
20021
20046
|
const textCache = /* @__PURE__ */ new Map();
|
|
20022
20047
|
for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
|
|
20023
20048
|
const groups = /* @__PURE__ */ new Map();
|
|
@@ -20028,14 +20053,14 @@ void main() {
|
|
|
20028
20053
|
}
|
|
20029
20054
|
let offset = 0, lane = 0;
|
|
20030
20055
|
for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
|
|
20031
|
-
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont
|
|
20056
|
+
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
|
|
20032
20057
|
for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
|
|
20033
20058
|
offset += size;
|
|
20034
20059
|
lane++;
|
|
20035
20060
|
}
|
|
20036
20061
|
const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
|
|
20037
20062
|
result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
|
|
20038
|
-
|
|
20063
|
+
result2.contentMargins[side] = offset;
|
|
20039
20064
|
}
|
|
20040
20065
|
return result2;
|
|
20041
20066
|
}
|
|
@@ -21401,7 +21426,7 @@ void main() {
|
|
|
21401
21426
|
this.prepareCustomTickPlacementLengths(axesX, axesY);
|
|
21402
21427
|
const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21403
21428
|
const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21404
|
-
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont
|
|
21429
|
+
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
|
|
21405
21430
|
const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21406
21431
|
const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21407
21432
|
if (this.kind === "polar") {
|
|
@@ -23354,6 +23379,7 @@ void main() {
|
|
|
23354
23379
|
this.coordsAxis.z = this.axesZ[0];
|
|
23355
23380
|
if (this.renderer?.gl && this.canvas)
|
|
23356
23381
|
this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
|
|
23382
|
+
this.layout();
|
|
23357
23383
|
this.invalidate();
|
|
23358
23384
|
}
|
|
23359
23385
|
/** Project full XYZ axis coordinates with the existing original GPU camera
|
|
@@ -25142,7 +25168,7 @@ ${sample.position[0].toFixed(4)}, ${sample.position[1].toFixed(4)}`, contains: (
|
|
|
25142
25168
|
getChartCount: () => owned2.size
|
|
25143
25169
|
};
|
|
25144
25170
|
}
|
|
25145
|
-
var version = "1.0.
|
|
25171
|
+
var version = "1.0.5";
|
|
25146
25172
|
var Dashboard = class {
|
|
25147
25173
|
root;
|
|
25148
25174
|
cells = /* @__PURE__ */ new Map();
|
package/dist/crychart.js
CHANGED
|
@@ -16345,6 +16345,7 @@ void main(){
|
|
|
16345
16345
|
if(u_dashCount>0){float phase=mod(mix(v_dashPhase.x,v_dashPhase.y,rawT),u_dashPeriod);for(int i=0;i<16;i++){if(i>=u_dashCount)break;if(phase<u_dash[i]){if(i%2==1)discard;break;}phase-=u_dash[i];}}
|
|
16346
16346
|
}
|
|
16347
16347
|
}`;
|
|
16348
|
+
var canvasStrokePointLimit = 8192;
|
|
16348
16349
|
var DataRenderer = class {
|
|
16349
16350
|
constructor(canvas, options = {}) {
|
|
16350
16351
|
this.canvas = canvas;
|
|
@@ -16994,6 +16995,7 @@ var DataRenderer = class {
|
|
|
16994
16995
|
ctx.lineWidth = p.thickness;
|
|
16995
16996
|
ctx.setLineDash(p.mode === "line" ? [...p.dashPattern ?? []] : []);
|
|
16996
16997
|
const first = p.drawFirst ?? 0, end = first + (p.drawCount ?? p.count);
|
|
16998
|
+
const batchSolidLine = p.mode === "line" && !p.colors && !p.dashPattern?.length && a === 1 && Number.isFinite(p.thickness) && p.thickness > 0 && end - first > canvasStrokePointLimit;
|
|
16997
16999
|
if (pointOutline) for (let i = first; i < end; i++) {
|
|
16998
17000
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width;
|
|
16999
17001
|
const y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17016,6 +17018,7 @@ var DataRenderer = class {
|
|
|
17016
17018
|
}
|
|
17017
17019
|
ctx.beginPath();
|
|
17018
17020
|
let pen = false;
|
|
17021
|
+
let pathPoints = 0;
|
|
17019
17022
|
let previousX = 0, previousY = 0, arcLength = 0;
|
|
17020
17023
|
for (let i = first; i < end; i++) {
|
|
17021
17024
|
const x = rect.left + (p.positions[2 * i] + p.origin.x - p.domain.x.start) / (p.domain.x.end - p.domain.x.start) * rect.width, y = rect.top + rect.height - (p.positions[2 * i + 1] + p.origin.y - p.domain.y.start) / (p.domain.y.end - p.domain.y.start) * rect.height;
|
|
@@ -17074,10 +17077,27 @@ var DataRenderer = class {
|
|
|
17074
17077
|
previousX = x;
|
|
17075
17078
|
previousY = y;
|
|
17076
17079
|
pen = true;
|
|
17077
|
-
} else
|
|
17078
|
-
|
|
17079
|
-
|
|
17080
|
-
|
|
17080
|
+
} else {
|
|
17081
|
+
if (batchSolidLine && pathPoints === canvasStrokePointLimit - 1) {
|
|
17082
|
+
const midX = previousX / 2 + x / 2;
|
|
17083
|
+
const midY = previousY / 2 + y / 2;
|
|
17084
|
+
if (pen) ctx.lineTo(midX, midY);
|
|
17085
|
+
ctx.stroke();
|
|
17086
|
+
this.stats.drawCalls++;
|
|
17087
|
+
ctx.beginPath();
|
|
17088
|
+
if (pen) ctx.moveTo(midX, midY);
|
|
17089
|
+
pathPoints = pen ? 1 : 0;
|
|
17090
|
+
}
|
|
17091
|
+
if (pen) ctx.lineTo(x, y);
|
|
17092
|
+
else {
|
|
17093
|
+
ctx.moveTo(x, y);
|
|
17094
|
+
pen = true;
|
|
17095
|
+
}
|
|
17096
|
+
if (batchSolidLine) {
|
|
17097
|
+
previousX = x;
|
|
17098
|
+
previousY = y;
|
|
17099
|
+
pathPoints++;
|
|
17100
|
+
}
|
|
17081
17101
|
}
|
|
17082
17102
|
}
|
|
17083
17103
|
if (!p.colors) {
|
|
@@ -19730,7 +19750,6 @@ function fitEllipsoid3D(input, options = {}) {
|
|
|
19730
19750
|
// src/axis-canvas.ts
|
|
19731
19751
|
var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
|
|
19732
19752
|
var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
|
|
19733
|
-
var isDefaultFont = (font2) => font2.getSize() === 12 && font2.family === "sans-serif" && font2.weight === "normal" && font2.style === "normal" && font2.variant === "normal";
|
|
19734
19753
|
var lineBoxHeight = (font2) => font2.getSize() * 0.8;
|
|
19735
19754
|
function lineBoxBaseline(metrics2, font2) {
|
|
19736
19755
|
const size = font2.getSize();
|
|
@@ -19746,7 +19765,7 @@ function textMetrics(ctx, text, font2, cache) {
|
|
|
19746
19765
|
}
|
|
19747
19766
|
let measured;
|
|
19748
19767
|
try {
|
|
19749
|
-
measured = ctx?.measureText(text);
|
|
19768
|
+
measured = ctx?.measureText?.(text);
|
|
19750
19769
|
} finally {
|
|
19751
19770
|
if (ctx) {
|
|
19752
19771
|
if (previous !== void 0) ctx.font = previous;
|
|
@@ -19791,10 +19810,13 @@ function measuredTickLayout(axis, ctx, axisSizePixels = axis.getPixelLength(), c
|
|
|
19791
19810
|
return axis.direction === "x" ? measured.width : measured.ascent + measured.descent;
|
|
19792
19811
|
});
|
|
19793
19812
|
}
|
|
19794
|
-
function metrics(axis, ctx, cache, theme, resolveFont
|
|
19813
|
+
function metrics(axis, ctx, cache, theme, resolveFont) {
|
|
19795
19814
|
const horizontal = axis.direction === "x", strategy = axis.tickStrategy, tick = strategy.getMajorTickStyle();
|
|
19796
19815
|
const titleText = axis.getDisplayTitle(), titleVisible = titleText.length > 0 && color(axis.titleFill, ColorRGBA(190, 200, 215)).a > 0;
|
|
19797
|
-
const
|
|
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;
|
|
19798
19820
|
const baseFont = tick.hasLabelFontOverride() ? tick.getLabelFont() : theme?.font ?? tick.getLabelFont();
|
|
19799
19821
|
const labelFont = resolveFont?.(baseFont) ?? baseFont, titleFont = resolveFont?.(axis.titleFont) ?? axis.titleFont;
|
|
19800
19822
|
const visibleLevels = ["major", "minor", "great"].flatMap((level) => {
|
|
@@ -19804,36 +19826,39 @@ function metrics(axis, ctx, cache, theme, resolveFont, contentLayout = false) {
|
|
|
19804
19826
|
const fill = resolvedTickFill(axis, level, style, theme);
|
|
19805
19827
|
return [{ level, style, font: font2, visible: color(fill, ColorRGBA(0, 0, 0, 0)).a > 0 }];
|
|
19806
19828
|
});
|
|
19807
|
-
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));
|
|
19808
19830
|
const rotation = (axis.titleRotation ?? (horizontal ? 0 : -90)) * Math.PI / 180;
|
|
19809
|
-
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;
|
|
19810
|
-
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);
|
|
19811
|
-
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";
|
|
19812
|
-
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 };
|
|
19813
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)) : []);
|
|
19814
|
-
const
|
|
19815
|
-
|
|
19816
|
-
|
|
19817
|
-
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
|
|
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;
|
|
19821
19846
|
const extent2 = Math.max(labelOuter2, titleVisible ? titleOffset2 + titleHalf : 0);
|
|
19822
|
-
|
|
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 };
|
|
19823
19849
|
}
|
|
19824
19850
|
const titleBox = rotatedBounds(title.width, title.ascent, title.descent, rotation);
|
|
19825
|
-
const labelOffset = titleOnly ? 0 : horizontal ? axis.opposite ? Math.max(10, tickLength + labelDescent + 3) : Math.max(20, tickLength + labelAscent + 3) : Math.max(9, tickLength +
|
|
19826
|
-
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;
|
|
19827
19853
|
const titleInner = horizontal ? axis.opposite ? titleBox.bottom : -titleBox.top : axis.opposite ? -titleBox.left : titleBox.right;
|
|
19828
19854
|
const titleOuter = horizontal ? axis.opposite ? -titleBox.top : titleBox.bottom : axis.opposite ? titleBox.right : -titleBox.left;
|
|
19829
|
-
const
|
|
19830
|
-
const
|
|
19831
|
-
const
|
|
19832
|
-
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;
|
|
19833
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 };
|
|
19834
19859
|
}
|
|
19835
|
-
function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont
|
|
19836
|
-
const result2 = {
|
|
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() };
|
|
19837
19862
|
const textCache = /* @__PURE__ */ new Map();
|
|
19838
19863
|
for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
|
|
19839
19864
|
const groups = /* @__PURE__ */ new Map();
|
|
@@ -19844,14 +19869,14 @@ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, contentL
|
|
|
19844
19869
|
}
|
|
19845
19870
|
let offset = 0, lane = 0;
|
|
19846
19871
|
for (const [, axes] of [...groups].sort((a, b) => a[0] - b[0])) {
|
|
19847
|
-
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont
|
|
19872
|
+
const values = axes.map((axis) => [axis, metrics(axis, ctx, textCache, theme, resolveFont)]), size = Math.max(0, ...values.map(([, m]) => m.laneSize));
|
|
19848
19873
|
for (const [axis, value] of values) result2.axes.set(axis, { ...value, lane, laneOffset: offset, laneSize: size });
|
|
19849
19874
|
offset += size;
|
|
19850
19875
|
lane++;
|
|
19851
19876
|
}
|
|
19852
19877
|
const side = horizontal ? opposite ? "top" : "bottom" : opposite ? "right" : "left";
|
|
19853
19878
|
result2.extraMargins[side] = Math.max(0, offset - lane * (horizontal ? 44 : 54));
|
|
19854
|
-
|
|
19879
|
+
result2.contentMargins[side] = offset;
|
|
19855
19880
|
}
|
|
19856
19881
|
return result2;
|
|
19857
19882
|
}
|
|
@@ -21217,7 +21242,7 @@ var ChartXY = class {
|
|
|
21217
21242
|
this.prepareCustomTickPlacementLengths(axesX, axesY);
|
|
21218
21243
|
const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21219
21244
|
const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
|
|
21220
|
-
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont
|
|
21245
|
+
this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
|
|
21221
21246
|
const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21222
21247
|
const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
|
|
21223
21248
|
if (this.kind === "polar") {
|
|
@@ -23170,6 +23195,7 @@ var Chart3D = class extends ChartXY {
|
|
|
23170
23195
|
this.coordsAxis.z = this.axesZ[0];
|
|
23171
23196
|
if (this.renderer?.gl && this.canvas)
|
|
23172
23197
|
this.gpu3d = new DataRenderer3D(this.renderer.gl, this.canvas);
|
|
23198
|
+
this.layout();
|
|
23173
23199
|
this.invalidate();
|
|
23174
23200
|
}
|
|
23175
23201
|
/** Project full XYZ axis coordinates with the existing original GPU camera
|
|
@@ -24958,7 +24984,7 @@ function cryChart(_options = {}) {
|
|
|
24958
24984
|
getChartCount: () => owned2.size
|
|
24959
24985
|
};
|
|
24960
24986
|
}
|
|
24961
|
-
var version = "1.0.
|
|
24987
|
+
var version = "1.0.5";
|
|
24962
24988
|
var Dashboard = class {
|
|
24963
24989
|
root;
|
|
24964
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
|
-
/**
|
|
69
|
-
export declare function measureAxisCanvasLayout(ctx: CanvasRenderingContext2D | undefined, axesX: readonly Axis[], axesY: readonly Axis[], theme?: AxisCanvasTheme, resolveFont?: (font: FontSettings) => FontSettings
|
|
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
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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.
|
|
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