I have an attribute on nodes as “severity” of type int. This number is mapped to a color. For example 4 is red, 5 is blue.
Now, I’m looking for a way to get the “severity” of both nodes and compare them as numbers, take the bigger number and set it’s associated color to the link between the two nodes.
For example, if node1.severity = 3
and node2.severity = 5
, the link that is connecting these two nodes, must be blue, because 5 is bigger than 3 and 5 represents blue.
I was thinking I’ll use dataBinding to do that.
Now I already found this code:
https://gojs.net/latest/samples/productionProcess.html
// mark each Shape to get the link geometry with isPanelMain: true
$(go.Shape, { isPanelMain: true, stroke: "gray", strokeWidth: 10 },
// get the default stroke color from the fromNode
new go.Binding("stroke", "fromNode", function(n) { return go.Brush.lighten((n && Colors[n.data.color]) || "gray"); }).ofObject(),
// but use the link's data.color if it is set
new go.Binding("stroke", "color", colorFunc)),
Using the idea above, I might be able to do similar thing, binding the "stroke"
to "fromNode"
and access it’s severity
. But my question is, how I can access the "toNode"
as well?
To put it simple, I’m looking for something like this:
// the code below is not valid, it's just something I'm hoping to be able to implement.
new go.Binding("stroke", ["fromNode", "toNode"], function(n, m) { return go.Brush.lighten((n && m && decideFinalColor(n.data.severity, m.data.severity)) || "gray"); }).ofObject(),
Any suggesstion?