Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-cloud

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-cloud - npm Package Compare versions

Comparing version 1.2.5 to 1.2.6

75

build/d3.layout.cloud.js

@@ -1,11 +0,17 @@

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g=(g.d3||(g.d3 = {}));g=(g.layout||(g.layout = {}));g.cloud = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g=(g.d3||(g.d3 = {}));g=(g.layout||(g.layout = {}));g.cloud = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
// Word cloud layout by Jason Davies, https://www.jasondavies.com/wordcloud/
// Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf
// Algorithm due to Jonathan Feinberg, https://s3.amazonaws.com/static.mrfeinberg.com/bv_ch03.pdf
var dispatch = require("d3-dispatch").dispatch;
const dispatch = require("d3-dispatch").dispatch;
var cloudRadians = Math.PI / 180,
cw = 1 << 11 >> 5,
ch = 1 << 11;
const RADIANS = Math.PI / 180;
const SPIRALS = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
const cw = 1 << 11 >> 5;
const ch = 1 << 11;
module.exports = function() {

@@ -86,2 +92,5 @@ var size = [256, 256],

}
for (const tag of tags) {
delete tag.sprite;
}
return cloud;

@@ -91,12 +100,12 @@ };

function getContext(canvas) {
const context = canvas.getContext("2d", {willReadFrequently: true});
canvas.width = canvas.height = 1;
var ratio = Math.sqrt(canvas.getContext("2d").getImageData(0, 0, 1, 1).data.length >> 2);
const ratio = Math.sqrt(context.getImageData(0, 0, 1, 1).data.length >> 2);
canvas.width = (cw << 5) / ratio;
canvas.height = ch / ratio;
var context = canvas.getContext("2d");
context.fillStyle = context.strokeStyle = "red";
context.textAlign = "center";
return {context: context, ratio: ratio};
return {context, ratio};
}

@@ -128,4 +137,4 @@

// TODO only check for collisions within current bounds.
if (!bounds || !cloudCollide(tag, board, size[0])) {
if (!bounds || collideRects(tag, bounds)) {
if (!bounds || collideRects(tag, bounds)) {
if (!cloudCollide(tag, board, size[0])) {
var sprite = tag.sprite,

@@ -147,3 +156,2 @@ w = tag.width >> 5,

}
delete tag.sprite;
return true;

@@ -189,3 +197,3 @@ }

cloud.spiral = function(_) {
return arguments.length ? (spiral = spirals[_] || _, cloud) : spiral;
return arguments.length ? (spiral = SPIRALS[_] || _, cloud) : spiral;
};

@@ -230,3 +238,3 @@

function cloudRotate() {
return (~~(Math.random() * 6) - 3) * 30;
return (~~(random() * 6) - 3) * 30;
}

@@ -255,7 +263,9 @@

c.font = d.style + " " + d.weight + " " + ~~((d.size + 1) / ratio) + "px " + d.font;
var w = c.measureText(d.text + "m").width * ratio,
h = d.size << 1;
const metrics = c.measureText(d.text);
const anchor = -Math.floor(metrics.width / 2);
let w = (metrics.width + 1) * ratio;
let h = d.size << 1;
if (d.rotate) {
var sr = Math.sin(d.rotate * cloudRadians),
cr = Math.cos(d.rotate * cloudRadians),
var sr = Math.sin(d.rotate * RADIANS),
cr = Math.cos(d.rotate * RADIANS),
wcr = w * cr,

@@ -278,5 +288,5 @@ wsr = w * sr,

c.translate((x + (w >> 1)) / ratio, (y + (h >> 1)) / ratio);
if (d.rotate) c.rotate(d.rotate * cloudRadians);
c.fillText(d.text, 0, 0);
if (d.padding) c.lineWidth = 2 * d.padding, c.strokeText(d.text, 0, 0);
if (d.rotate) c.rotate(d.rotate * RADIANS);
c.fillText(d.text, anchor, 0);
if (d.padding) c.lineWidth = 2 * d.padding, c.strokeText(d.text, anchor, 0);
c.restore();

@@ -405,14 +415,9 @@ d.width = w;

var spirals = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
},{"d3-dispatch":2}],2:[function(require,module,exports){
// https://d3js.org/d3-dispatch/ Version 1.0.3. Copyright 2017 Mike Bostock.
// https://d3js.org/d3-dispatch/ v1.0.6 Copyright 2019 Mike Bostock
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.d3 = global.d3 || {}));
}(this, function (exports) { 'use strict';

@@ -423,3 +428,3 @@ var noop = {value: function() {}};

for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
_[t] = [];

@@ -507,5 +512,5 @@ }

})));
}));
},{}]},{},[1])(1)
});
});
var d3 = require("d3"),
cloud = require("../");
var fill = d3.scale.category20();
var layout = cloud()

@@ -32,3 +30,2 @@ .size([500, 500])

.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")

