-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eric Rowell
authored and
Eric Rowell
committed
Jan 21, 2019
1 parent
43f894a
commit 4ce7f53
Showing
17 changed files
with
280 additions
and
331 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,62 @@ | ||
let Cluster = function(config) { | ||
let model = { | ||
nodes: { | ||
xs: [], | ||
ys: [], | ||
colors: config.nodes.colors.slice() | ||
}, | ||
edges: config.edges.slice() | ||
}; | ||
|
||
// keys are color integers, values are arrays. The arrays contain node indices | ||
let groups = {}; | ||
|
||
config.nodes.colors.forEach(function(color, n) { | ||
if (groups[color] === undefined) { | ||
groups[color] = []; | ||
} | ||
|
||
groups[color].push(n); | ||
}); | ||
|
||
//console.log(groups); | ||
|
||
let keys = Object.keys(groups); | ||
let numGroups = keys.length; | ||
//let clusterRadius = 0.2; | ||
|
||
let key; | ||
let groupIndex = 0; | ||
for (key in groups) { | ||
let indices = groups[key]; | ||
let centerAngle = -2*Math.PI*groupIndex/numGroups; | ||
let clusterCenterX = Math.cos(centerAngle); | ||
let clusterCenterY = Math.sin(centerAngle); | ||
|
||
|
||
let ARC_LENGTH = 0.1; | ||
|
||
|
||
let radius = ARC_LENGTH / 4; | ||
let angleStep = ARC_LENGTH / radius; // arc length = radius * angle -> angle = arc length / radius | ||
let angle = 0; | ||
|
||
indices.forEach(function(index) { | ||
let x = Math.cos(angle) * radius; | ||
let y = Math.sin(angle) * radius; | ||
|
||
model.nodes.xs[index] = clusterCenterX + x; | ||
model.nodes.ys[index] = clusterCenterY + y; | ||
|
||
radius += ARC_LENGTH * angleStep / (2 * Math.PI); | ||
angleStep = ARC_LENGTH / radius; | ||
angle -= angleStep; | ||
}); | ||
|
||
groupIndex++; | ||
} | ||
|
||
return model; | ||
}; | ||
|
||
module.exports = Cluster; |
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
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
Oops, something went wrong.