npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-wordcloud-custom-tooltip

v1.1.1

Published

A Vue.js Word Cloud component

Downloads

14

Readme

vue-wordcloud

A Vue.js Word Cloud component based on the original d3-cloud plugin.

What's New?

V1.1 Nov 25, 2018:

  • Fix #6 add showTooltip option
  • Fix #5 add support for custom color scales

V1.0.2 Aug 12, 2017:

  • Additional font scale options
  • Easy to use rotation setting

For details please refer to options.

Install

npm install vue-wordcloud

Import

import wordcloud from 'vue-wordcloud'

Examples

Using D3 color scheme Category10:

Word Cloud Example

Using single color of your choice, e.g. ['#1f77b4']:

Word Cloud Example

Using single-hue color of your choice, e.g. ['#1f77b4', '#629fc9', '#94bedb', '#c9e0ef']:

Word Cloud Example

Code:

<template>
  <div id="app">
      <wordcloud
      :data="defaultWords"
      nameKey="name"
      valueKey="value"
      :color="myColors"
      :showTooltip="true"
      :wordClick="wordClickHandler">
      </wordcloud>
  </div>
</template>

<script>
import wordcloud from 'vue-wordcloud'

export default {
  name: 'app',
  components: {
    wordcloud
  },
  methods: {
    wordClickHandler(name, value, vm) {
      console.log('wordClickHandler', name, value, vm);
    }
  },
  data() {
    return {
      myColors: ['#1f77b4', '#629fc9', '#94bedb', '#c9e0ef'],
      defaultWords: [{
          "name": "Cat",
          "value": 26
        },
        {
          "name": "fish",
          "value": 19
        },
        {
          "name": "things",
          "value": 18
        },
        {
          "name": "look",
          "value": 16
        },
        {
          "name": "two",
          "value": 15
        },
        {
          "name": "fun",
          "value": 9
        },
        {
          "name": "know",
          "value": 9
        },
        {
          "name": "good",
          "value": 9
        },
        {
          "name": "play",
          "value": 6
        }
      ]
    }
  }
}
</script>

For using D3 categorical color schemes:

<template>
  <div id="app">
      <wordcloud
      :data="defaultWords"
      nameKey="name"
      valueKey="value"
      color="Accent">
      </wordcloud>
  </div>
</template>

Options

选项|简介|默认值|说明 :-----:|:-----:|:-----:|:-----: data|词云文本数据|defaultWords|数据格式:数组。数组中每个元素是对象{ 词:数值 } nameKey|数据中表示要显示的词的字段名称|'name'|- valueKey|数据中表示词的权重的字段名称|'value'|- margin|图表外边矩|{top: 15, right: 15, bottom: 15, left: 15 }|- wordPadding|词间间距|3|- rotate|词的旋转角度|{from: -60, to: 60, numOfOrientation: 5 }|可设置角度范围及角度的个数 spiral|词的布局方式|'archimedian'|可选择'archimedian'或'rectangular' fontScale|词的大小缩放比例|'sqrt'|可选择'sqrt','log'或'n' fontSize|词的字号范围| [10, 80]| [minSize, maxSize] font|词的字体名称,对应 font-family 的值 |"impact"|例如,衬线字体'serif',非衬线字体'Arial' color|配色集合,可配置两种类型的值:String (D3 scheme name),或 Array(自定义的颜色列表)|'Category10'|可采用D3内置的任意 Category 配色,或自定义的颜色列表;单色可通过传入只有一个颜色的数组实现,详见 examples showTooltip|显示 Tooltip|true| true/false; tooltip 的样式(如宽高、颜色等)可以通过 CSS 类 div.tooltip 配置 wordClick|词的点击事件的回调函数|null|函数传入三个变量,第一个是点击的词 text,第二个是该词对应的权重 value,第三个是 Vue 实例 vm

Todo

  • minimize component
  • add formatter option for tooltip
  • support D3 V5