{
const height = 800;
const margin = { top: 20, left: 20, right: 20, bottom: 20 }
const innerWidth = width - margin.right - margin.left
const innerHeight = height - margin.top - margin.bottom
const svg = d3.select(DOM.svg(width, height))
.attr('overflow', 'hidden')
const sizeValue = d => d.children.length + 1
const colorValue = d => d.height
const nameValue = d => d.data.name !== '__general' ? d.data.name : d.parent.data.name
const titleValue = d => nameValue(d) +
( d.data.description !== '' ? '\n' + d.data.description : '' ) +
'\n' + d.ancestors().reverse().map(d => d.data.name).filter(s => s.indexOf('__') !== 0).join('/')
const filterLabel = d => d.height === 3
const colorScale = d3.scaleOrdinal()
.domain(d3.hierarchy(parsedDocs).descendants().map(colorValue))
.range(d3.schemeBlues[5])
const root = d3.hierarchy(parsedDocs)
.sum(sizeValue)
.sort((a, b) => b.value - a.value)
const pack = d3.pack()
.size([innerWidth, innerHeight])
.padding(3)
const packRoot = pack(root)
const g = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`)
const nodes = g.selectAll('g')
.data(d3.nest().key(d => d.height).entries(packRoot.descendants()))
.join('g')
.selectAll('g').data(d => d.values, d => (d.nodeUid = DOM.uid('node')).id)
.join('g')
.attr('id', d => d.nodeUid.id)
.attr('transform', d => `translate(${d.x},${d.y})`)
nodes.append('circle')
.attr('fill', d => colorScale(colorValue(d)))
.attr('r', d => d.r)
.append('title')
.text(titleValue)
const pathGenerator = d3.arc()
.startAngle(- Math.PI / 2)
.endAngle(Math.PI / 2)
const labels = g.selectAll('.pathLabel').data(packRoot.descendants().filter(filterLabel)).enter().append('g')
.attr('class', 'pathLabel')
.attr('transform', d => `translate(${d.x},${d.y})`)
labels.append('path')
.attr('d', d => pathGenerator({ outerRadius: d.r }))
.attr('id', d => (d.pathUid = DOM.uid('path')).id)
.attr('fill', 'none')
labels.append('text')
.attr('font-size', d => d.r / 4)
.append('textPath')
.attr('href', d => "#" + d.pathUid.id)
.style("text-anchor","middle")
.attr("startOffset", "50%")
.text(nameValue)
const zoom = d3.zoom()
.on('zoom', handleZoomPack)
g.call(zoom)
.on('wheel.zoom', null)
return svg.node()
}