Skip to content

Instantly share code, notes, and snippets.

@js418
Last active February 25, 2022 15:26
Show Gist options
  • Save js418/5aef8c58b0baa5bc009f228f0a6f2830 to your computer and use it in GitHub Desktop.
Save js418/5aef8c58b0baa5bc009f228f0a6f2830 to your computer and use it in GitHub Desktop.
dc word cloud
license: mit
// Word cloud layout by Jason Davies, http://www.jasondavies.com/word-cloud/
// Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf
(function(exports) {
function cloud() {
var size = [256, 256],
text = cloudText,
font = cloudFont,
fontSize = cloudFontSize,
fontStyle = cloudFontNormal,
fontWeight = cloudFontNormal,
rotate = cloudRotate,
padding = cloudPadding,
spiral = archimedeanSpiral,
words = [],
timeInterval = Infinity,
event = d3.dispatch("word", "end"),
timer = null,
cloud = {};
cloud.start = function() {
var board = zeroArray((size[0] >> 5) * size[1]),
bounds = null,
n = words.length,
i = -1,
tags = [],
data = words.map(function(d, i) {
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);
return d;
}).sort(function(a, b) { return b.size - a.size; });
if (timer) clearInterval(timer);
timer = setInterval(step, 0);
step();
return cloud;
function step() {
var start = +new Date,
d;
while (+new Date - start < timeInterval && ++i < n && timer) {
d = data[i];
d.x = (size[0] * (Math.random() + .5)) >> 1;
d.y = (size[1] * (Math.random() + .5)) >> 1;
cloudSprite(d, data, i);
if (d.hasText && place(board, d, bounds)) {
tags.push(d);
event.word(d);
if (bounds) cloudBounds(bounds, d);
else bounds = [{x: d.x + d.x0, y: d.y + d.y0}, {x: d.x + d.x1, y: d.y + d.y1}];
// Temporary hack
d.x -= size[0] >> 1;
d.y -= size[1] >> 1;
}
}
if (i >= n) {
cloud.stop();
event.end(tags, bounds);
}
}
}
cloud.stop = function() {
if (timer) {
clearInterval(timer);
timer = null;
}
return cloud;
};
cloud.timeInterval = function(x) {
if (!arguments.length) return timeInterval;
timeInterval = x == null ? Infinity : x;
return cloud;
};
function place(board, tag, bounds) {
var perimeter = [{x: 0, y: 0}, {x: size[0], y: size[1]}],
startX = tag.x,
startY = tag.y,
maxDelta = Math.sqrt(size[0] * size[0] + size[1] * size[1]),
s = spiral(size),
dt = Math.random() < .5 ? 1 : -1,
t = -dt,
dxdy,
dx,
dy;
while (dxdy = s(t += dt)) {
dx = ~~dxdy[0];
dy = ~~dxdy[1];
if (Math.min(dx, dy) > maxDelta) break;
tag.x = startX + dx;
tag.y = startY + dy;
if (tag.x + tag.x0 < 0 || tag.y + tag.y0 < 0 ||
tag.x + tag.x1 > size[0] || tag.y + tag.y1 > size[1]) continue;
// TODO only check for collisions within current bounds.
if (!bounds || !cloudCollide(tag, board, size[0])) {
if (!bounds || collideRects(tag, bounds)) {
var sprite = tag.sprite,
w = tag.width >> 5,
sw = size[0] >> 5,
lx = tag.x - (w << 4),
sx = lx & 0x7f,
msx = 32 - sx,
h = tag.y1 - tag.y0,
x = (tag.y + tag.y0) * sw + (lx >> 5),
last;
for (var 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;
}
delete tag.sprite;
return true;
}
}
}
return false;
}
cloud.words = function(x) {
if (!arguments.length) return words;
words = x;
return cloud;
};
cloud.size = function(x) {
if (!arguments.length) return size;
size = [+x[0], +x[1]];
return cloud;
};
cloud.font = function(x) {
if (!arguments.length) return font;
font = d3.functor(x);
return cloud;
};
cloud.fontStyle = function(x) {
if (!arguments.length) return fontStyle;
fontStyle = d3.functor(x);
return cloud;
};
cloud.fontWeight = function(x) {
if (!arguments.length) return fontWeight;
fontWeight = d3.functor(x);
return cloud;
};
cloud.rotate = function(x) {
if (!arguments.length) return rotate;
rotate = d3.functor(x);
return cloud;
};
cloud.text = function(x) {
if (!arguments.length) return text;
text = d3.functor(x);
return cloud;
};
cloud.spiral = function(x) {
if (!arguments.length) return spiral;
spiral = spirals[x + ""] || x;
return cloud;
};
cloud.fontSize = function(x) {
if (!arguments.length) return fontSize;
fontSize = d3.functor(x);
return cloud;
};
cloud.padding = function(x) {
if (!arguments.length) return padding;
padding = d3.functor(x);
return cloud;
};
return d3.rebind(cloud, event, "on");
}
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 (~~(Math.random() * 6) - 3) * 30;
}
function cloudPadding() {
return 1;
}
// Fetches a monochrome sprite bitmap for the specified text.
// Load in batches for speed.
function cloudSprite(d, data, di) {
if (d.sprite) return;
c.clearRect(0, 0, (cw << 5) / ratio, ch / ratio);
var x = 0,
y = 0,
maxh = 0,
n = data.length;
--di;
while (++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)) + 0x1f) >> 5 << 5;
h = ~~Math.max(Math.abs(wsr + hcr), Math.abs(wsr - hcr));
} else {
w = (w + 0x1f) >> 5 << 5;
}
if (h > maxh) maxh = h;
if (x + w >= (cw << 5)) {
x = 0;
y += maxh;
maxh = 0;
}
if (y + h >= ch) break;
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);
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 = true;
x += w;
}
var pixels = c.getImageData(0, 0, (cw << 5) / ratio, ch / ratio).data,
sprite = [];
while (--di >= 0) {
d = data[di];
if (!d.hasText) continue;
var w = d.width,
w32 = w >> 5,
h = d.y1 - d.y0;
// Zero the buffer
for (var i = 0; i < h * w32; i++) sprite[i] = 0;
x = d.xoff;
if (x == null) return;
y = d.yoff;
var seen = 0,
seenRow = -1;
for (var j = 0; j < h; j++) {
for (var 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;
}
if (seen) seenRow = j;
else {
d.y0++;
h--;
j--;
y++;
}
}
d.y1 = d.y0 + seenRow;
d.sprite = sprite.slice(0, (d.y1 - d.y0) * w32);
}
}
// Use mask-based collision detection.
function cloudCollide(tag, board, sw) {
sw >>= 5;
var sprite = tag.sprite,
w = tag.width >> 5,
lx = tag.x - (w << 4),
sx = lx & 0x7f,
msx = 32 - sx,
h = tag.y1 - tag.y0,
x = (tag.y + tag.y0) * sw + (lx >> 5),
last;
for (var 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 true;
}
x += sw;
}
return false;
}
function cloudBounds(bounds, d) {
var b0 = bounds[0],
b1 = bounds[1];
if (d.x + d.x0 < b0.x) b0.x = d.x + d.x0;
if (d.y + d.y0 < b0.y) b0.y = d.y + d.y0;
if (d.x + d.x1 > b1.x) b1.x = d.x + d.x1;
if (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 rectangularSpiral(size) {
var dy = 4,
dx = dy * size[0] / size[1],
x = 0,
y = 0;
return function(t) {
var sign = t < 0 ? -1 : 1;
// See triangular numbers: T_n = n * (n + 1) / 2.
switch ((Math.sqrt(1 + 4 * sign * t) - sign) & 3) {
case 0: x += dx; break;
case 1: y += dy; break;
case 2: x -= dx; break;
default: y -= dy; break;
}
return [x, y];
};
}
// TODO reuse arrays?
function zeroArray(n) {
var a = [],
i = -1;
while (++i < n) a[i] = 0;
return a;
}
var cloudRadians = Math.PI / 180,
cw = 1 << 11 >> 5,
ch = 1 << 11,
canvas,
ratio = 1;
if (typeof document !== "undefined") {
canvas = document.createElement("canvas");
canvas.width = 1;
canvas.height = 1;
ratio = Math.sqrt(canvas.getContext("2d").getImageData(0, 0, 1, 1).data.length >> 2);
canvas.width = (cw << 5) / ratio;
canvas.height = ch / ratio;
} else {
// node-canvas support
var Canvas = require("canvas");
canvas = new Canvas(cw << 5, ch);
}
var c = canvas.getContext("2d"),
spirals = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
c.fillStyle = c.strokeStyle = "red";
c.textAlign = "center";
exports.cloud = cloud;
})(typeof exports === "undefined" ? d3.layout || (d3.layout = {}) : exports);
text size
plane 547
cargo 394
crashed 393
pilot 202
aircraft 167
flight 123
runway 118
engine 116
failure 112
approach 102
altitude 97
struck 86
conditions 82
takeoff 81
weather 80
crew 76
route 73
control 71
en 69
attempting 69
landing 67
mountain 67
trees 65
taking 65
terrain 62
land 62
lost 61
ground 59
airport 59
unknown 59
maintain 58
low 54
failed 53
accident 47
right 44
short 43
mail 43
loss 41
shortly 40
ft 38
improper 38
fog 37
poor 37
wing 35
left 34
airplane 34
emergency 32
flew 32
factors 32
fuel 31
night 30
instrument 30
high 30
resulted 29
contributing 27
clearance 27
collided 26
vfr 25
did 25
miles 25
adverse 25
captain 24
turn 24
air 24
power 24
icing 23
hit 23
descent 23
continued 23
command 23
flying 22
return 22
climb 22
procedures 22
undetermined 22
inadequate 21
descended 20
speed 20
nose 20
took 19
engines 19
impacted 19
caught 19
lack 19
reasons 19
decision 19
stalled 19
rain 18
visual 18
resulting 18
attempt 17
ice 17
attempted 17
area 17
caused 17
stall 17
error 17
making 17
visibility 17
height 16
make 16
flames 16
tried 16
feet 16
sea 16
carrying 16
fatigue 16
began 16
gain 16
snow 15
overloaded 15
burned 15
planning 15
ceiling 14
unable 14
water 14
killed 14
ifr 14
cause 14
final 14
mountainous 14
minutes 14
went 13
second 13
procedure 13
course 13
later 13
burst 13
field 13
company 13
broke 13
collision 13
steep 13
end 12
adequate 12
entered 12
ocean 12
dark 12
inadvertent 12
heavy 12
hill 12
pilots 12
maintenance 12
crash 12
gear 12
aboard 11
destroyed 11
ran 11
causing 11
ils 11
canyon 11
descend 11
contact 11
helicopter 11
follow 11
departure 11
attitude 11
factor 11
river 11
position 11
airspeed 11
mt 10
bank 10
forced 10
result 10
diverted 10
near 10
losing 10
fly 10
meteorological 10
condition 10
prior 10
weight 10
operation 10
missed 10
encountered 10
use 10
lose 10
disorientation 9
reported 9
disappeared 9
mile 9
spatial 9
pass 9
landed 9
minimum 9
mountains 9
winds 9
cruise 9
center 9
avoid 9
loaded 8
ceilings 8
pitch 8
subsequent 8
trying 8
tail 8
radar 8
house 8
probable 8
lower 8
warning 8
cloud 8
rising 8
controller 8
proper 8
safe 7
encountering 7
elevator 7
contamination 7
gravity 7
descending 7
officer 7
holding 7
clouds 7
normal 7
tower 7
time 7
rate 7
soon 7
airborne 7
storm 7
overran 7
ditched 7
approved 7
snowstorm 7
led 7
degree 7
controls 7
misjudged 6
operations 6
mda 6
atc 6
heading 6
bad 6
rolled 6
aviation 6
east 6
meters 6
flaps 6
float 6
initial 6
maximum 6
port 6
passengers 6
following 6
non 6
feathered 6
severe 6
reduced 6
improperly 6
oil 6
cockpit 6
houses 6
km 6
attention 6
turbulence 6
experiencing 6
related 6
controlled 6
sufficient 6
wreckage 6
lake 6
thunderstorms 6
told 5
path 5
separated 5
wind 5
appeared 5
possible 5
check 5
radioed 5
cessna 5
order 5
banked 5
dive 5
vicinity 5
striking 5
equipment 5
impairment 5
maneuvering 5
vertical 5
mount 5
diversion 5
setting 5
rules 5
maintained 5
pitched 5
incorrect 5
experience 5
destination 5
initiated 5
known 5
navigational 5
airframe 5
shifted 5
clear 5
early 5
loading 5
continue 5
inspection 5
thunderstorm 5
rotation 5
inverted 5
management 5
able 5
pattern 5
copilot 5
surface 5
disoriented 5
propeller 5
wooded 4
likely 4
lights 4
indicated 4
executed 4
imc 4
structural 4
standard 4
tree 4
preparation 4
bounced 4
grove 4
chartered 4
twice 4
reference 4
prescribed 4
uncontrolled 4
fuselage 4
nm 4
tip 4
suffered 4
p 4
box 4
half 4
initiate 4
blind 4
open 4
accordance 4
san 4
turned 4
downdraft 4
shot 4
threshold 4
forecast 4
killing 4
nearby 4
minima 4
pole 4
climbing 4
aborted 4
electrical 4
conditons 4
critical 4
operator 4
distracted 4
complete 4
included 4
debris 4
small 4
overshot 4
followed 4
marginal 4
information 4
horizontal 4
lateral 4
instructions 4
reason 4
positioning 4
recovered 4
powerplant 4
experienced 4
warnings 4
distance 4
approaching 4
avoidance 4
missing 4
load 4
alternate 4
big 4
prop 4
tcas 4
drifted 4
properly 4
russian 4
planes 4
came 4
veered 4
stabilizer 4
lock 4
located 4
forest 4
farm 4
lines 4
contaminated 4
instruments 4
covered 4
tupolev 4
ridge 4
divert 4
wall 4
injured 4
tons 4
midair 4
rock 4
dropping 4
uncontrollable 4
north 4
trafficontroller 4
cashed 4
horn 3
surrounding 3
contributed 3
supplies 3
brought 3
recovery 3
faulty 3
wrong 3
baggage 3
ambulance 3
spiraled 3
combination 3
prevented 3
lifted 3
restricted 3
formation 3
certified 3
days 3
service 3
spoiler 3
circled 3
incomplete 3
inoperative 3
despite 3
comply 3
observed 3
decided 3
spin 3
balance 3
rotor 3
published 3
suitable 3
assigned 3
victoria 3
manual 3
dense 3
track 3
starvation 3
head 3
physical 3
trouble 3
minute 3
level 3
accumulation 3
prevent 3
international 3
navigation 3
airstrip 3
stated 3
nearest 3
allowed 3
requirements 3
deviated 3
designed 3
pulled 3
years 3
monitor 3
main 3
bursting 3
receiving 3
mountainside 3
inflight 3
pre 3
detect 3
slow 3
equipped 3
awareness 3
secondary 3
outside 3
tour 3
anti 3
associated 3
west 3
direction 3
premature 3
dangerously 3
trip 3
airfield 3
rear 3
gross 3
fell 3
references 3
determine 3
deteriorating 3
valley 3
required 3
shut 3
antenna 3
requested 3
alcohol 3
building 3
decisions 3
returning 3
hours 3
operating 3
strong 3
base 3
action 3
taken 3
door 3
flightcrew 3
lighting 3
turbine 3
fully 3
adhere 3
induced 3
members 3
airway 3
number 3
approximately 3
jet 3
compartment 3
directives 3
extremely 3
cover 3
rest 3
remove 3
set 3
available 3
reverse 3
point 3
precision 3
frozen 3
used 3
swiss 3
wings 3
communications 3
run 3
obscured 3
sightseeing 3
line 3
preflight 3
problems 3
desert 3
rudder 3
telling 3
timely 3
piper 3
seconds 3
missile 3
aft 3
light 3
subsequently 3
material 3
obstructions 3
approaches 3
rearward 3
south 3
acceleration 3
angle 3
switch 3
gradual 3
local 3
means 3
planned 3
limits 3
rpm 3
addition 3
effect 3
judgment 3
excessive 3
checklist 3
intersection 3
elevators 3
pressure 3
limit 3
problem 3
limited 2
localizer 2
facilities 2
buddy 2
cruising 2
encounter 2
obtained 2
climbed 2
seven 2
drowned 2
total 2
type 2
successful 2
locked 2
roof 2
deficiencies 2
temperatures 2
returned 2
provide 2
beach 2
minimums 2
undetected 2
windshield 2
directional 2
fix 2
potter 2
break 2
l 2
disconnection 2
aids 2
speeds 2
primary 2
western 2
design 2
manner 2
altimeters 2
coin 2
darkness 2
medical 2
swamp 2
lodge 2
dc 2
bay 2
said 2
away 2
extend 2
receiver 2
drugs 2
lift 2
luggage 2
cylinder 2
manoeuvring 2
ditching 2
brake 2
shift 2
unfamiliarity 2
tops 2
hand 2
departed 2
occupants 2
postal 2
elevation 2
psychological 2
performing 2
people 2
multiple 2
shifting 2
bolt 2
permitted 2
existed 2
crews 2
snowy 2
inside 2
trim 2
passenger 2
toss 2
ship 2
glacier 2
roll 2
felt 2
sank 2
rod 2
loads 2
meadow 2
explosion 2
yards 2
appears 2
exiting 2
obstacle 2
secured 2
data 2
lifting 2
st 2
truck 2
african 2
maintaining 2
execute 2
workload 2
el 2
stalling 2
entering 2
adequately 2
intended 2
looking 2
seriously 2
correct 2
maneuver 2
bolts 2
enroute 2
training 2
george 2
flowers 2
relative 2
remained 2
fracture 2
performance 2
enter 2
cleared 2
crashing 2
freezing 2
mission 2
morning 2
mogadishu 2
declared 2
seat 2
federal 2
wheels 2
continuation 2
exhaustion 2
disconnected 2
telephone 2
iowa 2
wires 2
model 2
actions 2
death 2
scheduled 2
traffic 2
holly 2
execution 2
t 2
ascend 2
specified 2
assembly 2
malfunctioning 2
preoccupied 2
communication 2
locks 2
felix 2
al 2
resultant 2
peak 2
sounded 2
executing 2
children 2
mph 2
neighborhood 2
fence 2
bopper 2
witnesses 2
beacon 2
ahead 2
pick 2
narrow 2
suddenly 2
flap 2
controlling 2
hour 2
remain 2
v 2
downdrafts 2
beaver 2
misinterpretation 2
stayed 2
long 2
blood 2
coming 2
supervision 2
unita 2
surveillance 2
disregarded 2
rwy 2
stopped 2
malfunction 2
safety 2
highway 2
dirt 2
running 2
conducted 2
outeniqua 2
consequence 2
leading 2
selector 2
self 2
plan 2
colliding 2
aileron 2
kt 2
gold 2
hillside 2
impact 2
proximity 2
activity 2
close 2
won 2
nav 2
pacifiocean 2
reduction 2
crack 2
overrunning 2
lodged 2
rig 2
edge 2
grossly 2
precedence 2
circling 2
injuries 2
valens 2
spins 2
brakes 2
metres 2
palm 2
exceeding 2
flameout 2
continuing 2
altimeter 2
goods 2
bell 2
single 2
retract 2
regulations 2
fighter 2
rescued 2
imprecise 2
having 2
initiating 2
try 2
whiteout 2
chose 2
sink 2
leaving 2
danger 2
apply 2
taxiing 2
mid 2
occurred 2
sharply 2
tab 2
crosswind 2
including 2
chosen 2
attachment 2
auto 2
asymmetrical 2
going 2
density 2
aggravated 2
exceeded 2
situational 2
thrust 2
overshoot 2
reached 2
reversed 2
intentional 2
environmental 2
briefing 2
tide 2
segment 2
construction 2
fact 2
deviation 2
parked 2
rough 2
gust 2
shrouded 2
officials 2
operated 2
correctly 2
attributed 2
overstressing 2
charts 2
anomaly 2
received 2
cross 2
parts 2
slammed 2
northwest 2
i 2
soviet 2
negligence 2
heavily 2
obtain 2
supply 2
day 2
clipped 2
increased 2
immediately 2
drizzle 2
limitations 2
noise 2
reaching 2
insufficient 2
extended 2
contradictory 2
misty 2
apporach 2
pic 2
eastern 2
inboard 2
commencement 2
richardson 2
repositioning 1
khalif 1
sleet 1
sleep 1
hanging 1
increase 1
physiological 1
isiro 1
void 1
toisa 1
malfunctioned 1
stabbed 1
obstruction 1
upload 1
fairfax 1
commented 1
charter 1
force 1
japanese 1
scraped 1
blue 1
established 1
uncontained 1
haze 1
conduct 1
prelanding 1
officially 1
consisting 1
simultaneously 1
dahl 1
undershot 1
chino 1
buckled 1
items 1
reports 1
electricity 1
smoke 1
stipulated 1
settled 1
diameter 1
secure 1
visible 1
unit 1
saran 1
calabar 1
leaks 1
knoll 1
strike 1
tell 1
mush 1
ferrying 1
helideck 1
brushy 1
warn 1
loadmaster 1
ware 1
phraseology 1
work 1
gasoline 1
leaped 1
experts 1
salvage 1
mountainsides 1
table 1
tangled 1
activation 1
offshore 1
lay 1
las 1
effective 1
jungle 1
farmlands 1
personal 1
shear 1
belly 1
eventually 1
affected 1
school 1
effects 1
yopal 1
defected 1
oxygen 1
strayed 1
leaned 1
series 1
displacement 1
slew 1
manizales 1
mayday 1
banning 1
got 1
gate 1
domodedovo 1
perception 1
turning 1
barrier 1
free 1
obstructing 1
juan 1
restarting 1
starts 1
loud 1
thick 1
ditch 1
rated 1
jamba 1
intermediate 1
master 1
flagpole 1
breaker 1
ahmed 1
target 1
ababa 1
flame 1
bridge 1
lbs 1
navigate 1
nonconforming 1
juneau 1
seen 1
configure 1
erratiaction 1
concrete 1
recommended 1
lumpur 1
forces 1
effectiveness 1
atlantiocean 1
waylon 1
cronje 1
exercised 1
extending 1
mouth 1
observation 1
baldy 1
flow 1
crankshaft 1
responded 1
saying 1
contacted 1
departing 1
radio 1
bust 1
touched 1
easterly 1
rice 1
wide 1
stop 1
pocket 1
watermelon 1
report 1
jiles 1
adherence 1
respond 1
mandatory 1
testing 1
checks 1
radius 1
skyguide 1
fail 1
mus 1
rings 1
declaired 1
vernon 1
extent 1
carbon 1
improve 1
maneuvers 1
protect 1
veer 1
himalayas 1
uncertainty 1
juba 1
feathering 1
erupted 1
requests 1
confronted 1
toruuguero 1
headlights 1
skidded 1
life 1
victorville 1
attacked 1
inattention 1
shattering 1
intakes 1
tank 1
tunas 1
lesser 1
abrupt 1
mistake 1
mexico 1
yongai 1
soldier 1
perform 1
saw 1
contaminate 1
mixtures 1
ingested 1
perimeter 1
declaring 1
fuse 1
failing 1
game 1
mother 1
just 1
rotated 1
fighters 1
identify 1
transporting 1
depart 1
scattering 1
elk 1
remedial 1
hills 1
hilly 1
spread 1
requiring 1
save 1
gave 1
ravine 1
intercom 1
possibly 1
forested 1
advanced 1
apart 1
appearing 1
security 1
valence 1
old 1
creek 1
mosques 1
successfully 1
precluded 1
firemen 1
months 1
burbank 1
ensure 1
raised 1
facility 1
bound 1
rendering 1
balanced 1
electripole 1
support 1
knowing 1
fight 1
stuck 1
way 1
war 1
selection 1
vectoring 1
berm 1
sustained 1
removed 1
nosedown 1
fort 1
portions 1
anunstabilized 1
minor 1
foodstuffs 1
wetness 1
covers 1
evidence 1
floor 1
tin 1
test 1
tie 1
kenyan 1
panay 1
nw 1
permitting 1
unarrested 1
rolling 1
died 1
outskirts 1
inconviently 1
commenced 1
vietnam 1
rainier 1
teeth 1
overturned 1
dance 1
avalanche 1
skin 1
layers 1
hold 1
passage 1
environment 1
finally 1
propellers 1
southwest 1
division 1
midjudge 1
hydraulisystem 1
advised 1
ketchican 1
posts 1
standards 1
team 1
lever 1
unaware 1
talked 1
prairie 1
patient 1
penetrated 1
fluxgate 1
matari 1
current 1
falling 1
alertness 1
supporting 1
kilometers 1
change 1
canadian 1
flamed 1
franklin 1
linhas 1
spatially 1
touchdown 1
mentaya 1
working 1
positive 1
live 1
msl 1
criteria 1
sharing 1
apparent 1
misreading 1
behalf 1
organizations 1
car 1
flu 1
schedule 1
pyrenees 1
ferry 1
detached 1
arrive 1
lamjura 1
parachute 1
heard 1
abort 1
spanning 1
winter 1
mismanagement 1
fourth 1
pins 1
southern 1
destructive 1
man 1
stress 1
nosed 1
lagoon 1
approx 1
postcrash 1
correlation 1
deactivated 1
unfavorable 1
peterson 1
blocked 1
accepted 1
presence 1
unserviceability 1
platform 1
insturment 1
policy 1
coordinated 1
instantly 1
douglassville 1
qualified 1
corroded 1
ritchie 1
didn 1
h 1
glidepath 1
populated 1
peacekeepers 1
year 1
space 1
wamena 1
traffiservices 1
fargo 1
disintegrated 1
divergence 1
cart 1
rebel 1
ore 1
care 1
place 1
massive 1
turf 1
toulouse 1
surviving 1
specifically 1
directly 1
carry 1
ring 1
checked 1
district 1
runways 1
overshooting 1
hub 1
forward 1
deceleration 1
tehran 1
rugged 1
r 1
mariner 1
lashkar 1
portsmouth 1
sao 1
craig 1
southeasterly 1
allsup 1
recover 1
instructed 1
potential 1
coincide 1
blinding 1
channel 1
tornado 1
aerodrome 1
operate 1
bateau 1
juwata 1
salt 1
luxor 1
slope 1
german 1
fifty 1
injection 1
gulf 1
flightcraft 1
interstate 1
fligth 1
closed 1
conrete 1
baghdad 1
nearly 1
awaiting 1
resource 1
held 1
bearings 1
tenerife 1
roger 1
predicted 1
worries 1
collilded 1
aguadita 1
dived 1
famine 1
elected 1
mistrimmed 1
monongahela 1
gazette 1
reading 1
ruptured 1
notice 1
originated 1
screen 1
guyana 1
dome 1
densely 1
singers 1
spark 1
reaction 1
acquiring 1
contol 1
region 1
according 1
flipped 1
duty 1
deviating 1
dispatch 1
pod 1
airliner 1
airlines 1
enable 1
transportation 1
narita 1
downwind 1
observe 1
minister 1
ignition 1
cancelled 1
coupled 1
characteristics 1
engaged 1
sudanese 1
instruction 1
ambient 1
loosing 1
airloads 1
develop 1
overspeed 1
bowl 1
guadalajara 1
ethiopia 1
status 1
exhaust 1
transceiver 1
lamentation 1
drain 1
largely 1
minimize 1
vacant 1
relief 1
drafts 1
inability 1
conform 1
guided 1
violent 1
prejudiced 1
weekly 1
mechaniwas 1
rose 1
improvement 1
pile 1
treatment 1
nielsen 1
starvaion 1
discontinue 1
confines 1
warehouse 1
reas 1
fortune 1
jammed 1
overheated 1
regina 1
circumnavigate 1
process 1
airfame 1
inspect 1
asad 1
conducting 1
radiographs 1
airline 1
pockets 1
act 1
road 1
heater 1
whitey 1
lands 1
burning 1
beacons 1
variable 1
strip 1
bergen 1
assumed 1
lom 1
arey 1
stressors 1
delayed 1
shroud 1
unreliable 1
belated 1
pitting 1
drills 1
miguel 1
throttles 1
tones 1
flats 1
yawed 1
ac 1
certain 1
contributory 1
alarm 1
ensuing 1
cables 1
inspections 1
personnel 1
narcotics 1
gaining 1
spoilers 1
drift 1
coverage 1
remote 1
wife 1
tete 1
mast 1
starting 1
original 1
splitting 1
month 1
referring 1
subjected 1
removal 1
maintenace 1
roadway 1
worse 1
activated 1
attemping 1
balancing 1
faa 1
list 1
align 1
uncontroled 1
past 1
villavicencio 1
cottonwood 1
recalculate 1
sub 1
section 1
prevailed 1
attitudes 1
movement 1
loose 1
sampit 1
observing 1
loma 1
misinterpret 1
difficulty 1
compliance 1
exceptionally 1
family 1
trained 1
thatched 1
establish 1
select 1
chelyabinsk 1
pitching 1
firth 1
authorization 1
fiords 1
keeping 1
include 1
tuam 1
talkeetna 1
scan 1
suggestions 1
rainstorm 1
attain 1
sharp 1
imminent 1
breaking 1
utilize 1
maps 1
plant 1
reflect 1
response 1
shore 1
banks 1
infant 1
developed 1
installed 1
disabled 1
lava 1
signs 1
autofeather 1
rapidly 1
detected 1
systems 1
uberaba 1
lookout 1
entire 1
food 1
walls 1
disapppeared 1
capability 1
habits 1
sops 1
fish 1
hard 1
positioned 1
empennage 1
undertake 1
surrounded 1
douglas 1
shipment 1
evaluation 1
confidence 1
basketball 1
backed 1
finland 1
rack 1
kosti 1
circuit 1
contingency 1
knots 1
botany 1
precautionary 1
mistakenly 1
occurrence 1
story 1
regulation 1
station 1
northbound 1
gps 1
calculations 1
trapped 1
mediterranean 1
beechcraft 1
park 1
immediate 1
determines 1
cartwheeled 1
double 1
intermittent 1
contrary 1
yunque 1
procedural 1
mickey 1
gale 1
showers 1
build 1
flighing 1
exploded 1
province 1
kan 1
impacting 1
starboard 1
humanitarian 1
undulations 1
dragged 1
thomas 1
rebels 1
chelan 1
securing 1
grazed 1
boulder 1
boniface 1
batten 1
compass 1
throttle 1
incapacitated 1
seperated 1
alteration 1
banking 1
unintentionally 1
precaution 1
champadevi 1
kilo 1
backfire 1
jettisoning 1
shower 1
pictures 1
various 1
probably 1
numerous 1
imclement 1
floats 1
c 1
restaurant 1
carelessness 1
barely 1
foreign 1
mimimum 1
rashed 1
retarded 1
thoa 1
distress 1
unsuccessful 1
platinum 1
java 1
raise 1
acceptance 1
hitting 1
pa 1
initiation 1
cosmetics 1
gas 1
overloading 1
representative 1
gah 1
wheeled 1
loon 1
thirty 1
straight 1
governor 1
behavior 1
leland 1
welding 1
rim 1
powerline 1
albany 1
unlit 1
kelowna 1
lukla 1
montseny 1
grand 1
meduxnekeag 1
conflict 1
temporary 1
overweight 1
alert 1
moment 1
flown 1
user 1
plugs 1
culvert 1
task 1
person 1
abilities 1
alignment 1
blizzard 1
workers 1
overfew 1
location 1
sydney 1
remaining 1
indonesian 1
showing 1
suffering 1
emergence 1
like 1
congolese 1
rotate 1
imposed 1
signal 1
glideslope 1
condtions 1
unstable 1
deicing 1
methods 1
talkeoff 1
gunung 1
sight 1
alkali 1
contacts 1
connecting 1
incapacitation 1
geographiand 1
restrictive 1
step 1
santa 1
relating 1
intense 1
completing 1
papua 1
stricken 1
range 1
germany 1
consequently 1
appropriate 1
computer 1
mka 1
apparently 1
fast 1
occupy 1
spar 1
alcoholiimpairment 1
frost 1
link 1
deployed 1
planel 1
consumed 1
precipitated 1
aerial 1
corrective 1
defined 1
tagbao 1
chafed 1
nautical 1
arctiocean 1
preventing 1
application 1
antidetonation 1
drag 1
allowing 1
suppression 1
vehicles 1
walked 1
summit 1
attaining 1
failures 1
harcourt 1
pinion 1
advisory 1
existing 1
kato 1
psycho 1
adjustment 1
turkish 1
gravel 1
wished 1
imparement 1
miners 1
severely 1
transmission 1
ryan 1
yasirua 1
obiou 1
noted 1
keene 1
bogota 1
honore 1
digboi 1
boots 1
traffipattern 1
giving 1
assisted 1
waiting 1
indian 1
baucau 1
commercial 1
believed 1
let 1
separation 1
chkalovsky 1
extreme 1
parameters 1
survivor 1
involved 1
alaska 1
harrington 1
apple 1
airspace 1
private 1
anomalies 1
lima 1
causal 1
iced 1
remains 1
icer 1
vehicle 1
started 1
disabling 1
customer 1
account 1
stabilized 1
f 1
island 1
slid 1
calculation 1
pieces 1
kiunga 1
pulling 1
seatbelts 1
sir 1
monoxide 1
defective 1
traders 1
instead 1
profile 1
buildings 1
attend 1
perceive 1
bluff 1
monitoring 1
hawk 1
ambiguous 1
realized 1
boeing 1
lined 1
interpreted 1
la 1
winning 1
degrees 1
holiday 1
greater 1
impaired 1
realize 1
sufficiently 1
disregard 1
beneath 1
exacerbated 1
globe 1
frequency 1
separating 1
patch 1
special 1
suphan 1
valve 1
laramie 1
hidalgo 1
autopilot 1
red 1
harold 1
approached 1
frank 1
vieja 1
stehekin 1
likelihood 1
physioiogical 1
corrosion 1
yard 1
yegar 1
g 1
diminished 1
length 1
removing 1
tabubil 1
windsock 1
scene 1
sadly 1
attach 1
accretion 1
evansville 1
cabin 1
shallow 1
steel 1
detection 1
ipao 1
bed 1
tommy 1
patients 1
mojave 1
traffithe 1
false 1
lightly 1
unlikely 1
biega 1
purification 1
demonstration 1
dolorosa 1
linda 1
mit 1
unless 1
centre 1
device 1
consequences 1
eachother 1
clearlake 1
stronger 1
face 1
pipe 1
unfeathered 1
mechanical 1
businessman 1
son 1
affair 1
parker 1
chances 1
airlift 1
rotating 1
touching 1
soldiers 1
determined 1
staff 1
estuary 1
replenishing 1
communist 1
spun 1
handle 1
quartering 1
bear 1
hansie 1
cubs 1
areas 1
drillilng 1
trucks 1
canadair 1
maria 1
ohio 1
jenning 1
view 1
geographiarea 1
kaduqli 1
national 1
denpasair 1
discintegrated 1
khasi 1
airmail 1
closer 1
bost 1
state 1
bruno 1
piston 1
petrified 1
weighing 1
addis 1
configuration 1
distribution 1
assure 1
estimation 1
safely 1
contorl 1
respect 1
labor 1
benningham 1
slowly 1
feather 1
inbound 1
airplanes 1
ensuring 1
carburetor 1
homer 1
hubs 1
transitioned 1
layer 1
completed 1
lihu 1
weighed 1
claimed 1
partner 1
administration 1
paulo 1
party 1
difficult 1
conflicting 1
columbia 1
bali 1
reporting 1
issuance 1
manshahr 1
ringani 1
english 1
latest 1
accurate 1
overhauling 1
coordination 1
rapid 1
panther 1
residential 1
arrest 1
climbout 1
wet 1
stowed 1
adi 1
provisions 1
kellogg 1
supervise 1
midspar 1
clevis 1
controllers 1
kuala 1
heed 1
audible 1
springs 1
home 1
peter 1
fedex 1
guarulhos 1
glacial 1
inaccurate 1
execssive 1
described 1
pike 1
actual 1
extension 1
crankcase 1
carrier 1
fatally 1
rendered 1
kano 1
previously 1
kahuzi 1
terminated 1
uncontrollably 1
van 1
additional 1
rushed 1
captains 1
cliff 1
cricket 1
bus 1
hazardous 1
ricthie 1
repeated 1
lowered 1
cells 1
j 1
placed 1
display 1
bearing 1
penetrating 1
intentionally 1
immobilized 1
ingestion 1
boom 1
sick 1
balad 1
rural 1
exposure 1
velino 1
gwammaja 1
northerly 1
compromised 1
[{"key":"chicken","value":10},{"key":"egg","value":5},{"key":"rabbit","value":14},{"key":"kambing","value":20}]
(function (){
'use strict';
if(dc.wordcloudChart){
return false;
}
dc.wordcloudChart = function (parent, chartGroup){
var _chart = dc.baseMixin({});
var _cloud = null,
_g = null,
_padding = 5,
_font = "Impact",
_relativeSize = 10,
_minX = 0,
_minY = 0,
_fill = d3.scale.category20();
_chart._doRender = function (){
_chart.on('postRender',function(){
_chart.apply();
})
drawWordCloud();
return _chart._doRedraw();
}
function initializeSvg(){
_chart.select('svg').remove();
_g = d3.select(_chart.anchor())
.append("svg")
.attr("height",_chart.height())
.attr("width",_chart.width())
.append('g')
//.on('click', _chart.onClick)
.attr('cursor', 'pointer');
}
var titleFunction = function (d) {
return _chart.title()(d);
};
function drawWordCloud(){
initializeSvg();
var groups = _chart._computeOrderedGroups(_chart.data()).filter(function (d){
return _chart.valueAccessor()(d) !== 0;
});
var data = groups.map(function (d){
var value = _chart.valueAccessor()(d);
var key = _chart.keyAccessor()(d);
var title = _chart.title()(d);
var result = {
'text' : d.key,
'size' : checkSize(d),
'value' : value,
'key' : key,
'title': title
}
return result;
})
_cloud = d3.layout.cloud()
.size([_chart.width(), _chart.height()]);
_cloud
.words(data)
.padding(_chart.padding())
.rotate(function() {
return ~~(Math.random() * 2) * 90;
})
.font(_chart.font())
.fontSize(function(d) {
return d.size;
})
.on("end", draw);
_cloud.start();
}
_chart._doRedraw = function (){
_chart.on('postRedraw',function(){
_chart.apply();
});
drawWordCloud();
}
_chart.apply = function(){
d3.select(_chart.anchor())
.select('svg')
.attr("viewBox", _chart.minX()+' '+_chart.minY()+' '+_chart.width()+' '+_chart.height())
}
function checkSize(d){
var x = 0;
if(d.value <= 0) {
x = 0
} else {
x = Math.log(d.value)*_chart.relativeSize();
}
return x;
}
function draw(words) {
_g
.attr("width", _chart.width())
.attr("height", _chart.height())
.attr("transform", "translate(150,150)")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", _chart.font())
.style("fill", function(d, i) { return _fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")";
})
.text(function(d) { return d.text; }).append('title').text(function(d){return d.title});
}
_chart.minX = function (_){
if(!arguments.length){
return _minX;
}
_minX = _;
return _chart;
}
_chart.minY = function (_){
if(!arguments.length){
return _minY;
}
_minY = _;
return _chart;
}
_chart.padding = function (_){
if(!arguments.length){
return _padding;
}
_padding = _;
return _chart;
}
_chart.font = function (_){
if(!arguments.length){
return _font;
}
_font = _;
return _chart;
}
_chart.coordinateAccessor = function (_) {
if (!arguments.length) {
return _coordinate;
};
_coordinate = _;
return _chart;
};
_chart.radiusAccessor = function (_) {
if (!arguments.length) {
return _radiusAccessor;
}
_radiusAccessor = _;
return _chart;
};
_chart.relativeSize = function (_){
if(!arguments.length){
return _relativeSize;
}
_relativeSize = _;
return _chart;
}
return _chart.anchor(parent, chartGroup);
}
})();
var wordcloudChart = dc.wordcloudChart('#cloudChart');
(function(){
'use strict'
function drawWordcloudChart(ndx){
var wordDim = ndx.dimension(function(d){
console.log(d);
return d.key;
});
var wordGroup = wordDim.group().reduceSum(function(d){
return d.value;
});
wordcloudChart.options({
height: 500,
width: 1000,
minY: -100,
minX: -350,
relativeSize: 20,
dimension: wordDim,
group: wordGroup,
valueAccessor: function(d) {return d.value},
title: function (d) { return [d.key, 'Word Count: '+d.value].join('\n')},
});
wordcloudChart.render();
}
d3.json(data, function (key) {
console.log(key);
var ndx = crossfilter(key);
drawWordcloudChart(ndx);
})
})();
<!DOCTYPE html>
<html>
<head>
<title>dc-wordcloud example</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type="text/css" href="https://dc-js.github.io/dc.js/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://dc-js.github.io/dc.js/css/dc.css" />
</head>
<body>
<div id="cloudChart"></div>
</body>
<script type="text/javascript" src="https://dc-js.github.io/dc.js/js/d3.js"></script>
<script type="text/javascript" src="https://dc-js.github.io/dc.js/js/crossfilter.js"></script>
<script type="text/javascript" src="https://dc-js.github.io/dc.js/js/dc.js"></script>
<script type="text/javascript" src="d3.layout.cloud.js"></script>
<script type="text/javascript" src="dc-wordcloud.js"></script>
<script type="text/javascript">
var data = 'data.json';
</script>
<script type="text/javascript" src="example.js"></script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment