Skip to content

Commit

Permalink
Component | Chord Diagram | Events: Add background selector
Browse files Browse the repository at this point in the history
  • Loading branch information
reb-dev committed Dec 19, 2023
1 parent 185dfc6 commit b7f40c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/ts/src/components/chord-diagram/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export class ChordDiagram<
public config: ChordDiagramConfigInterface<N, L> = this._defaultConfig
datamodel: GraphDataModel<N, L> = new GraphDataModel()

background: Selection<SVGRectElement, unknown, SVGGElement, unknown>
nodeGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>
linkGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>
labelGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>

arcGen = arc<ChordNode<N>>()
radiusScale: ScalePower<number, number> = scalePow()

Expand Down Expand Up @@ -84,6 +86,7 @@ export class ChordDiagram<
constructor (config?: ChordDiagramConfigInterface<N, L>) {
super()
if (config) this.setConfig(config)
this.background = this.g.append('rect').attr('class', s.background)
this.linkGroup = this.g.append('g').attr('class', s.links)
this.nodeGroup = this.g.append('g').attr('class', s.nodes)
this.labelGroup = this.g.append('g').attr('class', s.labels)
Expand Down Expand Up @@ -170,9 +173,16 @@ export class ChordDiagram<
.innerRadius(d => this.radiusScale(d.y1) - getNumber(d, config.nodeWidth))
.outerRadius(d => this.radiusScale(d.y1))

// Center the view
this.g.attr('transform', `translate(${this._width / 2},${this._height / 2})`)
this.g.classed(s.transparent, this._forceHighlight)
this.background
.attr('width', this._width)
.attr('height', this._height)
.style('opacity', 0)

// Center the view
this.nodeGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`)
this.labelGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`)
this.linkGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`)

// Links
const linksSelection = this.linkGroup
Expand Down
4 changes: 4 additions & 0 deletions packages/ts/src/components/chord-diagram/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const variables = injectGlobal`
}
`

export const background = css`
label: background;
`

export const nodes = css`
label: nodes;
`
Expand Down

0 comments on commit b7f40c9

Please sign in to comment.