diff --git a/src/chart/index.js b/src/chart/index.js index c2b54ce..7d6d943 100644 --- a/src/chart/index.js +++ b/src/chart/index.js @@ -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 @@ -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) @@ -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() } diff --git a/src/chart/render.js b/src/chart/render.js index c14fbba..e2428a7 100644 --- a/src/chart/render.js +++ b/src/chart/render.js @@ -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(