Yoctol / react-d3-cloud

A word cloud react component built with d3-cloud.
https://yoctol.github.io/react-d3-cloud
MIT License
138 stars 47 forks source link

Question: How to make it render using 100% width/height of the container? #120

Closed carlosalvidrez closed 2 years ago

carlosalvidrez commented 3 years ago

How to make it render using 100% width/height of the container? Trying to figure out how to make it responsive to screen width changes for example.

PS. Thank you for sharing this library!

chentsulin commented 3 years ago

You can use useMeasure Custom React Hook or Resize Observer API to get width, height of the container. For example:

function App({ data }) {
  const [ref, { width, height }] = useMeasure();

  return (
    <div ref={ref} style={{ width: 500, height: 500 }}>
      <WordCloud
        width={width}
        height={height}
        data={newData}
      />
    </div>
  );
}
chentsulin commented 3 years ago

95 #132 I suppose viewBox can help in this case.

chentsulin commented 2 years ago

viewBox solves this problem perfectly. Just update to the latest version.

kongmengfei commented 2 years ago

viewBox solves this problem perfectly. Just update to the latest version.

how to use view box?

carlosalvidrez commented 2 years ago

I also have no idea what the solution using "viewBox" looks like @kongmengfei. @chentsulin could you please provide an example? Thanks