Skip to content

Instantly share code, notes, and snippets.

@carlosmondra
Created May 1, 2018 18:45
Show Gist options
  • Save carlosmondra/e1a5c584794f836ebe89d2bb4ac17090 to your computer and use it in GitHub Desktop.
Save carlosmondra/e1a5c584794f836ebe89d2bb4ac17090 to your computer and use it in GitHub Desktop.
// Get the svg element along with its attributes where all the elements will be drawn
var barSvg = d3.select("#bar-svg").append("svg")
.attr("width", 960)
.attr("height", 500)
// Establish inner margins to allow for some padding
var margin = {top: 20, right: 20, bottom: 80, left: 150},
width = +barSvg.attr("width") - margin.left - margin.right,
height = +barSvg.attr("height") - margin.top - margin.bottom;
var tooltipBar
var g
// Function that deletes the bar chart before creating a new one
function removeBarChart() {
if (tooltipBar !== undefined) {
tooltipBar.remove()
}
if (g !== undefined) {
g.remove()
}
}
// Reset the bar chart (delete everything)
var resetButton = d3.select("#reset")
resetButton.on('click', () => {
removeBarChart()
selectedForBarChart = [];
});
// Reset the word cloud (delete everything)
var resetCloud = d3.select("#resetCloud")
resetCloud.on('click', () => {
svg.selectAll("*").remove()
selectedForWordCloud = []
});
// Redraw the bar chart based on the radio buttons on the html
d3.selectAll("input[name='sort']").on("change", function(){
removeBarChart()
createBarChart(selectedForBarChart)
});
// Creates a Bar Chart from scratch based on the bar chart data passed as parameter
function createBarChart(data) {
tooltipBar = d3.select("body").append("div").attr("class", "toolTip");
// Let the sliders filter data
let greenSlider = d3.select('#green-slider');
let redSlider = d3.select('#red-slider');
let greenVal = greenSlider.attr('value')
let redVal = redSlider.attr('value');
data.sort(sortByFrequency)
data.reverse()
let len = data.length
let lower = Math.round(redVal / 100 * len)
let upper = Math.round(greenVal / 100 * len)
data = data.slice(lower, upper)
// Let the radio buttons define the sorting method
let sortMethod = d3.select('input[name="sort"]:checked').node().value
if (sortMethod == "alphatically") {
data.sort(sortAlphabetically)
} else if (sortMethod == "frequency") {
data.sort(sortByFrequency)
}
// Assign scales and ranges in the bar chart
var x = d3.scaleBand().rangeRound([0, width]).padding(0.1),
y = d3.scaleLinear().rangeRound([height, 0]);
g = barSvg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Assign doamains for x and y
// let value = yInput.node().value;
x.domain(data.map(d => d.key));
y.domain([0, d3.max(data, d => d.value)]);
// Draw the x-axis
g.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
// Draw the y-axis
g.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y).ticks(5).tickFormat(d => d)
.tickSizeInner([-width]))
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.attr("fill", "#5D6971")
.text("Frequency");
// Draw the bars of the bar chart
g.selectAll(".bar")
.data(data)
.enter().append("rect")
// Assign functionality to make points in the force graph bigger
.on("click", d => {
console.log("not implemented")
selectedForWordCloud.push(d)
svg.selectAll("*").remove()
drawWordCloud(selectedForWordCloud)
})
.attr("x", d => x(d.key))
.attr("y", d => y(d.value))
.attr("width", x.bandwidth())
.attr("height", d => height - y(d.value))
// Assign a different color to the selected university
.attr("fill", d => "#6F257F")
.on("mousemove", function(d){
tooltipBar
.style("left", d3.event.pageX - 50 + "px")
.style("top", d3.event.pageY - 70 + "px")
.style("display", "inline-block")
.html((d.key) + "<br>Frequency: " + (d.value));
})
.on("mouseout", function(d){ tooltipBar.style("display", "none");});
}
// Generate the bar chart data based on the closest points in the force graph
function createBarChartData(uni, links) {
let relatedUnis = []
relatedUnis.push({"id":uni, "SAT_AVG":dict[uni].SAT_AVG, "SATMTMID":dict[uni].SATMTMID, "SATWRMID":dict[uni].SATWRMID, "SATVRMID":dict[uni].SATVRMID, "ADM_RATE":dict[uni].ADM_RATE, "UGDS":dict[uni].UGDS, "main":true})
for (let i in links) {
if (links[i].source.id == uni) {
let target = links[i].target.id
relatedUnis.push({"id":target, "SAT_AVG":dict[target].SAT_AVG, "SATMTMID":dict[target].SATMTMID, "SATWRMID":dict[target].SATWRMID, "SATVRMID":dict[target].SATVRMID, "ADM_RATE":dict[target].ADM_RATE, "UGDS":dict[target].UGDS, "main":false})
}
if (links[i].target.id == uni) {
let source = links[i].source.id
relatedUnis.push({"id":source, "SAT_AVG":dict[source].SAT_AVG, "SATMTMID":dict[source].SATMTMID, "SATWRMID":dict[source].SATWRMID, "SATVRMID":dict[source].SATVRMID, "ADM_RATE":dict[source].ADM_RATE, "UGDS":dict[source].UGDS,"main":false})
}
}
return relatedUnis
}
// Sort the data alphatically based on the key of an object
function sortAlphabetically(a,b) {
if (a.key < b.key)
return -1;
if (a.key > b.key)
return 1;
return 0;
}
// Sort the data by frequency based on the key of an object
function sortByFrequency(a,b) {
if (a.value > b.value)
return -1;
if (a.value < b.value)
return 1;
return 0;
}
(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/
// Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf
var dispatch = require("d3-dispatch").dispatch;
var cloudRadians = Math.PI / 180,
cw = 1 << 11 >> 5,
ch = 1 << 11;
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 = Infinity,
event = dispatch("word", "end"),
timer = null,
random = Math.random,
cloud = {},
canvas = cloudCanvas;
cloud.canvas = function(_) {
return arguments.length ? (canvas = functor(_), cloud) : canvas;
};
cloud.start = function() {
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) {
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 = Date.now();
while (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);
if (d.hasText && place(board, d, bounds)) {
tags.push(d);
event.call("word", cloud, 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.call("end", cloud, tags, bounds);
}
}
}
cloud.stop = function() {
if (timer) {
clearInterval(timer);
timer = null;
}
return cloud;
};
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");
context.fillStyle = context.strokeStyle = "red";
context.textAlign = "center";
return {context: context, ratio: ratio};
}
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 = random() < .5 ? 1 : -1,
t = -dt,
dxdy,
dx,
dy;
while (dxdy = s(t += dt)) {
dx = ~~dxdy[0];
dy = ~~dxdy[1];
if (Math.min(Math.abs(dx), Math.abs(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.timeInterval = function(_) {
return arguments.length ? (timeInterval = _ == null ? Infinity : _, 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;
};
return cloud;
};
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(contextAndRatio, d, data, di) {
if (d.sprite) return;
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;
--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;
}
function cloudCanvas() {
return document.createElement("canvas");
}
function functor(d) {
return typeof d === "function" ? d : function() { return d; };
}
var spirals = {
archimedean: archimedeanSpiral,
rectangular: rectangularSpiral
};
},{"d3-dispatch":2}],2:[function(require,module,exports){
// https://d3js.org/d3-dispatch/ Version 1.0.2. Copyright 2016 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
var noop = {value: function() {}};
function dispatch() {
for (var i = 0, n = arguments.length, _ = {}, t; 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);
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 });
})));
},{}]},{},[1])(1)
});
var greenSvgSlider = d3.select("#green-slider-svg"),
greenMargin = {right: 50, left: 50},
greenWidth = +greenSvgSlider.attr("width") - greenMargin.left - greenMargin.right,
greenHeight = +greenSvgSlider.attr("height");
var greenX = d3.scaleLinear()
.domain([0, 100])
.range([0, greenWidth])
.clamp(true);
var greenSlider = greenSvgSlider.append("g")
.attr("class", "slider")
.attr("transform", "translate(" + greenMargin.left + "," + greenHeight / 2 + ")");
greenSlider.append("line")
.attr("class", "track")
.attr("x1", greenX.range()[0])
.attr("x2", greenX.range()[1])
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-inset")
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-overlay")
.call(d3.drag()
.on("start.interrupt", function() { greenSlider.interrupt(); })
.on("start drag", function() {
let value = Math.round(greenX.invert(d3.event.x));
greenHue(value);
let greenSlider = d3.select('#green-slider');
let redSlider = d3.select('#red-slider');
greenSlider.text('Show lower ' + value + '%');
greenSlider.attr('value', value);
let greenVal = greenSlider.attr('value')
let redVal = redSlider.attr('value');
removeBarChart()
createBarChart(selectedForBarChart)
}));
var greenHandle = greenSlider.insert("circle", ".track-overlay")
.attr("class", "green-handle-slider")
.attr("cx", greenWidth)
.attr("r", 9);
function greenHue(h) {
greenHandle.attr("cx", greenX(h));
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="cloud.js"></script>
<title>Word Cloud</title>
<link rel='stylesheet' href='style.css'>
</head>
<body>
<center>
<h1>Words</h1>
<h2>Carlos Daniel Mondragón Chapa</h2>
</center>
<h4>Dataset Description</h4>
<p class="info-text">
The dataset can be any text. In this particular case a book was selected: "The Little Prince". The visualization could be used to determine what the book is about based on the most common words found in it. This book in particular contains about 16,000 words.
</p>
<center>
<div>
<table class="instructions-table">
<tr>
<td style="text-align: left;">
<span><b>Instructions:</b>
<ul>
<li>The Word Cloud is generates the most common words that begin with a particular letter that can be selected from the dropdown at the bottom of the first graph.</li>
<li>Individual words can be clicked on for single or multiple selection. Eveytime a word is selected, it is added to the bar chart at the bottom. Note that the words in the bar chart do not need to start with the same letter.</li>
<li>The button "Add all" can be used to add all the words in the word cloud to the bar chart.</li>
<li>The bar chart can be sorted alphatically or by frequency to find words more easily in bar chart.</li>
<li>The bars in the bar chart can also be clicked to create a custom word cloud. Note, however, that as soon as the dropdow is changed the words in the current word cloud will be removed.</li>
<li>The sliders help filter the words in the bar chart by frequency. The red slider hides the least frequent words, while the green slider hides the most frequent words.</li>
<li>You can reset any of the charts by clicking on the reset buttons. Note that resetting the charts do not reset the position of the sliders.</li>
</ul>
</span>
</td>
</tr>
</table>
</div>
</center>
<center>
<div id="chart"></div>
</center>
<center>
<table class="settings-table">
<tr>
<td>
<span>Words starting with: </span>
<select id="xSelect"></select>
</td>
<td>
<span>Change Bar Chart settings: </span><br>
<input type="radio" name="sort" value="alphatically" checked> Sort Alphabetically<br>
<input type="radio" name="sort" value="frequency"> Sort by Frequency<br><br>
<span id="green-slider" value="100">Show lower 100%</span><br>
<svg id="green-slider-svg" width="300" height="30"></svg><br>
<span id="red-slider" value="0">Hide lower 0%</span>
<svg id="red-slider-svg" width="300" height="30"></svg>
</td>
<td>
<span>Add all words Bar Chart: </span>
<input id="addAll" class="button button5" type="button" value="Add all"/>
</td>
<td>
<span>Reset Word Cloud: </span><br>
<input id="resetCloud" class="button button5" type="button" value="Reset Cloud"/><br><br>
<span>Reset Bar Chart: </span><br>
<input id="reset" class="button button5" type="button" value="Reset Bar Chart"/>
</td>
</tr>
</table>
</center>
<center>
<div id="bar-svg"></div>
<!-- <svg id="bar-svg" width="960" height="500"></svg> -->
</center>
<div id="tooltip"></div>
<script src="script.js"></script>
<script src="barScript.js"></script>
<script src="greenSlider.js"></script>
<script src="redSlider.js"></script>
</body>
</html>
key value
once 22
when 56
was 193
six 14
years 12
old 20
saw 15
magnificent 8
picture 4
book 5
called 2
true 14
stories 1
from 76
nature 1
about 29
the 1011
primeval 2
forest 1
boa 15
constrictor 8
act 2
swallowing 1
animal 2
here 25
copy 1
drawing 24
said 195
constrictors 5
swallow 2
their 19
prey 2
whole 5
without 14
chewing 1
after 12
that 323
they 99
are 136
not 160
able 13
move 5
and 361
sleep 10
through 9
months 1
need 13
for 135
digestion 1
pondered 1
deeply 3
then 75
over 31
adventures 1
jungle 1
some 31
work 7
with 93
colored 1
pencil 4
succeeded 3
making 6
first 23
number 9
one 140
looked 17
something 11
like 58
this 94
hat 9
showed 3
masterpiece 1
grown 23
ups 20
asked 27
them 63
whether 4
frightened 3
but 150
answered 20
frighten 1
why 19
should 22
any 43
digesting 1
elephant 4
since 9
were 37
understand 22
made 37
another 13
drew 4
inside 8
could 27
see 31
clearly 2
always 17
have 141
things 8
explained 2
two 21
response 1
time 46
advise 3
lay 3
aside 1
drawings 2
outside 5
devote 1
myself 20
instead 4
geography 3
history 2
arithmetic 2
grammar 2
age 2
gave 6
what 87
might 10
been 32
career 2
painter 2
had 79
disheartened 1
failure 1
never 41
anything 21
themselves 4
tiresome 1
children 7
forever 3
explaining 1
chose 2
profession 3
learned 7
pilot 1
airplanes 1
flown 1
little 272
all 101
parts 1
world 13
has 39
very 81
useful 3
glance 3
can 35
distinguish 1
china 2
arizona 1
gets 1
lost 6
night 16
such 10
knowledge 2
valuable 1
course 2
life 21
great 19
many 6
encounters 1
people 14
who 51
concerned 5
matters 12
consequence 16
lived 5
deal 4
among 8
seen 10
intimately 1
close 4
hand 5
hasn 1
much 33
improved 1
opinion 1
whenever 3
met 5
seemed 12
clear 3
sighted 1
tried 2
experiment 1
showing 1
him 77
which 38
kept 1
would 62
try 6
find 10
out 44
person 4
understanding 3
whoever 1
she 51
say 23
talk 5
forests 1
stars 42
bring 5
down 26
his 119
level 1
bridge 1
golf 1
politics 1
neckties 1
greatly 1
pleased 1
sensible 1
man 35
alone 10
anyone 5
really 6
until 7
accident 2
plane 4
desert 16
sahara 3
ago 6
broken 1
engine 6
neither 2
mechanic 1
nor 2
passengers 1
set 11
attempt 1
difficult 7
repairs 1
question 14
death 7
scarcely 4
enough 8
drinking 6
water 19
last 15
week 5
went 16
sand 10
thousand 13
miles 7
human 3
habitation 3
more 41
isolated 1
than 15
shipwrecked 1
sailor 1
raft 1
middle 2
ocean 2
thus 3
you 312
imagine 3
amazement 1
sunrise 3
awakened 1
odd 3
voice 4
please 8
draw 11
sheep 44
jumped 1
feet 3
completely 3
thunderstruck 3
blinked 1
eyes 8
hard 4
carefully 5
around 9
most 10
extraordinary 4
small 17
stood 2
there 56
examining 1
seriousness 1
may 9
best 5
portrait 1
later 4
make 31
certainly 9
less 1
charming 4
its 11
model 1
prince 196
however 4
fault 6
discouraged 2
except 4
boas 2
now 31
stared 2
sudden 2
apparition 2
fairly 1
starting 1
head 8
astonishment 1
remember 6
crashed 1
inhabited 8
region 2
yet 8
straying 1
uncertainly 1
sands 2
fainting 1
fatigue 1
hunger 1
thirst 5
fear 2
nothing 32
suggestion 1
child 3
speak 4
doing 4
answer 10
repeated 5
slowly 6
speaking 3
matter 10
mystery 3
too 43
overpowering 1
dare 3
disobey 1
absurd 4
seem 3
danger 7
took 14
pocket 3
sheet 1
paper 3
fountain 2
pen 1
remembered 4
how 29
studies 1
concentrated 1
told 8
chap 1
crossly 1
did 35
know 37
doesn 4
drawn 3
pictures 2
often 3
astounded 1
hear 9
fellow 1
greet 2
want 18
dangerous 1
creature 3
cumbersome 1
where 32
live 14
everything 11
sick 1
already 10
sickly 1
ram 2
friend 15
smiled 2
gently 3
indulgently 1
yourself 4
horns 2
rejected 1
just 33
others 8
will 81
long 16
patience 1
exhausted 1
because 30
hurry 4
start 2
taking 3
apart 1
tossed 3
off 6
box 5
threw 1
explanation 3
only 34
surprised 4
light 5
break 1
face 3
young 2
judge 7
exactly 7
way 11
wanted 4
think 14
grass 5
surely 2
given 6
bent 1
look 30
gone 6
acquaintance 1
iii 1
learn 3
came 20
questions 8
ones 2
words 6
dropped 4
chance 3
revealed 2
airplane 4
instance 3
shall 35
complicated 2
object 3
flies 2
proud 5
fly 3
cried 3
sky 9
yes 26
modestly 1
funny 4
broke 2
into 18
lovely 1
peal 2
laughter 5
irritated 1
misfortunes 1
taken 2
seriously 2
added 17
come 37
your 42
planet 72
moment 10
caught 2
gleam 1
impenetrable 1
presence 3
demanded 10
abruptly 3
reply 5
far 10
away 23
sank 1
reverie 1
lasted 2
buried 2
himself 31
contemplation 1
treasure 3
curiosity 2
aroused 1
half 2
confidence 2
other 22
planets 4
effort 4
therefore 2
subject 4
take 11
reflective 1
silence 9
thing 14
good 49
use 12
house 10
give 6
string 1
tie 4
during 2
day 32
post 1
shocked 1
offer 1
queer 4
idea 7
don 11
wander 1
somewhere 6
get 10
anywhere 3
straight 3
ahead 2
earnestly 1
perhaps 9
hint 1
sadness 2
nobody 10
second 6
fact 2
importance 4
larger 2
surprise 1
knew 7
well 19
addition 2
earth 21
jupiter 1
mars 1
venus 1
names 1
also 17
hundreds 2
seeing 1
telescope 2
astronomer 6
discovers 1
these 14
does 23
name 1
call 3
example 6
asteroid 7
serious 4
reason 3
believe 9
known 7
turkish 4
star 13
gazer 1
discovery 3
presented 1
international 1
astronomical 1
congress 1
demonstration 2
costume 3
fortunately 1
reputation 2
dictator 1
law 1
subjects 2
under 8
pain 1
change 4
european 2
again 37
dressed 3
impressive 2
style 1
elegance 1
everybody 2
accepted 2
report 1
details 2
note 2
account 2
ways 1
tell 11
new 5
ask 7
essential 3
sound 5
games 1
love 12
collect 1
butterflies 4
demand 1
brothers 1
weigh 1
money 1
father 1
figures 5
beautiful 13
rosy 1
brick 1
geraniums 1
windows 1
doves 1
roof 1
cost 2
exclaim 1
pretty 2
proof 2
existed 1
laughed 11
looking 12
anybody 2
wants 1
exists 1
shrug 1
shoulders 2
treat 2
convinced 1
leave 8
peace 2
must 20
hold 1
against 6
show 3
forbearance 1
toward 7
indifference 1
liked 2
begin 3
story 4
fashion 1
fairy 1
tales 1
upon 9
bigger 1
those 16
greater 1
air 6
truth 4
read 1
carelessly 1
suffered 1
grief 2
setting 2
memories 2
passed 2
describe 2
sure 11
forget 7
sad 9
every 12
become 5
longer 4
interested 2
purpose 1
bought 1
paints 1
pencils 1
portraits 1
possible 7
success 1
goes 3
along 6
right 9
resemblance 1
errors 1
height 1
place 14
tall 1
short 2
feel 3
doubts 1
color 6
fumble 1
bad 9
hope 3
generally 1
fair 2
middling 1
certain 3
important 12
mistakes 2
thought 11
alas 1
walls 1
boxes 1
grow 5
each 6
our 4
departure 4
journey 7
information 1
fall 1
thoughts 2
heard 3
third 3
catastrophe 2
baobabs 17
thank 1
seized 2
grave 1
doubt 3
isn 1
eat 8
bushes 5
glad 4
follows 1
pointed 2
contrary 2
trees 1
big 5
castles 1
even 16
herd 3
elephants 2
single 9
baobab 4
laugh 6
put 18
top 2
elephans 1
wise 1
comment 1
before 11
being 5
strictly 1
correct 1
self 1
evident 1
obliged 2
mental 1
solve 2
problem 2
assistance 1
indeed 4
plants 4
seeds 5
invisible 5
deep 2
heart 12
darkness 2
desire 1
awaken 1
seed 3
stretch 1
itself 2
timidly 1
push 1
sprig 2
inoffensively 1
upward 1
sun 5
sprout 2
radish 1
rose 15
bush 1
let 12
wherever 1
wish 4
plant 2
destroy 2
soon 4
instant 4
recognizes 1
chare 1
terrible 3
home 5
soil 1
infested 1
rid 1
attend 2
late 1
spreads 1
entire 2
bores 1
roots 2
split 1
pieces 1
discipline 1
finished 1
own 14
toilet 2
morning 31
greatest 2
care 3
pull 1
regularly 1
distinguished 1
rosebushes 1
resemble 1
closely 2
earliest 1
youth 1
tedious 1
easy 1
ought 6
travel 3
sometimes 7
harm 2
putting 2
piece 1
means 6
lazy 3
neglected 3
three 17
described 1
tone 1
moralist 1
understood 2
considerable 1
risks 1
run 3
breaking 1
reserve 1
plainly 1
watch 3
friends 7
skirting 1
ever 11
knowing 1
worked 1
lesson 1
pass 1
worth 3
trouble 7
simple 4
successful 2
carried 1
beyond 2
inspiring 1
force 1
urgent 1
necessity 1
bit 3
secrets 1
found 9
entertainment 1
quiet 2
pleasure 3
sunset 11
detail 1
fourth 2
fond 1
sunsets 5
wait 6
thinking 3
knows 9
noon 2
united 1
states 1
france 3
minute 5
unfortunately 2
tiny 2
chair 3
few 1
steps 3
end 5
twilight 1
falling 1
forty 3
four 11
times 6
loves 2
vii 1
fifth 2
thanks 1
secret 6
lead 2
born 3
silent 4
meditation 1
eats 3
flowers 14
finds 1
reach 3
thorns 13
busy 4
trying 3
unscrew 1
bolt 4
got 4
stuck 1
worried 2
becoming 1
breakdown 1
extremely 2
left 4
worst 1
upset 1
spite 2
complete 5
flashed 2
back 22
kind 3
resentfulness 1
weak 3
creatures 2
reassure 2
weapons 1
saying 4
still 13
won 1
turn 5
going 5
knock 1
hammer 3
disturbed 4
actually 1
fingers 1
black 1
grease 1
bending 1
ugly 1
ashamed 4
relentlessly 1
mix 1
together 3
confuse 1
angry 1
golden 6
curls 1
breeze 1
red 4
faced 2
gentleman 5
smelled 1
flower 60
loved 3
done 3
add 3
says 2
makes 7
swell 1
pride 1
mushroom 2
white 3
rage 1
growing 2
millions 8
eating 1
same 13
warfare 1
between 1
fat 1
sums 1
unique 6
grows 2
nowhere 1
bite 4
noticing 1
turned 3
continued 9
blossom 1
happy 9
darkened 1
choked 1
sobbing 1
fallen 1
tools 1
drop 2
hands 4
comforted 3
arms 6
rocked 1
muzzle 5
railing 1
felt 10
awkward 1
blundering 1
overtake 1
land 1
tears 3
viii 1
better 4
ring 1
petals 4
room 4
appear 2
faded 1
peacefully 1
blown 1
watched 2
sprouts 1
shrub 1
stopped 2
began 5
ready 4
produce 1
present 5
appearance 1
huge 1
bud 1
sort 3
miraculous 1
emerge 1
satisfied 4
preparations 2
her 27
beauty 3
shelter 2
green 1
chamber 1
colors 1
herself 8
adjusted 1
rumpled 1
field 1
poppies 1
full 2
radiance 3
wished 2
coquettish 1
mysterious 2
adornment 1
days 6
suddenly 3
working 2
painstaking 1
precision 1
yawned 3
awake 1
beg 2
excuse 4
disarranged 1
restrain 2
admiration 1
responded 2
sweetly 2
guess 1
easily 4
modest 2
moving 1
exciting 1
breakfast 2
kindness 3
needs 2
princ 1
eis 1
watering 1
abashed 2
sprinkling 1
fresh 6
tended 1
quickly 2
torment 1
vanity 1
tigers 4
claws 3
objected 1
anyway 1
weeds 1
weed 1
replied 19
afraid 7
horror 2
drafts 3
suppose 1
wouldn 1
screen 3
luck 1
remarked 1
complex 1
saving 1
glass 7
globe 7
cold 3
interrupted 3
point 1
form 1
worlds 1
embarassed 2
having 7
verge 1
untruth 1
coughed 2
order 13
wrong 4
spoke 4
forced 1
cough 2
suffer 3
remorse 1
inseparable 1
unhappy 2
listened 3
confided 1
listen 3
simply 2
breathe 1
fragrance 2
mine 1
perfumed 1
grace 1
tale 1
filled 1
tenderness 2
pity 2
beast 1
confidences 1
judged 1
deeds 1
cast 3
guessed 1
affection 1
behind 2
poor 2
strategems 1
inconsistent 1
winter 1
escape 1
advantage 1
migration 1
flock 1
wild 1
birds 1
perfect 2
cleaned 3
active 3
volcanoes 12
possessed 1
convenient 1
heating 1
volcano 4
extinct 8
burn 1
steadily 2
eruptions 2
volcanic 1
fires 1
chimney 1
obviously 1
clean 3
pulled 1
sense 4
dejection 2
shoots 1
believed 1
return 3
familiar 1
tasks 1
precious 1
watered 2
prepared 1
realized 3
goodbye 7
silly 1
forgiveness 1
absence 1
reproaches 1
bewildered 1
held 1
arrested 1
mid 1
sweetness 3
while 2
foolish 1
price 2
cleaning 1
wind 6
cool 1
animals 2
endure 1
caterpillars 3
acquainted 1
seems 2
large 4
linger 1
decided 1
crying 2
neighborhood 1
asteroids 1
visiting 1
king 34
clad 1
royal 1
purple 1
ermine 3
seated 1
throne 1
both 3
majestic 1
exclaimed 3
coming 5
recognize 2
simplified 1
kings 4
men 22
approach 1
consumingly 1
somebody 1
everywhere 1
sit 4
crammed 1
obstructed 1
robe 1
remained 2
standing 2
upright 2
tired 5
etiquette 1
yawn 4
monarch 3
forbid 1
help 4
stop 2
thoroughly 1
embarrassed 1
yawning 2
yawns 1
objects 4
frightens 1
cannot 7
murmured 1
hum 8
sputtered 1
vexed 1
fundamentally 1
insisted 2
authority 4
respected 1
tolerated 1
disobedience 1
absolute 2
orders 13
reasonable 4
ordered 5
general 7
sea 3
bird 3
obey 3
timid 1
inquiry 3
majestically 1
gathered 1
fold 1
mantle 1
wondering 2
rule 3
sire 2
asking 1
hastened 1
assure 1
simplicity 1
gesture 2
universal 1
instantly 1
permit 1
insubordination 1
power 1
marvel 1
master 1
seventy 1
hundred 19
forsaken 1
plucked 1
courage 2
favor 1
butterfly 1
write 3
tragic 1
drama 1
carry 4
received 2
firmly 1
require 2
duty 1
perform 1
rests 1
throw 1
rise 1
revolution 1
obedience 1
reminded 1
forgot 3
command 1
according 1
science 1
government 1
conditions 2
favorable 2
inquired 2
else 5
consulted 1
bulky 1
almanac 1
evening 10
twenty 11
minutes 6
eight 2
obeyed 2
regretting 1
beginning 3
bored 2
minister 2
minster 1
justice 2
tour 1
kingdom 1
carriage 1
tires 1
walk 8
turning 1
side 2
oneself 1
succeed 1
judging 1
rightly 2
wisdom 1
rat 2
condemn 2
depend 1
pardon 1
occasion 1
treated 1
thriftily 1
completed 1
grieve 1
majesty 1
wishes 2
promptly 1
hesitated 2
sigh 2
ambassador 1
hastily 1
strange 3
conceited 13
receive 1
visit 4
admirer 1
afar 1
admirers 1
wearing 1
salutes 1
raise 4
salute 3
acclaim 1
passes 1
talking 4
clap 2
directed 1
clapped 1
raised 5
entertaining 2
five 17
exercise 2
grew 1
game 1
monotony 1
praise 1
admire 5
mean 11
regard 1
handsomest 1
richest 1
intelligent 1
shrugging 1
slightly 2
interest 1
xii 1
next 4
tippler 9
plunged 1
whom 3
settled 1
collection 2
empty 2
bottles 2
lugubrious 1
sorry 2
confessed 1
hanging 1
tipler 1
brought 5
speech 1
shut 1
impregnable 1
puzzled 1
xiii 1
belonged 1
businessman 12
occupied 1
arrival 1
cigarette 1
seven 6
twelve 2
fifteen 2
haven 3
thirty 6
phew 1
million 8
amuse 1
balderdash 1
fifty 4
giddy 1
goose 1
fell 3
goodness 1
frightful 1
noise 3
resounded 1
eleven 1
attack 1
rheumatism 1
loafing 2
sees 3
glittering 1
bees 1
idle 2
dreaming 3
accurate 1
reign 1
different 6
rich 3
buy 3
discovered 1
reasons 1
nevertheless 4
belong 2
retorted 1
peevishly 1
necessary 2
diamond 1
belongs 3
yours 6
discover 2
island 1
patent 1
owning 1
administer 1
count 3
recount 1
naturally 1
owned 2
silk 1
scarf 1
neck 2
pluck 2
heaven 2
bank 1
whatever 2
drawer 1
lock 1
key 1
rather 2
poetic 1
ideas 1
conversation 2
opened 3
mouth 1
altogether 5
xiv 1
smallest 1
street 4
lamp 15
lamplighter 13
heavens 2
least 1
meaning 1
lights 3
puts 1
sends 1
occupation 1
truly 1
arrived 2
respectfully 1
saluted 1
lighted 7
mopped 1
forehead 2
handkerchief 1
decorated 1
squares 1
follow 2
rest 5
relaxation 1
changed 4
tragedy 1
year 5
rapidly 1
repose 1
lasts 1
month 3
faithful 2
seek 1
merely 3
pulling 1
strides 1
sunshine 2
unlucky 2
farther 3
scorned 1
ridiculous 1
besides 2
breathed 2
regret 2
confess 1
blest 1
sixth 1
ten 1
wrote 1
voluminous 1
books 4
geographer 23
explorer 11
sat 7
table 1
panted 1
traveled 1
scholar 1
location 1
seas 2
rivers 3
towns 3
mountains 5
deserts 3
interesting 4
real 1
stately 1
oceans 2
couldn 3
disappointed 1
either 2
desk 1
receives 1
explorers 2
study 1
asks 1
notes 1
recall 1
travels 1
recollections 1
moral 2
character 2
lies 1
disaster 1
drank 3
intoxicated 1
double 1
shown 1
requires 2
furnish 1
proofs 2
mountain 5
stones 2
stirred 2
excitement 1
register 1
sharpened 2
recitals 1
waits 1
furnished 1
ink 1
expectantly 1
record 2
ephemeral 5
geographies 1
fashioned 1
rarely 2
changes 2
position 1
empties 1
waters 1
eternal 1
alive 2
comes 1
speedy 2
disappearance 2
defend 1
xvi 1
seventh 1
ordinary 3
forgetting 1
negro 1
geographers 1
businessmen 1
tipplers 1
size 1
invention 1
electricity 1
maintain 1
continents 1
veritable 1
army 2
lamplighters 5
lamps 2
slight 1
distance 3
splendid 1
spectacle 1
movements 1
regulated 1
ballet 1
opera 1
zealand 1
australia 1
alight 2
siberia 1
enter 1
dance 2
waved 1
wings 1
russia 1
indies 1
africa 2
europe 1
south 3
america 3
north 2
mistake 1
entry 1
stage 1
charge 1
pole 2
colleague 1
responsible 6
free 1
toil 1
twice 1
xvii 1
play 3
wit 1
wanders 1
honest 1
realize 1
risk 2
giving 1
false 1
occupy 1
billion 1
inhabitants 1
surface 1
stand 2
somewhat 1
crowded 1
public 2
assembly 1
square 1
wide 1
humanity 1
piled 1
pacific 1
islet 1
fill 1
space 1
fancy 1
calculations 1
adore 1
waste 2
extra 1
task 1
unnecessary 1
coil 1
gold 2
moonlight 3
across 3
courteously 2
snake 15
stone 2
wonder 1
above 2
lonely 2
gazed 3
thicker 1
finger 2
powerful 2
ship 1
twined 1
ankle 2
bracelet 1
whomever 1
touch 1
send 4
whence 1
innocent 1
granite 1
homesick 1
riddles 1
xviii 1
crossed 1
politely 2
caravan 1
passing 1
echoed 1
existence 1
several 2
blows 1
xix 1
climbed 1
high 2
knees 2
used 2
footstool 1
save 3
peaks 1
rock 1
needles 1
echo 4
dry 1
harsh 1
forbidding 1
imagination 1
repeat 1
happened 1
walking 4
rocks 1
snow 2
road 1
roads 1
abodes 1
garden 4
bloom 2
roses 10
overcome 1
universe 2
alike 3
annoyed 1
dreadfully 1
pretend 2
dying 4
avoid 1
nursing 1
humble 1
allow 1
die 4
reflections 1
common 2
xxi 1
fox 35
appeared 2
although 1
apple 1
tree 3
lying 1
medow 1
proposed 1
tamed 8
tame 9
guns 1
hunt 3
disturbing 1
chickens 5
interests 1
establish 2
ties 2
boy 3
boys 1
part 1
foxes 2
sorts 1
perplexed 1
curious 1
hunters 3
sighed 1
monotonous 1
shine 1
step 4
hurrying 1
underneath 1
ground 1
music 3
burrow 1
grain 2
fields 3
yonder 1
bread 1
wheat 4
hair 3
wonderful 2
understands 1
tames 1
shops 1
shop 1
friendship 1
patient 1
corner 1
eye 3
source 1
closer 1
hour 5
clock 3
afternoon 1
happier 2
advances 1
worrying 2
jumping 1
observe 1
proper 1
rites 1
rite 2
hunter 1
actions 1
hours 2
thursday 2
village 3
girls 1
vineyards 1
danced 1
vacation 1
near 2
cry 4
passerby 1
sheltered 1
killed 1
saved 1
grumbled 1
boasted 1
meet 1
wasted 2
forgotten 2
xxii 1
railway 1
switchman 8
travelers 3
bundles 1
trains 2
brilliantly 3
express 4
train 1
shook 1
cabin 1
rushed 1
roar 1
thunder 2
locomotive 1
engineer 1
thundered 1
opposite 1
direction 1
exchange 1
roaring 1
pursuing 2
asleep 3
flattening 1
noses 1
windowpanes 1
rag 1
doll 1
becomes 1
takes 1
lucky 1
xxiii 1
merchant 4
sold 1
pills 2
invented 1
quench 1
pill 1
drink 6
selling 1
tremendous 1
amount 1
computations 1
experts 1
spend 1
leisure 2
spring 3
xxiv 1
eighth 1
supply 1
repairing 1
dear 3
reasoning 1
guessing 1
hungry 1
thirsty 4
weariness 1
random 1
immensity 1
started 1
trudged 1
feverish 1
dream 2
reeling 1
memory 2
impossible 1
cross 1
examine 1
beside 3
ridges 1
stretched 1
sits 1
dune 1
hears 1
throbs 1
gleams 1
hides 1
astonished 2
radiation 1
legend 1
enchantment 1
hiding 1
depths 1
gives 1
agree 1
moved 1
carrying 1
fragile 3
pale 1
closed 2
locks 1
trembled 1
shell 2
lips 2
suspicion 1
smile 2
moves 1
sleeping 1
loyalty 1
image 1
shines 1
flame 2
protecting 1
extinguished 1
puff 1
walked 1
daybreak 2
xxv 1
rush 1
excited 1
round 2
wells 3
mere 1
holes 1
dug 1
pulley 7
bucket 3
rope 4
touched 1
moaned 1
weathervane 1
wakened 1
singing 1
tire 1
heavy 3
hoisted 1
edge 1
achievement 1
song 2
ears 2
sunlight 1
shimmer 1
trembling 1
sweet 2
special 1
festival 1
nourishment 1
christmas 1
midnight 1
mass 1
smiling 1
faces 1
gifts 1
blind 1
drunk 1
honey 2
keep 2
promise 2
softly 1
rough 1
cabbages 1
sketch 1
torn 2
plans 1
descent 1
tomorrow 2
anniversary 2
flushed 3
sorrow 3
occurred 1
strolling 1
landed 1
hesitancy 1
flushes 1
waiting 1
reassured 1
runs 1
weeping 1
lets 1
xxvi 1
ruin 1
wall 8
sitting 1
dangling 1
exact 1
spot 2
track 1
begins 1
tonight 3
meters 1
poison 2
tracks 1
asunder 1
foot 1
leaped 1
facing 1
yellow 2
snakes 3
seconds 1
digging 1
pocked 1
revolver 1
running 1
flow 1
spray 1
apparent 1
disappeared 2
metallic 1
reached 1
catch 1
loosened 1
muffler 1
wore 1
moistened 1
temples 1
gravely 1
beating 1
shot 1
someone 1
rifle 1
dared 1
today 1
sadly 1
happening 2
holding 1
rushing 1
headlong 1
abyss 1
waited 1
reviving 1
lightly 1
frozen 1
irreparable 1
bear 1
hearing 1
affair 1
meeting 1
plea 1
lives 1
guides 1
scholars 1
problems 1
wealth 1
living 1
laughing 3
soothes 1
sorrows 1
content 2
open 1
window 1
properly 1
crazy 1
shabby 1
trick 1
played 1
bells 4
became 1
suffering 1
malicious 1
fun 1
catching 1
quick 1
resolute 1
dead 1
body 3
abandoned 1
shells 1
nice 1
rusty 1
pour 1
amusing 1
springs 1
becuase 1
protect 1
flash 1
motionless 1
falls 1
xxvii 1
companions 1
entirely 1
leather 1
strap 1
fasten 1
eaten 3
shuts 1
watches 1
absent 1
minded 1
yourselves 1
loveliest 2
saddest 2
landscape 2
preceding 1
page 1
impress 1
case 1
african 1
appears 1
laughs 1
refuses 1
happen 1
comfort 1
word 1
var redSvgSlider = d3.select("#red-slider-svg"),
redMargin = {right: 50, left: 50},
redWidth = +redSvgSlider.attr("width") - redMargin.left - redMargin.right,
redHeight = +redSvgSlider.attr("height");
var redX = d3.scaleLinear()
.domain([0, 100])
.range([0, redWidth])
.clamp(true);
var redSlider = redSvgSlider.append("g")
.attr("class", "slider")
.attr("transform", "translate(" + redMargin.left + "," + redHeight / 2 + ")");
redSlider.append("line")
.attr("class", "track")
.attr("x1", redX.range()[0])
.attr("x2", redX.range()[1])
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-inset")
.select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
.attr("class", "track-overlay")
.call(d3.drag()
.on("start.interrupt", function() { redSlider.interrupt(); })
.on("start drag", function() {
let value = Math.round(redX.invert(d3.event.x));
redHue(value);
let greenSlider = d3.select('#green-slider');
let redSlider = d3.select('#red-slider');
redSlider.text('Hide lower ' + value + '%');
redSlider.attr('value', value);
let greenVal = greenSlider.attr('value')
let redVal = redSlider.attr('value');
removeBarChart()
createBarChart(selectedForBarChart)
}));
var redHandle = redSlider.insert("circle", ".track-overlay")
.attr("class", "red-handle-slider")
.attr("r", 9);
function redHue(h) {
redHandle.attr("cx", redX(h));
}
// Selecting the tooltip from the html
const tooltip = d3.select("#tooltip");
// Initialize lists that will hold the information of both charts
var selectedForBarChart = [];
var selectedForWordCloud = [];
// Change loaded values from string to number
const row = d => {
d.value = +d.value
return d
}
// Do not consider common words in the word cloud
const common = "the,and,poop,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";
// Generate SVG where the word cloud will be placed
var svg_location = "#chart";
var width = $(document).width();
var height = $(document).height();
var svg = d3.select(svg_location).append("svg")
.attr("width", 960)
.attr("height", 500)
// Try to make word cloud centered
svg.attr("viewBox", "" + (-70) + " " + (-20) + " " + 960 + " " + 500)
// svg.attr("viewBox", "" + (-960 / 2) + " " + (-500 / 2))
// Load the little prince book
d3.csv("prince.csv",row, data => {
data = data.filter(d => common.indexOf(d.key)==-1)
// data.sort(compare)
selectedForWordCloud = data.filter(d => d.key.charAt(0) == "a")
drawWordCloud(selectedForWordCloud)
// Filter words from data to the word cloud every time the value of the dropdown changes
var xInput = d3.select("#xSelect")
xInput
.on('change',() => {
svg.selectAll("*").remove()
let letter = xInput.node().value;
selectedForWordCloud = data.filter(d => d.key.charAt(0) == letter)
drawWordCloud(selectedForWordCloud)
})
.selectAll('option')
.data(genCharArray('a', 'z'))
.enter()
.append('option')
.attr('value', d => d)
.text(d => d.toUpperCase());
// Passes all the words in the word cloud to the bar chart
var addAll = d3.select("#addAll")
addAll.on('click', () => {
removeBarChart()
selectedForBarChart = selectedForBarChart.concat(selectedForWordCloud)
createBarChart(selectedForBarChart)
});
});
// Function that draws words passed on data
function drawWordCloud(data){
var word_count = {};
data.forEach(d => {
word_count[d.key] = d.value
})
var fill = d3.scaleOrdinal(d3.schemeCategory20);
var word_entries = d3.entries(word_count);
var xScale = d3.scaleLinear()
.domain([0, d3.max(word_entries, function(d) {
return d.value;
})
])
.range([10,100]);
// Set the fond and size of the words in the word cloud
d3.layout.cloud().size([width, height])
.timeInterval(20)
.words(word_entries)
.fontSize(function(d) { return xScale(+d.value); })
.text(function(d) { return d.key; })
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.on("end", draw)
.start();
// function that draws words on the word cloud
function draw(words) {
var g = svg.append("g")
.attr("transform", "translate(" + [width >> 1, height >> 1] + ")")
.selectAll("text")
.data(words)
.enter().append("text")
.attr("class", "word")
.style("font-size", function(d) { return xScale(d.value) + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.key; })
.on("click", d => {
selectedForBarChart.push({"key":d.key, "value":d.value})
removeBarChart()
createBarChart(selectedForBarChart)
})
.on("mouseover", d => tooltipMouseOver(d))
.on("mouseout", tooltipMouseOut)
}
d3.layout.cloud().stop();
}
// Show tooltip when on top of a word
var tooltipMouseOver = d => {
// var value = yInput.node().value;
// Setting tooltip transition
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html("Frequency: " + d.value)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}
// Disappear tooltip
var tooltipMouseOut = () => {
tooltip.transition()
.duration(500)
.style("opacity", 0);
}
// Generate data for the dropdown that generates the word cloud
function genCharArray(charA, charZ) {
var a = [], i = charA.charCodeAt(0), j = charZ.charCodeAt(0);
for (; i <= j; ++i) {
a.push(String.fromCharCode(i));
}
return a;
}
#tooltip {
position: absolute;
text-align: center;
width: 100px;
height: 14px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
opacity: 0;
}
body {
margin: 0px;
}
.tick {
font-size: 2em;
}
.axis-label {
fill: black;
font-size: 3em;
font-family: sans-serif;
}
.legendCells {
font-size: 1.5em;
}
.legend-label {
fill: black;
font-size: 1em;
font-family: sans-serif;
}
.info-text {
padding-left: 100px;
padding-right: 100px;
}
h4 {
padding-left: 100px;
}
ul, ol {
padding-left: 120px;
}
#table {
width: 100%;
visibility: hidden;
position: absolute;
/* top: 30px; */
/* left: 500px; */
font-family: sans-serif;
font-size: 1.2em;
}
.brush-table > tr:nth-child(even) {
background-color: #d9d9d9;
}
.brush-table {
margin-left:auto;
margin-right:auto;
}
.settings-table td {
padding: 20px;
width: 400px;
}
.settings-table {
border: 1px solid black;
}
.instructions-table td {
padding: 20px;
width: 1000px;
}
.instructions-table {
border: 1px solid black;
}
.brushed {
fill: #ff3399;
stroke: #8e1b54;
opacity: 1.0;
}
.non_brushed {
/* fill: #404040; */
fill: 'blue';
opacity: 0.5;
}
td {
text-align: center;
}
/* for force graph */
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
/* for bar chart */
.toolTip {
position: absolute;
display: none;
min-width: 80px;
height: auto;
background: none repeat scroll 0 0 #ffffff;
border: 1px solid #6F257F;
padding: 14px;
text-align: center;
}
.axis {
font: 15px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #D4D8DA;
stroke-width: 1px;
shape-rendering: crispEdges;
}
/* Slider from here */
.ticks {
font: 10px sans-serif;
}
.track,
.track-inset,
.track-overlay {
stroke-linecap: round;
}
.track {
stroke: #000;
stroke-opacity: 0.3;
stroke-width: 10px;
}
.track-inset {
stroke: #ddd;
stroke-width: 8px;
}
.track-overlay {
pointer-events: stroke;
stroke-width: 50px;
stroke: transparent;
cursor: crosshair;
}
.green-handle-slider {
fill: green;
stroke: #000;
stroke-opacity: 0.5;
stroke-width: 1.25px;
}
.red-handle-slider {
fill: red;
stroke: #000;
stroke-opacity: 0.5;
stroke-width: 1.25px;
}
/* Test for a nice button */
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button5 {
background-color: white;
color: black;
border: 2px solid #555555;
}
.button5:hover {
background-color: #555555;
color: white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment