shift canvas up/down if node circle off canvas

This commit is contained in:
David Kaltschmidt
2015-09-11 16:39:00 +02:00
parent bc7e8f27fc
commit 6191999c9e
3 changed files with 14 additions and 1 deletions

View File

@@ -297,6 +297,17 @@ const NodesChart = React.createClass({
const shift = offsetX - offsetX + centerX - radius;
translate[0] = -shift;
}
const offsetY = translate[1];
if (offsetY + centerY + radius > props.height) {
// shift up if past bottom
const shift = centerY + radius - props.height;
translate[1] = -shift;
} else if (offsetY + centerY - radius - props.topMargin < 0) {
// shift down if off canvas
const shift = offsetY - offsetY + centerY - radius - props.topMargin;
translate[1] = -shift;
}
// saving translate in d3's panning cache
this.zoom.translate(translate);

View File

@@ -62,6 +62,7 @@ const App = React.createClass({
const versionString = this.state.version ? 'Version ' + this.state.version : '';
// width of details panel blocking a view
const detailsWidth = showingDetails ? 420 : 0;
const topMargin = 100;
return (
<div>
@@ -79,7 +80,7 @@ const App = React.createClass({
<Nodes nodes={this.state.nodes} highlightedNodeIds={this.state.highlightedNodeIds}
highlightedEdgeIds={this.state.highlightedEdgeIds} detailsWidth={detailsWidth}
selectedNodeId={this.state.selectedNodeId}
selectedNodeId={this.state.selectedNodeId} topMargin={topMargin}
topologyId={this.state.currentTopologyId} />
<div className="footer">

View File

@@ -40,6 +40,7 @@ const Nodes = React.createClass({
height={this.state.height}
topologyId={this.props.topologyId}
detailsWidth={this.props.detailsWidth}
topMargin={this.props.topMargin}
/>
</div>
);