@@ -35,0 +32,0 @@ .attr("transform", function(d) {

@@ -1,6 +0,5 @@

var Canvas = require("canvas");
const { createCanvas } = require("canvas");
const cloud = require("d3-cloud");
var cloud = require("../");
var words = ["Hello", "world", "normally", "you", "want", "more", "words", "than", "this"]
const words = ["Hello", "world", "normally", "you", "want", "more", "words", "than", "this"]
.map(function(d) {

@@ -11,11 +10,9 @@ return {text: d, size: 10 + Math.random() * 90};

cloud().size([960, 500])
.canvas(function() { return new Canvas(1, 1); })
.canvas(() => createCanvas(1, 1))
.words(words)
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.rotate(() => Math.floor(Math.random() * 2) * 90)
.font("Impact")
.fontSize(function(d) { return d.size; })
.on("end", end)
.fontSize(d => d.size)
.on("end", words => console.log(JSON.stringify(words)))
.start();
function end(words) { console.log(JSON.stringify(words)); }
// Word cloud layout by Jason Davies, https://www.jasondavies.com/wordcloud/
// Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf
// Algorithm due to Jonathan Feinberg, https://s3.amazonaws.com/static.mrfeinberg.com/bv_ch03.pdf
var dispatch = require("d3-dispatch").dispatch;
const dispatch = require("d3-dispatch").dispatch;
var cloudRadians = Math.PI / 180,
cw = 1 << 11 >> 5,
ch = 1 << 11;
const RADIANS = Math.PI / 180;
const SPIRALS = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
const cw = 1 << 11 >> 5;
const ch = 1 << 11;
module.exports = function() {

@@ -85,2 +91,5 @@ var size = [256, 256],

}
for (const tag of tags) {
delete tag.sprite;
}
return cloud;

@@ -90,12 +99,12 @@ };

function getContext(canvas) {
const context = canvas.getContext("2d", {willReadFrequently: true});
canvas.width = canvas.height = 1;
var ratio = Math.sqrt(canvas.getContext("2d").getImageData(0, 0, 1, 1).data.length >> 2);
const ratio = Math.sqrt(context.getImageData(0, 0, 1, 1).data.length >> 2);
canvas.width = (cw << 5) / ratio;
canvas.height = ch / ratio;
var context = canvas.getContext("2d");
context.fillStyle = context.strokeStyle = "red";
context.textAlign = "center";
return {context: context, ratio: ratio};
return {context, ratio};
}

@@ -127,4 +136,4 @@

// TODO only check for collisions within current bounds.
if (!bounds || !cloudCollide(tag, board, size[0])) {
if (!bounds || collideRects(tag, bounds)) {
if (!bounds || collideRects(tag, bounds)) {
if (!cloudCollide(tag, board, size[0])) {
var sprite = tag.sprite,

@@ -146,3 +155,2 @@ w = tag.width >> 5,

}
delete tag.sprite;
return true;

@@ -188,3 +196,3 @@ }

cloud.spiral = function(_) {
return arguments.length ? (spiral = spirals[_] || _, cloud) : spiral;
return arguments.length ? (spiral = SPIRALS[_] || _, cloud) : spiral;
};

@@ -229,3 +237,3 @@

function cloudRotate() {
return (~~(Math.random() * 6) - 3) * 30;
return (~~(random() * 6) - 3) * 30;
}

@@ -254,7 +262,9 @@

c.font = d.style + " " + d.weight + " " + ~~((d.size + 1) / ratio) + "px " + d.font;
var w = c.measureText(d.text + "m").width * ratio,
h = d.size << 1;
const metrics = c.measureText(d.text);
const anchor = -Math.floor(metrics.width / 2);
let w = (metrics.width + 1) * ratio;
let h = d.size << 1;
if (d.rotate) {
var sr = Math.sin(d.rotate * cloudRadians),
cr = Math.cos(d.rotate * cloudRadians),
var sr = Math.sin(d.rotate * RADIANS),
cr = Math.cos(d.rotate * RADIANS),
wcr = w * cr,

@@ -277,5 +287,5 @@ wsr = w * sr,

c.translate((x + (w >> 1)) / ratio, (y + (h >> 1)) / ratio);
if (d.rotate) c.rotate(d.rotate * cloudRadians);
c.fillText(d.text, 0, 0);
if (d.padding) c.lineWidth = 2 * d.padding, c.strokeText(d.text, 0, 0);
if (d.rotate) c.rotate(d.rotate * RADIANS);
c.fillText(d.text, anchor, 0);
if (d.padding) c.lineWidth = 2 * d.padding, c.strokeText(d.text, anchor, 0);
c.restore();

@@ -403,6 +413,1 @@ d.width = w;

}
var spirals = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
{
"name": "d3-cloud",
"version": "1.2.5",
"version": "1.2.6",
"description": "Generate word clouds in JavaScript.",

@@ -32,4 +32,4 @@ "keywords": [

"devDependencies": {
"browserify": "^11.2.0"
"browserify": "^17.0.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc