fix: normalizeSlide transforme {label,value} → {name,value} pour recharts
Le graphe était noir car recharts cherchait xKey='name' mais les données
avaient {label,value}. Fix dans normalizeSlide case 'chart':
- data.map({label,value} → {name,value})
- xKey: 'name', yKeys: ['value'] explicitement
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -25,21 +25,10 @@ const GRID_STROKE = 'rgba(255,255,255,0.07)'
|
||||
|
||||
// ── Chart ──────────────────────────────────────────────────────────────────────
|
||||
function SlideChart({ slide }: { slide: SlideSpec }) {
|
||||
// Support both old format (slide.chart) and new flat format (slide.chartType + slide.data)
|
||||
const chart = slide.chart ?? (
|
||||
slide.chartType || slide.data
|
||||
? {
|
||||
type: slide.chartType ?? 'bar',
|
||||
data: (slide.data as any[])?.map((d: any) => ({ name: d.label ?? d.name, value: d.value })) ?? [],
|
||||
xKey: 'name',
|
||||
yKeys: ['value'],
|
||||
showLegend: true,
|
||||
}
|
||||
: undefined
|
||||
)
|
||||
const chart = slide.chart
|
||||
if (!chart?.data?.length) return null
|
||||
|
||||
const colors = chart.colors ?? CHART_COLORS
|
||||
const colors = (chart as any).colors ?? CHART_COLORS
|
||||
const xKey = chart.xKey ?? 'name'
|
||||
const yKeys = chart.yKeys ?? Object.keys(chart.data[0]).filter(k => k !== xKey)
|
||||
const legend = chart.showLegend !== false && yKeys.length > 1
|
||||
@@ -580,7 +569,13 @@ function normalizeSlide(slide: any, index: number): SlideSpec {
|
||||
layout: 'chart',
|
||||
chart: {
|
||||
type: slide.chartType ?? 'bar',
|
||||
data: slide.data ?? []
|
||||
// Normalize {label,value} → {name,value} so recharts xKey='name' works
|
||||
data: (slide.data ?? []).map((d: any) => ({
|
||||
name: d.label ?? d.name ?? '',
|
||||
value: typeof d.value === 'number' ? d.value : Number(d.value) || 0,
|
||||
})),
|
||||
xKey: 'name',
|
||||
yKeys: ['value'],
|
||||
},
|
||||
notes: slide.notes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user