diff --git a/packages/circle-packing/src/CirclePacking.tsx b/packages/circle-packing/src/CirclePacking.tsx index 45bb08309..98ca29d81 100644 --- a/packages/circle-packing/src/CirclePacking.tsx +++ b/packages/circle-packing/src/CirclePacking.tsx @@ -1,4 +1,4 @@ -import React, { createElement, Fragment, ReactNode } from 'react' +import React, { createElement, Fragment, ReactNode, useMemo } from 'react' import { // @ts-ignore bindDefs, @@ -42,6 +42,8 @@ const InnerCirclePacking = ({ borderWidth = defaultProps.borderWidth, borderColor = defaultProps.borderColor as InheritedColorConfig>, circleComponent = CircleSvg, + defs = defaultProps.defs, + fill = defaultProps.fill, enableLabels = defaultProps.enableLabels, label = defaultProps.label, labelsFilter, @@ -81,6 +83,12 @@ const InnerCirclePacking = ({ const zoomedNodes = useCirclePackingZoom(nodes, zoomedId, innerWidth, innerHeight) + const boundDefs = useMemo(() => bindDefs(defs, zoomedNodes, fill, { targetKey: 'fill' }), [ + defs, + zoomedNodes, + fill, + ]) + const layerById: Record = { circles: null, labels: null, @@ -127,7 +135,7 @@ const InnerCirclePacking = ({ width={outerWidth} height={outerHeight} margin={margin} - //defs={boundDefs} + defs={boundDefs} role={role} > {layers.map((layer, i) => { diff --git a/packages/circle-packing/src/CircleSvg.tsx b/packages/circle-packing/src/CircleSvg.tsx index 9e1f4cddb..c07522b72 100644 --- a/packages/circle-packing/src/CircleSvg.tsx +++ b/packages/circle-packing/src/CircleSvg.tsx @@ -24,7 +24,7 @@ export const CircleSvg = ({ cx={style.x} cy={style.y} r={style.radius} - fill={style.color} + fill={node.fill || style.color} stroke={style.borderColor} strokeWidth={style.borderWidth} opacity={style.opacity} diff --git a/packages/circle-packing/src/props.ts b/packages/circle-packing/src/props.ts index 8a02f98ab..d275c7fa7 100644 --- a/packages/circle-packing/src/props.ts +++ b/packages/circle-packing/src/props.ts @@ -17,6 +17,8 @@ export const defaultProps = { from: 'color', modifiers: [['darker', 0.3]], }, + defs: [], + fill: [], enableLabels: false, label: 'id', labelTextColor: { diff --git a/packages/circle-packing/src/types.ts b/packages/circle-packing/src/types.ts index 610956193..35f2184ef 100644 --- a/packages/circle-packing/src/types.ts +++ b/packages/circle-packing/src/types.ts @@ -1,11 +1,12 @@ import * as React from 'react' +import { Interpolation, SpringValue } from 'react-spring' import { Box, - Dimensions, ModernMotionProps, Theme, PropertyAccessor, ValueFormat, + SvgDefsAndFill, } from '@nivo/core' import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors' @@ -84,7 +85,8 @@ export interface CirclePackingCommonProps { } export type CirclePackingSvgProps = CirclePackingCommonProps & - MouseHandlers + MouseHandlers & + SvgDefsAndFill> export type CirclePackingHtmlProps = CirclePackingCommonProps & MouseHandlers