-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #89 note that the extent's definition in this PR is [[*xmin*, *ymin*], [*xmax*, *ymax*]], more in line with, for example zoom.extent. Defaults to [[0,0], [960,500]].
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default function(extent) { | ||
var nodes; | ||
|
||
if (extent === undefined) extent = [[0, 0], [960, 500]]; | ||
|
||
function force() { | ||
for (var i = 0; i < nodes.length; ++i) { | ||
var node = nodes[i], r = node.radius || 0; | ||
node.x = clamp(node.x, extent[0][0] - r, extent[1][0] + r); | ||
node.y = clamp(node.y, extent[0][1] - r, extent[1][0] + r); | ||
} | ||
} | ||
|
||
force.initialize = function(_) { nodes = _; }; | ||
|
||
force.extent = function(_) { | ||
return arguments.length ? (extent = _, force) : extent; | ||
}; | ||
|
||
return force; | ||
} | ||
|
||
function clamp(x, min, max) { | ||
return Math.max(min, Math.min(max, x)); | ||
} |
This file contains 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