From 55327df5e4a5ef90e611016c606f0ae91eed57ad Mon Sep 17 00:00:00 2001 From: lyun Date: Sat, 24 Oct 2026 10:29:37 +0800 Subject: [PATCH] Align combined defect chart rows and spacing --- web/src/AnalysisVisuals.tsx | 1 + web/src/analysisVisualsModel.ts | 14 +++++++++----- web/verification/analysis_visuals.test.mjs | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/AnalysisVisuals.tsx b/web/src/AnalysisVisuals.tsx index d0e0a5e..f1c09ca 100644 --- a/web/src/AnalysisVisuals.tsx +++ b/web/src/AnalysisVisuals.tsx @@ -272,6 +272,7 @@ function AnalysisVisualCard({ visual, beforeExport }: { visual: AnalysisVisual; tabIndex={0} aria-label={`${chartSummary(visual)}。按 Enter 或空格查看数据。`} aria-busy={chartLoading} + style={visual.sectionKey === 'defect_combined' ? { height: Math.max(320, visual.categories.length * 38 + 48) } : undefined} onClick={openData} onKeyDown={event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); openData(); } diff --git a/web/src/analysisVisualsModel.ts b/web/src/analysisVisualsModel.ts index 04a031c..6c859d7 100644 --- a/web/src/analysisVisualsModel.ts +++ b/web/src/analysisVisualsModel.ts @@ -758,6 +758,7 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC }; } + const combinedDefects = visual.sectionKey === 'defect_combined' && visual.type === 'bar'; const series = visual.series.map((item, seriesIndex) => ({ name: plainRichText(item.label), type: visual.type === 'area' ? 'line' : visual.type === 'column' ? 'bar' : visual.type, @@ -770,7 +771,8 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC connectNulls: false, smooth: false, ...(['bar', 'column'].includes(visual.type) ? { - barMaxWidth: 32, + barMaxWidth: combinedDefects ? 18 : 32, + ...(combinedDefects ? { stack: 'combined-defect-stage', barWidth: 18 } : {}), ...(visual.type === 'column' ? { barCategoryGap: '35%' } : {}), label: { show: true, position: visual.type === 'column' ? 'top' : 'right', color: ink, fontSize: 11, @@ -787,8 +789,8 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC const horizontalBar = visual.type === 'bar'; const verticalBar = visual.type === 'column'; const tooltip = { trigger: 'axis' as const, renderMode: 'richText' as const, backgroundColor: theme.surface || '#ffffff', borderColor: line, textStyle: { color: ink }, axisPointer: { type: horizontalBar || verticalBar ? 'shadow' as const : 'line' as const }, formatter }; - const legend = { show: visual.series.length > 1, type: 'scroll' as const, top: 8, textStyle: { color: mutedInk, fontSize: 11 } }; - const grid = { left: horizontalBar ? 18 : 48, right: horizontalBar ? 96 : 24, top: visual.series.length > 1 ? 48 : 18, bottom: verticalBar ? 78 : 24, containLabel: true }; + const legend = { show: visual.series.length > 1 && !combinedDefects, type: 'scroll' as const, top: 8, textStyle: { color: mutedInk, fontSize: 11 } }; + const grid = { left: horizontalBar ? 18 : 48, right: horizontalBar ? 96 : 24, top: visual.series.length > 1 && !combinedDefects ? 48 : 18, bottom: verticalBar ? 78 : 24, containLabel: true }; const shared = { animation: false as const, color: colors, tooltip, legend, grid, aria: { enabled: true, decal: { show: false } } }; const valueAxis = { type: 'value' as const, @@ -895,11 +897,13 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width = 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 maxCategoryLines = Math.max(1, ...wrappedCategories.map(lines => lines.length)); + const combinedDefects = visual.sectionKey === 'defect_combined' && visual.type === 'bar'; 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); + : combinedDefects ? Math.max(reportMode ? 350 : 410, visual.categories.length * (reportMode ? 42 : 46)) + : 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')); @@ -934,7 +938,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width = textStyle: { color: '#65748b', fontSize: 11 }, } : { - show: visual.series.length > 1, + show: visual.series.length > 1 && !combinedDefects, type: 'scroll' as const, top: reportMode ? chartTop + 2 : chartTop - 26, left: 56, diff --git a/web/verification/analysis_visuals.test.mjs b/web/verification/analysis_visuals.test.mjs index d28c885..c1f8356 100644 --- a/web/verification/analysis_visuals.test.mjs +++ b/web/verification/analysis_visuals.test.mjs @@ -115,6 +115,13 @@ test('same-scope black and bright defect changes become one stage-colored chart' assert.deepEqual(combined[0].series[0].values, [265.85, null, null, -12]); assert.deepEqual(combined[0].series[1].values, [null, 123.42, 39.25, null]); assert.equal(combined[0].chartable, true); + const chart = buildAnalysisVisualOption(combined[0]); + assert.equal(chart.legend.show, false); + assert.equal(chart.series[0].stack, chart.series[1].stack); + assert.equal(chart.series[0].barWidth, 18); + const reportChart = buildAnalysisVisualExportOption(combined[0], 1280, 'report').option; + assert.equal(reportChart.legend.show, false); + assert.equal(reportChart.series[0].stack, reportChart.series[1].stack); assert.equal(combined[1].scope.product, '规格 B'); assert.equal(combineStageDefectVisuals(combined).length, 2); });