Skip to content

Commit 3d1b457

Browse files
committed
add check to ensure sratch edge has mapping to object ref.
1 parent 7f15cf3 commit 3d1b457

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

src/js/panel._utils.js

+18-26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ window.Widgets.Panel.Utils = {};
1111
constructor() {
1212
this.t = new Map();
1313
}
14+
getEdge(node1) {
15+
return this.t.get(node1);
16+
}
1417
addEdge(node1, node2) {
1518
const s = this.t.get(node1);
1619
if (s == null) {
@@ -95,6 +98,7 @@ window.Widgets.Panel.Utils = {};
9598
nodeStrength: -100,
9699
centreStrength: 80,
97100
promoSim: true,
101+
scratchSim: true,
98102
theme: 'light',
99103
light_theme: {
100104
treeFill: 'white',
@@ -146,25 +150,6 @@ window.Widgets.Panel.Utils = {};
146150
ns.contentMenuItem = false;
147151

148152

149-
// 1. Instantiate Visualisation Variables
150-
// 3. Setup RMB Menu Items
151-
// ns.menuItems = [
152-
// {
153-
// title: 'Copy Object',
154-
// action: (d) => {
155-
// // TODO: add any action you want to perform
156-
// console.log('Copy Object', d);
157-
// },
158-
// },
159-
// {
160-
// title: 'Create Relationship',
161-
// action: (d) => {
162-
// // TODO: add any action you want to perform
163-
// console.log('Create Relationship ->', d);
164-
// },
165-
// },
166-
// ];
167-
168153
// setup the left click capability
169154
ns.selectArray = [];
170155
ns.leftclick = function(event, d) {
@@ -516,7 +501,7 @@ window.Widgets.Panel.Utils = {};
516501

517502
// B. Update Data, Simulations and Drive Show Graph
518503
ns.processGraphData = function(graphData) {
519-
console.group('Widgets.Panel.Utils.updateGraph');
504+
console.groupCollapsed('Widgets.Panel.Utils.updateGraph');
520505
// console.log('graphData->', graphData);
521506

522507
let nodes = graphData.nodes;
@@ -606,7 +591,9 @@ window.Widgets.Panel.Utils = {};
606591
let centreX = dummywidth/2 // ns.options.width/2; this is NaN
607592
// 4. Setup layout
608593
let j = -1;
594+
var nodeRef = {};
609595
nodes.forEach(function(node) {
596+
nodeRef[node.id] = node;
610597
let annotate = {};
611598
annotate.connections = [];
612599
annotate.promo_IDs = [];
@@ -691,15 +678,10 @@ window.Widgets.Panel.Utils = {};
691678
}
692679
});
693680

694-
console.log('annotate list->', ns.split.promo_annotate_list)
695-
696681
ns.split.promo_IDs = Array.from(
697682
ns.split.adjacency.dirs(ns.split.promo_nodes_IDs),
698683
(path) => path.at(-1),
699684
);
700-
// console.log('ns.split.promo_nodes_IDs->', ns.split.promo_nodes_IDs);
701-
// console.log('ns.split.promo_IDs->', ns.split.promo_IDs);
702-
703685

704686
// 4. Now split the Graphs and update the
705687
nodes.forEach(function(node) {
@@ -712,7 +694,6 @@ window.Widgets.Panel.Utils = {};
712694
ns.split.scratch.nodes.push(node);
713695
}
714696
});
715-
console.log('ns.split.promo.nodes->', ns.split.promo.nodes)
716697

717698
edges.forEach(function(edge) {
718699
if (
@@ -722,6 +703,17 @@ window.Widgets.Panel.Utils = {};
722703
ns.split.promo.edges.push(edge);
723704
} else {
724705
ns.split.scratch.edges.push(edge);
706+
//TODO: find out why edges for sratch do not get mapped to object
707+
const edge_source = edge.source;
708+
const edge_target = edge.target;
709+
710+
//if string try to find in nodeRef
711+
if (typeof edge_source === 'string') {
712+
edge.source = nodeRef[edge_source];
713+
}
714+
if (typeof edge_target === 'string') {
715+
edge.target = nodeRef[edge_target];
716+
}
725717
}
726718
});
727719

0 commit comments

Comments
 (0)