Skip to content

Commit

Permalink
feat(circle-packing): restore patterns and gradients support for the …
Browse files Browse the repository at this point in the history
…SVG implementation
  • Loading branch information
plouc authored and wyze committed Apr 26, 2021
1 parent b864de9 commit 08ee515
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/circle-packing/src/CirclePacking.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createElement, Fragment, ReactNode } from 'react'
import React, { createElement, Fragment, ReactNode, useMemo } from 'react'
import {
// @ts-ignore
bindDefs,
Expand Down Expand Up @@ -42,6 +42,8 @@ const InnerCirclePacking = <RawDatum,>({
borderWidth = defaultProps.borderWidth,
borderColor = defaultProps.borderColor as InheritedColorConfig<ComputedDatum<RawDatum>>,
circleComponent = CircleSvg,
defs = defaultProps.defs,
fill = defaultProps.fill,
enableLabels = defaultProps.enableLabels,
label = defaultProps.label,
labelsFilter,
Expand Down Expand Up @@ -81,6 +83,12 @@ const InnerCirclePacking = <RawDatum,>({

const zoomedNodes = useCirclePackingZoom<RawDatum>(nodes, zoomedId, innerWidth, innerHeight)

const boundDefs = useMemo(() => bindDefs(defs, zoomedNodes, fill, { targetKey: 'fill' }), [
defs,
zoomedNodes,
fill,
])

const layerById: Record<CirclePackingLayerId, ReactNode> = {
circles: null,
labels: null,
Expand Down Expand Up @@ -127,7 +135,7 @@ const InnerCirclePacking = <RawDatum,>({
width={outerWidth}
height={outerHeight}
margin={margin}
//defs={boundDefs}
defs={boundDefs}
role={role}
>
{layers.map((layer, i) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/circle-packing/src/CircleSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CircleSvg = <RawDatum,>({
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}
Expand Down
2 changes: 2 additions & 0 deletions packages/circle-packing/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const defaultProps = {
from: 'color',
modifiers: [['darker', 0.3]],
},
defs: [],
fill: [],
enableLabels: false,
label: 'id',
labelTextColor: {
Expand Down
6 changes: 4 additions & 2 deletions packages/circle-packing/src/types.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -84,7 +85,8 @@ export interface CirclePackingCommonProps<RawDatum> {
}

export type CirclePackingSvgProps<RawDatum> = CirclePackingCommonProps<RawDatum> &
MouseHandlers<RawDatum>
MouseHandlers<RawDatum> &
SvgDefsAndFill<ComputedDatum<RawDatum>>

export type CirclePackingHtmlProps<RawDatum> = CirclePackingCommonProps<RawDatum> &
MouseHandlers<RawDatum>
Expand Down

0 comments on commit 08ee515

Please sign in to comment.