jasondavies / d3-cloud

Create word clouds in JavaScript.
https://www.jasondavies.com/wordcloud/
Other
3.85k stars 1.07k forks source link

Unreadable under D3 V7 #179

Closed remember9069 closed 1 year ago

remember9069 commented 1 year ago

When i import this as import * as d3 from 'd3', shows Uncaught TypeError: Cannot read properties of undefined (reading 'cloud') in console, in line where i call cloud = d3.layout.cloud(); And if i import this as import * as cloud from "d3-cloud", it shows Cannot find module 'd3-cloud' or its corresponding type declarations.

jasondavies commented 1 year ago

Strictly speaking, you don't need D3 to use d3-cloud, although that's the most common scenario. d3-cloud is a completely standalone module. If you're using ESM you should be able to do:

import d3_cloud from "d3-cloud";

const cloud = d3_cloud();
...
remember9069 commented 1 year ago

Strictly speaking, you don't need D3 to use d3-cloud, although that's the most common scenario. d3-cloud is a completely standalone module. If you're using ESM you should be able to do:

import d3_cloud from "d3-cloud";

const cloud = d3_cloud();
...

Thank you very much for the quick and helpful reply. After I did what you said, it appears

This expression is not callable.
  Type 'Cloud<Word>' has no call signatures.js(2349)

and in console shows Uncaught TypeError: cloud is not a function

Regarding this line var layout = cloud()

jasondavies commented 1 year ago
var layout = d3_cloud()
remember9069 commented 1 year ago
var layout = d3_cloud()

Yes, i found that mistake as well, thanks.