Socket
Socket
Sign inDemoInstall

@slc3/word-cloud

Package Overview
Dependencies
37
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

dist/word-cloud.d.ts

131

build/word-cloud.js

@@ -1,2 +0,4 @@

(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.SLC3 = 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.SLC3 = 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){
(function (global){(function (){
(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){
// Word cloud layout by Jason Davies, https://www.jasondavies.com/wordcloud/

@@ -499,9 +501,116 @@ // Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf

},{}]},{},[1])(1)
});
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"d3-dispatch":2}],2:[function(require,module,exports){
// 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) :
(global = global || self, factory(global.d3 = global.d3 || {}));
}(this, function (exports) { 'use strict';
var noop = {value: function() {}};
function dispatch() {
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
_[t] = [];
}
return new Dispatch(_);
}
function Dispatch(_) {
this._ = _;
}
function parseTypenames(typenames, types) {
return typenames.trim().split(/^|\s+/).map(function(t) {
var name = "", i = t.indexOf(".");
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
return {type: t, name: name};
});
}
Dispatch.prototype = dispatch.prototype = {
constructor: Dispatch,
on: function(typename, callback) {
var _ = this._,
T = parseTypenames(typename + "", _),
t,
i = -1,
n = T.length;
// If no callback was specified, return the callback of the given type and name.
if (arguments.length < 2) {
while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
return;
}
// If a type was specified, set the callback for the given type and name.
// Otherwise, if a null callback was specified, remove callbacks of the given name.
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
while (++i < n) {
if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
}
return this;
},
copy: function() {
var copy = {}, _ = this._;
for (var t in _) copy[t] = _[t].slice();
return new Dispatch(copy);
},
call: function(type, that) {
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
},
apply: function(type, that, args) {
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
}
};
function get(type, name) {
for (var i = 0, n = type.length, c; i < n; ++i) {
if ((c = type[i]).name === name) {
return c.value;
}
}
}
function set(type, name, callback) {
for (var i = 0, n = type.length; i < n; ++i) {
if (type[i].name === name) {
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
break;
}
}
if (callback != null) type.push({name: name, value: callback});
return type;
}
exports.dispatch = dispatch;
Object.defineProperty(exports, '__esModule', { value: true });
}));
},{}],3:[function(require,module,exports){
(function (global){
(function (global){(function (){
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var d3 = (typeof window !== "undefined" ? window['d3'] : typeof global !== "undefined" ? global['d3'] : null);
var cloud = require("d3-cloud");
var WordCloud = (function () {
var d3 = __importStar((typeof window !== "undefined" ? window['d3'] : typeof global !== "undefined" ? global['d3'] : null));
var cloud = __importStar(require("d3-cloud"));
var WordCloud = /** @class */ (function () {
function WordCloud() {

@@ -511,3 +620,3 @@ this.svg = d3.select(document.createElementNS(d3.namespaces.svg, 'svg'));

this.wordsGroup = this.zoomGroup.append('g');
this.layout = cloud();
this.layout = cloud.default();
this.layoutAttempt = 0;

@@ -621,3 +730,3 @@ this.zoom = d3.zoom();

var size = this._size(this);
// Don't proceed if height or width is NaN, it can cause the
// Don't proceed if height or width is NaN, it can cause the
// browser to lock up during layout.

@@ -639,3 +748,3 @@ if (isNaN(size[0]) || isNaN(size[1]))

// The algorithm in d3-cloud will remove words all together if they don't
// fit within the bounds of the layout. This tends to cause frequent
// fit within the bounds of the layout. This tends to cause frequent
// longer words to disappear. This is a work around to recursively shrink

@@ -647,2 +756,4 @@ // the max font size until all words fit.

}
// If everything fits or it's exceeded the max number of attempts we're
// good to render.
else {

@@ -666,4 +777,4 @@ console.info('Layout complete - %i attempts, %i words missing', this.layoutAttempt, this._words.length - placedWords.length);

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"d3-cloud":1}]},{},[3])(3)
});
});

2

build/word-cloud.min.js

@@ -1,1 +0,1 @@

!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).SLC3=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&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||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function cloudText(d){return d.text}function cloudFont(){return"serif"}function cloudFontNormal(){return"normal"}function cloudFontSize(d){return Math.sqrt(d.value)}function cloudRotate(){return 30*(~~(6*Math.random())-3)}function cloudPadding(){return 1}function cloudSprite(contextAndRatio,d,data,di){if(!d.sprite){var c=contextAndRatio.context,ratio=contextAndRatio.ratio;c.clearRect(0,0,(cw<<5)/ratio,ch/ratio);var x=0,y=0,maxh=0,n=data.length;for(--di;++di<n;){d=data[di],c.save(),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;if(d.rotate){var sr=Math.sin(d.rotate*cloudRadians),cr=Math.cos(d.rotate*cloudRadians),wcr=w*cr,wsr=w*sr,hcr=h*cr,hsr=h*sr;w=Math.max(Math.abs(wcr+hsr),Math.abs(wcr-hsr))+31>>5<<5,h=~~Math.max(Math.abs(wsr+hcr),Math.abs(wsr-hcr))}else w=w+31>>5<<5;if(h>maxh&&(maxh=h),x+w>=cw<<5&&(x=0,y+=maxh,maxh=0),y+h>=ch)break;c.translate((x+(w>>1))/ratio,(y+(h>>1))/ratio),d.rotate&&c.rotate(d.rotate*cloudRadians),c.fillText(d.text,0,0),d.padding&&(c.lineWidth=2*d.padding,c.strokeText(d.text,0,0)),c.restore(),d.width=w,d.height=h,d.xoff=x,d.yoff=y,d.x1=w>>1,d.y1=h>>1,d.x0=-d.x1,d.y0=-d.y1,d.hasText=!0,x+=w}for(var pixels=c.getImageData(0,0,(cw<<5)/ratio,ch/ratio).data,sprite=[];--di>=0;)if((d=data[di]).hasText){for(var w32=(w=d.width)>>5,h=d.y1-d.y0,i=0;i<h*w32;i++)sprite[i]=0;if(null==(x=d.xoff))return;y=d.yoff;for(var seen=0,seenRow=-1,j=0;j<h;j++){for(i=0;i<w;i++){var k=w32*j+(i>>5),m=pixels[(y+j)*(cw<<5)+(x+i)<<2]?1<<31-i%32:0;sprite[k]|=m,seen|=m}seen?seenRow=j:(d.y0++,h--,j--,y++)}d.y1=d.y0+seenRow,d.sprite=sprite.slice(0,(d.y1-d.y0)*w32)}}}function cloudCollide(tag,board,sw){sw>>=5;for(var last,sprite=tag.sprite,w=tag.width>>5,lx=tag.x-(w<<4),sx=127&lx,msx=32-sx,h=tag.y1-tag.y0,x=(tag.y+tag.y0)*sw+(lx>>5),j=0;j<h;j++){last=0;for(var i=0;i<=w;i++)if((last<<msx|(i<w?(last=sprite[j*w+i])>>>sx:0))&board[x+i])return!0;x+=sw}return!1}function cloudBounds(bounds,d){var b0=bounds[0],b1=bounds[1];d.x+d.x0<b0.x&&(b0.x=d.x+d.x0),d.y+d.y0<b0.y&&(b0.y=d.y+d.y0),d.x+d.x1>b1.x&&(b1.x=d.x+d.x1),d.y+d.y1>b1.y&&(b1.y=d.y+d.y1)}function collideRects(a,b){return a.x+a.x1>b[0].x&&a.x+a.x0<b[1].x&&a.y+a.y1>b[0].y&&a.y+a.y0<b[1].y}function archimedeanSpiral(size){var e=size[0]/size[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function zeroArray(n){for(var a=[],i=-1;++i<n;)a[i]=0;return a}function cloudCanvas(){return document.createElement("canvas")}function functor(d){return"function"==typeof d?d:function(){return d}}var dispatch=require("d3-dispatch").dispatch,cloudRadians=Math.PI/180,cw=64,ch=2048;module.exports=function(){function getContext(canvas){canvas.width=canvas.height=1;var ratio=Math.sqrt(canvas.getContext("2d").getImageData(0,0,1,1).data.length>>2);canvas.width=(cw<<5)/ratio,canvas.height=ch/ratio;var context=canvas.getContext("2d");return context.fillStyle=context.strokeStyle="red",context.textAlign="center",{context:context,ratio:ratio}}function place(board,tag,bounds){size[0],size[1];for(var dxdy,dx,dy,startX=tag.x,startY=tag.y,maxDelta=Math.sqrt(size[0]*size[0]+size[1]*size[1]),s=spiral(size),dt=random()<.5?1:-1,t=-dt;(dxdy=s(t+=dt))&&(dx=~~dxdy[0],dy=~~dxdy[1],!(Math.min(Math.abs(dx),Math.abs(dy))>=maxDelta));)if(tag.x=startX+dx,tag.y=startY+dy,!(tag.x+tag.x0<0||tag.y+tag.y0<0||tag.x+tag.x1>size[0]||tag.y+tag.y1>size[1])&&(!bounds||!cloudCollide(tag,board,size[0]))&&(!bounds||collideRects(tag,bounds))){for(var last,sprite=tag.sprite,w=tag.width>>5,sw=size[0]>>5,lx=tag.x-(w<<4),sx=127&lx,msx=32-sx,h=tag.y1-tag.y0,x=(tag.y+tag.y0)*sw+(lx>>5),j=0;j<h;j++){last=0;for(var i=0;i<=w;i++)board[x+i]|=last<<msx|(i<w?(last=sprite[j*w+i])>>>sx:0);x+=sw}return delete tag.sprite,!0}return!1}var size=[256,256],text=cloudText,font=cloudFont,fontSize=cloudFontSize,fontStyle=cloudFontNormal,fontWeight=cloudFontNormal,rotate=cloudRotate,padding=cloudPadding,spiral=archimedeanSpiral,words=[],timeInterval=1/0,event=dispatch("word","end"),timer=null,random=Math.random,cloud={},canvas=cloudCanvas;return cloud.canvas=function(_){return arguments.length?(canvas=functor(_),cloud):canvas},cloud.start=function(){function step(){for(var start=Date.now();Date.now()-start<timeInterval&&++i<n&&timer;){var d=data[i];d.x=size[0]*(random()+.5)>>1,d.y=size[1]*(random()+.5)>>1,cloudSprite(contextAndRatio,d,data,i),d.hasText&&place(board,d,bounds)&&(tags.push(d),event.call("word",cloud,d),bounds?cloudBounds(bounds,d):bounds=[{x:d.x+d.x0,y:d.y+d.y0},{x:d.x+d.x1,y:d.y+d.y1}],d.x-=size[0]>>1,d.y-=size[1]>>1)}i>=n&&(cloud.stop(),event.call("end",cloud,tags,bounds))}var contextAndRatio=getContext(canvas()),board=zeroArray((size[0]>>5)*size[1]),bounds=null,n=words.length,i=-1,tags=[],data=words.map(function(d,i){return d.text=text.call(this,d,i),d.font=font.call(this,d,i),d.style=fontStyle.call(this,d,i),d.weight=fontWeight.call(this,d,i),d.rotate=rotate.call(this,d,i),d.size=~~fontSize.call(this,d,i),d.padding=padding.call(this,d,i),d}).sort(function(a,b){return b.size-a.size});return timer&&clearInterval(timer),timer=setInterval(step,0),step(),cloud},cloud.stop=function(){return timer&&(clearInterval(timer),timer=null),cloud},cloud.timeInterval=function(_){return arguments.length?(timeInterval=null==_?1/0:_,cloud):timeInterval},cloud.words=function(_){return arguments.length?(words=_,cloud):words},cloud.size=function(_){return arguments.length?(size=[+_[0],+_[1]],cloud):size},cloud.font=function(_){return arguments.length?(font=functor(_),cloud):font},cloud.fontStyle=function(_){return arguments.length?(fontStyle=functor(_),cloud):fontStyle},cloud.fontWeight=function(_){return arguments.length?(fontWeight=functor(_),cloud):fontWeight},cloud.rotate=function(_){return arguments.length?(rotate=functor(_),cloud):rotate},cloud.text=function(_){return arguments.length?(text=functor(_),cloud):text},cloud.spiral=function(_){return arguments.length?(spiral=spirals[_]||_,cloud):spiral},cloud.fontSize=function(_){return arguments.length?(fontSize=functor(_),cloud):fontSize},cloud.padding=function(_){return arguments.length?(padding=functor(_),cloud):padding},cloud.random=function(_){return arguments.length?(random=_,cloud):random},cloud.on=function(){var value=event.on.apply(event,arguments);return value===event?cloud:value},cloud};var spirals={archimedean:archimedeanSpiral,rectangular:function(size){var dx=4*size[0]/size[1],x=0,y=0;return function(t){var sign=t<0?-1:1;switch(Math.sqrt(1+4*sign*t)-sign&3){case 0:x+=dx;break;case 1:y+=4;break;case 2:x-=dx;break;default:y-=4}return[x,y]}}}},{"d3-dispatch":2}],2:[function(require,module,exports){!function(global,factory){factory("object"==typeof exports&&void 0!==module?exports:global.d3=global.d3||{})}(this,function(exports){"use strict";function dispatch(){for(var t,i=0,n=arguments.length,_={};i<n;++i){if(!(t=arguments[i]+"")||t in _)throw new Error("illegal type: "+t);_[t]=[]}return new Dispatch(_)}function Dispatch(_){this._=_}function parseTypenames(typenames,types){return typenames.trim().split(/^|\s+/).map(function(t){var name="",i=t.indexOf(".");if(i>=0&&(name=t.slice(i+1),t=t.slice(0,i)),t&&!types.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:name}})}function get(type,name){for(var c,i=0,n=type.length;i<n;++i)if((c=type[i]).name===name)return c.value}function set(type,name,callback){for(var i=0,n=type.length;i<n;++i)if(type[i].name===name){type[i]=noop,type=type.slice(0,i).concat(type.slice(i+1));break}return null!=callback&&type.push({name:name,value:callback}),type}var noop={value:function(){}};Dispatch.prototype=dispatch.prototype={constructor:Dispatch,on:function(typename,callback){var t,_=this._,T=parseTypenames(typename+"",_),i=-1,n=T.length;{if(!(arguments.length<2)){if(null!=callback&&"function"!=typeof callback)throw new Error("invalid callback: "+callback);for(;++i<n;)if(t=(typename=T[i]).type)_[t]=set(_[t],typename.name,callback);else if(null==callback)for(t in _)_[t]=set(_[t],typename.name,null);return this}for(;++i<n;)if((t=(typename=T[i]).type)&&(t=get(_[t],typename.name)))return t}},copy:function(){var copy={},_=this._;for(var t in _)copy[t]=_[t].slice();return new Dispatch(copy)},call:function(type,that){if((n=arguments.length-2)>0)for(var n,t,args=new Array(n),i=0;i<n;++i)args[i]=arguments[i+2];if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(i=0,n=(t=this._[type]).length;i<n;++i)t[i].value.apply(that,args)},apply:function(type,that,args){if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(var t=this._[type],i=0,n=t.length;i<n;++i)t[i].value.apply(that,args)}},exports.dispatch=dispatch,Object.defineProperty(exports,"__esModule",{value:!0})})},{}],3:[function(require,module,exports){(function(global){"use strict";function functor(value){return"function"==typeof value?value:function(d,index){return value}}Object.defineProperty(exports,"__esModule",{value:!0});var d3="undefined"!=typeof window?window.d3:void 0!==global?global.d3:null,cloud=require("d3-cloud"),WordCloud=function(){function WordCloud(){this.svg=d3.select(document.createElementNS(d3.namespaces.svg,"svg")),this.zoomGroup=this.svg.append("g"),this.wordsGroup=this.zoomGroup.append("g"),this.layout=cloud(),this.layoutAttempt=0,this.zoom=d3.zoom(),this.zoomRect=this.svg.append("rect"),this.layout.on("end",this.onLayoutEnd.bind(this)),this.zoom.scaleExtent([.5,10]).on("zoom",this.onZoom.bind(this)),this.zoomRect.style("fill","none").style("pointer-events","all").call(this.zoom),this.fill("black").maxLayoutAttempts(3).words([])}return WordCloud.prototype.element=function(){return this.svg.node()},WordCloud.prototype.render=function(){return this.updateLayout(this._words),this},WordCloud.prototype.fill=function(fill){return arguments.length?(this._fill=functor(fill),this):this._fill},WordCloud.prototype.font=function(font){return arguments.length?(this.layout.font(font),this):this.layout.font()},WordCloud.prototype.maxLayoutAttempts=function(attempts){return arguments.length?(this._maxLayoutAttempts=attempts,this):this._maxLayoutAttempts},WordCloud.prototype.size=function(size){return arguments.length?(this._size=functor(size),this):this._size},WordCloud.prototype.words=function(words){return void 0===words?this._words:(this._words=words.slice(),this)},WordCloud.prototype.fontSizeRange=function(size){var maxSize=Math.min(size[0],size[1])/5*this.placementFactor(),minSize=maxSize/5;return[minSize,maxSize]},WordCloud.prototype.frequencyDomain=function(words){var frequencies=words.map(function(w){return w.frequency}),domain=d3.extent(frequencies);return domain},WordCloud.prototype.placementFactor=function(){var pf=Math.pow(.8,this.layoutAttempt);return pf},WordCloud.prototype.createFontSizeAccessor=function(words,size){var fontSize=d3.scalePow().range(this.fontSizeRange(size)).domain(this.frequencyDomain(words));return function(d){return fontSize(d.frequency)}},WordCloud.prototype.renderLayout=function(words,bounds){var _a=this.layout.size(),width=_a[0],height=_a[1];this.svg.attr("width",width).attr("height",height),this.zoomRect.attr("width",width).attr("height",height);var cloudText=this.wordsGroup.selectAll("text").data(words,function(d){return d.text});cloudText.enter().append("text").attr("text-anchor","middle").style("fill",this.fill()).style("font-family",this.font()).style("font-size",function(d){return"1px"}).text(function(d){return d.text}).merge(cloudText).transition().duration(1e3).attr("transform",function(d){return"translate("+[d.x,d.y]+")rotate("+d.rotate+")"}).style("font-size",function(d){return d.size+"px"}),cloudText.exit().transition().duration(200).style("fill-opacity",1e-6).style("font-size","1px").remove(),this.wordsGroup.attr("transform","translate("+width/2+","+height/2+")")},WordCloud.prototype.updateLayout=function(words){var size=this._size(this);isNaN(size[0])||isNaN(size[1])||(this.layoutAttempt++,this.layout.stop().size(size).font(this.font()).fontSize(this.createFontSizeAccessor(words,size)).padding(5).rotate(0).words(words).start())},WordCloud.prototype.onLayoutEnd=function(placedWords,bounds){placedWords.length!==this._words.length&&this.layoutAttempt<this._maxLayoutAttempts?this.updateLayout(this._words):(this.renderLayout(placedWords,bounds),this.layoutAttempt=0)},WordCloud.prototype.onZoom=function(){this.zoomGroup.attr("transform",d3.event.transform)},WordCloud}();exports.WordCloud=WordCloud}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"d3-cloud":1}]},{},[3])(3)});
!function(f){"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define([],f):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).SLC3=f()}(function(){return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var p="function"==typeof require&&require;if(!f&&p)return p(i,!0);if(u)return u(i,!0);throw(p=new Error("Cannot find module '"+i+"'")).code="MODULE_NOT_FOUND",p}p=n[i]={exports:{}},e[i][0].call(p.exports,function(r){return o(e[i][1][r]||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}({1:[function(require,module,exports){(function(global){(function(){!function(f){var g;"object"==typeof exports&&void 0!==module?module.exports=f():(g=(g=(g="undefined"!=typeof window?window:void 0!==global?global:"undefined"!=typeof self?self:this).d3||(g.d3={})).layout||(g.layout={})).cloud=f()}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var l="function"==typeof require&&require;if(!u&&l)return l(o,!0);if(i)return i(o,!0);l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var dispatch=require("d3-dispatch").dispatch,cloudRadians=Math.PI/180,cw=64,ch=2048;function cloudText(d){return d.text}function cloudFont(){return"serif"}function cloudFontNormal(){return"normal"}function cloudFontSize(d){return Math.sqrt(d.value)}function cloudRotate(){return 30*(~~(6*Math.random())-3)}function cloudPadding(){return 1}function archimedeanSpiral(size){var e=size[0]/size[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function cloudCanvas(){return document.createElement("canvas")}function functor(d){return"function"==typeof d?d:function(){return d}}module.exports=function(){var size=[256,256],text=cloudText,font=cloudFont,fontSize=cloudFontSize,fontStyle=cloudFontNormal,fontWeight=cloudFontNormal,rotate=cloudRotate,padding=cloudPadding,spiral=archimedeanSpiral,words=[],timeInterval=1/0,event=dispatch("word","end"),timer=null,random=Math.random,cloud={},canvas=cloudCanvas;return cloud.canvas=function(_){return arguments.length?(canvas=functor(_),cloud):canvas},cloud.start=function(){var contextAndRatio=function(context){context.width=context.height=1;var ratio=Math.sqrt(context.getContext("2d").getImageData(0,0,1,1).data.length>>2);context.width=(cw<<5)/ratio,context.height=ch/ratio;context=context.getContext("2d");return context.fillStyle=context.strokeStyle="red",context.textAlign="center",{context:context,ratio:ratio}}(canvas()),board=function(n){var a=[],i=-1;for(;++i<n;)a[i]=0;return a}((size[0]>>5)*size[1]),bounds=null,n=words.length,i=-1,tags=[],data=words.map(function(d,i){return d.text=text.call(this,d,i),d.font=font.call(this,d,i),d.style=fontStyle.call(this,d,i),d.weight=fontWeight.call(this,d,i),d.rotate=rotate.call(this,d,i),d.size=~~fontSize.call(this,d,i),d.padding=padding.call(this,d,i),d}).sort(function(a,b){return b.size-a.size});return timer&&clearInterval(timer),timer=setInterval(step,0),step(),cloud;function step(){for(var start=Date.now();Date.now()-start<timeInterval&&++i<n&&timer;){var d=data[i];d.x=size[0]*(random()+.5)>>1,d.y=size[1]*(random()+.5)>>1,function(contextAndRatio,d,data,di){if(!d.sprite){var c=contextAndRatio.context,ratio=contextAndRatio.ratio;c.clearRect(0,0,(cw<<5)/ratio,ch/ratio);var x=0,y=0,maxh=0,n=data.length;for(--di;++di<n;){d=data[di],c.save(),c.font=d.style+" "+d.weight+" "+~~((d.size+1)/ratio)+"px "+d.font;var wcr,wsr,hcr,hsr,w=c.measureText(d.text+"m").width*ratio,h=d.size<<1;if(d.rotate?(hsr=Math.sin(d.rotate*cloudRadians),hcr=Math.cos(d.rotate*cloudRadians),wcr=w*hcr,wsr=w*hsr,hcr=h*hcr,hsr=h*hsr,w=Math.max(Math.abs(wcr+hsr),Math.abs(wcr-hsr))+31>>5<<5,h=~~Math.max(Math.abs(wsr+hcr),Math.abs(wsr-hcr))):w=w+31>>5<<5,maxh<h&&(maxh=h),cw<<5<=x+w&&(y+=maxh,maxh=x=0),ch<=y+h)break;c.translate((x+(w>>1))/ratio,(y+(h>>1))/ratio),d.rotate&&c.rotate(d.rotate*cloudRadians),c.fillText(d.text,0,0),d.padding&&(c.lineWidth=2*d.padding,c.strokeText(d.text,0,0)),c.restore(),d.width=w,d.height=h,d.xoff=x,d.yoff=y,d.x1=w>>1,d.y1=h>>1,d.x0=-d.x1,d.y0=-d.y1,d.hasText=!0,x+=w}for(var pixels=c.getImageData(0,0,(cw<<5)/ratio,ch/ratio).data,sprite=[];0<=--di;)if((d=data[di]).hasText){for(var w32=(w=d.width)>>5,h=d.y1-d.y0,i=0;i<h*w32;i++)sprite[i]=0;if(null==(x=d.xoff))return;y=d.yoff;for(var seen=0,seenRow=-1,j=0;j<h;j++){for(i=0;i<w;i++){var k=w32*j+(i>>5),m=pixels[(y+j)*(cw<<5)+(x+i)<<2]?1<<31-i%32:0;sprite[k]|=m,seen|=m}seen?seenRow=j:(d.y0++,h--,j--,y++)}d.y1=d.y0+seenRow,d.sprite=sprite.slice(0,(d.y1-d.y0)*w32)}}}(contextAndRatio,d,data,i),d.hasText&&function(board,tag,bounds){size[0],size[1];var dx,dy,startX=tag.x,startY=tag.y,maxDelta=Math.sqrt(size[0]*size[0]+size[1]*size[1]),s=spiral(size),dt=random()<.5?1:-1,t=-dt;for(;(lx=s(t+=dt))&&(dx=~~lx[0],dy=~~lx[1],!(Math.min(Math.abs(dx),Math.abs(dy))>=maxDelta));)if(tag.x=startX+dx,tag.y=startY+dy,!(tag.x+tag.x0<0||tag.y+tag.y0<0||tag.x+tag.x1>size[0]||tag.y+tag.y1>size[1])&&(!bounds||!function(tag,board,sw){sw>>=5;for(var last,sprite=tag.sprite,w=tag.width>>5,lx=tag.x-(w<<4),sx=127&lx,msx=32-sx,h=tag.y1-tag.y0,x=(tag.y+tag.y0)*sw+(lx>>5),j=0;j<h;j++){for(var i=last=0;i<=w;i++)if((last<<msx|(i<w?(last=sprite[j*w+i])>>>sx:0))&board[x+i])return!0;x+=sw}return!1}(tag,board,size[0]))&&(!bounds||function(a,b){return a.x+a.x1>b[0].x&&a.x+a.x0<b[1].x&&a.y+a.y1>b[0].y&&a.y+a.y0<b[1].y}(tag,bounds))){for(var last,sprite=tag.sprite,w=tag.width>>5,sw=size[0]>>5,lx=tag.x-(w<<4),sx=127&lx,msx=32-sx,h=tag.y1-tag.y0,x=(tag.y+tag.y0)*sw+(lx>>5),j=0;j<h;j++){for(var i=last=0;i<=w;i++)board[x+i]|=last<<msx|(i<w?(last=sprite[j*w+i])>>>sx:0);x+=sw}return delete tag.sprite,!0}return!1}(board,d,bounds)&&(tags.push(d),event.call("word",cloud,d),bounds?function(b1,d){var b0=b1[0],b1=b1[1];d.x+d.x0<b0.x&&(b0.x=d.x+d.x0),d.y+d.y0<b0.y&&(b0.y=d.y+d.y0),d.x+d.x1>b1.x&&(b1.x=d.x+d.x1),d.y+d.y1>b1.y&&(b1.y=d.y+d.y1)}(bounds,d):bounds=[{x:d.x+d.x0,y:d.y+d.y0},{x:d.x+d.x1,y:d.y+d.y1}],d.x-=size[0]>>1,d.y-=size[1]>>1)}n<=i&&(cloud.stop(),event.call("end",cloud,tags,bounds))}},cloud.stop=function(){return timer&&(clearInterval(timer),timer=null),cloud},cloud.timeInterval=function(_){return arguments.length?(timeInterval=null==_?1/0:_,cloud):timeInterval},cloud.words=function(_){return arguments.length?(words=_,cloud):words},cloud.size=function(_){return arguments.length?(size=[+_[0],+_[1]],cloud):size},cloud.font=function(_){return arguments.length?(font=functor(_),cloud):font},cloud.fontStyle=function(_){return arguments.length?(fontStyle=functor(_),cloud):fontStyle},cloud.fontWeight=function(_){return arguments.length?(fontWeight=functor(_),cloud):fontWeight},cloud.rotate=function(_){return arguments.length?(rotate=functor(_),cloud):rotate},cloud.text=function(_){return arguments.length?(text=functor(_),cloud):text},cloud.spiral=function(_){return arguments.length?(spiral=spirals[_]||_,cloud):spiral},cloud.fontSize=function(_){return arguments.length?(fontSize=functor(_),cloud):fontSize},cloud.padding=function(_){return arguments.length?(padding=functor(_),cloud):padding},cloud.random=function(_){return arguments.length?(random=_,cloud):random},cloud.on=function(){var value=event.on.apply(event,arguments);return value===event?cloud:value},cloud};var spirals={archimedean:archimedeanSpiral,rectangular:function(size){var dx=4*size[0]/size[1],x=0,y=0;return function(t){var sign=t<0?-1:1;switch(Math.sqrt(1+4*sign*t)-sign&3){case 0:x+=dx;break;case 1:y+=4;break;case 2:x-=dx;break;default:y-=4}return[x,y]}}}},{"d3-dispatch":2}],2:[function(require,module,exports){var global;global=this,function(exports){"use strict";var noop={value:function(){}};function dispatch(){for(var t,i=0,n=arguments.length,_={};i<n;++i){if(!(t=arguments[i]+"")||t in _)throw new Error("illegal type: "+t);_[t]=[]}return new Dispatch(_)}function Dispatch(_){this._=_}function set(type,name,callback){for(var i=0,n=type.length;i<n;++i)if(type[i].name===name){type[i]=noop,type=type.slice(0,i).concat(type.slice(i+1));break}return null!=callback&&type.push({name:name,value:callback}),type}Dispatch.prototype=dispatch.prototype={constructor:Dispatch,on:function(typename,callback){var t,types,_=this._,T=(types=_,(typename+"").trim().split(/^|\s+/).map(function(t){var name="",i=t.indexOf(".");if(0<=i&&(name=t.slice(i+1),t=t.slice(0,i)),t&&!types.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:name}})),i=-1,n=T.length;if(!(arguments.length<2)){if(null!=callback&&"function"!=typeof callback)throw new Error("invalid callback: "+callback);for(;++i<n;)if(t=(typename=T[i]).type)_[t]=set(_[t],typename.name,callback);else if(null==callback)for(t in _)_[t]=set(_[t],typename.name,null);return this}for(;++i<n;)if((t=(typename=T[i]).type)&&(t=function(type,name){for(var c,i=0,n=type.length;i<n;++i)if((c=type[i]).name===name)return c.value}(_[t],typename.name)))return t},copy:function(){var t,copy={},_=this._;for(t in _)copy[t]=_[t].slice();return new Dispatch(copy)},call:function(type,that){if(0<(n=arguments.length-2))for(var n,t,args=new Array(n),i=0;i<n;++i)args[i]=arguments[i+2];if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(i=0,n=(t=this._[type]).length;i<n;++i)t[i].value.apply(that,args)},apply:function(type,that,args){if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(var t=this._[type],i=0,n=t.length;i<n;++i)t[i].value.apply(that,args)}},exports.dispatch=dispatch,Object.defineProperty(exports,"__esModule",{value:!0})}("object"==typeof exports&&void 0!==module?exports:global.d3=global.d3||{})},{}]},{},[1])(1)})}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"d3-dispatch":2}],2:[function(require,module,exports){var global,factory;global=this,factory=function(exports){"use strict";var noop={value:function(){}};function dispatch(){for(var t,i=0,n=arguments.length,_={};i<n;++i){if(!(t=arguments[i]+"")||t in _||/[\s.]/.test(t))throw new Error("illegal type: "+t);_[t]=[]}return new Dispatch(_)}function Dispatch(_){this._=_}function set(type,name,callback){for(var i=0,n=type.length;i<n;++i)if(type[i].name===name){type[i]=noop,type=type.slice(0,i).concat(type.slice(i+1));break}return null!=callback&&type.push({name:name,value:callback}),type}Dispatch.prototype=dispatch.prototype={constructor:Dispatch,on:function(typename,callback){var t,types,_=this._,T=(types=_,(typename+"").trim().split(/^|\s+/).map(function(t){var name="",i=t.indexOf(".");if(0<=i&&(name=t.slice(i+1),t=t.slice(0,i)),t&&!types.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:name}})),i=-1,n=T.length;if(!(arguments.length<2)){if(null!=callback&&"function"!=typeof callback)throw new Error("invalid callback: "+callback);for(;++i<n;)if(t=(typename=T[i]).type)_[t]=set(_[t],typename.name,callback);else if(null==callback)for(t in _)_[t]=set(_[t],typename.name,null);return this}for(;++i<n;)if((t=(typename=T[i]).type)&&(t=function(type,name){for(var c,i=0,n=type.length;i<n;++i)if((c=type[i]).name===name)return c.value}(_[t],typename.name)))return t},copy:function(){var t,copy={},_=this._;for(t in _)copy[t]=_[t].slice();return new Dispatch(copy)},call:function(type,that){if(0<(n=arguments.length-2))for(var n,t,args=new Array(n),i=0;i<n;++i)args[i]=arguments[i+2];if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(i=0,n=(t=this._[type]).length;i<n;++i)t[i].value.apply(that,args)},apply:function(type,that,args){if(!this._.hasOwnProperty(type))throw new Error("unknown type: "+type);for(var t=this._[type],i=0,n=t.length;i<n;++i)t[i].value.apply(that,args)}},exports.dispatch=dispatch,Object.defineProperty(exports,"__esModule",{value:!0})},"object"==typeof exports&&void 0!==module?factory(exports):factory((global=global||self).d3=global.d3||{})},{}],3:[function(require,module,exports){(function(global){(function(){"use strict";var WordCloud=this&&this.__importStar||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(null!=mod)for(var k in mod)Object.hasOwnProperty.call(mod,k)&&(result[k]=mod[k]);return result.default=mod,result};Object.defineProperty(exports,"__esModule",{value:!0});var d3=WordCloud("undefined"!=typeof window?window.d3:void 0!==global?global.d3:null),cloud=WordCloud(require("d3-cloud")),WordCloud=function(){function WordCloud(){this.svg=d3.select(document.createElementNS(d3.namespaces.svg,"svg")),this.zoomGroup=this.svg.append("g"),this.wordsGroup=this.zoomGroup.append("g"),this.layout=cloud.default(),this.layoutAttempt=0,this.zoom=d3.zoom(),this.zoomRect=this.svg.append("rect"),this.layout.on("end",this.onLayoutEnd.bind(this)),this.zoom.scaleExtent([.5,10]).on("zoom",this.onZoom.bind(this)),this.zoomRect.style("fill","none").style("pointer-events","all").call(this.zoom),this.fill("black").maxLayoutAttempts(3).words([])}return WordCloud.prototype.element=function(){return this.svg.node()},WordCloud.prototype.render=function(){return this.updateLayout(this._words),this},WordCloud.prototype.fill=function(fill){return arguments.length?(this._fill=functor(fill),this):this._fill},WordCloud.prototype.font=function(font){return arguments.length?(this.layout.font(font),this):this.layout.font()},WordCloud.prototype.maxLayoutAttempts=function(attempts){return arguments.length?(this._maxLayoutAttempts=attempts,this):this._maxLayoutAttempts},WordCloud.prototype.size=function(size){return arguments.length?(this._size=functor(size),this):this._size},WordCloud.prototype.words=function(words){return void 0===words?this._words:(this._words=words.slice(),this)},WordCloud.prototype.fontSizeRange=function(minSize){var maxSize=Math.min(minSize[0],minSize[1])/5*this.placementFactor(),minSize=maxSize/5;return[minSize,maxSize]},WordCloud.prototype.frequencyDomain=function(domain){domain=domain.map(function(w){return w.frequency}),domain=d3.extent(domain);return domain},WordCloud.prototype.placementFactor=function(){var pf=Math.pow(.8,this.layoutAttempt);return pf},WordCloud.prototype.createFontSizeAccessor=function(words,size){var fontSize=d3.scalePow().range(this.fontSizeRange(size)).domain(this.frequencyDomain(words));return function(d){return fontSize(d.frequency)}},WordCloud.prototype.renderLayout=function(cloudText,bounds){var height=this.layout.size(),width=height[0],height=height[1];this.svg.attr("width",width).attr("height",height),this.zoomRect.attr("width",width).attr("height",height);cloudText=this.wordsGroup.selectAll("text").data(cloudText,function(d){return d.text});cloudText.enter().append("text").attr("text-anchor","middle").style("fill",this.fill()).style("font-family",this.font()).style("font-size",function(d){return"1px"}).text(function(d){return d.text}).merge(cloudText).transition().duration(1e3).attr("transform",function(d){return"translate("+[d.x,d.y]+")rotate("+d.rotate+")"}).style("font-size",function(d){return d.size+"px"}),cloudText.exit().transition().duration(200).style("fill-opacity",1e-6).style("font-size","1px").remove(),this.wordsGroup.attr("transform","translate("+width/2+","+height/2+")")},WordCloud.prototype.updateLayout=function(words){var size=this._size(this);isNaN(size[0])||isNaN(size[1])||(this.layoutAttempt++,this.layout.stop().size(size).font(this.font()).fontSize(this.createFontSizeAccessor(words,size)).padding(5).rotate(0).words(words).start())},WordCloud.prototype.onLayoutEnd=function(placedWords,bounds){placedWords.length!==this._words.length&&this.layoutAttempt<this._maxLayoutAttempts?this.updateLayout(this._words):(this.renderLayout(placedWords,bounds),this.layoutAttempt=0)},WordCloud.prototype.onZoom=function(){this.zoomGroup.attr("transform",d3.event.transform)},WordCloud}();function functor(value){return"function"==typeof value?value:function(d,index){return value}}exports.WordCloud=WordCloud}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"d3-cloud":1}]},{},[3])(3)});
{
"name": "@slc3/word-cloud",
"version": "1.0.0",
"version": "1.1.0",
"description": "An interactive word cloud based on d3-cloud",
"main": "build/word-cloud.js",
"types": "dist/word-cloud.d.ts",
"scripts": {
"build": "mkdirp build && browserify src/word-cloud.ts -p [ tsify ] --standalone SLC3 > build/word-cloud.js",
"minify": "uglifyjs --compress drop_console build/word-cloud.js -o build/word-cloud.min.js",
"prepare": "npm run build && npm run minify"
"make-types": "tsc",
"prepare": "npm run build && npm run minify && npm run make-types"
},

@@ -28,9 +30,9 @@ "keywords": [

"@types/d3": "^4.9.0",
"browserify": "^14.4.0",
"browserify": "^14.5.0",
"browserify-shim": "^3.8.14",
"mkdirp": "^0.5.1",
"mkdirp": "~0.5.1",
"roboto-fontface": "^0.8.0",
"tsify": "^3.0.1",
"typescript": "^2.4.2",
"uglify-js": "^3.0.26"
"typescript": "^2.9.2",
"uglify-js": "^3.12.1"
},

@@ -37,0 +39,0 @@ "browserify": {

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