question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal with code - Word Cloud

See original GitHub issue

This is not a PR because I’m new here and do not have the environment to set up the repo, nor do I want to add a PR with a whole new package.

Using the vx style I created a word cloud component and am adding it here as a proposal for another chart. I am currently using it in my own code and it works quite well.

import React from 'react';
import cx from 'classnames';
import cloud from 'd3-cloud';
import { Group } from '@vx/group';

const WordCloud = ({
  className,
  top,
  left,
  width = 1,
  height = 1,
  words,
  padding,
  text,
  font,
  fontSize,
  fontStyle,
  fontWeight,
  rotate,
  spiral,
  random,
  colourScale,
  children,
  ...restProps
}) => {
  const layout = cloud();
  layout.size([width, height]);
    
  if (words) layout.words(words.map(x => ({ ...x })));
  if (text) layout.text(text);
  if (padding) layout.padding(padding);
  if (font) layout.font(font);
  if (fontSize) layout.fontSize(fontSize);
  if (fontStyle) layout.fontStyle(fontStyle);
  if (fontWeight) layout.fontWeight(fontWeight);
  if (rotate) layout.rotate(rotate);
  if (random) layout.random(random);
  if (spiral) layout.spiral(spiral);
  layout.start();

  const elements = layout.words();
  if (children) return (
    <>{children({ words: elements })}</>
  );
  return (
    <Group className={'vx-word-cloud-group'} top={top} left={left}>
      {elements.map(
        (word, i) => {
          const { font, style, weight, rotate, size, x, y } = word;
          return (
            <text
              key={`word-cloud-text-${i}`}
              className={cx('vx-word-cloud-text', className)}
              textAnchor={'middle'}
              fontFamily={font}
              fontSize={size}
              fontWeight={weight}
              fontStyle={style}
              transform={`translate(${x}, ${y})rotate(${rotate})`}
              fill={colourScale? colourScale(word, i): undefined}
              {...restProps}
            >
              {text(word)}
            </text>
          );
        }
      )}
    </Group>
  );
};

export default WordCloud;

And it can then be used as such

<WordCloud
  left={xMax/2}
  top={yMax/2}
  width={xMax}
  height={yMax}
  words={words}

  text={textAccessor}
  font={FONT_FAMILY}
  fontSize={fontSize}

  padding={5}
  spiral={spiral}
  rotate={rotate}
  colourScale={colourScale}
/>

Since d3-cloud falls under d3.layout, would this then fall under a new package of vx-layout? If anyone would like to get a word cloud pr going I would happily contribute

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
craciuncezarcommented, Aug 13, 2021

Hey @williaster @mitchellwarr I’ve created a PR for this https://github.com/airbnb/visx/pull/1311 and abstracted that layout logic into a hook as suggested. When you have a chance, please take a look 👀

0reactions
mitchellwarrcommented, Aug 13, 2021

@craciuncezar This is awesome! Thanks so much for moving this forward. Im not a maintainer so i cant speak for the pr much, but im impressed with it nonetheless

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making a word cloud for your ARC application - Vimeo
RMS generates a word cloud of a proposal based on: – • Proposal title • Proposal summary • Impact statement • FoR codes...
Read more >
How to generate Word Clouds from multiple news source (with ...
The below tutorial will be divided into two parts — retrieve news information from the News API, and the generation of word clouds....
Read more >
An easy way to make word clouds for data scientists
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons ......
Read more >
Personalised Word Art / Word Cloud Engagement / Proposal
Word clouds or word art are a wonderful gift for someone who wants something unique and different. They can be created in any...
Read more >
15 Graphics: Word clouds ideas - Pinterest
Apr 15, 2016 - Explore Karen Ching's board "Graphics: Word clouds" on Pinterest. See more ideas about word cloud, words, ... Subtraction, Proposal,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found