Skip to content

Commit

Permalink
Merge pull request #25 from ETH-PEACH-Lab/leftmost-cluster
Browse files Browse the repository at this point in the history
cluster graph sorted and fixed clusters issue
  • Loading branch information
mchami02 authored Aug 28, 2024
2 parents b08c6ba + 7325758 commit 5d7ae9b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Flowchart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,29 @@ class Flowchart extends Component<Props, State> {
const arrowheadSize = 6; // Adjust this to the size of the arrowhead
let yCounter = 0;

// Generate nodes, sorting by the order in colorScheme
const clusterFrequencies = d3.rollup(
selectedCells,
v => v.length,
d => d.cluster
);

// Generate nodes, sorting by the order in colorScheme
const classGroups = d3.group(selectedCells, d => d.class);

// Sort classGroups by the frequency of clusters
classGroups.forEach((cells, cls) => {
cells.sort((a, b) => {
const freqA = clusterFrequencies.get(a.cluster);
const freqB = clusterFrequencies.get(b.cluster);
if (freqA === undefined || freqB === undefined) {
return 0;
}
return freqB - freqA;
}
);
});

classGroups.forEach((cells, cls) => {
cells.sort((a, b) => {
const colorOrderA = Object.keys(colorScheme).indexOf(a.cluster);
Expand Down Expand Up @@ -248,10 +268,10 @@ class Flowchart extends Component<Props, State> {
if (index < selectedCells.length - 1) {
const sourceNode = nodes.find(node => node.cluster === cell.cluster);
const targetCell = selectedCells[index + 1];
const targetNode = nodes.find(node => node.cluster === targetCell.cluster && sourceNode?.cluster !== node.cluster && node.notebook_id === targetCell.notebook_id);
const targetNode = nodes.find(node => node.cluster === targetCell.cluster && sourceNode?.cluster !== node.cluster);

// Only create a link if both nodes belong to the same notebook_id
if (sourceNode && targetNode) {
if (sourceNode && targetNode && cell.notebook_id === targetCell.notebook_id) {
links.push({ source: sourceNode, target: targetNode });
}
}
Expand Down

0 comments on commit 5d7ae9b

Please sign in to comment.