Commit 8689854f authored by Themousaillon's avatar Themousaillon

add link support for node summary

parent 5e5528b2
import IdSet from "../../misc/customTypes/IdSet"
export class Node2d {
constructor(id, label, type, color=null, data=null, size=1, hide=false){
this.id = id
this.label = label
this.type = type
this.targets = new Set()
this.parents = new Set()
this.targets = new IdSet()
this.parents = new IdSet()
this.color = color ? color : "#DCDCDC"
this.data = data
this.size = size
......@@ -24,46 +26,60 @@ export class Node2d {
})
getEdgesId = () => {
const targets = [...this.targets].map(targetId => `${this.id} ${targetId}`)
const parents = [...this.parents].map(parentId => `${parentId} ${this.id}`)
const targets = this.targets.ids() .map(targetId => `${this.id} ${targetId}`)
const parents = this.parents.ids().map(parentId => `${parentId} ${this.id}`)
return targets.concat(parents)
}
getParents = () => [...this.parents]
getParents = (relationType="all") => this.parents.toArray(link => relationType === "all" || link.type === relationType)
getTargets = () => [...this.targets]
getTargets = (relationType="all") => this.targets.toArray(link => relationType === "all" || link.type === relationType)
getRelated= () => [...this.getParents(), ...this.getTargets()]
getRelated= (relationType="all") => [...this.getParents(relationType), ...this.getTargets(relationType)]
addTarget = targetId => {this.targets.add(targetId)}
addTarget = targetId => {this.targets.addOne(targetId)}
addParent = parentId => {this.parents.add(parentId)}
addParent = parentId => {this.parents.addOne(parentId)}
removeTarget = targetId => {this.targets.delete(targetId)}
removeTarget = targetId => {this.targets.removeOne(targetId)}
removeParent = parentId => {this.parents.delete(parentId)}
removeParent = parentId => {this.parents.removeOne(parentId)}
childrenSummary = (nodes, excludeHidden=false) => {
let valueCounts = {}
nodes.collectFromKeys([...this.targets]).forEach(n => {
let valueCounts = {nodes: {}, links: {}}
nodes.collectFromKeys(this.targets.ids()).forEach(n => {
if (!(n.excluded && excludeHidden)){
if (valueCounts[n.type] && !(n.excluded && excludeHidden))
valueCounts[n.type] += 1
if (valueCounts.nodes[n.type] && !(n.excluded && excludeHidden))
valueCounts.nodes[n.type] += 1
else
valueCounts[n.type] = 1
valueCounts.nodes[n.type] = 1
}})
this.targets.forEachEntry(link => {
if (valueCounts.links[link.type])
valueCounts.links[link.type] += 1
else
valueCounts.links[link.type] = 1
})
return valueCounts
}
parentSummary = (nodes, excludeHidden=false) => {
let valueCounts = {}
nodes.collectFromKeys([...this.parents]).forEach(n => {
let valueCounts = {nodes: {}, links: {}}
nodes.collectFromKeys(this.parents.ids()).forEach(n => {
if (!(n.excluded && excludeHidden)){
if (valueCounts[n.type])
valueCounts[n.type] += 1
if (valueCounts.nodes[n.type] && !(n.excluded && excludeHidden))
valueCounts.nodes[n.type] += 1
else
valueCounts[n.type] = 1
}})
valueCounts.nodes[n.type] = 1
}})
this.parents.forEachEntry(link => {
if (valueCounts.links[link.type])
valueCounts.links[link.type] += 1
else
valueCounts.links[link.type] = 1
})
return valueCounts
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment