Skip to content

Commit

Permalink
feat(sunburst): pass child node to childColor function (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
onionhammer committed May 22, 2021
1 parent cb98390 commit 5580e96
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/colors/src/inheritedColor.ts
Expand Up @@ -15,7 +15,7 @@ export type ColorModifierFunction = (color: RGBColor) => RGBColor

export type InheritedColorConfigStaticColor = string

export type InheritedColorConfigCustomFunction<Datum> = (d: Datum) => string
export type InheritedColorConfigCustomFunction<Datum> = (d: Datum, ...drest: Datum[]) => string

export interface InheritedColorConfigFromTheme {
theme: string
Expand Down Expand Up @@ -61,7 +61,7 @@ export const getInheritedColorGenerator = <Datum = any>(
) => {
// user provided function
if (typeof config === 'function') {
return (datum: Datum) => config(datum)
return config
}

if (isPlainObject(config)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/sunburst/src/hooks.ts
Expand Up @@ -108,7 +108,7 @@ export const useSunburst = <RawDatum>({
}

if (inheritColorFromParent && parent && normalizedNode.depth > 1) {
normalizedNode.color = getChildColor(parent)
normalizedNode.color = getChildColor(parent, normalizedNode)
} else {
normalizedNode.color = getColor(normalizedNode)
}
Expand Down
7 changes: 7 additions & 0 deletions packages/sunburst/stories/sunburst.stories.tsx
Expand Up @@ -46,6 +46,13 @@ stories.add('with custom colors', () => (
<Sunburst<RawDatum> {...commonProperties} colors={customPalette} />
))

stories.add('with custom child colors', () => (
<Sunburst<RawDatum> {...commonProperties} childColor={(parent, child) => {
// @ts-expect-error
return child.data.color;
}} />
))

stories.add('with formatted tooltip value', () => (
<Sunburst<RawDatum> {...commonProperties} valueFormat=" >-$,.2f" />
))
Expand Down

0 comments on commit 5580e96

Please sign in to comment.