Socket
Socket
Sign inDemoInstall

d3-cloud-element

Package Overview
Dependencies
14
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    d3-cloud-element

D3 word cloud component for Lit Element built upon d3-cloud


Version published
Weekly downloads
4
Maintainers
1
Install size
1.95 MB
Created
Weekly downloads
 

Readme

Source

D3 Word Cloud Element

D3 Word Cloud for Lit Element built upon d3-cloud

Installation

npm install --save d3-cloud-element

Usage

First import the package to your app module

import { LitElement, html, customElement, property } from 'lit-element'
import 'd3-cloud-element'
@customElement('demo-element')
export default class DemoElement extends LitElement {
  data: any = []

  @property({ type: Number })
  width = 700

  constructor() {
    super()
    const str = 'Exercitation duis ex laboris laboris est aliqua Lorem veniam ad. Minim aliqua enim do exercitation duis eiusmod sunt do exercitation qui ex. Aliqua velit sunt in commodo anim. Sunt labore sunt dolor exercitation non commodo laboris culpa culpa exercitation ex proident laborum.\n\nId dolore commodo occaecat in velit. Aliqua mollit ea qui ad aute est excepteur non aliqua occaecat ad non ea. Labore incididunt excepteur tempor culpa proident ex commodo. Nisi nostrud tempor deserunt ipsum adipisicing aute do adipisicing.\n\nOfficia pariatur eiusmod tempor magna occaecat. Ut proident anim aute aliquip pariatur et. Pariatur ad ea sint ut excepteur amet id do. Labore eu velit non cillum nulla.\n\nIncididunt duis tempor sunt dolor magna occaecat esse elit consequat. Ea sint et labore amet ullamco non tempor. Ad voluptate nisi duis minim elit in adipisicing et laboris nulla culpa ad'
    this.data = str.split(' ').map((d) => {
      return { text: d, value: 10 + Math.random() * 90, fill: '0' };
    })
  }

  @property({ type: Boolean })
  useWordMouseOverEvent = true

  updateProps() {
    this.width = 900
    this.useWordMouseOverEvent = false
  }

  onWordClick (e: Event) {
    console.log(e)
  }
  render() {
    return html`
      <button
        @click=${this.updateProps}
      >
        Update Props
      </button>
      <d3-cloud-element
        .width="${this.width}"
        .height="${600}"
        .data="${this.data}"
        .autoFill="${true}"
        .useWordClickEvent=${false}
        .useWordMouseOverEvent=${this.useWordMouseOverEvent}
        @wordMouseOver="${this.onWordClick}"
      ></d3-cloud-element>
    `
  }
}

Props

NameDescriptionTypeRequiredDefault
dataThe input data for renderingArray<{ text: string, value: number }>
widthWidth of component (px)number700
heightHeight of component (px)number600
fontSizeMapperMap each element of data to font size (px)Function: (word: string, idx: number): numberword => word.value;
rotateMap each element of data to font rotation degree. Or simply provide a number for global rotation. (degree)Function | number0
paddingMap each element of data to font padding. Or simply provide a number for global padding. (px)Function | number5
fontThe font of text shownFunction | stringserif
autoFillWhether texts should be fill with random color or notbooleanfalse

Events

NameDescriptionPayload
wordClickEvent triggered when click event triggered on a word{ event: MouseEvent, word: Word }
wordMouseOverEvent triggered when mouseover event triggered on a word{ event: MouseEvent, word: Word }
wordMouseOutEvent triggered when mouseout event triggered on a word{ event: MouseEvent, word: Word }

The Word interface imported from d3-cloud

You can slightly improve performance by disable which event you don't use by passing the following values:

NameDescriptionTypeDefault value
useWordClickEventWhether to use wordClickbooleantrue
useWordMouseOverEventWhether to use wordMouseOverbooleantrue
useWordMouseOutEventWhether to use wordMouseOutbooleantrue

Example

Run the following commands to start sample project:

npm run dev

Then open /src/demo-element.ts and update the import:

import './d3-cloud-element' // update to this

Thanks

This project is built with the idea of React D3 Cloud

Keywords

FAQs

Last updated on 27 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc