Skip to content

Commit

Permalink
feat(commDetection): ✨ Label as group name!
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 4, 2021
1 parent eb03e1e commit 243fd05
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
29 changes: 18 additions & 11 deletions main.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/Components/CommunityDetection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
export let settings: GraphAnalysisSettings
export let view: AnalysisView
let currFile = app.workspace.getActiveFile()
$: currNode = currFile?.path.split('.md', 1)[0]
app.workspace.on('active-leaf-change', () => {
Expand Down Expand Up @@ -55,7 +54,7 @@
</div>
{#if promiseSortedComms}
{#await promiseSortedComms then sortedComms}
{#each sortedComms as comm, i}
{#each sortedComms as comm}
{#if comm.comm.length > 1}
<div class="GA-CC">
<details>
Expand All @@ -69,7 +68,7 @@
: ''}"
>
<span>
{i}
{comm.label}
</span>
<span class={TD_MEASURE}>{comm.comm.length}</span>
</span>
Expand Down
10 changes: 5 additions & 5 deletions src/MyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ export default class MyGraph extends Graph {
a: string,
options: { iterations: number }
): Promise<Communities> => {
let labeledNodes: { [node: string]: number } = {}
let labeledNodes: { [node: string]: string } = {}
this.nodes().forEach((node, i) => {
labeledNodes[node] = i
labeledNodes[node] = node
})

for (let i = 0; i < options.iterations; i++) {
const newLabeledNodes: {[node: string]: number} = {}
const newLabeledNodes: { [node: string]: string } = {}
this.nodes().forEach((node) => {
const neighbours = this.neighbors(node) as string[]

Expand All @@ -397,14 +397,14 @@ export default class MyGraph extends Graph {
const maxKey = getMaxKey(counts)
// console.log({neighbours,neighbourLabels, counts, maxKey})

newLabeledNodes[node] = Number.parseInt(maxKey)
newLabeledNodes[node] = maxKey
}
})
labeledNodes = newLabeledNodes
}

const communities: Communities = {}
Object.entries(labeledNodes).forEach((labeledNode: [string, number]) => {
Object.entries(labeledNodes).forEach((labeledNode: [string, string]) => {
const [node, label] = labeledNode
if (communities[label] === undefined) {
communities[label] = [node]
Expand Down
2 changes: 1 addition & 1 deletion src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function getPromiseResults(
return resultsPromise
}

export function getCounts(arr: number[]) {
export function getCounts(arr: any[]) {
const counts: { [item: string]: number } = {}
for (const num of arr) {
counts[num] = counts[num] ? counts[num] + 1 : 1
Expand Down

0 comments on commit 243fd05

Please sign in to comment.