Skip to content

Commit 39b7d00

Browse files
committed
feat: support simple nested objects as data
1 parent 4a57ec0 commit 39b7d00

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/solid-charts/src/lib/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import type { ChartContextType } from '@src/components/context'
22
import { scaleBand } from 'd3-scale'
33

44
const accessData = <T>(data: unknown, dataKey: string | undefined): T[] => {
5-
return (
6-
dataKey
7-
? (data as Record<string, unknown>[]).map((entry) => entry[dataKey])
8-
: data
5+
if (!dataKey) return data as T[]
6+
7+
const keys = dataKey.split('.')
8+
9+
return (data as Record<string, any>[]).map((entry) =>
10+
keys.reduce((acc, key) => acc?.[key], entry),
911
) as T[]
1012
}
1113

0 commit comments

Comments
 (0)