-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
“Wind”: a physics force that pushes all node in a given direction.
- Loading branch information
Showing
8 changed files
with
144 additions
and
4 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
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,55 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Vis Network | Physics | Wind</title> | ||
|
||
<script type="text/javascript" src="../../../standalone/umd/vis-network.min.js"></script> | ||
|
||
<style type="text/css"> | ||
#mynetwork { | ||
width: 600px; | ||
height: 400px; | ||
border: 1px solid lightgray; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<p> | ||
Node 1 is fixed, while a "wind" force pushes other nodes to the right. | ||
</p> | ||
|
||
<div id="mynetwork"></div> | ||
|
||
<script type="text/javascript"> | ||
// create an array with nodes | ||
var nodes = new vis.DataSet([ | ||
{id: 1, label: 'Node 1', fixed: true }, | ||
{id: 2, label: 'Node 2'}, | ||
{id: 3, label: 'Node 3'}, | ||
{id: 4, label: 'Node 4'}, | ||
{id: 5, label: 'Node 5'} | ||
]); | ||
|
||
// create an array with edges | ||
var edges = new vis.DataSet([ | ||
{from: 1, to: 3}, | ||
{from: 1, to: 2}, | ||
{from: 2, to: 4}, | ||
{from: 2, to: 5}, | ||
{from: 3, to: 3} | ||
]); | ||
|
||
// create a network | ||
var container = document.getElementById('mynetwork'); | ||
var data = { | ||
nodes: nodes, | ||
edges: edges | ||
}; | ||
var options = { physics: { enabled: true, wind: { x: 1, y: 0 } } }; | ||
var network = new vis.Network(container, data, options); | ||
</script> | ||
|
||
|
||
</body> | ||
</html> |
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
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,49 @@ | ||
import { expect } from "chai"; | ||
import Network from "../../lib/network/Network"; | ||
import canvasMockify from "../canvas-mock"; | ||
|
||
describe("wind", function(): void { | ||
beforeEach(function() { | ||
this.clearJSDOM = canvasMockify("<div id='mynetwork'></div>"); | ||
this.container = document.getElementById("mynetwork"); | ||
}); | ||
|
||
afterEach(function() { | ||
this.clearJSDOM(); | ||
|
||
delete this.clearJSDOM; | ||
delete this.container; | ||
}); | ||
|
||
it("All nodes are on the correct side of the fixed node", async function(): Promise< | ||
void | ||
> { | ||
const network = new Network( | ||
this.container, | ||
{ | ||
nodes: [ | ||
{ id: 1, fixed: true, x: 0, y: 0 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 } | ||
], | ||
edges: [ | ||
{ from: 1, to: 2 }, | ||
{ from: 2, to: 3 }, | ||
{ from: 3, to: 4 } | ||
] | ||
}, | ||
{ physics: { wind: { x: 10, y: 0 }, stabilization: { iterations: 10 } } } | ||
); | ||
|
||
// Wait for the physics to stabilize. | ||
await new Promise((resolve): void => { | ||
network.on("stabilized", resolve); | ||
}); | ||
|
||
const positions = network.getPositions(); | ||
expect(positions[2].x).to.be.greaterThan(0); | ||
expect(positions[3].x).to.be.greaterThan(0); | ||
expect(positions[4].x).to.be.greaterThan(0); | ||
}); | ||
}); |