Last active
December 31, 2015 23:29
-
-
Save oshikryu/8060638 to your computer and use it in GitHub Desktop.
An attempt to automatically scroll an svg when a d3 tree node is added
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_scrollContainer: -> | |
targets = d3.select(d3.selectAll('g.node.selection').pop()).node() | |
return unless targets | |
selectionCoord = targets.pop().getBoundingClientRect() | |
selectedTarget = d3.select('g.selected') | |
selectedTarget = _.compact selectedTarget[0] | |
return unless selectedTarget.length > 0 | |
selectedCoord = selectedTarget[0].getBoundingClientRect() | |
bottomCoord = Math.max selectionCoord.bottom, selectedCoord.bottom | |
topCoord = Math.min selectionCoord.top, selectedCoord.top | |
scrollHeight = @$('#tree-container')[0].scrollHeight - @$('#tree-container').height() | |
curScroll = @$('#tree-container').scrollTop() | |
if topCoord < 100 | |
curScroll -= (topCoord + 100) | |
return curScroll | |
if bottomCoord > 340 | |
curScroll += (bottomCoord - 340) | |
else | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment