Skip to content

Commit

Permalink
fix type and remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Aug 28, 2023
1 parent c3cf566 commit b4703e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 55 deletions.
3 changes: 3 additions & 0 deletions src/layout/forceInABox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function forceInABox() {
tmpCount.count = tmpCount.count + 1;
tmpCount.sumforceNodeSize =
tmpCount.sumforceNodeSize +
// @ts-ignore
Math.PI * (forceNodeSize(d) * forceNodeSize(d)) * 1.3;
clustersCounts.set(groupBy(d), tmpCount);
});
Expand Down Expand Up @@ -190,6 +191,7 @@ export function forceInABox() {
cc,
clustersCounts;

// @ts-ignore
clustersCounts = computeClustersNodeCounts(force.nodes());

for (c of clustersCounts.keys()) {
Expand All @@ -201,6 +203,7 @@ export function forceInABox() {

function getFocisFromTemplate() {
//compute foci
// @ts-ignore
foci.none = { x: 0, y: 0 };
templateNodes.forEach(function (d) {
if (template === 'treemap') {
Expand Down
55 changes: 0 additions & 55 deletions src/utils/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,58 +53,3 @@ export function calculateClusters({

return result;
}

export interface CalculateCentersInput {
nodes: InternalGraphNode[];
clusterAttribute?: string;
strength?: number;
}

/**
* Takes a number n and calculates n x/y coordinates along a circle such
* that they are equally spaced from each other.
* Inspired by: https://github.com/ToxicJojo/github-issue-visualizer/blob/63c10b75551af57e557f52d9a9ccebbe05e3d12d/app/js/graph/calculate-centers.js
*/
export function caluculateCenters({
nodes,
clusterAttribute,
strength = 100
}: CalculateCentersInput) {
const centers = new Map<string, { x: number; y: number; z: number }>();

if (clusterAttribute) {
const groups = buildClusterGroups(nodes, clusterAttribute);
const numGroups = groups.size;
const numNodes = nodes?.length;

// Heuristics to adjust spacing between clusters
const [maxCap, numGroupsFactor] =
numGroups < 6 ? [8, 10 * numGroups] : [20, 20 * numGroups];

let idx = 0;
for (const [key, value] of groups) {
const radiant = ((2 * Math.PI) / numGroups) * idx;
const groupSize = value.length;

// Heuristics to adjust spacing between clusters
const factor = (groupSize * numGroupsFactor) / numNodes;
const cappedFactor =
groupSize < 10 && numGroups < 8
? numGroups / 2
: Math.max(2, Math.min(maxCap, factor));

const x = Math.cos(radiant) * strength * cappedFactor;
const y = Math.sin(radiant) * strength * cappedFactor;

idx++;

centers.set(key, {
x,
y,
z: 1
});
}
}

return centers;
}

0 comments on commit b4703e6

Please sign in to comment.