-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use matrix API to bootstrap graph view (#216)
* use matrix API to bootstrap graph view * add score to links (but do not use it yet) * spanning tree (#225) * Fix graph (#226) * tests for getMinimalSpanningTree * fixes * canvas resize fix * Update src/lib/graph-visualization-helpers.js --------- Co-authored-by: trean <[email protected]>
- Loading branch information
Showing
5 changed files
with
239 additions
and
14 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,9 @@ | ||
export const resizeObserverWithCallback = (callback) => { | ||
return new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
const { target } = entry; | ||
const { width, height } = target.getBoundingClientRect(); | ||
if (typeof callback === 'function') callback(width, height); | ||
} | ||
}); | ||
}; |
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,56 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { getMinimalSpanningTree } from '../graph-visualization-helpers'; | ||
|
||
describe('getMinimalSpanningTree', () => { | ||
it('should return the minimal spanning tree for a given set of links (ascending order)', () => { | ||
const links = [ | ||
{ source: 'A', target: 'B', score: 1 }, | ||
{ source: 'B', target: 'C', score: 2 }, | ||
{ source: 'A', target: 'C', score: 3 }, | ||
{ source: 'C', target: 'D', score: 4 }, | ||
{ source: 'B', target: 'D', score: 5 }, | ||
]; | ||
|
||
const expectedMST = [ | ||
{ source: 'B', target: 'D', score: 5 }, | ||
{ source: 'C', target: 'D', score: 4 }, | ||
{ source: 'A', target: 'C', score: 3 }, | ||
]; | ||
|
||
const result = getMinimalSpanningTree(links, true); | ||
expect(result).toEqual(expectedMST); | ||
}); | ||
|
||
it('should return the minimal spanning tree for a given set of links (descending order)', () => { | ||
const links = [ | ||
{ source: 'A', target: 'B', score: 1 }, | ||
{ source: 'B', target: 'C', score: 2 }, | ||
{ source: 'A', target: 'C', score: 3 }, | ||
{ source: 'C', target: 'D', score: 4 }, | ||
{ source: 'B', target: 'D', score: 5 }, | ||
]; | ||
|
||
const expectedMST = [ | ||
{ source: 'A', target: 'B', score: 1 }, | ||
{ source: 'B', target: 'C', score: 2 }, | ||
{ source: 'C', target: 'D', score: 4 }, | ||
]; | ||
|
||
const result = getMinimalSpanningTree(links, false); | ||
expect(result).toEqual(expectedMST); | ||
}); | ||
|
||
it('should return an empty array if no links are provided', () => { | ||
const links = []; | ||
const expectedMST = []; | ||
const result = getMinimalSpanningTree(links, true); | ||
expect(result).toEqual(expectedMST); | ||
}); | ||
|
||
it('should handle a single link correctly', () => { | ||
const links = [{ source: 'A', target: 'B', score: 1 }]; | ||
const expectedMST = [{ source: 'A', target: 'B', score: 1 }]; | ||
const result = getMinimalSpanningTree(links, true); | ||
expect(result).toEqual(expectedMST); | ||
}); | ||
}); |
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