UNPKG

angular-d3-word-cloud

Version:
9 lines (8 loc) 2.3 kB
/* * angular-d3-word-cloud 0.5.2 * Running example base on express server * https://weihanchen.github.io/angular-d3-word-cloud/ * * Released under the MIT license. */ !function(){"use strict";function t(){function t(t,e){function n(){return 60*~~(2*Math.random())}function i(t){var n=d3.select(e[0]),i=u.size()[0],o=u.size()[1];n.select("svg").remove(),n.append("svg").attr("width",i).attr("height",o).append("g").attr("transform","translate("+i/2+","+o/2+")").selectAll("text").data(t).enter().append("text").on("click",function(t){a.onClick&&a.onClick(t)}).on("mouseover",function(t){a.useTooltip&&d.style("font-size",t.size+"px").style("visibility","visible").text(t.tooltipText||t.text),a.useTransition&&d3.select(this).transition().style("font-size",function(t){return 1.2*t.size+"px"}).attr("opacity",.5)}).on("mouseout",function(){a.useTooltip&&d.style("visibility","hidden"),a.useTransition&&d3.select(this).transition().style("font-size",function(t){return t.size+"px"}).attr("opacity",1)}).on("mousemove",function(){return d.style("top",event.pageY-10+"px").style("left",event.pageX+10+"px")}).style("font-size",function(t){return t.size+"px"}).style("font-family","Impact").style("fill",function(t,e){return t.color||l(e)}).attr("text-anchor","middle").attr("cursor","pointer").transition().attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})}function o(t,e,i,o,r){o=o||5,r=r||n,u.size([t,e]).rotate(r).padding(o).words(i),u.start()}function r(){return a}function s(t){var e=angular.copy(t);angular.isUndefined(e.words)||angular.isUndefined(e.width)||angular.isUndefined(e.height)||o(e.width,e.height,e.words,e.padding,e.rotate)}var a=this,l=d3.hasOwnProperty("scale")?d3.scale.category20():d3.scaleOrdinal(d3.schemeCategory20),d=d3.select("body").append("div").style("position","absolute").style("visibility","hidden"),u=d3.layout.cloud().fontSize(function(t){return t.size}).on("end",i);t.$watch(r,s,!0)}return{restrict:"E",scope:{height:"=",padding:"=?",rotate:"=?",useTooltip:"=?",useTransition:"=?",words:"=",width:"=",onClick:"="},template:"<div></div>",controller:["$scope","$element",t],controllerAs:"wordsCloudCtrl",bindToController:!0}}angular.module("angular-d3-word-cloud",[]).directive("wordCloud",[t])}();