({svgElement, root, onHover, onUnhover})
| 8 | |
| 9 | |
| 10 | export default function createVisualization({svgElement, root, onHover, onUnhover}) { |
| 11 | let chartSize = (root.maxDepth > 9) ? 950 : 750; |
| 12 | let radius = Math.min(chartSize, chartSize) / 2; |
| 13 | |
| 14 | |
| 15 | let partition = d3.layout.partition() |
| 16 | .size([2 * Math.PI, radius * radius]) |
| 17 | .value(d => d.size); |
| 18 | |
| 19 | |
| 20 | let arc = d3.svg.arc() |
| 21 | .startAngle(d => d.x) |
| 22 | .endAngle(d => d.x + d.dx) |
| 23 | //.innerRadius(d => d.y / 400 + 60) |
| 24 | //.outerRadius(d => (d.y + d.dy) / 400 + 60); |
| 25 | .innerRadius(d => Math.sqrt(d.y)) |
| 26 | .outerRadius(d => Math.sqrt(d.y + d.dy)); |
| 27 | |
| 28 | |
| 29 | if (vis) { |
| 30 | svgElement.innerHTML = ''; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | // Filter out very small nodes |
| 35 | let nodes = partition.nodes(root).filter(d => d.dx > 0.005); // 0.005 radians |
| 36 | |
| 37 | markDuplicates(nodes); |
| 38 | |
| 39 | |
| 40 | vis = d3.select(svgElement) |
| 41 | .attr('width', chartSize) |
| 42 | .attr('height', chartSize) |
| 43 | .append('svg:g') |
| 44 | .attr('id', 'svgWrapper') |
| 45 | .attr('transform', `translate(${chartSize / 2}, ${chartSize / 2})`); |
| 46 | |
| 47 | |
| 48 | paths = vis.data([root]).selectAll('path') |
| 49 | .data(nodes) |
| 50 | .enter() |
| 51 | .append('svg:path') |
| 52 | .attr('display', d => (d.depth ? null : 'none')) |
| 53 | .attr('d', arc) |
| 54 | .attr('fill-rule', 'evenodd') |
| 55 | .style('stroke', d => (d.duplicate) ? '#000' : '') |
| 56 | .style('fill', d => getColor(d)) |
| 57 | .style('opacity', 1) |
| 58 | .on('mouseover', object => { |
| 59 | mouseover(object, onHover); |
| 60 | }); |
| 61 | |
| 62 | totalSize = paths.node().__data__.value; |
| 63 | |
| 64 | |
| 65 | let svgWrapper = vis[0][0]; |
| 66 | let chart = svgElement.parentNode; |
| 67 |
no test coverage detected