From 51c2342089a34b7ec63665da485f1f016674da89 Mon Sep 17 00:00:00 2001 From: Matt Vickers Date: Wed, 26 Jun 2024 15:09:09 -0400 Subject: [PATCH] We be formatting --- .../BarChart/stories/Default.stories.tsx | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/packages/polaris-viz/src/components/BarChart/stories/Default.stories.tsx b/packages/polaris-viz/src/components/BarChart/stories/Default.stories.tsx index 057893628..27b356d3b 100644 --- a/packages/polaris-viz/src/components/BarChart/stories/Default.stories.tsx +++ b/packages/polaris-viz/src/components/BarChart/stories/Default.stories.tsx @@ -8,8 +8,63 @@ import {DEFAULT_DATA, Template} from './data'; export const Default: Story = Template.bind({}); +const data = [ + { + name: 'Monday', + data: [ + {key: 'Breakfast', value: 3}, + {key: 'Lunch', value: 4}, + {key: 'Dinner', value: 7}, + ], + }, + { + name: 'Tuesday', + data: [ + {key: 'Lunch', value: 14}, + {key: 'Dinner', value: 17}, + ], + color: 'red', + }, + { + name: 'Wednesday', + data: [ + {key: 'Breakfast', value: 23}, + {key: 'Dinner', value: 27}, + ], + }, + { + name: 'Thursday', + data: [ + {key: 'Breakfast', value: 33}, + {key: 'Lunch', value: 34}, + ], + }, +]; + +function formatData(data) { + const keys = new Set(); + + for (const series of data) { + for (const {key} of series.data) { + keys.add(key); + } + } + + return [...keys].map((key, index) => { + return { + ...data[index], + name: key, + data: data.map((series) => { + const values = series.data.find((d) => d.key === key); + + return {key: series.name ?? '', value: values?.value ?? 0}; + }), + }; + }); +} + Default.args = { - data: DEFAULT_DATA, + data: formatData(data), onError: (a, b) => { console.log({a, b}); },