@andyreagan/hedotools 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2016-2026, Andy Reagan
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ hedotools
2
+ =========
3
+
4
+ a collection of js tools in use at hedonometer.org
package/bundle.sh ADDED
@@ -0,0 +1,11 @@
1
+ # version them with d3 versions
2
+ cat hedotools.init.js hedotools.urllib.js hedotools.barchart.js hedotools.lens.js hedotools.map.js hedotools.sankey.js hedotools.shifter.js > hedotools.v3.js
3
+ cat hedotools.init.v4.js hedotools.urllib.js hedotools.shifter.v4.js > hedotools.v4.js
4
+ # minify
5
+ node ../node_modules/minifier/index.js hedotools.v3.js
6
+ node ../node_modules/minifier/index.js hedotools.v4.js
7
+ # link
8
+ rm hedotools.js hedotools.min.js
9
+ ln -s hedotools.v3.js hedotools.js
10
+ ln -s hedotools.v3.min.js hedotools.min.js
11
+
@@ -0,0 +1,164 @@
1
+ Let's try to see where this code has ended up.
2
+
3
+ This helps:
4
+ find . -name "*shifter*.js"
5
+
6
+ 1. Here
7
+ ~/tools/d3/hedotools/js/hedotools.shifter.js
8
+ ~/tools/d3/hedotools/js/hedotools.shifter.v4.js
9
+
10
+ 2. Hedonometer.org
11
+ ~/websites/hedonometer.org/hedonometer/static/hedonometer/hedotools-1.0.1/js/hedotools.shifter.js
12
+ - d3.urllib instead of hedotools.urllib
13
+ - no getfigure()
14
+ - missing setBgcolor
15
+ - missing _fontString
16
+ ~/websites/hedonometer.org/hedonometer/static/hedonometer/js/hedotools.shifter.js
17
+ - all of the whitespace changes...
18
+ - no _viz_type_use_URL()
19
+ - d3.urllib instead of hedotools.urllib
20
+ - return hedotools.shifter instead of return that
21
+ - different height and margin:
22
+ - var fullwidth = 400;
23
+ - var fullheight = 550 // 650; // make sure to change num words too
24
+ -
25
+ - var margin = {top: 0, right: 0, bottom: 0, left: 0};
26
+ + var fullwidth = 700;
27
+ + var fullheight = 500 // 650; // make sure to change num words too
28
+ +
29
+ + var margin = {
30
+ + top: 0,
31
+ + right: 0,
32
+ + bottom: 0,
33
+ + left: 0
34
+ + };
35
+ different number of words:
36
+ - var numWords = 28; // 37 with height 650 // 23 with height 500
37
+ - // I should be able to compute this?
38
+ + var numWords = 23; // 37 with height 650
39
+ missing - var sortedWordsRaw, sortedWordsEnRaw
40
+ missing function for that
41
+ - var _sortedWordsRaw = function(_) {
42
+ - var that = this;
43
+ - if (!arguments.length) return sortedWordsRaw;
44
+ - sortedWordsRaw = _;
45
+ - return that;
46
+ - }
47
+ missing get_word_index
48
+ added:
49
+ + var _sortedWordsEn = function(_) {
50
+ + if (!arguments.length) return sortedWordsEn;
51
+ + sortedWordsEn = _;
52
+ + return hedotools.shifter;
53
+ }
54
+ uses transform on the top;
55
+ - .attr({"class": function(d,i) { return "shifttext "+intStr0[sortedType[i]]; },
56
+ - "x": 0,
57
+ - "y": 0,
58
+ - "transform": function(d,i) {
59
+ - if (d>0) { return "translate("+(x(d)+2)+","+(y(i+1)+iBarH)+")"; }
60
+ - else { return "translate("+(x(d)-2)+","+(y(i+1)+iBarH)+")"; }
61
+ - },})
62
+ - // .attr("x",function(d,i) { if (d>0) {return x(d)+2;} else {return x(d)-2; } } )
63
+ - // .attr("y",function(d,i) { return y(i+1)+iBarH; } )
64
+ - .style({"text-anchor": function(d,i) { return ((d < 0) ? "end" : "start"); },
65
+ - "font-size": wordfontsize})
66
+ - .text(function(d,i) { return sortedWords[i]; });
67
+ + .attr("class", function(d, i) {
68
+ + return "shifttext " + intStr0[sortedType[i]];
69
+ + })
70
+ + .attr("x", function(d, i) {
71
+ + if (d > 0) {
72
+ + return x(d) + 2;
73
+ + } else {
74
+ + return x(d) - 2;
75
+ + }
76
+ + })
77
+ + .attr("y", function(d, i) {
78
+ + return y(i + 1) + iBarH;
79
+ + })
80
+ + .style({
81
+ + "text-anchor": function(d, i) {
82
+ + if (sortedMag[i] < 0) {
83
+ + return "end";
84
+ + } else {
85
+ + return "start";
86
+ + }
87
+ + },
88
+ + "font-size": bigshifttextsize
89
+ + })
90
+ + .text(function(d, i) {
91
+ + return sortedWords[i];
92
+ + });
93
+ - some changes on the replot() function
94
+ - missing some of the stuff for the word cloud
95
+ - all of the transitions on the bars use y position rather than y in the transform translate
96
+ - the transitions updates seem new....
97
+
98
+ 4. Teletherm: https://github.com/andyreagan/teletherm.org/blob/master/js/hedotools.shifter.js
99
+ ~/websites/teletherm.org/js/hedotools.shifter.js
100
+ - same version as sentiment comparison paper
101
+
102
+ 5, labMTsimple:
103
+ ~/tools/python/labMTsimple/labMTsimple/static/hedotools.shifter.js
104
+ - d3.urllib instead of hedotools.urllib
105
+ - no getfigure()
106
+ - missing a few new functions (word list, word paragraph)
107
+
108
+ 6. Sentiment comparison paper:
109
+ ~/projects/2015/03-sentiment-comparison/figures/twitter/twitter-shifts/static/hedotools.shifter.js
110
+ (and many other in this paper, but they should all be the same version)
111
+ - same version as mathcounts below
112
+
113
+ 7. Mathcounts
114
+ ~/projects/2015/02-mathcounts/js/hedotools.shifter.js
115
+ - same version as in the emotional arc installation, an older one (I think)
116
+
117
+ 8. AMA, many versions. Take just the latest one:
118
+ ~/projects/2019/ama/ama-web/v15/js/hedotools.shifter.v4.js
119
+ - no changes
120
+
121
+ 9. IBM Talk:
122
+ ~/projects/2016/04-ibm-watson-talk/reveal/js/hedotools.shifter.js
123
+ - identical!
124
+
125
+ 10: Emotional arc installation:
126
+ ~/projects/2016/04-emotional-arc-installation/static/js/hedotools.shifter.js
127
+ - TONS of changes. I think that this code is just older. Missing lots of bits
128
+ - uses just transform to move bars instead of y and transform
129
+ - remove viz_type URL usage
130
+ - d3.urllib instead of hedotools.urllib
131
+ - remove getfigure()
132
+ - return hedotools.shifter instead of return that in a few places
133
+ - font size hardcoded
134
+ - widths changed
135
+ - no raw words
136
+ - x and y label functions added:
137
+ + var xlabel_text = "Per word average happiness shift";
138
+ + var _xlabel_text = function(_) {
139
+ + if (!arguments.length) return xlabel_text;
140
+ + xlabel_text = _;
141
+ + return hedotools.shifter;
142
+ + }
143
+ +
144
+ + var ylabel_text = "Word Rank";
145
+ + var _ylabel_text = function(_) {
146
+ + if (!arguments.length) return ylabel_text;
147
+ + ylabel_text = _;
148
+ + return hedotools.shifter;
149
+ + }
150
+ - hm, we already have them, though. they just moved.
151
+
152
+
153
+ 11. Wordshifterator:
154
+ ~/projects/2016/05-wordshifterator/app/js/lib/hedotools.shifter.js
155
+ ~/projects/2016/05-wordshifterator/app/js/src/hedotools.shifter.js
156
+ - d3.urllib instead of hedotools.urllib
157
+ - remove top level getfigure()
158
+ - remove top level setBgcolor(), set manually to white in a few places
159
+
160
+ 12. UAE
161
+ https://github.com/andyreagan/quokkalabs-UAE/blob/master/js/hedotools.v4.js
162
+ Changes:
163
+ - attribution to Quokka Labs
164
+ - setBgcolor moved outside of plot() function to global
@@ -0,0 +1,36 @@
1
+ /* normal colors */
2
+ .negdown { fill: #B3B3FF; }
3
+ .posdown { fill: #FFFFB3; }
4
+ .negup { fill: #4C4CFF; }
5
+ .posup { fill: #FFFF4C; }
6
+ .sumgrey { fill: #272727; }
7
+
8
+ .legendrect { cursor: pointer; }
9
+ .yearrect { cursor: pointer; }
10
+ .expanderbutton { cursor: pointer; }
11
+ .sumrectL { cursor: pointer; }
12
+ .sumrectR { cursor: pointer; }
13
+ .resetbutton { cursor: pointer; }
14
+ svg image { cursor: pointer; }
15
+ g.help { cursor: pointer; }
16
+
17
+ /* got font from here */
18
+ /* https://github.com/naoyat/dvi.js/tree/master/texfonts */
19
+ /* see MDN for reference */
20
+ /* https://developer.mozilla.org/en-US/docs/Web/CSS/font-family */
21
+ @font-face {
22
+ font-family:'Latex default';
23
+ src: url('http://hedonometer.org/data/fonts/cmr10.woff') format('woff');
24
+ font-weight:normal;
25
+ font-style:normal;
26
+ }
27
+ text
28
+ {
29
+ font-family: "Latex default",serif;
30
+ }
31
+
32
+ div.outwrapper {
33
+ background: #e6e0cc;
34
+ padding: 20px;
35
+ }
36
+
Binary file
Binary file
@@ -0,0 +1 @@
1
+ function flatten(t,e){if("string"==typeof t)return t;var n=[];for(e in t){var a=flatten(t[e],e);a&&n.push(a)}return n.join(" ")}function parseText(t){tags={};var e={};t.split(d3.select("#per-line").property("checked")?/\n/g:wordSeparators).forEach(function(t){discard.test(t)||(t=t.replace(punctuation,""),stopWords.test(t.toLowerCase())||(t=t.substr(0,maxLength),e[t.toLowerCase()]=t,tags[t=t.toLowerCase()]=(tags[t]||0)+1))}),tags=d3.entries(tags).sort(function(t,e){return e.value-t.value}),tags.forEach(function(t){t.key=e[t.key]}),generate()}function generate(){layout.font(d3.select("#font").property("value")).spiral(d3.select("input[name=spiral]:checked").property("value")),fontSize=d3.scale[d3.select("input[name=scale]:checked").property("value")]().range([10,100]),tags.length&&fontSize.domain([+tags[tags.length-1].value||1,+tags[0].value]),complete=0,statusText.style("display",null),words=[],layout.stop().words(tags.slice(0,max=Math.min(tags.length,+d3.select("#max").property("value")))).start()}function progress(t){statusText.text(++complete+"/"+max)}function draw(t,e){statusText.style("display","none"),scale=e?Math.min(w/Math.abs(e[1].x-w/2),w/Math.abs(e[0].x-w/2),h/Math.abs(e[1].y-h/2),h/Math.abs(e[0].y-h/2))/2:1,words=t;var n=vis.selectAll("text").data(words,function(t){return t.text.toLowerCase()});n.transition().duration(1e3).attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).style("font-size",function(t){return t.size+"px"}),n.enter().append("text").attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).style("font-size","1px").transition().duration(1e3).style("font-size",function(t){return t.size+"px"}),n.style("font-family",function(t){return t.font}).style("fill",function(t){return fill(t.text.toLowerCase())}).text(function(t){return t.text});var a=background.append("g").attr("transform",vis.attr("transform")),r=a.node();n.exit().each(function(){r.appendChild(this)}),a.transition().duration(1e3).style("opacity",1e-6).remove(),vis.transition().delay(1e3).duration(750).attr("transform","translate("+[w>>1,h>>1]+")scale("+scale+")")}function downloadPNG(){d3.event.preventDefault();var t=document.createElement("canvas"),e=t.getContext("2d");t.width=w,t.height=h,e.translate(w>>1,h>>1),e.scale(scale,scale),words.forEach(function(t,n){e.save(),e.translate(t.x,t.y),e.rotate(t.rotate*Math.PI/180),e.textAlign="center",e.fillStyle=fill(t.text.toLowerCase()),e.font=t.size+"px "+t.font,e.fillText(t.text,0,0),e.restore()}),echoContentType.attr("value","image/png"),echoInput.attr("value",t.toDataURL("image/png")),echoForm.node().submit()}function downloadSVG(){d3.event.preventDefault(),echoContentType.attr("value","image/svg+xml;charset=utf-8"),echoInput.attr("value",svg.attr("version","1.1").attr("xmlns","http://www.w3.org/2000/svg").node().parentNode.innerHTML),echoForm.node().submit()}var unicodePunctuationRe="!-#%-*,-/:;?@\\[-\\]_{}\xa1\xa7\xab\xb6\xb7\xbb\xbf\u037e\u0387\u055a-\u055f\u0589\u058a\u05be\u05c0\u05c3\u05c6\u05f3\u05f4\u0609\u060a\u060c\u060d\u061b\u061e\u061f\u066a-\u066d\u06d4\u0700-\u070d\u07f7-\u07f9\u0830-\u083e\u085e\u0964\u0965\u0970\u0af0\u0df4\u0e4f\u0e5a\u0e5b\u0f04-\u0f12\u0f14\u0f3a-\u0f3d\u0f85\u0fd0-\u0fd4\u0fd9\u0fda\u104a-\u104f\u10fb\u1360-\u1368\u1400\u166d\u166e\u169b\u169c\u16eb-\u16ed\u1735\u1736\u17d4-\u17d6\u17d8-\u17da\u1800-\u180a\u1944\u1945\u1a1e\u1a1f\u1aa0-\u1aa6\u1aa8-\u1aad\u1b5a-\u1b60\u1bfc-\u1bff\u1c3b-\u1c3f\u1c7e\u1c7f\u1cc0-\u1cc7\u1cd3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205e\u207d\u207e\u208d\u208e\u2329\u232a\u2768-\u2775\u27c5\u27c6\u27e6-\u27ef\u2983-\u2998\u29d8-\u29db\u29fc\u29fd\u2cf9-\u2cfc\u2cfe\u2cff\u2d70\u2e00-\u2e2e\u2e30-\u2e3b\u3001-\u3003\u3008-\u3011\u3014-\u301f\u3030\u303d\u30a0\u30fb\ua4fe\ua4ff\ua60d-\ua60f\ua673\ua67e\ua6f2-\ua6f7\ua874-\ua877\ua8ce\ua8cf\ua8f8-\ua8fa\ua92e\ua92f\ua95f\ua9c1-\ua9cd\ua9de\ua9df\uaa5c-\uaa5f\uaade\uaadf\uaaf0\uaaf1\uabeb\ufd3e\ufd3f\ufe10-\ufe19\ufe30-\ufe52\ufe54-\ufe61\ufe63\ufe68\ufe6a\ufe6b\uff01-\uff03\uff05-\uff0a\uff0c-\uff0f\uff1a\uff1b\uff1f\uff20\uff3b-\uff3d\uff3f\uff5b\uff5d\uff5f-\uff65";!function(t){function e(){function t(t,n,a){for(var r,o,s,l=([{x:0,y:0},{x:e[0],y:e[1]}],n.x),i=n.y,d=Math.sqrt(e[0]*e[0]+e[1]*e[1]),h=m(e),f=Math.random()<.5?1:-1,p=-f;(r=h(p+=f))&&(o=~~r[0],s=~~r[1],!(Math.min(o,s)>d));)if(n.x=l+o,n.y=i+s,!(n.x+n.x0<0||n.y+n.y0<0||n.x+n.x1>e[0]||n.y+n.y1>e[1])&&(!a||!u(n,t,e[0]))&&(!a||c(n,a))){for(var y,g=n.sprite,v=n.width>>5,x=e[0]>>5,w=n.x-(v<<4),M=127&w,b=32-M,z=n.y1-n.y0,k=(n.y+n.y0)*x+(w>>5),T=0;z>T;T++){y=0;for(var A=0;v>=A;A++)t[k+A]|=y<<b|(v>A?(y=g[T*v+A])>>>M:0);k+=x}return delete n.sprite,!0}return!1}var e=[256,256],h=n,p=a,y=r,g=o,v=s,m=d,x=[],w=1/0,b=d3.dispatch("word","end"),z=null,k={};return k.start=function(){function n(){for(var n,s=+new Date;+new Date-s<w&&++u<o&&z;)n=d[u],n.x=e[0]*(Math.random()+.5)>>1,n.y=e[1]*(Math.random()+.5)>>1,l(n,d,u),t(a,n,r)&&(c.push(n),b.word(n),r?i(r,n):r=[{x:n.x+n.x0,y:n.y+n.y0},{x:n.x+n.x1,y:n.y+n.y1}],n.x-=e[0]>>1,n.y-=e[1]>>1);u>=o&&(k.stop(),b.end(c,r))}var a=f((e[0]>>5)*e[1]),r=null,o=x.length,u=-1,c=[],d=x.map(function(t,e){return{text:h.call(this,t,e),font:p.call(this,t,e),rotate:g.call(this,t,e),size:~~y.call(this,t,e),padding:s.call(this,t,e)}}).sort(function(t,e){return e.size-t.size});return z&&clearInterval(z),z=setInterval(n,0),n(),k},k.stop=function(){return z&&(clearInterval(z),z=null),k},k.timeInterval=function(t){return arguments.length?(w=null==t?1/0:t,k):w},k.words=function(t){return arguments.length?(x=t,k):x},k.size=function(t){return arguments.length?(e=[+t[0],+t[1]],k):e},k.font=function(t){return arguments.length?(p=d3.functor(t),k):p},k.rotate=function(t){return arguments.length?(g=d3.functor(t),k):g},k.text=function(t){return arguments.length?(h=d3.functor(t),k):h},k.spiral=function(t){return arguments.length?(m=M[t+""]||t,k):m},k.fontSize=function(t){return arguments.length?(y=d3.functor(t),k):y},k.padding=function(t){return arguments.length?(v=d3.functor(t),k):v},d3.rebind(k,b,"on")}function n(t){return t.text}function a(){return"serif"}function r(t){return Math.sqrt(t.value)}function o(){return 30*(~~(6*Math.random())-3)}function s(){return 1}function l(t,e,n){if(!t.sprite){w.clearRect(0,0,(g<<5)/m,v/m);var a=0,r=0,o=0,s=e.length;for(n--;++n<s;){t=e[n],w.save(),w.font=~~((t.size+1)/m)+"px "+t.font;var l=w.measureText(t.text+"m").width*m,u=t.size<<1;if(t.rotate){var i=Math.sin(t.rotate*y),c=Math.cos(t.rotate*y),d=l*c,h=l*i,f=u*c,p=u*i;l=Math.max(Math.abs(d+p),Math.abs(d-p))+31>>5<<5,u=~~Math.max(Math.abs(h+f),Math.abs(h-f))}else l=l+31>>5<<5;if(u>o&&(o=u),a+l>=g<<5&&(a=0,r+=o,o=0),r+u>=v)break;w.translate((a+(l>>1))/m,(r+(u>>1))/m),t.rotate&&w.rotate(t.rotate*y),w.fillText(t.text,0,0),w.restore(),t.width=l,t.height=u,t.xoff=a,t.yoff=r,t.x1=l>>1,t.y1=u>>1,t.x0=-t.x1,t.y0=-t.y1,a+=l}for(var x=w.getImageData(0,0,(g<<5)/m,v/m).data,M=[];--n>=0;){t=e[n];for(var l=t.width,b=l>>5,u=t.y1-t.y0,z=t.padding,k=0;u*b>k;k++)M[k]=0;if(a=t.xoff,null==a)return;r=t.yoff;for(var T=0,A=-1,C=0;u>C;C++){for(var k=0;l>k;k++){var S=b*C+(k>>5),I=x[(r+C)*(g<<5)+(a+k)<<2]?1<<31-k%32:0;z&&(C&&(M[S-b]|=I),l-1>C&&(M[S+b]|=I),I|=I<<1|I>>1),M[S]|=I,T|=I}T?A=C:(t.y0++,u--,C--,r++)}t.y1=t.y0+A,t.sprite=M.slice(0,(t.y1-t.y0)*b)}}}function u(t,e,n){n>>=5;for(var a,r=t.sprite,o=t.width>>5,s=t.x-(o<<4),l=127&s,u=32-l,i=t.y1-t.y0,c=(t.y+t.y0)*n+(s>>5),d=0;i>d;d++){a=0;for(var h=0;o>=h;h++)if((a<<u|(o>h?(a=r[d*o+h])>>>l:0))&e[c+h])return!0;c+=n}return!1}function i(t,e){var n=t[0],a=t[1];e.x+e.x0<n.x&&(n.x=e.x+e.x0),e.y+e.y0<n.y&&(n.y=e.y+e.y0),e.x+e.x1>a.x&&(a.x=e.x+e.x1),e.y+e.y1>a.y&&(a.y=e.y+e.y1)}function c(t,e){return t.x+t.x1>e[0].x&&t.x+t.x0<e[1].x&&t.y+t.y1>e[0].y&&t.y+t.y0<e[1].y}function d(t){var e=t[0]/t[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function h(t){var e=4,n=e*t[0]/t[1],a=0,r=0;return function(t){var o=0>t?-1:1;switch(Math.sqrt(1+4*o*t)-o&3){case 0:a+=n;break;case 1:r+=e;break;case 2:a-=n;break;default:r-=e}return[a,r]}}function f(t){for(var e=[],n=-1;++n<t;)e[n]=0;return e}var p,y=Math.PI/180,g=64,v=2048,m=1;if("undefined"!=typeof document)p=document.createElement("canvas"),p.width=1,p.height=1,m=Math.sqrt(p.getContext("2d").getImageData(0,0,1,1).data.length>>2),p.width=(g<<5)/m,p.height=v/m;else{var x=require("canvas");p=new x(g<<5,v)}var w=p.getContext("2d"),M={archimedean:d,rectangular:h};w.fillStyle="red",w.textAlign="center",t.cloud=e}("undefined"==typeof exports?d3.layout||(d3.layout={}):exports);var fill=d3.scale.category20b(),w=960,h=600,words=[],max,scale=1,complete=0,keyword="",tags,fontSize,maxLength=30,fetcher,statusText=d3.select("#status"),layout=d3.layout.cloud().timeInterval(10).size([w,h]).fontSize(function(t){return fontSize(+t.value)}).text(function(t){return t.key}).on("word",progress).on("end",draw),echoForm=d3.select("body").append("form").attr("action","https://www.jasondavies.com/echo").attr("target","_blank").attr("method","POST"),echoContentType=echoForm.append("input").attr("type","hidden").attr("name","content-type"),echoInput=echoForm.append("input").attr("type","hidden").attr("name","echo"),svg=d3.select("#vis").append("svg").attr("width",w).attr("height",h),background=svg.append("g"),vis=svg.append("g").attr("transform","translate("+[w>>1,h>>1]+")");d3.select("#download-svg").on("click",downloadSVG),d3.select("#download-png").on("click",downloadPNG);var form=d3.select("#form").on("submit",function(){parseText(d3.select("#text").property("value")),d3.event.preventDefault()});form.selectAll("input[type=number]").on("click.refresh",function(){this.value!==this.defaultValue&&(generate(),this.defaultValue=this.value)}),form.selectAll("input[type=radio], #font").on("change",generate);var stopWords=/^(i|me|my|myself|we|us|our|ours|ourselves|you|your|yours|yourself|yourselves|he|him|his|himself|she|her|hers|herself|it|its|itself|they|them|their|theirs|themselves|what|which|who|whom|whose|this|that|these|those|am|is|are|was|were|be|been|being|have|has|had|having|do|does|did|doing|will|would|should|can|could|ought|i'm|you're|he's|she's|it's|we're|they're|i've|you've|we've|they've|i'd|you'd|he'd|she'd|we'd|they'd|i'll|you'll|he'll|she'll|we'll|they'll|isn't|aren't|wasn't|weren't|hasn't|haven't|hadn't|doesn't|don't|didn't|won't|wouldn't|shan't|shouldn't|can't|cannot|couldn't|mustn't|let's|that's|who's|what's|here's|there's|when's|where's|why's|how's|a|an|the|and|but|if|or|because|as|until|while|of|at|by|for|with|about|against|between|into|through|during|before|after|above|below|to|from|up|upon|down|in|out|on|off|over|under|again|further|then|once|here|there|when|where|why|how|all|any|both|each|few|more|most|other|some|such|no|nor|not|only|own|same|so|than|too|very|say|says|said|shall)$/,punctuation=new RegExp("["+unicodePunctuationRe+"]","g"),wordSeparators=/[ \f\n\r\t\v\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\u3031-\u3035\u309b\u309c\u30a0\u30fc\uff70]+/g,discard=/^(@|https?:|\/\/)/,htmlTags=/(<[^>]*?>|<script.*?<\/script>|<style.*?<\/style>|<head.*?><\/head>)/g,matchTwitter=/^https?:\/\/([^\.]*\.)?twitter\.com/;parseText(d3.select("#text").property("value")),d3.select("#random-palette").on("click",function(){paletteJSON("http://www.colourlovers.com/api/palettes/random",{},function(t){fill.range(t[0].colors),vis.selectAll("text").style("fill",function(t){return fill(t.text.toLowerCase())})}),d3.event.preventDefault()}),function(){function t(){c=+d3.select("#angle-count").property("value"),u=Math.max(-90,Math.min(90,+d3.select("#angle-from").property("value"))),i=Math.max(-90,Math.min(90,+d3.select("#angle-to").property("value"))),e()}function e(){h.domain([0,c-1]).range([u,i]);var t=l.selectAll("path.angle").data([{startAngle:u*d,endAngle:i*d}]);t.enter().insert("path","circle").attr("class","angle").style("fill","#fc0"),t.attr("d",f);var o=l.selectAll("line.angle").data(d3.range(c).map(h));o.enter().append("line").attr("class","angle"),o.exit().remove(),o.attr("transform",function(t){return"rotate("+(90+t)+")"}).attr("x2",function(t,e){return e&&e!==c-1?-r:-r-5});var s=l.selectAll("path.drag").data([u,i]);s.enter().append("path").attr("class","drag").attr("d","M-9.5,0L-3,3.5L-3,-3.5Z").call(d3.behavior.drag().on("drag",function(t,o){t=(o?i:u)+90;var s=[-r*Math.cos(t*d),-r*Math.sin(t*d)],l=[d3.event.x,d3.event.y],c=~~(Math.atan2(n(s,l),a(s,l))/d);t=Math.max(-90,Math.min(90,t+c-90)),c=i-u,o?(i=t,c>360?u+=c-360:0>c&&(u=i)):(u=t,c>360?i+=360-c:0>c&&(i=u)),e()}).on("dragend",generate)),s.attr("transform",function(t){return"rotate("+(t+90)+")translate(-"+r+")"}),layout.rotate(function(){return h(~~(Math.random()*c))}),d3.select("#angle-count").property("value",c),d3.select("#angle-from").property("value",u),d3.select("#angle-to").property("value",i)}function n(t,e){return t[0]*e[1]-t[1]*e[0]}function a(t,e){return t[0]*e[0]+t[1]*e[1]}var r=40.5,o=35,s=20,l=d3.select("#angles").append("svg").attr("width",2*(r+o)).attr("height",r+1.5*s).append("g").attr("transform","translate("+[r+o,r+s]+")");l.append("path").style("fill","none").attr("d",["M",-r,0,"A",r,r,0,0,1,r,0].join(" ")),l.append("line").attr("x1",-r-7).attr("x2",r+7),l.append("line").attr("y2",-r-7),l.selectAll("text").data([-90,0,90]).enter().append("text").attr("dy",function(t,e){return 1===e?null:".3em"}).attr("text-anchor",function(t,e){return["end","middle","start"][e]}).attr("transform",function(t){return t+=90,"rotate("+t+")translate("+-(r+10)+")rotate("+-t+")translate(2)"}).text(function(t){return t+"\xb0"});var u,i,c,d=Math.PI/180,h=d3.scale.linear(),f=d3.svg.arc().innerRadius(0).outerRadius(r);d3.selectAll("#angle-count, #angle-from, #angle-to").on("change",t).on("mouseup",t),t()}();