Skip to content

Commit

Permalink
fix(arcLinkLabels): fix arcLinkLabelsOffset for pie chart (#2369)
Browse files Browse the repository at this point in the history
* Render arcLinkLabels layer after arcs

Adjusting the `arcLinkLabelsOffset` prop does not currently appear to do anything because the arcs are rendered on top of the label links. Moving arcs to the first layer fixes this issue.

* Include offset in useMemo dependency array

* Reorganize layers
  • Loading branch information
aautem authored Jun 26, 2023
1 parent 78d6d2a commit 2250a31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const useTransitionPhases = <Datum extends DatumWithArcAndColor>({
opacity: 0,
}),
}),
[diagonalLength, straightLength, textOffset, getLinkColor, getTextColor]
[diagonalLength, straightLength, textOffset, getLinkColor, getTextColor, offset]
)

const interpolateLink = (
Expand Down
42 changes: 21 additions & 21 deletions packages/pie/src/Pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,12 @@ const InnerPie = <RawDatum extends MayHaveLabel>({
const boundDefs = bindDefs(defs, dataWithArc, fill)

const layerById: Record<PieLayerId, ReactNode> = {
arcLinkLabels: null,
arcs: null,
arcLinkLabels: null,
arcLabels: null,
legends: null,
}

if (enableArcLinkLabels && layers.includes('arcLinkLabels')) {
layerById.arcLinkLabels = (
<ArcLinkLabelsLayer<ComputedDatum<RawDatum>>
key="arcLinkLabels"
center={[centerX, centerY]}
data={dataWithArc}
label={arcLinkLabel}
skipAngle={arcLinkLabelsSkipAngle}
offset={arcLinkLabelsOffset}
diagonalLength={arcLinkLabelsDiagonalLength}
straightLength={arcLinkLabelsStraightLength}
strokeWidth={arcLinkLabelsThickness}
textOffset={arcLinkLabelsTextOffset}
textColor={arcLinkLabelsTextColor}
linkColor={arcLinkLabelsColor}
component={arcLinkLabelComponent}
/>
)
}

if (layers.includes('arcs')) {
layerById.arcs = (
<Arcs<RawDatum>
Expand All @@ -169,6 +149,26 @@ const InnerPie = <RawDatum extends MayHaveLabel>({
)
}

if (enableArcLinkLabels && layers.includes('arcLinkLabels')) {
layerById.arcLinkLabels = (
<ArcLinkLabelsLayer<ComputedDatum<RawDatum>>
key="arcLinkLabels"
center={[centerX, centerY]}
data={dataWithArc}
label={arcLinkLabel}
skipAngle={arcLinkLabelsSkipAngle}
offset={arcLinkLabelsOffset}
diagonalLength={arcLinkLabelsDiagonalLength}
straightLength={arcLinkLabelsStraightLength}
strokeWidth={arcLinkLabelsThickness}
textOffset={arcLinkLabelsTextOffset}
textColor={arcLinkLabelsTextColor}
linkColor={arcLinkLabelsColor}
component={arcLinkLabelComponent}
/>
)
}

if (enableArcLabels && layers.includes('arcLabels')) {
layerById.arcLabels = (
<ArcLabelsLayer<ComputedDatum<RawDatum>>
Expand Down
2 changes: 1 addition & 1 deletion packages/pie/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const defaultProps = {
padAngle: 0,
cornerRadius: 0,

layers: ['arcLinkLabels', 'arcs', 'arcLabels', 'legends'],
layers: ['arcs', 'arcLinkLabels', 'arcLabels', 'legends'],

// layout
startAngle: 0,
Expand Down

1 comment on commit 2250a31

@vercel
Copy link

@vercel vercel bot commented on 2250a31 Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nivo – ./

nivo.vercel.app
nivo.rocks
nivo-git-master-plouc.vercel.app
nivo-plouc.vercel.app
www.nivo.rocks

Please sign in to comment.