Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #17 add fake node to graph view #18

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions app/graph/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function getCategoryColorName(index: number): string {
return COLORS_ORDER[index]
}

function getCategoryColorValue(index: number): string {
function getCategoryColorValue(index=0): string {
gkorland marked this conversation as resolved.
Show resolved Hide resolved
index = index<COLORS_ORDER.length ? index : 0
let colorName = COLORS_ORDER[index]

Expand Down Expand Up @@ -133,18 +133,35 @@ export class Graph {
this.edgesMap.set(cell.id, edge)
this.elements.push({data:edge})
newElements.push({data:edge})
// // creates a fakeS node for the source and target
// let source = nodes.get(cell.sourceId)
// if (!source) {
// source = { id: cell.sourceId.toString(), name: cell.sourceId.toString(), value: "", color: COLORS[0] }
// nodes.set(cell.sourceId, source)
// }

// let destination = nodes.get(cell.destinationId)
// if (!destination) {
// destination = { id: cell.destinationId.toString(), name: cell.destinationId.toString(), value: "", color: COLORS[0] }
// nodes.set(cell.destinationId, destination)
// }

// creates a fakeS node for the source and target
let source = this.nodesMap.get(cell.sourceId)
if (!source) {
source = {
id: cell.sourceId.toString(),
name: cell.sourceId.toString(),
value: "",
category: "",
color: getCategoryColorValue()
}
this.nodesMap.set(cell.sourceId, source)
this.elements.push({data:source})
newElements.push({data:source})
}
gkorland marked this conversation as resolved.
Show resolved Hide resolved

let destination = this.nodesMap.get(cell.destinationId)
if (!destination) {
destination = {
id: cell.destinationId.toString(),
name: cell.destinationId.toString(),
value: "",
category: "",
color: getCategoryColorValue()
}
this.nodesMap.set(cell.destinationId, destination)
this.elements.push({data:destination})
newElements.push({data:destination})
}
gkorland marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (cell.labels) {

Expand All @@ -158,7 +175,7 @@ export class Graph {

// check if node already exists in nodes or fake node was created
let node = this.nodesMap.get(cell.id)
if (!node || node.value === "") {
if (!node) {
node = {
id: cell.id.toString(),
name: cell.id.toString(),
Expand All @@ -169,6 +186,14 @@ export class Graph {
this.nodesMap.set(cell.id, node)
this.elements.push({data:node})
newElements.push({data:node})
} else if (node.category === ""){
// set values in a fake node
node.id = cell.id.toString(),
node.name = cell.id.toString(),
node.value = JSON.stringify(cell),
node.category = category.name
node.color = getCategoryColorValue(category.index)
newElements.push({data:node})
}
}
}
Expand Down
Loading