Skip to content

Commit f2750d2

Browse files
committed
Component | Chord: Fix link value zero issue, add handle to 0, null and undefined cases
1 parent dfb9a8e commit f2750d2

File tree

2 files changed

+37
-1
lines changed
  • packages
    • ts/src/components/chord-diagram

2 files changed

+37
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react'
2+
import { VisSingleContainer, VisChordDiagram } from '@unovis/react'
3+
import { ExampleViewerDurationProps } from '@src/components/ExampleViewer/index'
4+
5+
export const title = 'Chord Diagram Zero Value Link'
6+
export const subTitle = 'External select node'
7+
8+
const data = {
9+
nodes: Array(5).fill(0).map((_, i) => ({ id: String.fromCharCode(i + 65) })),
10+
links: [
11+
{ source: 'A', target: 'B', value: undefined },
12+
{ source: 'A', target: 'D', value: null },
13+
{ source: 'B', target: 'E', value: 0 },
14+
{ source: 'B', target: 'D', value: null },
15+
{ source: 'C', target: 'D', value: 0 },
16+
{ source: 'D', target: 'A', value: 1 },
17+
{ source: 'D', target: 'E', value: 0 },
18+
],
19+
}
20+
21+
export const component = (props: ExampleViewerDurationProps): React.ReactNode => {
22+
return (
23+
<>
24+
<VisSingleContainer data={data} height={600}>
25+
<VisChordDiagram
26+
nodeLabelAlignment='perpendicular'
27+
nodeLabel={React.useCallback((d: { id: string }) => `Segment ${d.id}`, [])}
28+
padAngle={0.75}
29+
duration={props.duration}
30+
/>
31+
</VisSingleContainer>
32+
</>
33+
)
34+
}

packages/ts/src/components/chord-diagram/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export class ChordDiagram<
126126
}
127127

128128
_layoutData (): void {
129-
const { nodes, links } = this.datamodel
129+
const { nodes } = this.datamodel
130+
let { links } = this.datamodel
130131
const { padAngle, linkValue, nodeLevels } = this.config
131132
nodes.forEach(n => { delete n._state.value })
132133
links.forEach(l => {
@@ -136,6 +137,7 @@ export class ChordDiagram<
136137
l.target._state.value = (l.target._state.value || 0) + getNumber(l, linkValue)
137138
})
138139

140+
links = links.filter(d => d._state.value)
139141
const root = getHierarchyNodes(nodes, d => d._state?.value, nodeLevels)
140142

141143
const partitionData = partition().size([this.config.angleRange[1], 1])(root) as ChordNode<N>

0 commit comments

Comments
 (0)