优化:按分析章节整合图表解读与完整报告导出

This commit is contained in:
2026-10-23 21:36:28 +08:00
parent 13695da433
commit ec71609343
21 changed files with 1607 additions and 259 deletions
+261 -62
View File
@@ -2,6 +2,8 @@ import type { EChartsCoreOption } from 'echarts/core';
export type AnalysisVisualUnit = 'ratio' | 'kg' | 'pp' | 'count';
export type AnalysisVisualStage = 'black' | 'bright';
export type AnalysisVisualSectionKey = 'overview' | 'stage' | 'department' | 'group' | 'product' | 'category_black' | 'category_bright' | 'defect_black' | 'defect_bright' | 'trend' | 'composition';
export type AnalysisVisualDimension = 'department' | 'group' | 'product' | 'category' | 'defect';
export type AnalysisVisualContextValue = string | number | boolean | Array<string | number | boolean> | Record<string, string[]>;
export type AnalysisVisualContext = Record<string, AnalysisVisualContextValue>;
@@ -37,6 +39,8 @@ export interface AnalysisVisual {
invalidValueCells: string[];
chartable: boolean;
chartIssue?: string;
sectionKey?: AnalysisVisualSectionKey;
dimension?: AnalysisVisualDimension;
}
export interface ParseVisualsResult {
@@ -52,13 +56,20 @@ export interface VisualChartTheme {
colors?: string[];
}
export const MAX_ANALYSIS_VISUALS = 3;
export const MAX_ANALYSIS_VISUALS = 12;
export const MAX_VISUAL_BYTES = 256 * 1024;
export const MAX_VISUAL_CATEGORIES = 36;
export const MAX_VISUAL_SERIES = 4;
const UNIT_VALUES = new Set<AnalysisVisualUnit>(['ratio', 'kg', 'pp', 'count']);
const CHART_TYPES = new Set(['bar', 'line', 'column', 'area', 'heatmap', 'donut', 'pareto']);
const CHART_TYPES = new Set(['bar', 'line', 'column', 'area', 'heatmap', 'donut', 'pareto', 'waterfall']);
const SECTION_KEYS = new Set<AnalysisVisualSectionKey>(['overview', 'stage', 'department', 'group', 'product', 'category_black', 'category_bright', 'defect_black', 'defect_bright', 'trend', 'composition']);
const DIMENSIONS = new Set<AnalysisVisualDimension>(['department', 'group', 'product', 'category', 'defect']);
const VISUAL_KEYS = new Set(['id', 'type', 'title', 'subtitle', 'unit', 'categories', 'series', 'evidenceRefs', 'requiredFields', 'scope', 'period', 'comparisonPeriod', 'stage', 'metric', 'coverage', 'note', 'originTurnId', 'sectionKey', 'dimension']);
const CATEGORY_KEYS = new Set(['key', 'label']);
const SERIES_KEYS = new Set(['key', 'label', 'values']);
const COVERAGE_KEYS = new Set(['totalRows', 'returnedRows', 'truncated', 'shareBasis']);
const PARSED_VISUALS = new WeakSet<object>();
const DONUT_CATEGORY_KEYS: Record<AnalysisVisualStage, Set<string>> = {
black: new Set(['black_responsibility_scrap', 'black_material_scrap', 'black_external_scrap']),
bright: new Set(['bright_plating_scrap', 'bright_material_scrap', 'bright_processing_scrap', 'bright_diffusion_scrap']),
@@ -69,6 +80,61 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
function hasOnlyKeys(value: Record<string, unknown>, allowed: Set<string>): boolean {
return Object.keys(value).every(key => allowed.has(key));
}
/** 解析前仅复制普通 JSON 数据,阻止 getter、toJSON、原型和函数进入渲染链路。 */
function copyJsonData(value: unknown, seen = new Set<object>(), budget = { nodes: 0 }, depth = 0): unknown {
if (depth > 32 || ++budget.nodes > 100_000) throw new Error('unsafe JSON data');
if (value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number' || value === undefined) return value;
if (typeof value !== 'object' || seen.has(value)) throw new Error('unsafe JSON data');
if (PARSED_VISUALS.has(value)) {
seen.add(value);
try {
const descriptors = Object.getOwnPropertyDescriptors(value);
const result: Record<string, unknown> = Object.create(null);
for (const key of VISUAL_KEYS) {
const descriptor = descriptors[key];
if (!descriptor) continue;
if (!('value' in descriptor)) throw new Error('unsafe JSON data');
result[key] = copyJsonData(descriptor.value, seen, budget, depth + 1);
}
return result;
} finally {
seen.delete(value);
}
}
seen.add(value);
try {
if (Array.isArray(value)) {
if (Object.getPrototypeOf(value) !== Array.prototype || Object.getOwnPropertySymbols(value).length) throw new Error('unsafe JSON data');
const descriptors = Object.getOwnPropertyDescriptors(value);
const result: unknown[] = [];
for (let index = 0; index < value.length; index++) {
const descriptor = descriptors[String(index)];
if (!descriptor || !('value' in descriptor)) throw new Error('unsafe JSON data');
result.push(copyJsonData(descriptor.value, seen, budget, depth + 1));
}
if (Object.keys(descriptors).some(key => key !== 'length' && (!/^\d+$/.test(key) || String(Number(key)) !== key || Number(key) >= value.length))) {
throw new Error('unsafe JSON data');
}
return result;
}
const prototype = Object.getPrototypeOf(value);
if (prototype !== Object.prototype && prototype !== null) throw new Error('unsafe JSON data');
if (Object.getOwnPropertySymbols(value).length) throw new Error('unsafe JSON data');
const result: Record<string, unknown> = Object.create(null);
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
if (!('value' in descriptor)) throw new Error('unsafe JSON data');
result[key] = copyJsonData(descriptor.value, seen, budget, depth + 1);
}
return result;
} finally {
seen.delete(value);
}
}
function boundedText(value: unknown, maxLength = 200): string | null {
if (typeof value !== 'string') return null;
const text = value.trim();
@@ -98,24 +164,24 @@ function safeContext(value: unknown): AnalysisVisualContext | null {
for (const [filterKey, filterValues] of Object.entries(raw)) {
if (!/^[\w.-]{1,128}$/.test(filterKey) || !Array.isArray(filterValues) || filterValues.length > 20
|| !filterValues.every(item => typeof item === 'string' && item.length <= 160)) return null;
filters[filterKey] = [...filterValues];
Object.defineProperty(filters, filterKey, { value: [...filterValues], enumerable: true, configurable: true, writable: true });
}
result[key] = filters;
Object.defineProperty(result, key, { value: filters, enumerable: true, configurable: true, writable: true });
} else if (typeof raw === 'string') {
if (raw.length > 160) return null;
result[key] = raw;
Object.defineProperty(result, key, { value: raw, enumerable: true, configurable: true, writable: true });
} else if (typeof raw === 'boolean' || (typeof raw === 'number' && Number.isFinite(raw))) {
result[key] = raw;
Object.defineProperty(result, key, { value: raw, enumerable: true, configurable: true, writable: true });
} else if (Array.isArray(raw) && raw.length <= 20 && raw.every(item =>
typeof item === 'boolean' || (typeof item === 'string' && item.length <= 160) || (typeof item === 'number' && Number.isFinite(item)))) {
result[key] = raw as Array<string | number | boolean>;
Object.defineProperty(result, key, { value: raw as Array<string | number | boolean>, enumerable: true, configurable: true, writable: true });
} else return null;
}
return result;
}
function parseVisual(value: unknown, index: number, issues: string[]): AnalysisVisual | null {
if (!isRecord(value)) {
if (!isRecord(value) || !hasOnlyKeys(value, VISUAL_KEYS)) {
issues.push(`第 ${index + 1} 张图表结构无效`);
return null;
}
@@ -133,8 +199,10 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
const requiredFields = safeTextList(value.requiredFields, 100);
const note = value.note === undefined ? undefined : boundedText(value.note, 500);
const stage = value.stage === undefined ? undefined : value.stage;
const sectionKey = value.sectionKey === undefined ? undefined : value.sectionKey;
const dimension = value.dimension === undefined ? undefined : value.dimension;
const coverage = isRecord(value.coverage) ? value.coverage : null;
const coverage = isRecord(value.coverage) && hasOnlyKeys(value.coverage, COVERAGE_KEYS) ? value.coverage : null;
const validCoverage = coverage && Number.isSafeInteger(coverage.totalRows) && Number(coverage.totalRows) >= 0
&& Number.isSafeInteger(coverage.returnedRows) && Number(coverage.returnedRows) >= 0
&& Number(coverage.returnedRows) <= Number(coverage.totalRows)
@@ -150,7 +218,7 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
const categories = Array.isArray(value.categories) && value.categories.length > 0 && value.categories.length <= MAX_VISUAL_CATEGORIES
? value.categories.map(category => {
if (!isRecord(category)) return null;
if (!isRecord(category) || !hasOnlyKeys(category, CATEGORY_KEYS)) return null;
const key = boundedText(category.key, 128);
const label = boundedText(category.label, 240);
return key && label ? { key, label } : null;
@@ -167,7 +235,7 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
const series: AnalysisVisualSeries[] = [];
if (rawSeries && validCategories) {
for (const [seriesIndex, raw] of rawSeries.entries()) {
if (!isRecord(raw)) { series.length = 0; break; }
if (!isRecord(raw) || !hasOnlyKeys(raw, SERIES_KEYS)) { series.length = 0; break; }
const key = boundedText(raw.key, 128);
const label = boundedText(raw.label, 160);
if (!key || !label || !Array.isArray(raw.values) || raw.values.length !== validCategories.length) { series.length = 0; break; }
@@ -191,6 +259,8 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
&& !!metric && !!originTurnId && !!scope && !!period && (value.comparisonPeriod === undefined || !!comparisonPeriod)
&& !!evidenceRefs && !!requiredFields && (value.note === undefined || note !== null)
&& (stage === undefined || stage === 'black' || stage === 'bright')
&& (sectionKey === undefined || SECTION_KEYS.has(sectionKey as AnalysisVisualSectionKey))
&& (dimension === undefined || DIMENSIONS.has(dimension as AnalysisVisualDimension))
&& !!validCoverage && !!validCategories && validSeries;
if (!valid) {
issues.push(`第 ${index + 1} 张图表未通过结构校验`);
@@ -205,6 +275,8 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
scope: scope!, period: period!, ...(comparisonPeriod ? { comparisonPeriod } : {}),
...(stage ? { stage } : {}), metric: metric!, coverage: validCoverage!,
...(note ? { note } : {}), originTurnId: originTurnId!, invalidValueCells, chartable: false,
...(sectionKey ? { sectionKey: sectionKey as AnalysisVisualSectionKey } : {}),
...(dimension ? { dimension: dimension as AnalysisVisualDimension } : {}),
};
const semanticIssue = visualSemanticIssue(candidate);
const chartable = CHART_TYPES.has(type!) && hasData && invalidValueCells.length === 0 && !semanticIssue;
@@ -217,14 +289,37 @@ function parseVisual(value: unknown, index: number, issues: string[]): AnalysisV
else if (semanticIssue) chartIssue = `${semanticIssue},以下展示原始数据表`;
if (!chartable) issues.push(`“${title}”已降级为数据表:${chartIssue}`);
return {
const parsedVisual: AnalysisVisual = {
...candidate, chartable, ...(chartIssue ? { chartIssue } : {}),
};
PARSED_VISUALS.add(parsedVisual);
return parsedVisual;
}
function visualSemanticIssue(visual: AnalysisVisual): string | undefined {
if (visual.type === 'area' && visual.series.length !== 1) return '面积趋势图仅支持单一序列';
if (visual.type === 'area' && visual.series.some(series => series.values.some(value => value !== null && value < 0))) return '面积趋势图不支持负值';
if (visual.type === 'waterfall') {
const allowedFields = new Set(['black_good_weight', 'black_total_weight', 'bright_good_weight', 'bright_total_weight']);
const actualFields = visual.requiredFields;
if (visual.metric !== 'composite_impact_pp' || visual.unit !== 'pp') return '瀑布图仅支持综合率阶段数学影响(百分点)';
if (visual.categories.length !== 3 || visual.categories.map(item => item.key).join('|') !== 'black|bright|total') return '瀑布图类别必须依次为黑片、亮片和综合变化';
if (visual.series.length !== 1 || visual.series[0].key !== 'composite_impact_pp') return '瀑布图仅支持综合阶段影响序列';
if (actualFields.length !== allowedFields.size || new Set(actualFields).size !== allowedFields.size || actualFields.some(field => !allowedFields.has(field))) {
return '瀑布图必须具备黑片和亮片的合格重量、总重量字段权限';
}
if (visual.stage !== undefined || visual.scope.stage !== undefined || visual.scope.category !== undefined || visual.scope.defect !== undefined) {
return '瀑布图只支持未按阶段、类别或缺陷筛选的综合范围';
}
if (!visual.comparisonPeriod || Object.keys(visual.period).length === 0 || Object.keys(visual.comparisonPeriod).length === 0
|| plainPeriod(visual.period) === '当前期间' || plainPeriod(visual.comparisonPeriod) === '当前期间'
|| plainPeriod(visual.period) === plainPeriod(visual.comparisonPeriod)) return '瀑布图必须提供两个不同的有效期间';
const values = visual.series[0].values;
if (values.length !== 3 || values.some(value => value === null || !Number.isFinite(value))) return '瀑布图的三项影响必须是有限数值';
const sum = (values[0] as number) + (values[1] as number);
if (!Number.isFinite(sum) || Math.abs(sum - (values[2] as number)) > 1e-8) return '黑片与亮片影响之和必须等于综合率变化';
return undefined;
}
if (visual.type !== 'donut' && visual.type !== 'pareto') return undefined;
const chartName = visual.type === 'donut' ? '环形图' : '柏拉图';
if (visual.unit !== 'kg' || visual.metric !== 'source_defect_weight') return `${chartName}仅支持来源类别重量`;
@@ -255,11 +350,17 @@ function visualSemanticIssue(visual: AnalysisVisual): string | undefined {
/** Parse untrusted JSON-shaped chart data. An object wrapper may also include visualSchemaVersion. */
export function parseAnalysisVisuals(input: unknown, schemaVersion?: unknown): ParseVisualsResult {
const issues: string[] = [];
let rawVisuals = input;
let safeInput: unknown;
try { safeInput = copyJsonData(input); }
catch { return { visuals: [], issues: ['图表数据无法安全读取'] }; }
let rawVisuals = safeInput;
let version = schemaVersion;
if (isRecord(input) && 'visuals' in input) {
rawVisuals = input.visuals;
if (version === undefined) version = input.visualSchemaVersion;
if (isRecord(safeInput) && 'visuals' in safeInput) {
if (!hasOnlyKeys(safeInput, new Set(['visuals', 'visualSchemaVersion']))) {
return { visuals: [], issues: ['图表数据包含未知字段'] };
}
rawVisuals = safeInput.visuals;
if (version === undefined) version = safeInput.visualSchemaVersion;
}
if (version !== undefined && version !== 1) {
return { visuals: [], issues: ['不支持此版本的图表数据'] };
@@ -269,7 +370,7 @@ export function parseAnalysisVisuals(input: unknown, schemaVersion?: unknown): P
let serialized: string;
try { serialized = JSON.stringify(rawVisuals); }
catch { return { visuals: [], issues: ['图表数据无法安全读取'] }; }
if (new TextEncoder().encode(serialized).byteLength > MAX_VISUAL_BYTES) {
if (typeof serialized !== 'string' || new TextEncoder().encode(serialized).byteLength > MAX_VISUAL_BYTES) {
return { visuals: [], issues: ['图表数据超过安全大小限制'] };
}
const result: AnalysisVisual[] = [];
@@ -303,6 +404,18 @@ function chartNumber(value: number): number {
return Number(value.toPrecision(10));
}
function formatChartValue(value: number | null, unit: AnalysisVisualUnit, showPositiveSign = true): string {
if (value === null) return '—';
if (!Number.isFinite(value)) return '无效值';
const plotted = unit === 'ratio' ? value * 100 : value;
const numberText = unit === 'kg' || unit === 'pp' || unit === 'ratio'
? new Intl.NumberFormat('zh-CN', { useGrouping: false, maximumFractionDigits: 2 }).format(plotted)
: new Intl.NumberFormat('zh-CN', { useGrouping: false, maximumSignificantDigits: 10 }).format(plotted);
if (unit === 'ratio') return `${numberText}%`;
const signed = unit === 'pp' && showPositiveSign && value > 0 ? `+${numberText}` : numberText;
return unit === 'kg' ? `${signed} kg` : unit === 'pp' ? `${signed} pp` : signed;
}
export function visualCategoryLabel(visual: AnalysisVisual, categoryIndex: number): string {
const category = visual.categories[categoryIndex];
if (!category) return '';
@@ -367,11 +480,12 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
const colors = theme.colors?.length ? theme.colors : visual.stage === 'black'
? ['#607ae1', '#a8b4c4', '#d58c35', '#8b68c5']
: visual.stage === 'bright' ? ['#008f7d', '#a8b4c4', '#d58c35', '#8b68c5'] : DEFAULT_COLORS;
// 坐标数据保留原始业务标签;提示框等富文本区域单独转义 ECharts 标记。
const categories = visual.categories.map((_item, index) => visualCategoryLabel(visual, index));
const categoryAxisLabel = { color: ink, fontSize: 11, hideOverlap: true, overflow: 'truncate' as const, width: 160 };
const numberAxisLabel = (value: number) => visual.unit === 'ratio'
? `${chartNumber(value)}%`
: `${chartNumber(value)}${visual.unit === 'pp' ? ' pp' : visual.unit === 'kg' ? ' kg' : ''}`;
: formatChartValue(value, visual.unit, false);
const formatter = (raw: unknown): string => {
const params = Array.isArray(raw) ? raw : [raw];
const first = params[0];
@@ -409,6 +523,17 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
`累计占本图已列类别合计:${visualDonutShareText(point.cumulativeShare)}`,
].join('\n');
}
if (visual.type === 'waterfall') {
const value = visual.series[0]?.values[dataIndex] ?? null;
if (value === null) return '';
return [
plainRichText(visualCategoryLabel(visual, dataIndex)),
plainRichText(`期间:${plainPeriod(visual.comparisonPeriod || {})} → ${plainPeriod(visual.period)}`),
`阶段数学影响:${formatVisualValue(value, 'pp')}`,
...(dataIndex === 2 ? ['黑片与亮片影响之和构成综合率变化。'] : []),
'该拆解不代表生产根因。',
].join('\n');
}
const category = visual.categories[dataIndex];
const lines = category ? [plainRichText(visualCategoryLabel(visual, dataIndex))] : [];
if (visual.comparisonPeriod) lines.push(plainRichText(`期间:${plainPeriod(visual.comparisonPeriod)} → ${plainPeriod(visual.period)}`));
@@ -422,6 +547,42 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
return lines.join('\n');
};
if (visual.type === 'waterfall') {
const [black, bright, total] = visual.series[0].values as [number, number, number];
const endAfterBlack = black;
const endAfterBright = black + bright;
const baseline = [Math.min(0, black), Math.min(endAfterBlack, endAfterBright), 0];
const deltaValues = [Math.abs(black), Math.abs(bright), 0];
const minValue = Math.min(0, black, endAfterBright, total);
const maxValue = Math.max(0, black, endAfterBright, total);
const padding = Math.max((maxValue - minValue) * 0.18, 0.25);
const barData = deltaValues.map((value, index) => ({
value,
label: { ...(index === 2 ? { show: false } : {}), position: (index === 0 ? black : bright) < 0 ? 'bottom' : 'top' },
itemStyle: { color: index === 0 ? (black < 0 ? '#c66565' : '#607ae1') : (bright < 0 ? '#c66565' : '#008f7d') },
}));
const totalData = [{ value: 0, label: { show: false } }, { value: 0, label: { show: false } }, {
value: total,
label: { position: total < 0 ? 'bottom' : 'top' },
itemStyle: { color: total < 0 ? '#c66565' : '#435d7a' },
}];
return {
animation: false,
color: ['#607ae1', '#435d7a'],
tooltip: { trigger: 'axis', renderMode: 'richText', backgroundColor: theme.surface || '#ffffff', borderColor: line, textStyle: { color: ink }, axisPointer: { type: 'shadow' }, formatter },
legend: { show: true, selectedMode: false, type: 'plain', top: 8, data: ['阶段影响', '综合变化'], textStyle: { color: mutedInk, fontSize: 11 } },
grid: { left: 72, right: 34, top: 48, bottom: 64, containLabel: true },
xAxis: { type: 'category', data: categories, axisLabel: { color: ink, fontSize: 12, interval: 0, width: 150, overflow: 'break', lineHeight: 16 }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false } },
yAxis: { type: 'value', min: minValue - padding, max: maxValue + padding, scale: false, name: '变化(百分点)', nameTextStyle: { color: mutedInk, fontSize: 10 }, axisLabel: { color: mutedInk, formatter: numberAxisLabel }, axisLine: { show: false }, splitLine: { lineStyle: { color: line, type: 'dashed' } } },
series: [
{ name: '辅助基线', type: 'bar', stack: 'impact', stackStrategy: 'all', data: baseline, itemStyle: { color: 'transparent' }, emphasis: { disabled: true }, silent: true, tooltip: { show: false }, legendHoverLink: false },
{ name: '阶段影响', type: 'bar', stack: 'impact', stackStrategy: 'all', data: barData, barMaxWidth: 56, label: { show: true, position: 'top', color: ink, fontSize: 11, formatter: (params: { dataIndex: number }) => formatChartValue(visual.series[0].values[params.dataIndex] ?? null, 'pp') }, emphasis: { disabled: true } },
{ name: '综合变化', type: 'bar', stack: 'impact', stackStrategy: 'all', data: totalData, barMaxWidth: 56, label: { show: true, position: 'top', color: ink, fontSize: 11, formatter: () => formatChartValue(total, 'pp') }, emphasis: { disabled: true } },
],
aria: { enabled: true, decal: { show: false } },
};
}
if (visual.type === 'heatmap') {
const finiteValues = visual.series.flatMap(item => item.values.filter((value): value is number => value !== null)
.map(value => visual.unit === 'ratio' ? chartNumber(value * 100) : chartNumber(value)));
@@ -440,7 +601,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
tooltip: { trigger: 'item', renderMode: 'richText', backgroundColor: theme.surface || '#ffffff', borderColor: line, textStyle: { color: ink }, formatter },
grid: { left: 18, right: 92, top: 18, bottom: 58, containLabel: true, backgroundColor: '#eef1f5' },
xAxis: { type: 'category', data: categories, axisLabel: { ...categoryAxisLabel, interval: 0, rotate: categories.length > 8 ? 25 : 0, width: 150 }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false }, splitArea: { show: false } },
yAxis: { type: 'category', data: visual.series.map(item => item.label), axisLabel: { color: ink, fontSize: 11, width: 150, overflow: 'truncate' }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false } },
yAxis: { type: 'category', data: visual.series.map(item => plainRichText(item.label)), axisLabel: { color: ink, fontSize: 11, width: 150, overflow: 'truncate' }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false } },
visualMap: {
type: 'continuous', min: visualMin, max: visualMax, calculable: false, orient: 'vertical', right: 2, top: 'middle', itemHeight: 120,
text: [numberAxisLabel(visualMax), numberAxisLabel(visualMin)], textStyle: { color: mutedInk, fontSize: 10 },
@@ -448,7 +609,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
...(hasNegative ? {} : { outOfRange: { color: '#e8ebef' } }),
},
series: [{
name: visual.series[0]?.label || '数值', type: 'heatmap', data: matrixData,
name: plainRichText(visual.series[0]?.label || '数值'), type: 'heatmap', data: matrixData,
label: { show: true, color: ink, fontSize: 11, formatter: (params: { data?: unknown }) => {
const tuple = Array.isArray(params?.data) ? params.data : [];
return typeof tuple[2] === 'number' ? tuple[2].toFixed(2) : '';
@@ -463,7 +624,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
const shares = visualDonutShares(visual);
const total = shares.reduce((sum, item) => sum + item.valueKg, 0);
const pieData = shares.map(({ categoryIndex, valueKg, share }) => ({
name: visualCategoryLabel(visual, categoryIndex),
name: plainRichText(visualCategoryLabel(visual, categoryIndex)),
value: valueKg,
visualCategoryIndex: categoryIndex,
visualShare: share,
@@ -476,20 +637,20 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
legend: { show: true, selectedMode: false, type: 'scroll', orient: 'horizontal', bottom: 3, left: 10, right: 10, textStyle: { color: mutedInk, fontSize: 11 } },
graphic: [{
type: 'text', left: 'center', top: '39%', silent: true,
style: { text: `所列类别合计\n${formatVisualValue(total, 'kg')}`, textAlign: 'center', fill: ink, font: '600 15px sans-serif', lineHeight: 24 },
style: { text: `所列类别合计\n${formatChartValue(total, 'kg')}`, textAlign: 'center', fill: ink, font: '600 15px sans-serif', lineHeight: 24 },
}, {
type: 'text', left: 'center', bottom: 30, silent: true,
style: { text: '占比以本图列出类别重量合计为分母,不代表正式总报废占比', textAlign: 'center', fill: mutedInk, font: '10px sans-serif', width: 560, overflow: 'break', lineHeight: 15 },
}],
series: [{
name: visual.series[0].label, type: 'pie', radius: ['42%', '66%'], center: ['50%', '44%'], avoidLabelOverlap: true,
name: plainRichText(visual.series[0].label), type: 'pie', radius: ['42%', '66%'], center: ['50%', '44%'], avoidLabelOverlap: true,
data: pieData,
label: { show: true, position: 'outside', alignTo: 'labelLine', edgeDistance: 12, width: 210, overflow: 'break', lineHeight: 16, color: ink, fontSize: 11,
formatter: (params: { dataIndex?: number }) => {
const index = Number.isInteger(params?.dataIndex) ? params.dataIndex as number : -1;
const share = shares[index];
if (!share) return '';
return `${visualCategoryLabel(visual, index)}\n${formatVisualValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`;
return `${plainRichText(visualCategoryLabel(visual, index))}\n${formatChartValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`;
} },
labelLine: { show: true, length: 16, length2: 12, lineStyle: { color: line } },
emphasis: { disabled: true },
@@ -501,7 +662,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
series: [{ radius: ['44%', '72%'], center: ['50%', '45%'], label: { show: false }, labelLine: { show: false } }],
graphic: [{
type: 'text', left: 'center', top: '39%', silent: true,
style: { text: `所列类别合计\n${formatVisualValue(total, 'kg')}`, textAlign: 'center', fill: ink, font: '600 15px sans-serif', lineHeight: 23 },
style: { text: `所列类别合计\n${formatChartValue(total, 'kg')}`, textAlign: 'center', fill: ink, font: '600 15px sans-serif', lineHeight: 23 },
}, {
type: 'text', left: 'center', bottom: 8, silent: true,
style: { text: '占比以本图列出类别重量合计为分母,不代表正式总报废占比', textAlign: 'center', fill: mutedInk, font: '9px sans-serif', width: 300, overflow: 'break', lineHeight: 13 },
@@ -519,15 +680,15 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
animation: false,
color: [colors[0], '#435d7a'],
tooltip: { trigger: 'axis', renderMode: 'richText', backgroundColor: theme.surface || '#ffffff', borderColor: line, textStyle: { color: ink }, axisPointer: { type: 'shadow' }, formatter },
legend: { show: true, selectedMode: false, type: 'plain', top: 6, left: 12, data: [visual.series[0].label, cumulativeName], textStyle: { color: mutedInk, fontSize: 10 } },
legend: { show: true, selectedMode: false, type: 'plain', top: 6, left: 12, data: [plainRichText(visual.series[0].label), cumulativeName], textStyle: { color: mutedInk, fontSize: 10 } },
grid: { left: 56, right: 66, top: 36, bottom: 70, containLabel: true },
xAxis: { type: 'category', data: categories.map(label => truncateText(label, 16)), axisLabel: { color: ink, fontSize: 10, interval: 0, rotate: categories.length > 3 ? 18 : 0, width: 130 }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false } },
xAxis: { type: 'category', data: categories, axisLabel: { color: ink, fontSize: 10, interval: 0, rotate: categories.length > 3 ? 34 : 0, width: 160, overflow: 'break', hideOverlap: false, lineHeight: 13 }, axisLine: { lineStyle: { color: line } }, axisTick: { show: false } },
yAxis: [
{ type: 'value', min: 0, name: '重量(kg)', nameTextStyle: { color: mutedInk, fontSize: 10 }, axisLabel: { color: mutedInk, formatter: (value: number) => `${chartNumber(value)} kg` }, axisLine: { show: false }, splitLine: { lineStyle: { color: line, type: 'dashed' } } },
{ type: 'value', min: 0, name: '重量(kg)', nameTextStyle: { color: mutedInk, fontSize: 10 }, axisLabel: { color: mutedInk, formatter: (value: number) => formatChartValue(value, 'kg') }, axisLine: { show: false }, splitLine: { lineStyle: { color: line, type: 'dashed' } } },
{ type: 'value', min: 0, max: 100, position: 'right', name: '累计占比', nameTextStyle: { color: mutedInk, fontSize: 10 }, axisLabel: { color: mutedInk, formatter: (value: number) => `${chartNumber(value)}%` }, axisLine: { show: false }, splitLine: { show: false } },
],
series: [
{ name: visual.series[0].label, type: 'bar', yAxisIndex: 0, data: visual.series[0].values, barMaxWidth: 48, itemStyle: { color: colors[0] }, label: { show: true, position: 'top', color: ink, fontSize: 10, formatter: (params: { dataIndex: number }) => formatVisualValue(points[params.dataIndex]?.valueKg ?? null, 'kg') }, emphasis: { disabled: true } },
{ name: plainRichText(visual.series[0].label), type: 'bar', yAxisIndex: 0, data: visual.series[0].values, barMaxWidth: 48, itemStyle: { color: colors[0] }, label: { show: true, position: 'top', color: ink, fontSize: 10, formatter: (params: { dataIndex: number }) => formatChartValue(points[params.dataIndex]?.valueKg ?? null, 'kg') }, emphasis: { disabled: true } },
{ name: cumulativeName, type: 'line', yAxisIndex: 1, data: points.map(point => chartNumber(point.cumulativeShare * 100)), symbol: 'circle', symbolSize: 7, lineStyle: { width: 2.2, color: ink }, itemStyle: { color: ink }, label: { show: true, position: 'top', color: ink, fontSize: 10, formatter: (params: { data?: number }) => visualDonutShareText((params.data || 0) / 100) }, emphasis: { disabled: true } },
],
aria: { enabled: true, decal: { show: false } },
@@ -535,7 +696,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
}
const series = visual.series.map((item, seriesIndex) => ({
name: item.label,
name: plainRichText(item.label),
type: visual.type === 'area' ? 'line' : visual.type === 'column' ? 'bar' : visual.type,
data: item.values.map(value => {
if (value === null) return null;
@@ -552,8 +713,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
color: ink, fontSize: 11,
formatter: (raw: { dataIndex: number }) => {
const value = item.values[raw.dataIndex];
return value === null || value === undefined ? '—'
: `${(visual.unit === 'ratio' ? value * 100 : value).toLocaleString('zh-CN', { maximumFractionDigits: 2 })}${visual.unit === 'ratio' ? '%' : visual.unit === 'pp' ? ' pp' : visual.unit === 'kg' ? ' kg' : ''}`;
return formatChartValue(value ?? null, visual.unit);
} },
emphasis: { focus: 'series' },
} : {
@@ -637,9 +797,12 @@ export interface AnalysisVisualExportOption {
}
/** Add static report context around the complete, unfiltered snapshot for PNG export. */
export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width = 1280): AnalysisVisualExportOption {
const titleLines = wrapLines(visual.title, 34, 3);
const headerParts = [
export type AnalysisVisualRenderContext = 'standalone' | 'report';
export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width = 1280, context: AnalysisVisualRenderContext = 'standalone'): AnalysisVisualExportOption {
const reportMode = context === 'report';
const titleLines = reportMode ? [] : wrapLines(visual.title, 34, 3);
const headerParts = reportMode ? [] : [
visual.subtitle,
`期间:${visualPeriodSummary(visual)}`,
`范围:${visualScopeSummary(visual.scope) || '按本轮查询条件'}`,
@@ -654,31 +817,34 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
: visual.coverage.shareBasis ? [`占比口径:${visual.coverage.shareBasis}`] : []),
].filter(Boolean);
const headerLines = headerParts.flatMap(part => wrapLines(part, 96, 4));
const chartTop = 30 + titleLines.length * 28 + headerLines.length * 17 + 20;
const chartTop = reportMode ? 18 : 30 + titleLines.length * 28 + headerLines.length * 17 + 20;
const footerParts = [
...(visual.type === 'donut' ? visualDonutShares(visual).map(({ categoryIndex, valueKg, share }) =>
`${visualCategoryLabel(visual, categoryIndex)}:${formatVisualValue(valueKg, 'kg')}(占本图已列类别重量合计 ${visualDonutShareText(share)})`) : []),
...(!reportMode && visual.type === 'donut' ? visualDonutShares(visual).map(({ categoryIndex, valueKg, share }) =>
`${visualCategoryLabel(visual, categoryIndex)}:${formatChartValue(valueKg, 'kg')}(占本图已列类别重量合计 ${visualDonutShareText(share)})`) : []),
...(visual.type === 'pareto' ? ['柏拉图累计占比=累计重量÷本图已列类别重量合计;不代表正式总报废累计占比'] : []),
...(visual.note ? [`说明:${visual.note}`] : []),
...(visual.evidenceRefs.length ? [`证据引用:${visual.evidenceRefs.join(' · ')}`] : []),
...(visual.type === 'waterfall' ? ['阶段影响是对综合合格率变化的数学拆解,不代表生产根因。'] : []),
...(!reportMode && visual.note ? [`说明:${visual.note}`] : []),
...(!reportMode && visual.evidenceRefs.length ? [`证据引用:${visual.evidenceRefs.join(' · ')}`] : []),
];
const footerLines = footerParts.flatMap(part => wrapLines(part, 124));
const chartBottom = footerLines.length ? footerLines.length * 15 + 28 : 24;
const chartBottom = footerLines.length ? footerLines.length * 15 + (reportMode ? 20 : 28) : (reportMode ? 10 : 24);
const wrappedCategories = visual.categories.map((_category, index) =>
wrapLines(visualCategoryLabel(visual, index), 18, 4));
const wrappedCategories = visual.categories.map((_category, index) => wrapLines(visualCategoryLabel(visual, index), 14));
const categoryLabelHeight = wrappedCategories.reduce((total, lines) => total + Math.max(28, lines.length * 14 + 8), 0);
const chartHeight = visual.type === 'donut' ? 600
: visual.type === 'heatmap' ? Math.max(240, visual.series.length * 90)
: Math.max(480, categoryLabelHeight);
const maxCategoryLines = Math.max(1, ...wrappedCategories.map(lines => lines.length));
const chartHeight = visual.type === 'donut' ? (reportMode ? Math.max(390, 290 + maxCategoryLines * 20) : Math.max(600, 300 + maxCategoryLines * 20))
: visual.type === 'waterfall' ? (reportMode ? 300 : 480)
: visual.type === 'heatmap' ? Math.max(reportMode ? 180 : 240, visual.series.length * (reportMode ? 62 : 90))
: visual.type === 'pareto' ? (reportMode ? Math.max(300, 170 + maxCategoryLines * 18) : Math.max(480, categoryLabelHeight))
: reportMode ? visual.type === 'bar' ? Math.max(230, categoryLabelHeight * 1.3) : Math.max(230, 165 + maxCategoryLines * 20) : Math.max(480, categoryLabelHeight);
const height = chartTop + chartHeight + chartBottom;
const base = buildAnalysisVisualOption(visual, { ink: '#263c5a', mutedInk: '#65748b', line: '#dfe5ef', surface: '#ffffff' });
const categories = wrappedCategories.map(lines => lines.join('\n'));
const donutShares = visual.type === 'donut' ? visualDonutShares(visual) : [];
const valueAxisLabel = (value: number) => visual.unit === 'ratio'
? `${chartNumber(value)}%`
: `${chartNumber(value)}${visual.unit === 'pp' ? ' pp' : visual.unit === 'kg' ? ' kg' : ''}`;
const allSeriesSelected = Object.fromEntries(visual.series.map(series => [series.label, true]));
: formatChartValue(value, visual.unit, false);
const allSeriesSelected = Object.fromEntries(visual.series.map(series => [plainRichText(series.label), true]));
const legendOption = visual.type === 'donut'
? {
show: true,
@@ -690,24 +856,24 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
bottom: chartBottom + 4,
textStyle: { color: '#65748b', fontSize: 11 },
formatter: (name: string) => {
const index = visual.categories.findIndex((_category, categoryIndex) => visualCategoryLabel(visual, categoryIndex) === name);
const index = visual.categories.findIndex((_category, categoryIndex) => plainRichText(visualCategoryLabel(visual, categoryIndex)) === name);
const share = donutShares[index];
return index < 0 || !share ? plainRichText(name) : plainRichText(`${name} · ${formatVisualValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`);
return index < 0 || !share ? plainRichText(name) : plainRichText(`${name} · ${formatChartValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`);
},
}
: visual.type === 'pareto'
? {
show: true,
type: 'plain' as const,
top: chartTop - 26,
top: reportMode ? chartTop + 2 : chartTop - 26,
left: 56,
data: [visual.series[0].label, '累计占本图已列类别合计'],
data: [plainRichText(visual.series[0].label), '累计占本图已列类别合计'],
textStyle: { color: '#65748b', fontSize: 11 },
}
: {
show: visual.series.length > 1,
type: 'scroll' as const,
top: chartTop - 26,
top: reportMode ? chartTop + 2 : chartTop - 26,
left: 56,
selected: allSeriesSelected,
textStyle: { color: '#65748b', fontSize: 11 },
@@ -717,7 +883,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
...base,
animation: false,
tooltip: { show: false },
title: {
title: reportMode ? { show: false, text: '', subtext: '' } : {
text: plainRichText(titleLines.join('\n')),
subtext: plainRichText(headerLines.join('\n')),
left: 56,
@@ -744,7 +910,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
elements: [
...(donutShares.length ? [{
type: 'text', left: 'center', top: chartTop + chartHeight * 0.39 - 22, silent: true,
style: { text: `所列类别合计\n${formatVisualValue(donutShares.reduce((sum, item) => sum + item.valueKg, 0), 'kg')}`, textAlign: 'center', fill: '#263c5a', font: '600 16px sans-serif', lineHeight: 25 },
style: { text: `所列类别合计\n${formatChartValue(donutShares.reduce((sum, item) => sum + item.valueKg, 0), 'kg')}`, textAlign: 'center', fill: '#263c5a', font: '600 16px sans-serif', lineHeight: 25 },
}] : []),
...(footerLines.length ? [{
type: 'text', left: 56, top: chartTop + chartHeight + 14, silent: true,
@@ -762,7 +928,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
formatter: (params: { dataIndex?: number }) => {
const index = Number.isInteger(params?.dataIndex) ? params.dataIndex as number : -1;
const share = donutShares[index];
return share ? plainRichText(`${visualCategoryLabel(visual, index)}\n${formatVisualValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`) : '';
return share ? plainRichText(`${visualCategoryLabel(visual, index)}\n${formatChartValue(share.valueKg, 'kg')} · ${visualDonutShareText(share.share)}`) : '';
},
},
labelLine: { show: true, length: 16, length2: 12, lineStyle: { color: '#dfe5ef' } },
@@ -798,14 +964,31 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
axisLine: { lineStyle: { color: '#dfe5ef' } }, axisTick: { show: false },
},
yAxis: [
{ type: 'value', min: 0, name: '重量(kg)', nameTextStyle: { color: '#65748b', fontSize: 10 }, axisLabel: { color: '#65748b', formatter: (value: number) => `${chartNumber(value)} kg` }, axisLine: { show: false }, splitLine: { lineStyle: { color: '#dfe5ef', type: 'dashed' } } },
{ type: 'value', min: 0, name: '重量(kg)', nameTextStyle: { color: '#65748b', fontSize: 10 }, axisLabel: { color: '#65748b', formatter: (value: number) => formatChartValue(value, 'kg') }, axisLine: { show: false }, splitLine: { lineStyle: { color: '#dfe5ef', type: 'dashed' } } },
{ type: 'value', min: 0, max: 100, position: 'right', name: '累计占比(本图已列类别)', nameTextStyle: { color: '#65748b', fontSize: 10 }, axisLabel: { color: '#65748b', formatter: (value: number) => `${chartNumber(value)}%` }, axisLine: { show: false }, splitLine: { show: false } },
],
series: [
{ name: visual.series[0].label, type: 'bar', yAxisIndex: 0, data: visual.series[0].values, barMaxWidth: 48, itemStyle: { color: '#607ae1' }, label: { show: true, position: 'top', color: '#263c5a', fontSize: 10, formatter: (params: { dataIndex: number }) => formatVisualValue(visualParetoPoints(visual)[params.dataIndex]?.valueKg ?? null, 'kg') } },
{ name: plainRichText(visual.series[0].label), type: 'bar', yAxisIndex: 0, data: visual.series[0].values, barMaxWidth: 48, itemStyle: { color: '#607ae1' }, label: { show: true, position: 'top', color: '#263c5a', fontSize: 10, formatter: (params: { dataIndex: number }) => formatChartValue(visualParetoPoints(visual)[params.dataIndex]?.valueKg ?? null, 'kg') } },
{ name: '累计占本图已列类别合计', type: 'line', yAxisIndex: 1, data: visualParetoPoints(visual).map(point => chartNumber(point.cumulativeShare * 100)), symbol: 'circle', symbolSize: 7, lineStyle: { width: 2.2, color: '#435d7a' }, itemStyle: { color: '#435d7a' }, label: { show: true, position: 'top', color: '#435d7a', fontSize: 10, formatter: (params: { data?: number }) => visualDonutShareText((params.data || 0) / 100) } },
],
}
: visual.type === 'waterfall'
? {
legend: { show: false },
grid: { left: 76, right: 42, top: chartTop + 8, bottom: chartBottom + 76, containLabel: true },
xAxis: {
type: 'category', data: categories, boundaryGap: true,
axisLabel: { color: '#263c5a', fontSize: 11, lineHeight: 15, width: 180, overflow: 'break', interval: 0, hideOverlap: false },
axisLine: { lineStyle: { color: '#dfe5ef' } }, axisTick: { show: false },
},
yAxis: {
type: 'value', min: (base as any).yAxis?.min, max: (base as any).yAxis?.max, scale: false,
name: '变化(百分点)', nameTextStyle: { color: '#65748b', fontSize: 10 },
axisLabel: { color: '#65748b', formatter: valueAxisLabel }, axisLine: { show: false },
splitLine: { lineStyle: { color: '#dfe5ef', type: 'dashed' } },
},
series: (base as any).series,
}
: visual.type === 'bar'
? {
xAxis: {
@@ -832,7 +1015,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
type: 'category',
data: categories,
boundaryGap: visual.type === 'column',
axisLabel: { color: '#263c5a', fontSize: 10, lineHeight: 12, rotate: categories.length > 10 ? 28 : 0, width: 112, overflow: 'break', hideOverlap: true },
axisLabel: { color: '#263c5a', fontSize: 10, lineHeight: 13, rotate: categories.length > 5 ? 42 : 0, width: 160, overflow: 'break', interval: 0, hideOverlap: false },
axisLine: { lineStyle: { color: '#dfe5ef' } },
axisTick: { show: false },
},
@@ -845,9 +1028,22 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
axisLine: { show: false },
splitLine: { lineStyle: { color: '#dfe5ef', type: 'dashed' } },
},
grid: { left: 64, right: 42, top: chartTop, bottom: chartBottom + (visual.type === 'column' ? 80 : 68), containLabel: true },
grid: { left: 64, right: 42, top: chartTop, bottom: chartBottom + (visual.type === 'column' ? 80 : reportMode ? 110 : 68), containLabel: true },
}),
};
if (reportMode) {
// 图片按报告正文列宽显示,确保缩放后的标签仍然可读。
const enlargeText = (value: unknown): void => {
if (!value || typeof value !== 'object') return;
for (const [key, child] of Object.entries(value)) {
if (key === 'fontSize' && typeof child === 'number') (value as Record<string, unknown>)[key] = Math.max(14, child);
else if (key === 'lineHeight' && typeof child === 'number') (value as Record<string, unknown>)[key] = Math.max(18, child);
else enlargeText(child);
}
};
enlargeText(option);
(option as Record<string, unknown>).textStyle = { fontSize: 14, fontFamily: '-apple-system,BlinkMacSystemFont,PingFang SC,Microsoft YaHei,sans-serif' };
}
return { option, width, height };
}
@@ -986,6 +1182,9 @@ function waitForFont(signal?: AbortSignal): Promise<void> {
function svgToPng(svg: string, width: number, height: number, signal?: AbortSignal): Promise<string> {
return new Promise((resolve, reject) => {
throwIfAborted(signal);
const parsedSvg = new DOMParser().parseFromString(svg, 'image/svg+xml');
const syntaxError = parsedSvg.querySelector('parsererror');
if (syntaxError) { reject(new Error(`图表 SVG 格式错误:${syntaxError.textContent?.slice(0, 240)}`)); return; }
const svgUrl = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml;charset=utf-8' }));
const image = new Image();
const canvas = document.createElement('canvas');
@@ -1020,13 +1219,13 @@ function svgToPng(svg: string, width: number, height: number, signal?: AbortSign
}
/** Render a snapshot independently of any visible chart instance or current legend state. */
export async function renderVisualPng(visualOrUnknown: AnalysisVisual | unknown, signal?: AbortSignal): Promise<string> {
export async function renderVisualPng(visualOrUnknown: AnalysisVisual | unknown, signal?: AbortSignal, context: AnalysisVisualRenderContext = 'standalone'): Promise<string> {
const parsed = parseAnalysisVisuals([visualOrUnknown]);
const visual = parsed.visuals[0];
if (!visual || !visual.chartable) throw new Error(visual?.chartIssue || parsed.issues[0] || '没有可导出的图表数据');
if (typeof document === 'undefined') throw new Error('图表图片只能在浏览器中生成');
throwIfAborted(signal);
const { option, width, height } = buildAnalysisVisualExportOption(visual, 1280);
const { option, width, height } = buildAnalysisVisualExportOption(visual, context === 'report' ? 900 : 1280, context);
const node = document.createElement('div');
Object.assign(node.style, { position: 'fixed', left: '-10000px', top: '0', width: `${width}px`, height: `${height}px`, background: '#ffffff', color: '#263c5a', pointerEvents: 'none' });
document.body.appendChild(node);