Skip to content

Commit

Permalink
feat(circle-packing): add colorBy property to control which property …
Browse files Browse the repository at this point in the history
…should be used to assign a color
  • Loading branch information
plouc authored and wyze committed Apr 26, 2021
1 parent 82cb7c5 commit 1091468
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/circle-packing/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const defaultProps = {
leavesOnly: false,
layers: ['circles', 'labels'] as CirclePackingLayerId[],
colors: { scheme: 'nivo' } as OrdinalColorScaleConfig,
colorBy: 'id' as const,
colorBy: 'depth' as const,
childColor: {
from: 'color',
modifiers: [['darker', 0.3]],
Expand Down
6 changes: 3 additions & 3 deletions packages/circle-packing/stories/bubble.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { Bubble } from '../src'
const commonProperties = {
width: 900,
height: 500,
root: generateLibTree(),
identity: 'name',
data: generateLibTree(),
id: 'name',
value: 'loc',
label: 'name',
labelSkipRadius: 16,
labelsSkipRadius: 16,
}

storiesOf('Bubble', module)
Expand Down
38 changes: 37 additions & 1 deletion website/src/data/components/circle-packing/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const props = [
themeProperty,
{
key: 'colors',
help: 'Defines how to compute node color.',
help: 'Define how to compute node color.',
description: `
colors used to colorize the circles,
[see dedicated documentation](self:/guides/colors).
Expand All @@ -188,6 +188,25 @@ const props = [
controlType: 'ordinalColors',
group: 'Style',
},
{
key: 'colorBy',
help: `Define the property to use to assign a color to circles.`,
description: `
When using \`id\`, each node will get a new color,
and when using \`depth\` the nodes' color will depend on their depth.
`,
type: `'id' | 'depth'`,
required: false,
defaultValue: defaultProps.colorBy,
controlType: 'radio',
group: 'Style',
controlOptions: {
choices: [
{ label: 'id', value: 'id' },
{ label: 'depth', value: 'depth' },
],
},
},
{
key: 'childColor',
help: 'Defines how to compute child nodes color.',
Expand Down Expand Up @@ -257,6 +276,23 @@ const props = [
),
},
},
{
key: 'labelsFilter',
help: 'Filter labels using custom conditions.',
description: `
Can be used to only show labels at a certain depth for example:
\`\`\`
<CirclePacking
labelsFilter={label => label.node.depth == 2}
{...props}
/>
\`\`\`
`,
type: '(label) => boolean',
required: false,
group: 'Labels',
},
{
key: 'labelsSkipRadius',
help: 'Skip label rendering if node radius is lower than given value, 0 to disable.',
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/circle-packing/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialProperties = {
value: 'value',
valueFormat: { format: '', enabled: false },
colors: { scheme: 'spectral' },
colorBy: 'id',
childColor: 'noinherit',
padding: 1,
leavesOnly: true,
Expand Down

0 comments on commit 1091468

Please sign in to comment.