Skip to content

Commit

Permalink
improve: allow adding class names to words
Browse files Browse the repository at this point in the history
This commit adds new prop `wordClassNames`, which allows to define
custom class name(s) for each word separately. This expands the ability
to customize words presentation at call-site.
  • Loading branch information
uson1x committed Jul 9, 2024
1 parent b7a35e3 commit 76bd94b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/WordCloud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function WordCloud({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The ordinal function should accept number
fill = (_, i) => defaultScaleOrdinal(i),
wordClassNames = () => '',
onWordClick,
onWordMouseOver,
onWordMouseOut,
Expand Down Expand Up @@ -115,6 +116,7 @@ function WordCloud({
((d) => `${d.size}px`) as ValueFn<SVGTextElement, Word, string>
)
.style('fill', fill)
.attr('class', (d, i, nodes) => wordClassNames.call(nodes[i], d, i, nodes))
.attr('text-anchor', 'middle')
.attr('transform', (d) => `translate(${[d.x, d.y]})rotate(${d.rotate})`)
.text((d) => d.text);
Expand Down

0 comments on commit 76bd94b

Please sign in to comment.