// Generated by CoffeeScript 1.10.0 (function() { var a, base7_n1, base7_n2, circles, color, enter_hexes, height, hexes, hexes_data, n1, n2, r, svg, vis, width; width = 960; height = 500; color = d3.scale.ordinal().domain(['n1', 'n2', 'empty']).range(['steelblue', 'orange', '#f9f9f9']); svg = d3.select('svg').attr({ width: width, height: height, viewBox: (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); vis = svg.append('g'); /* Generating random numbers */ n1 = Math.floor(Math.random() * 7); n2 = Math.floor(Math.random() * (7 - n1)); base7_n1 = hept_tree_utils.base10_to_base7(n1); base7_n2 = hept_tree_utils.base10_to_base7(n1 + n2); svg.append('text').html("Class1 = " + n1).attr({ "class": 'c1', x: -width / 2 + 30, y: -height / 2 + 40 }); svg.append('text').html("Class2 = " + n2).attr({ "class": 'c2', x: -width / 2 + 30, y: -height / 2 + 70 }); /* Drawing Hexagons */ a = height / 6; r = a / Math.sin(Math.PI / 3); hexes_data = [ { x: -a, y: r + r / 2 }, { x: a, y: r + r / 2 }, { x: 0, y: 0 }, { x: -2 * a, y: 0 }, { x: -a, y: -r - r / 2 }, { x: a, y: -r - r / 2 }, { x: 2 * a, y: 0 } ]; hexes_data = hept_tree_utils.base7_to_hex(base7_n1, base7_n2, 0, hexes_data); hexes = vis.selectAll('.hex').data(hexes_data); enter_hexes = hexes.enter().append('path').attr({ "class": 'hex', d: hept_tree_utils.hex_generate_svg_path(a), transform: function(d) { return "translate(" + d.x + ", " + d.y + ")"; }, fill: function(d) { return color(d["class"]); } }); circles = vis.selectAll('circle').data(hexes_data); enter_hexes = hexes.enter().append('circle').attr({ r: 5, cx: function(d) { return d.x; }, cy: function(d) { return d.y; } }); vis.append('path').attr({ "class": 'line', d: "M" + hexes_data[0].x + " " + hexes_data[0].y + " L" + hexes_data[1].x + " " + hexes_data[1].y + " L" + hexes_data[2].x + " " + hexes_data[2].y + " L" + hexes_data[3].x + " " + hexes_data[3].y + " L" + hexes_data[4].x + " " + hexes_data[4].y + " L" + hexes_data[5].x + " " + hexes_data[5].y + " L" + hexes_data[6].x + " " + hexes_data[6].y }); }).call(this);