Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ function init(options) {
.attr(
'transform',
'translate(' +
parseInt(
childrenWidth + (elemWidth - childrenWidth * 2) / 2 - margin.left / 2
) +
',' +
48 +
')'
parseInt(
childrenWidth + (elemWidth - childrenWidth * 2) / 2 - margin.left / 2
) +
',' +
48 +
')'
)

// Define box shadow and avatar border radius
Expand All @@ -119,9 +119,13 @@ function init(options) {
config.render = render

// Defined zoom behavior

const isMobile = document.documentElement.clientWidth <= 460;
const weights = isMobile ? 4 : 12;

var zoom = d3.behavior
.zoom()
.scaleExtent([0.1, 2])
.scaleExtent([0.2, weights])
.duration(50)
.on('zoom', zoomed)

Expand Down Expand Up @@ -151,10 +155,10 @@ function init(options) {
return d3
.transition()
.duration(350)
.tween('zoom', function() {
.tween('zoom', function () {
var iTranslate = d3.interpolate(zoom.translate(), translate),
iScale = d3.interpolate(zoom.scale(), scale)
return function(t) {
return function (t) {
zoom.scale(iScale(t)).translate(iTranslate(t))
zoomed()
}
Expand Down
15 changes: 11 additions & 4 deletions src/chart/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,23 @@ function render(config) {
} = config

// Compute the new tree layout.
const nodes = tree.nodes(treeData).reverse()
const nodes = window.innerWidth <= 460 ? tree.nodes(treeData) : tree.nodes(treeData).reverse()
const links = tree.links(nodes)

config.links = links
config.nodes = nodes

// Normalize for fixed-depth.
nodes.forEach(function(d) {
d.y = d.depth * lineDepthY
})
if (typeof window !== 'undefined' && window.innerWidth <= 460) {
nodes.forEach((d, i) => {
d.x = 0
d.y = i === 0 ? 0 : i * (nodeHeight + nodePaddingY)
})
} else {
nodes.forEach(d => {
d.y = d.depth * lineDepthY
})
}

// Update the nodes
const node = svg.selectAll('g.' + CHART_NODE_CLASS).data(
Expand Down