Skip to content

Commit c40006f

Browse files
authoredMay 10, 2022
feat(radial-bar): implement defs/fill, modeled after Bar implementation (#1957)
* working checkpoint of hard coded defs for a patterned render of a radial arc * instead bind the fill to root datum * remove disabled props for fill on datum.data * convert hard code to story * remove diagnostics * run make fmt
1 parent 1b539a4 commit c40006f

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed
 

‎packages/radial-bar/src/RadialBar.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { createElement, Fragment, ReactNode } from 'react'
2-
import { Container, useDimensions, SvgWrapper, clampArc } from '@nivo/core'
2+
import {
3+
Container,
4+
useDimensions,
5+
SvgWrapper,
6+
clampArc,
7+
// @ts-ignore
8+
bindDefs,
9+
} from '@nivo/core'
10+
311
import { ArcLabelsLayer } from '@nivo/arcs'
412
import { BoxLegendSvg } from '@nivo/legends'
513
import { PolarGrid, RadialAxis, CircularAxis } from '@nivo/polar-axes'
@@ -37,6 +45,8 @@ const InnerRadialBar = <D extends RadialBarDatum>({
3745
circularAxisInner = svgDefaultProps.circularAxisInner,
3846
circularAxisOuter = svgDefaultProps.circularAxisOuter,
3947
colors = svgDefaultProps.colors,
48+
defs = svgDefaultProps.defs,
49+
fill = svgDefaultProps.fill,
4050
borderWidth = svgDefaultProps.borderWidth,
4151
borderColor = svgDefaultProps.borderColor,
4252
enableLabels = svgDefaultProps.enableLabels,
@@ -219,11 +229,17 @@ const InnerRadialBar = <D extends RadialBarDatum>({
219229
)
220230
}
221231

232+
const boundDefs = bindDefs(defs, bars, fill, {
233+
dataKey: 'data',
234+
targetKey: 'fill',
235+
})
236+
222237
return (
223238
<SvgWrapper
224239
width={outerWidth}
225240
height={outerHeight}
226241
margin={margin}
242+
defs={boundDefs}
227243
role={role}
228244
ariaLabel={ariaLabel}
229245
ariaLabelledBy={ariaLabelledBy}

‎packages/radial-bar/src/props.ts

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export const commonDefaultProps = {
3939

4040
legends: [],
4141

42+
defs: [],
43+
fill: [],
44+
4245
animate: true,
4346
motionConfig: 'gentle' as const,
4447
transitionMode: 'centerRadius' as const,

‎packages/radial-bar/src/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ModernMotionProps,
77
PropertyAccessor,
88
ValueFormat,
9+
SvgDefsAndFill,
910
} from '@nivo/core'
1011
import { Arc, ArcGenerator, ArcLabelsProps, ArcTransitionMode } from '@nivo/arcs'
1112
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
@@ -123,4 +124,5 @@ export type RadialBarSvgProps<D extends RadialBarDatum = RadialBarDatum> = Parti
123124
> &
124125
RadialBarDataProps<D> &
125126
Dimensions &
126-
ModernMotionProps
127+
ModernMotionProps &
128+
SvgDefsAndFill<D>

‎packages/radial-bar/stories/radialBar.stories.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ const demoPhases: {
245245
enableLabels: true,
246246
},
247247
},
248+
{
249+
description: 'Patterned Fill',
250+
props: {
251+
...commonProperties,
252+
defs: [
253+
{
254+
id: 'lines',
255+
type: 'patternLines',
256+
background: 'rgba(0, 0, 0, 0)',
257+
color: 'inherit',
258+
rotation: -45,
259+
lineWidth: 4,
260+
spacing: 8,
261+
},
262+
],
263+
fill: [
264+
{
265+
match: {
266+
// id: 'Online.Fruits'
267+
x: 'Fruits',
268+
},
269+
id: 'lines',
270+
},
271+
],
272+
},
273+
},
248274
]
249275

250276
const demoTheme: Theme = {

0 commit comments

Comments
 (0)
Please sign in to comment.