Align combined defect chart rows and spacing

This commit is contained in:
2026-10-24 10:29:37 +08:00
parent e2fb128911
commit 55327df5e4
3 changed files with 17 additions and 5 deletions
+1
View File
@@ -272,6 +272,7 @@ function AnalysisVisualCard({ visual, beforeExport }: { visual: AnalysisVisual;
tabIndex={0} tabIndex={0}
aria-label={`${chartSummary(visual)}。按 Enter 或空格查看数据。`} aria-label={`${chartSummary(visual)}。按 Enter 或空格查看数据。`}
aria-busy={chartLoading} aria-busy={chartLoading}
style={visual.sectionKey === 'defect_combined' ? { height: Math.max(320, visual.categories.length * 38 + 48) } : undefined}
onClick={openData} onClick={openData}
onKeyDown={event => { onKeyDown={event => {
if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); openData(); } if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); openData(); }
+8 -4
View File
@@ -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) => ({ const series = visual.series.map((item, seriesIndex) => ({
name: plainRichText(item.label), name: plainRichText(item.label),
type: visual.type === 'area' ? 'line' : visual.type === 'column' ? 'bar' : visual.type, type: visual.type === 'area' ? 'line' : visual.type === 'column' ? 'bar' : visual.type,
@@ -770,7 +771,8 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
connectNulls: false, connectNulls: false,
smooth: false, smooth: false,
...(['bar', 'column'].includes(visual.type) ? { ...(['bar', 'column'].includes(visual.type) ? {
barMaxWidth: 32, barMaxWidth: combinedDefects ? 18 : 32,
...(combinedDefects ? { stack: 'combined-defect-stage', barWidth: 18 } : {}),
...(visual.type === 'column' ? { barCategoryGap: '35%' } : {}), ...(visual.type === 'column' ? { barCategoryGap: '35%' } : {}),
label: { show: true, position: visual.type === 'column' ? 'top' : 'right', label: { show: true, position: visual.type === 'column' ? 'top' : 'right',
color: ink, fontSize: 11, color: ink, fontSize: 11,
@@ -787,8 +789,8 @@ export function buildAnalysisVisualOption(visual: AnalysisVisual, theme: VisualC
const horizontalBar = visual.type === 'bar'; const horizontalBar = visual.type === 'bar';
const verticalBar = visual.type === 'column'; 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 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 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 ? 48 : 18, bottom: verticalBar ? 78 : 24, containLabel: true }; 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 shared = { animation: false as const, color: colors, tooltip, legend, grid, aria: { enabled: true, decal: { show: false } } };
const valueAxis = { const valueAxis = {
type: 'value' as const, type: 'value' as const,
@@ -895,10 +897,12 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
const wrappedCategories = visual.categories.map((_category, index) => wrapLines(visualCategoryLabel(visual, index), 14)); 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 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 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)) 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 === 'waterfall' ? (reportMode ? 300 : 480)
: visual.type === 'heatmap' ? Math.max(reportMode ? 180 : 240, visual.series.length * (reportMode ? 62 : 90)) : 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)) : visual.type === 'pareto' ? (reportMode ? Math.max(300, 170 + maxCategoryLines * 18) : 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); : 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 height = chartTop + chartHeight + chartBottom;
const base = buildAnalysisVisualOption(visual, { ink: '#263c5a', mutedInk: '#65748b', line: '#dfe5ef', surface: '#ffffff' }); const base = buildAnalysisVisualOption(visual, { ink: '#263c5a', mutedInk: '#65748b', line: '#dfe5ef', surface: '#ffffff' });
@@ -934,7 +938,7 @@ export function buildAnalysisVisualExportOption(visual: AnalysisVisual, width =
textStyle: { color: '#65748b', fontSize: 11 }, textStyle: { color: '#65748b', fontSize: 11 },
} }
: { : {
show: visual.series.length > 1, show: visual.series.length > 1 && !combinedDefects,
type: 'scroll' as const, type: 'scroll' as const,
top: reportMode ? chartTop + 2 : chartTop - 26, top: reportMode ? chartTop + 2 : chartTop - 26,
left: 56, left: 56,
@@ -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[0].values, [265.85, null, null, -12]);
assert.deepEqual(combined[0].series[1].values, [null, 123.42, 39.25, null]); assert.deepEqual(combined[0].series[1].values, [null, 123.42, 39.25, null]);
assert.equal(combined[0].chartable, true); 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(combined[1].scope.product, '规格 B');
assert.equal(combineStageDefectVisuals(combined).length, 2); assert.equal(combineStageDefectVisuals(combined).length, 2);
}); });