// Generated by CoffeeScript 1.4.0 (function() { var color, correct_x, correct_y, height, svg, treemap, vis, width, zoom, zoomable_layer; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; treemap = d3.layout.treemap().size([width, height]).value(function(node) { return node.count; }).sort(function(a, b) { if (a.name === 'a' || b.name === 'b') { return +1; } if (a.name === 'b' || b.name === 'a') { return -1; } return a.count - b.count; }).ratio(1 / 3).padding(function(node) { if (node.depth === 0) { return [0, 0, 40, 0]; } else if (node.depth === 1) { return 4; } else { return 0; } }).round(false); correct_x = d3.scale.linear().domain([0, width]).range([0, width * 1.05]); correct_y = d3.scale.linear().domain([0, height]).range([0, height * 3 / 4]); color = function(txt, set) { var iset, noise; iset = { 'a': 0, 'intersection': 1, 'b': 2 }[set]; Math.seedrandom(txt + 'abcdef'); noise = function(W) { return Math.random() * W - W / 2; }; return d3.hcl(iset * 90 + noise(90), 40, 50); }; svg.attr({ viewBox: "" + (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); zoomable_layer = svg.append('g'); zoom = d3.behavior.zoom().scaleExtent([1, 10]).on('zoom', function() { return zoomable_layer.attr({ transform: "translate(" + (zoom.translate()) + ")scale(" + (zoom.scale()) + ")" }); }); svg.call(zoom); vis = zoomable_layer.append('g').attr({ transform: "translate(" + (-width / 2) + "," + (-height / 2) + ")" }); d3.csv('english_stopwords_long.txt', function(stopwords_array) { var stopwords; stopwords = {}; stopwords_array.forEach(function(w) { return stopwords[w.word] = true; }); return d3.text('infovis.txt', function(infovis_txt) { var data_a, index_a; data_a = nlp.ngram(infovis_txt, { min_count: 1, max_size: 1 })[0].filter(function(w) { return !(w.word in stopwords); }); index_a = {}; data_a.forEach(function(d) { return index_a[d.word] = d; }); return d3.text('hci.txt', function(hci_txt) { var a, b, data_b, diff_a, diff_b, enter_labels, index_b, intersection, labels, nodes_data, tree; data_b = nlp.ngram(hci_txt, { min_count: 1, max_size: 1 })[0].filter(function(w) { return !(w.word in stopwords); }); index_b = {}; data_b.forEach(function(d) { return index_b[d.word] = d; }); diff_a = data_a.filter(function(a) { return !(a.word in index_b); }); diff_b = data_b.filter(function(b) { return !(b.word in index_a); }); intersection = []; data_a.forEach(function(a) { return data_b.forEach(function(b) { var min; if (a.word === b.word) { min = Math.min(a.count, b.count); intersection.push({ word: a.word, count: min }); if (a.count - min > 0) { diff_a.push({ word: a.word, count: a.count - min }); } if (b.count - min > 0) { return diff_b.push({ word: b.word, count: b.count - min }); } } }); }); a = { children: diff_a.filter(function(d) { return d.count > 1; }), name: "a" }; intersection = { children: intersection.filter(function(d) { return d.count > 1; }), name: "intersection" }; b = { children: diff_b.filter(function(d) { return d.count > 1; }), name: "b" }; tree = { children: [a, intersection, b], name: "root" }; nodes_data = treemap.nodes(tree); labels = vis.selectAll('.label').data(nodes_data.filter(function(node) { return node.depth === 2; })); enter_labels = labels.enter().append('svg').attr({ "class": 'label' }); enter_labels.append('text').text(function(node) { return node.word.toUpperCase(); }).attr({ dy: '0.35em', fill: function(node) { return color(node.word, node.parent.name); } }).each(function(node) { var bbox, bbox_aspect, node_bbox, node_bbox_aspect, rotate; bbox = this.getBBox(); bbox_aspect = bbox.width / bbox.height; node_bbox = { width: node.dx, height: node.dy }; node_bbox_aspect = node_bbox.width / node_bbox.height; rotate = bbox_aspect >= 1 && node_bbox_aspect < 1 || bbox_aspect < 1 && node_bbox_aspect >= 1; node.label_bbox = { x: bbox.x + (bbox.width - correct_x(bbox.width)) / 2, y: bbox.y + (bbox.height - correct_y(bbox.height)) / 2, width: correct_x(bbox.width), height: correct_y(bbox.height) }; if (rotate) { node.label_bbox = { x: node.label_bbox.y, y: node.label_bbox.x, width: node.label_bbox.height, height: node.label_bbox.width }; return d3.select(this).attr('transform', 'rotate(-90)'); } }); enter_labels.attr({ x: function(node) { return node.x; }, y: function(node) { return node.y; }, width: function(node) { return node.dx; }, height: function(node) { return node.dy; }, viewBox: function(node) { return "" + node.label_bbox.x + " " + node.label_bbox.y + " " + node.label_bbox.width + " " + node.label_bbox.height; }, preserveAspectRatio: 'none' }); vis.append('text').text('A ∖ B').attr({ "class": 'set_label', x: a.x + a.dx / 2, y: height - 22, dy: '0.35em' }); vis.append('text').text('A ∩ B').attr({ "class": 'set_label', x: intersection.x + intersection.dx / 2, y: height - 22, dy: '0.35em' }); return vis.append('text').text('B ∖ A').attr({ "class": 'set_label', x: b.x + b.dx / 2, y: height - 22, dy: '0.35em' }); }); }); }); }).call(this);