(function() { var clusters, height, items, leaves, original, result, scale, svg, tree, width; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; svg.attr({ viewBox: "" + (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); items = d3.range(147).map(function(d) { return [70 + Math.random() * 150, 70 + Math.random() * 150, 70 + Math.random() * 150]; }); console.debug('Computing hierarchical clustering...'); clusters = clusterfck.hcluster(items, clusterfck.EUCLIDEAN_DISTANCE, clusterfck.AVERAGE_LINKAGE); tree = tree_utils.binary_to_std(clusters); leaves = tree_utils.get_leaves(tree); console.debug('Computing the Space-Filling Curve layouts...'); scale = 28; sfc_layout.displace(items, sfc_layout.GOSPER, scale, scale, -Math.PI / 6); sfc_layout.displace(leaves, sfc_layout.GOSPER, scale, scale, -Math.PI / 6); console.debug('Drawing...'); original = svg.append('g').attr('transform', 'translate(-240,0)'); result = svg.append('g').attr('transform', 'translate(240,0)'); original.selectAll('.cell').data(items).enter().append('path').attr('class', 'cell').attr('d', jigsaw.hex_generate_svg_path(scale)).attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; }).attr('fill', function(d) { return d3.rgb(d[0], d[1], d[2]); }); result.selectAll('.cell').data(leaves).enter().append('path').attr('class', 'cell').attr('d', jigsaw.hex_generate_svg_path(scale)).attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; }).attr('fill', function(d) { return d3.rgb(d.value[0], d.value[1], d.value[2]); }); }).call(this);