Socket
Socket
Sign inDemoInstall

almete.wordcloud

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    almete.wordcloud

Generates a cloud out of the words.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

almete.WordCloud

almete.WordCloud(words, cloudWidth, cloudHeight, {
  createCanvas = function() {
    return document.createElement('canvas');
  },
  fontFamily = 'serif',
  fontSizeRatio = 0,
  fontStyle = 'normal',
  fontVariant = 'normal',
  fontWeight = 'normal',
  gap = 0,
  rotation = 0,
  rotationUnit = 'turn',
  text = '',
  weight = 1,
})

Generates a cloud out of the words.

argumentdescription
wordsAn array of the words to place into the cloud. A word is an object which is resolved to {text, weight, rotation, rotationUnit, fontFamily, fontStyle, fontVariant, fontWeight}.
cloudWidthThe width of the cloud, in pixels.
cloudHeightThe height of the cloud, in pixels.
createCanvasCreates a new Canvas instance.
fontFamilyThe default font family for each word.
fontSizeRatioThe font size ratio between the words. For example, if the value is 5, then the largest word will be 5 times larger than the smallest one. The value 5 has the same effect as the value 1/5.
fontStyleThe default font style for each word.
fontVariantThe default font variant for each word.
fontWeightThe default font weight for each word.
gapThe gap between the words. The value is relative to the font size.
rotationThe default rotation for each word.
rotationUnitThe default rotation unit for each word. Possible values are 'turn', 'deg' and 'rad'.
textThe default text for each word.
weightThe default weight for each word.

Returns bounded words as an array of objects.

[{
  centerLeft,
  centerTop,
  font,
  fontFamily,
  fontSize,
  fontStyle,
  fontVariant,
  fontWeight,
  height,
  left,
  rotationDeg,
  rotationRad,
  rotationTurn,
  text,
  textWidth,
  top,
  weight,
  width,
}]

demo

Try it out!

setup

npm

npm install almete.wordcloud

ES module

import WordCloud from 'almete.wordcloud';

Node

let WordCloud = require('almete.wordcloud');

browser

<script src="https://unpkg.com/almete.wordcloud"></script>

The function WordCloud will be available under the namespace almete.

usage

let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
let words = [
  {text: 'romance', weight: 19, rotation: 45},
  {text: 'horror', weight: 3, rotation: -45},
  {text: 'fantasy', weight: 7, rotation: 45},
  {text: 'adventure', weight: 3, rotation: -45},
];
let boundedWords = almete.WordCloud(words, canvas.width, canvas.height, {
  fontFamily: 'Roboto',
  fontWeight: 'bold',
  rotationUnit: 'deg',
});
boundedWords.forEach(({
  centerLeft,
  centerTop,
  font,
  rotationRad,
  text,
}) => {
  ctx.save();
  ctx.translate(centerLeft, centerTop);
  ctx.rotate(rotationRad);
  ctx.font = font;
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  ctx.fillStyle = 'LightCoral';
  ctx.fillText(text, 0, 0);
  ctx.restore();
});

see also

Keywords

FAQs

Last updated on 27 Dec 2018

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