├── wordcloud-min.png ├── .gitignore ├── wordcloud-blue-min.png ├── wordcloud-single-min.png ├── src ├── index.js └── components │ └── WordCloud.vue ├── LICENSE ├── package.json ├── webpack.config.js └── README.md /wordcloud-min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feifang/vue-wordcloud/HEAD/wordcloud-min.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log* 4 | yarn-debug.log* 5 | yarn-error.log* 6 | -------------------------------------------------------------------------------- /wordcloud-blue-min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feifang/vue-wordcloud/HEAD/wordcloud-blue-min.png -------------------------------------------------------------------------------- /wordcloud-single-min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feifang/vue-wordcloud/HEAD/wordcloud-single-min.png -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import wordcloud from './components/WordCloud.vue' 2 | export default wordcloud 3 | if (typeof window !== 'undefined' && window.Vue) { 4 | window.Vue.component('word-cloud', wordcloud) 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Karen (Fei) Fang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-wordcloud", 3 | "description": "A Vue.js Word Cloud component", 4 | "version": "1.1.1", 5 | "license": "MIT", 6 | "author": "fei.fang ", 7 | "private": false, 8 | "main": "dist/word-cloud.js", 9 | "scripts": { 10 | "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", 11 | "build": "cross-env NODE_ENV=production webpack --progress --hide-modules" 12 | }, 13 | "dependencies": { 14 | "d3": "^4.10.0", 15 | "d3-cloud": "^1.2.4", 16 | "d3-scale-chromatic": "^1.3.3", 17 | "vue": "^2.3.3", 18 | "vue-resize-directive": "^1.0.0" 19 | }, 20 | "devDependencies": { 21 | "babel-core": "^6.0.0", 22 | "babel-eslint": "7.1.1", 23 | "babel-loader": "^6.0.0", 24 | "babel-plugin-transform-runtime": "^6.15.0", 25 | "babel-preset-env": "^1.7.0", 26 | "babel-runtime": "^6.11.6", 27 | "cross-env": "^3.0.0", 28 | "css-loader": "^0.25.0", 29 | "eslint": "3.14.1", 30 | "eslint-config-airbnb-base": "11.0.1", 31 | "eslint-friendly-formatter": "2.0.7", 32 | "eslint-import-resolver-webpack": "0.8.1", 33 | "eslint-loader": "1.6.1", 34 | "eslint-plugin-html": "2.0.0", 35 | "eslint-plugin-import": "2.2.0", 36 | "file-loader": "^0.9.0", 37 | "uglifyjs-webpack-plugin": "^1.1.6", 38 | "vue-loader": "^12.1.0", 39 | "vue-template-compiler": "^2.3.3", 40 | "webpack": "3.10.0", 41 | "webpack-dev-server": "^3.1.10" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var webpack = require('webpack') 3 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 4 | 5 | function resolve(dir) { 6 | return path.join(__dirname, '..', dir) 7 | } 8 | module.exports = { 9 | entry: './src/index.js', 10 | output: { 11 | path: path.resolve(__dirname, './dist'), 12 | publicPath: '/dist/', 13 | filename: 'word-cloud.js', 14 | library: 'WordCloud', 15 | libraryTarget: 'umd', 16 | umdNamedDefine: true 17 | }, 18 | module: { 19 | rules: [{ 20 | test: /\.(js|vue)$/, 21 | loader: 'eslint-loader', 22 | enforce: 'pre', 23 | include: [resolve('src')], 24 | options: { 25 | formatter: require('eslint-friendly-formatter') 26 | } 27 | }, 28 | { 29 | test: /\.vue$/, 30 | loader: 'vue-loader', 31 | options: { 32 | loaders: { 33 | // Since sass-loader (weirdly) has SCSS as its default parse mode, we map 34 | // the "scss" and "sass" values for the lang attribute to the right configs here. 35 | // other preprocessors should work out of the box, no loader config like this necessary. 36 | // 'scss': 'vue-style-loader!css-loader!sass-loader', 37 | // 'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax' 38 | } 39 | // other vue-loader options go here 40 | } 41 | }, 42 | { 43 | test: /\.js$/, 44 | loader: 'babel-loader', 45 | exclude: /node_modules/ 46 | }, 47 | { 48 | test: /\.(png|jpg|gif|svg)$/, 49 | loader: 'file-loader', 50 | options: { 51 | name: '[name].[ext]?[hash]' 52 | } 53 | } 54 | ] 55 | }, 56 | resolve: { 57 | alias: { 58 | 'vue$': 'vue/dist/vue.esm.js' 59 | } 60 | }, 61 | devServer: { 62 | historyApiFallback: true, 63 | noInfo: true 64 | }, 65 | performance: { 66 | hints: false 67 | }, 68 | devtool: '#eval-source-map' 69 | } 70 | 71 | if (process.env.NODE_ENV === 'production') { 72 | module.exports.devtool = '#source-map' 73 | // http://vue-loader.vuejs.org/en/workflow/production.html 74 | module.exports.plugins = (module.exports.plugins || []).concat([ 75 | new webpack.DefinePlugin({ 76 | 'process.env': { 77 | NODE_ENV: '"production"' 78 | } 79 | }), 80 | new UglifyJsPlugin({ 81 | sourceMap: true, 82 | uglifyOptions: { 83 | ecma: 8, 84 | compress: { 85 | warnings: false 86 | } 87 | } 88 | }), 89 | new webpack.LoaderOptionsPlugin({ 90 | minimize: true 91 | }) 92 | ]) 93 | } 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-wordcloud 2 | 3 | A Vue.js Word Cloud component based on the original [d3-cloud](https://github.com/jasondavies/d3-cloud) plugin. 4 | 5 | **What's New?** 6 | 7 | V1.1 Nov 25, 2018: 8 | 9 | - Fix #6 add `showTooltip` option 10 | - Fix #5 add support for custom color scales 11 | 12 | V1.0.2 Aug 12, 2017: 13 | 14 | - Additional font scale options 15 | - Easy to use rotation setting 16 | 17 | For details please refer to [options](https://github.com/feifang/vue-wordcloud#options). 18 | 19 | ### Install 20 | ``` 21 | npm install vue-wordcloud 22 | 23 | ``` 24 | 25 | ### Import 26 | ``` 27 | import wordcloud from 'vue-wordcloud' 28 | ``` 29 | 30 | ### Examples 31 | 32 | Using D3 color scheme Category10: 33 | 34 | ![Word Cloud Example](wordcloud-min.png) 35 | 36 | Using single color of your choice, e.g. `['#1f77b4']`: 37 | 38 | ![Word Cloud Example](wordcloud-single-min.png) 39 | 40 | Using single-hue color of your choice, e.g. `['#1f77b4', '#629fc9', '#94bedb', '#c9e0ef']`: 41 | 42 | ![Word Cloud Example](wordcloud-blue-min.png) 43 | 44 | Code: 45 | ``` 46 | 58 | 59 | 116 | ``` 117 | 118 | For using [D3 categorical color schemes](https://github.com/d3/d3-scale-chromatic#categorical): 119 | ``` 120 | 130 | ``` 131 | 132 | ### Options 133 | **选项**|**简介**|**默认值**|**说明** 134 | :-----:|:-----:|:-----:|:-----: 135 | data|词云文本数据|defaultWords|数据格式:数组。数组中每个元素是对象{ 词:数值 } 136 | nameKey|数据中表示要显示的词的字段名称|'name'|- 137 | valueKey|数据中表示词的权重的字段名称|'value'|- 138 | margin|图表外边矩|{top: 15, right: 15, bottom: 15, left: 15 }|- 139 | wordPadding|词间间距|3|- 140 | rotate|词的旋转角度|{from: -60, to: 60, numOfOrientation: 5 }|可设置角度范围及角度的个数 141 | spiral|词的布局方式|'archimedian'|可选择'archimedian'或'rectangular' 142 | fontScale|词的大小缩放比例|'sqrt'|可选择'sqrt','log'或'n' 143 | fontSize|词的字号范围| `[10, 80]`| [minSize, maxSize] 144 | font|词的字体名称,对应 `font-family` 的值 |"impact"|例如,衬线字体'serif',非衬线字体'Arial' 145 | color|配色集合,可配置两种类型的值:String (D3 scheme name),或 Array(自定义的颜色列表)|'Category10'|可采用D3内置的任意 Category 配色,或自定义的颜色列表;单色可通过传入只有一个颜色的数组实现,详见 [examples](https://github.com/feifang/vue-wordcloud#examples) 146 | showTooltip|显示 Tooltip|true| true/false; tooltip 的样式(如宽高、颜色等)可以通过 CSS 类 `div.tooltip` 配置 147 | wordClick|词的点击事件的回调函数|null|函数传入三个变量,第一个是点击的词 `text`,第二个是该词对应的权重 `value`,第三个是 Vue 实例 `vm` 148 | 149 | 150 | 151 | ### Todo 152 | - minimize component 153 | - add formatter option for tooltip 154 | - support D3 V5 155 | -------------------------------------------------------------------------------- /src/components/WordCloud.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 262 | 263 | 264 | 291 | --------------------------------------------------------------------------------