{"id":17176258,"url":"https://github.com/wanglin2/simple-word-cloud","last_synced_at":"2025-07-26T23:32:30.756Z","repository":{"id":220752981,"uuid":"752507521","full_name":"wanglin2/simple-word-cloud","owner":"wanglin2","description":"一个简单的词云库","archived":false,"fork":false,"pushed_at":"2024-03-18T10:47:07.000Z","size":22729,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-15T23:59:31.005Z","etag":null,"topics":["word-cloud"],"latest_commit_sha":null,"homepage":"https://wanglin2.github.io/simple-word-cloud/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wanglin2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-04T03:22:03.000Z","updated_at":"2024-09-19T08:37:31.000Z","dependencies_parsed_at":"2024-03-18T11:57:21.121Z","dependency_job_id":"39e3ee8c-9d8d-4574-8b70-6935e2ff85d0","html_url":"https://github.com/wanglin2/simple-word-cloud","commit_stats":null,"previous_names":["wanglin2/word-cloud-demo","wanglin2/simple-word-cloud"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanglin2%2Fsimple-word-cloud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanglin2%2Fsimple-word-cloud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanglin2%2Fsimple-word-cloud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wanglin2%2Fsimple-word-cloud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wanglin2","download_url":"https://codeload.github.com/wanglin2/simple-word-cloud/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227732858,"owners_count":17811477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["word-cloud"],"created_at":"2024-10-14T23:59:42.575Z","updated_at":"2024-12-02T13:22:31.713Z","avatar_url":"https://github.com/wanglin2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-word-cloud\n\n\u003e 一个简单的词云库\n\n## 安装\n\n```bash\nnpm i simple-word-cloud\n```\n\n\u003e 注意：源码未打包直接发布，有需要请自行配置打包文件。\n\n## 使用\n\n```html\n\u003cdiv id=\"container\"\u003e\u003c/div\u003e\n```\n\n```js\nimport SimpleWordCloud from 'simple-word-cloud'\n\nconst wordCloud = new SimpleWordCloud({\n  el: document.getElementById('container') // 容器元素，大小不能为0\n  // 其他配置选项\n})\nwordCloud.render([\n  ['文字', 12, {}] // ['文字', 权重， 配置选项]\n  // ...\n])\n```\n\n## 文档\n\n### 创建实例\n\n```js\nconst wordCloud = new SimpleWordCloud(options)\n```\n\n#### 参数options\n\n对象类型，可以传递以下选项：\n\n| 属性                | 类型             | 默认值                    | 描述                                                         |\n| ------------------- | ---------------- | ------------------------- | ------------------------------------------------------------ |\n| el                  | DOM Element      |                           | 容器元素，必填                                               |\n| minFontSize         | Number           | 12                        | 文字最小的字号                                               |\n| maxFontSize         | Number           | 40                        | 文字最大的字号                                               |\n| fontFamily          | String           | 微软雅黑, Microsoft YaHei | 字体                                                         |\n| fontWeight          | String 、 number |                           | 加粗                                                         |\n| fontStyle           | String           |                           | 斜体                                                         |\n| space               | Number           | 0                         | 文字之间的间距，相对于字号，即该值会和字号相乘得到最终的间距，一般设置为0-1之间的小数 |\n| colorList           | Array            | 见下方                    | 文字颜色列表                                                 |\n| rotateType          | String           | none                      | 旋转类型，none（无）、cross（交叉，即要么是无旋转，要么是-90度旋转）、oblique（倾斜，即-45度旋转）、random（随机。即-90度到90度之间），如果要针对某个文本 |\n| fontSizeScale       | Number           | 1 / minFontSize           | 计算时文字整体的缩小比例，用于加快计算速度，一般是0-1之间的小数，如果你没有非常清楚该配置的功能，那么请不要修改 |\n| transition          | String           | all 0.5s ease             | 文本元素过渡动画，css的transition属性                        |\n| smallWeightInCenter | Boolean          | false                     | 按权重从小到大的顺序渲染，默认是按权重从大到小进行渲染       |\n| onClick（v1.0.1+）  | Function         |                           | 监听词云的点击事件。接收一个参数，代表被点击的词云数据。       |\n\n##### 默认颜色列表\n\n```js\n[\n  '#326BFF',\n  '#5C27FE',\n  '#C165DD',\n  '#FACD68',\n  '#FC76B3',\n  '#1DE5E2',\n  '#B588F7',\n  '#08C792',\n  '#FF7B02',\n  '#3bc4c7',\n  '#3a9eea',\n  '#461e47',\n  '#ff4e69'\n]\n```\n\n### 方法\n\n#### run(*words* = [], done = () =\u003e {})\n\n- `words`：数组，每一项也是一个数组，结构为：['文字','权重', '配置']，比如：\n\n```js\n[\n    ['文字', 12, {\n        rotate: 45\n    }]\n]\n```\n\n所有可用配置如下：\n\n```js\n{\n    rotate,// Number，旋转角度\n    space,// 同实例选项的space\n    color,// 文字颜色，不设置则随机\n    fontFamily,// 字体\n    fontWeight,// 加粗\n    fontStyle// 斜体\n}\n```\n\n- `done`：回调函数，接收一个参数，词云实例列表，你可以根据该列表进行渲染\n\n仅计算词云位置，不包含渲染操作，所以你需要拿到计算完位置和大小后的词云实例列表来自行渲染。\n\n\n\n#### render(words, done = () =\u003e {})\n\n计算并使用DOM方式直接渲染到容器内。\n\n#### renderUseCanvas(words, done = () =\u003e {})\n\n\u003e v1.0.1+\n\n计算并使用Canvas方式直接渲染到容器内。\n\n#### exportCanvas(isDownload = true, fileName = 'wordCloud')\n\n\u003e v1.0.1+\n\n- `isDownload`：是否直接触发下载，为false则返回data:URL数据\n\n导出画布为图片，只有当使用renderUseCanvas方法渲染时才有效。\n\n#### clear()\n\n\u003e v1.0.1+\n\n清除渲染的数据。\n\n#### updateOption(options)\n\n更新配置，`options`同实例化配置。不包含`el`选项。\n\n\n\n#### resize()\n\n当容器大小改变了需要调用该方法。此外，你需要自行再次调用`run`方法或`render`方法。\n\n\n\n## 本地开发\n\n```bash\ngit clone https://github.com/wanglin2/simple-word-cloud.git\ncd simple-word-cloud\nnpm i\nnpm link\ncd ..\nnpm i\nnpm link simple-word-cloud\nnpm run dev\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwanglin2%2Fsimple-word-cloud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwanglin2%2Fsimple-word-cloud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwanglin2%2Fsimple-word-cloud/lists"}