Skip to content

Commit

Permalink
Component | Chord Diagram | Adding labels event support
Browse files Browse the repository at this point in the history
  • Loading branch information
reb-dev committed Nov 21, 2023
1 parent d576856 commit 8165cf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/ts/src/components/chord-diagram/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class ChordDiagram<
mouseover: this._onLinkMouseOver.bind(this),
mouseout: this._onLinkMouseOut.bind(this),
},
[ChordDiagram.selectors.label]: {
mouseover: this._onNodeMouseOver.bind(this),
mouseout: this._onNodeMouseOut.bind(this),
},
}

private get _forceHighlight (): boolean {
Expand Down Expand Up @@ -208,11 +212,11 @@ export class ChordDiagram<
// Labels
const labelWidth = size - radius - config.nodeWidth
const labels = this.labelGroup
.selectAll<SVGGElement, ChordNode<N>>(`.${s.gLabel}`)
.selectAll<SVGGElement, ChordNode<N>>(`.${s.label}`)
.data(this._nodes, d => String(d.uid))

const labelEnter = labels.enter().append('g')
.attr('class', s.gLabel)
.attr('class', s.label)
.call(createLabel, config, this.radiusScale)

const labelsMerged = labels.merge(labelEnter)
Expand Down
4 changes: 2 additions & 2 deletions packages/ts/src/components/chord-diagram/modules/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function createLabel<N extends ChordInputNode, L extends ChordInputLink>
.attr('transform', d => getLabelTransform(d, config, radiusScale))

selection.append('text')
.attr('class', s.label)
.attr('class', s.labelText)
.style('fill', d => getColor(d.data, config.nodeColor, d.height))
}

Expand All @@ -100,7 +100,7 @@ export function updateLabel<N extends ChordInputNode, L extends ChordInputLink>
.attr('transform', d => getLabelTransform(d, config, radiusScale))
.style('opacity', 1)

const label: Selection<SVGTextElement, ChordNode<N>, SVGElement, unknown> = selection.select(`.${s.label}`)
const label: Selection<SVGTextElement, ChordNode<N>, SVGElement, unknown> = selection.select(`.${s.labelText}`)
label.select('textPath').remove()
label
.text(d => getString(d.data, nodeLabel))
Expand Down
9 changes: 4 additions & 5 deletions packages/ts/src/components/chord-diagram/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ export const highlightedNode = css`
stroke-width: 1.5;
`

export const gLabel = css`
label: group-label;
`

export const label = css`
label: label;
`

export const labelText = css`
label: label-text:
dominant-baseline: middle;
user-select: none;
pointer-events: none;
> textPath {
dominant-baseline: central;
Expand Down

0 comments on commit 8165cf5

Please sign in to comment.