// Generated by CoffeeScript 1.10.0 (function() { var base7, base7_n1, base7_n2, data, diagonal, distance, fill_color, height, i, link, links, max_depth, n1, n2, name1, name2, node, nodes, radius, stroke_color, svg, tree, vis, width; width = 960; height = 1000; distance = 16; max_depth = 10; radius = 8; svg = d3.select('svg').attr({ width: width, height: height }); vis = svg.append('g').attr({ transform: "translate(50, 100)" }); fill_color = d3.scale.ordinal().domain(['tree1full', 'tree1partially full', 'tree2full', 'tree2partially full', 'empty']).range(['steelblue', 'lightsteelblue', 'orange', '#ffdc9d', '#fff']); stroke_color = d3.scale.ordinal().domain(['tree1', 'tree2', 'empty']).range(['steelblue', 'orange', 'gray']); /* TREE CONSTRUCTION */ name1 = 'tree1'; name2 = 'tree2'; n1 = Math.floor(Math.random() * 1000); base7_n1 = hept_tree_utils.base10_to_base7(n1); n2 = Math.floor(Math.random() * 1000); base7_n2 = hept_tree_utils.base10_to_base7(n1 + n2); tree = { name: name1, type: ((base7_n1.reduce(function(t, s) { return t + s; })) === 1 ? 'full' : 'partially full'), children: [] }; base7 = hept_tree_utils.align_arrays(base7_n1, base7_n2); tree = hept_tree_utils.make_tree(tree, base7[0], base7[1], name1, name2, 0); data = tree; /* TREE VISUALIZATION */ svg.append('text').html("N1 = " + n1 + " (" + (base7[0].join('')) + "), N2 = " + n2 + " (" + (base7[1].join('')) + ")").attr({ "class": 'number', x: 40, y: 40 }); svg.selectAll('.order').data((function() { var j, ref, results; results = []; for (i = j = 0, ref = base7[0].length; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { results.push(i); } return results; })()).enter().append('text').text(function(d, i) { return "" + (base7[0].length - i); }).attr({ "class": 'order', x: function(d, i) { return 45 + 96 * i; }, y: 75 }); tree = d3.layout.tree().size([0, 0]); nodes = tree.nodes(data); links = tree.links(nodes); height = 0; nodes.forEach(function(n) { if ((n.parent != null) && n.parent.children[0] !== n) { height += distance; } n.x = height; return n.y = n.depth * (width / max_depth); }); diagonal = d3.svg.diagonal().projection(function(d) { return [d.y, d.x]; }); link = vis.selectAll('path.link').data(links).enter().append('path').attr({ "class": 'link', d: diagonal }); node = vis.selectAll('g.node').data(nodes).enter().append('g').attr({ "class": 'node', transform: function(d) { return "translate(" + d.y + "," + d.x + ")"; } }); node.append('path').attr({ "class": 'hex', d: function(d) { return hept_tree_utils.hex_generate_svg_path(12); }, fill: function(d) { return fill_color(d.name + d.type); }, stroke: function(d) { return stroke_color(d.name); } }).append('title').text(function(d) { return d.type; }); }).call(this);