forked from psa7rm/pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpathfinder.html
More file actions
1666 lines (1445 loc) · 70.4 KB
/
Copy pathpathfinder.html
File metadata and controls
1666 lines (1445 loc) · 70.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Pathfinder">
<meta name="author" content="Siddhartha Yarlagadda">
<title>Pathfinder</title>
<link rel="icon" type="image/svg+xml"
href='data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22999%22%20height%3D%22999%22%20fill%3D%22white%22%20class%3D%22bi%20bi-bounding-box-circles%22%0A%20%20%20%20viewBox%3D%220%200%2016%2016%22%3E%0A%20%20%20%20%3Cline%20x1%3D%222.5%22%20y1%3D%2213.5%22%20x2%3D%2214%22%20y2%3D%228%22%20style%3D%22stroke%3A%237D7D7D%3Bstroke-width%3A0.8%22%20%2F%3E%0A%20%20%20%20%3Cline%20x1%3D%225%22%20y1%3D%221.7%22%20x2%3D%222.5%22%20y2%3D%2213.5%22%20style%3D%22stroke%3A%237D7D7D%3Bstroke-width%3A0.8%22%20%2F%3E%0A%20%20%20%20%3Cline%20x1%3D%2214%22%20y1%3D%228%22%20x2%3D%225%22%20y2%3D%221.7%22%20style%3D%22stroke%3A%237D7D7D%3Bstroke-width%3A0.8%22%20%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%222.5%22%20cy%3D%2213.5%22%20r%3D%222.5%22%20fill%3D%22%23f46332%22%20%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%225%22%20cy%3D%221.7%22%20r%3D%221.7%22%20fill%3D%22%23ff6b6b%22%20%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2214%22%20cy%3D%228%22%20r%3D%222.0%22%20fill%3D%22%23ffc800%22%20%2F%3E%0A%3C%2Fsvg%3E' />
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- D3 -->
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: sans-serif;
overflow: hidden;
background: #fefefe;
}
#main-content {
display: none;
}
#initial-upload-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.custom-flex-layout {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
}
#upload-container {
position: absolute;
top: 5%;
left: 0%;
width: 25vw;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#map-container {
position: absolute;
top: 5%;
left: 75%;
width: 25vw;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#search-container {
position: absolute;
top: 5%;
left: 25%;
width: 50vw;
display: flex;
flex-direction: column;
align-items: flex-start;
}
#search {
width: 100%;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
#search-icon {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
#suggestions {
background: #fff;
border-radius: 4px;
width: 100%;
border: 1px solid #ccc;
border-top: none;
max-height: 40vh;
overflow-y: auto;
position: relative;
display: none;
}
#suggestions div {
padding: 2px;
cursor: pointer;
}
#suggestions div:hover {
background: hsla(0, 0%, 90%, 0.5);
}
#chart {
width: 100vw;
height: 100vh;
}
.upload-text {
font-size: 1.2rem;
font-weight: 500;
color: #495057;
margin-bottom: 15px;
}
.link {
stroke: #999;
stroke-opacity: 0.8;
fill: none;
stroke-width: 3px;
cursor: pointer;
}
.modal-dialog {
max-width: 85vw;
max-height: 85vh;
}
.modal-content {
height: 80vh;
overflow-y: auto;
}
.node {
cursor: pointer;
stroke: #fff;
stroke-width: 1.5px;
}
.user-message {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 5px 10px;
border-radius: 10px;
font-size: 14px;
display: none;
z-index: 1000;
transition: opacity 0.5s ease-in-out;
}
marker path {
fill: #999;
fill-opacity: 1;
}
text {
font-size: 12px;
pointer-events: none;
}
#link-tooltip,
#node-tooltip {
cursor: grab;
position: absolute;
display: none;
background: #fafafa;
border: 1px solid #ccc;
padding: 8px;
border-radius: 4px;
font-size: 14px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
z-index: 99999;
max-height: 200px;
overflow-y: auto;
pointer-events: auto;
}
</style>
</head>
<body>
<div id="fileMessage" class="user-message bg-warning"></div>
<div id="initial-upload-container" class="text-center">
<div class="position-absolute top-0 end-0 m-5">
<a id="helpBtn" class="btn btn-outline-primary" title="Help"
href="https://github.com/sy276/pathfinder?tab=readme-ov-file#-pathfinder" target="_blank"
rel="noopener noreferrer">
<i class="bi bi-info-circle"></i> Help
</a>
</div>
<div class="d-flex flex-column align-items-center">
<div class="upload-text">⚡Upload files to get started.</div>
<button id="initial-uploadBtn" class="btn btn-outline-primary me-2 w-50" title="Upload files">
<i class="bi bi-upload"></i>
</button>
<input type="file" id="initial-fileInput" accept=".json" multiple style="display: none;" />
</div>
</div>
<div id="main-content">
<div class="d-flex custom-flex-layout mb-2">
<div id="upload-container">
<button id="uploadBtn" class="btn btn-outline-primary me-2 w-50" title="Upload files">
<i class="bi bi-upload"></i> Fileloader
</button>
<input type="file" id="fileInput" accept=".json" multiple style="display: none;" />
</div>
<div id="search-container">
<div class="input-group d-flex align-items-center flex-nowrap">
<span id="search-icon" class="text-primary input-group-text border-primary bg-white"><i
class="bi bi-search"></i></span>
<input class="form-control border-primary" id="search" type="search"
placeholder="Search for business objects.." aria-label="Search"
title="Search for business objects to add to, remove from, or locate within the graph">
</div>
<div id="suggestions" class="rounded-bottom"></div>
</div>
<div id="map-container">
<button id="mapBtn" class="btn btn-outline-primary me-2 w-50" title="Find object relationships">
<i class="bi bi-compass"></i> Pathfinder
</button>
</div>
</div>
<div id="link-tooltip"></div>
<div id="node-tooltip"></div>
<div id="chart"></div>
</div>
<div class="modal fade" id="mapModal" tabindex="-1" aria-labelledby="mapModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="mapModalLabel">
Pathfinder
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="startBO" class="form-label"><strong>Source</strong> Object</label>
<input class="form-control" list="businessObjects" id="startBO"
placeholder="Search for source objects..">
</div>
<div class="mb-3">
<label for="endBO" class="form-label"><strong>Target</strong> Object</label>
<input class="form-control" list="businessObjects" id="endBO"
placeholder="Search for target objects..">
</div>
<div class="mb-3">
<label for="depthLevel" class="form-label"><strong>Depth</strong> Level</label>
<input type="number" class="form-control" id="depthLevel" value="1" min="1" max="99" />
</div>
<button id="mapSearchBtn" class="btn btn-outline-primary w-100"><i
class="bi bi-search"></i> Find Paths</button>
<hr>
<div id="mapSearchResults" class="mt-2"></div>
<div id="pathMessage" class="user-message bg-success text-white"></div>
</div>
</div>
</div>
</div>
<datalist id="businessObjects"></datalist>
<div class="modal fade" id="allFieldCombinationsModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Field Paths</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div id="allFieldCombosContainer"></div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="pathDetailModal" tabindex="-1" aria-labelledby="pathDetailModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="pathDetailModalLabel">Calculated Fields</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="alert alert-secondary" role="alert">
<div class="d-flex mb-2">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="calcFieldsRadio"
id="lrvesiCalcFieldsRadio" value="LRV + ESI" checked>
<label class="form-check-label small" for="lrvesiCalcFieldsRadio">LRV + ESI</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="calcFieldsRadio"
id="ariCalcFieldsRadio" value="ARI">
<label class="form-check-label small" for="ariCalcFieldsRadio">ARI</label>
</div>
</div>
<div class="small">ℹ️ For multi-instance fields, an LRV + ESI can always be replaced with an
ARI, and vice versa, even at the individual field level.</div>
</div>
<div id="lrvesiDiv">
</div>
<div id="ariDiv" style="display: none;">
</div>
</div>
</div>
</div>
</div>
<script>
/**
* Gather data into this array in the form:
* [
* { B: "...", R: "...", F: "..." },
* { B: "...", R: "...", F: "..." },
* ...
* ]
*/
const rawData = [];
// On clicking the "Upload" button, simulate a click on the hidden file input
document.getElementById("uploadBtn").addEventListener("click", () => {
document.getElementById("fileInput").click();
});
document.getElementById("initial-uploadBtn").addEventListener("click", () => {
document.getElementById("initial-fileInput").click();
});
// Listen for file input changes
document.getElementById("fileInput").addEventListener("change", handleFileSelect);
document.getElementById("initial-fileInput").addEventListener("change", handleFileSelect);
function handleFileSelect(event) {
let dataLoaded = 0;
let erroredFiles = [];
function fileErrorMessage() {
const messageBox = document.getElementById("fileMessage");
messageBox.textContent = "Failed to load files: Unsupported schema detected in " + erroredFiles.join(", ") + ".";
messageBox.style.display = "block";
messageBox.style.opacity = "1";
setTimeout(() => {
messageBox.style.opacity = "0";
setTimeout(() => {
messageBox.style.display = "none";
}, 500);
}, 3000);
}
const files = event.target.files;
if (!files || !files.length) return;
[...files].forEach(file => {
const reader = new FileReader();
reader.onload = (e) => {
try {
const jsonData = JSON.parse(e.target.result);
if (jsonData && Array.isArray(jsonData.Report_Entry)) {
jsonData.Report_Entry.forEach(entry => {
/** Schema 1:
{
"Report_Entry": [
{
"B": "bo1",
"R": "bo2",
"F": "f1"
},
{
"B": "bo3",
"R": "bo4",
"F": "f2"
}
]
}
**/
if (entry.B && entry.R && entry.F) {
if (entry.B !== entry.R) {
rawData.push({
B: entry.B,
R: entry.R,
F: entry.F
});
dataLoaded++;
}
}
/** Schema 2:
{
"Report_Entry": [
{
"B": "bo1",
"R_G": [
{
"R": "bo2",
"F": "f1"
},
{
"R": "bo3",
"F": "f2"
}
]
},
{
"B": "bo4",
"R_G": [
{
"R": "bo5",
"F": "f3"
}
]
}
]
}
**/
else if (entry.B && Array.isArray(entry.R_G)) {
entry.R_G.forEach(subObj => {
if (entry.B !== subObj.R) {
rawData.push({
B: entry.B,
R: subObj.R,
F: subObj.F
});
dataLoaded++;
}
});
}
//If not either of the files
else {
erroredFiles.push(file.name);
fileErrorMessage();
}
});
}
else {
erroredFiles.push(file.name);
fileErrorMessage();
}
} catch (err) {
erroredFiles.push(file.name);
fileErrorMessage();
}
// After reading all the files, rebuild adjacency
if (dataLoaded >= 1) {
rebuildDataStructures();
syncAllLinksBetweenExistingNodes();
updateGraph();
//initialize with the first available business object
if (graphNodes.length === 0 && rawData.length > 0) {
// Count occurrences of each business object (B)
const businessObjectCounts = rawData.reduce((acc, entry) => {
acc[entry.B] = (acc[entry.B] || 0) + 1;
return acc;
}, {});
// Find the business object with the highest occurrence
const mostFrequentB = Object.keys(businessObjectCounts).reduce((a, b) =>
businessObjectCounts[a] > businessObjectCounts[b] ? a : b
);
// Show the most frequently occurring business object
showBusinessObject(mostFrequentB);
}
document.getElementById("initial-upload-container").style.display = "none";
document.getElementById("main-content").style.display = "block";
}
};
reader.readAsText(file);
});
}
// This function is called after all files have been loaded into rawData
function rebuildDataStructures() {
// Rebuild adjacencyList from rawData
buildAdjacencyList();
// Rebuild 'allBusinessObjects' array
buildAllBusinessObjects();
// Rebuild the reverse adjacency to match
buildReverseAdjacencyList();
}
// adjacencyList functions
let adjacencyList = {};
function buildAdjacencyList() {
adjacencyList = {};
rawData.forEach(d => {
if (!adjacencyList[d.B]) {
adjacencyList[d.B] = [];
}
// Insert only if not already present:
const exists = adjacencyList[d.B].some(
(item) => item.target === d.R
);
if (!exists) {
adjacencyList[d.B].push({ target: d.R });
}
});
}
const reverseAdjacencyList = {};
// After normal adjacencyList is built, build the reverse adjacency list
function buildReverseAdjacencyList() {
// Clear it first
for (const key in reverseAdjacencyList) {
delete reverseAdjacencyList[key];
}
// and then populate
Object.keys(adjacencyList).forEach(src => {
adjacencyList[src].forEach(({ target }) => {
if (!reverseAdjacencyList[target]) {
reverseAdjacencyList[target] = [];
}
reverseAdjacencyList[target].push(src);
});
});
}
function buildReachableFromEndSet(end) {
// All nodes from which `end` is reachable
const canReachEnd = new Set();
const queue = [end];
canReachEnd.add(end);
while (queue.length) {
const current = queue.shift();
const neighbors = reverseAdjacencyList[current] || [];
for (const neighbor of neighbors) {
if (!canReachEnd.has(neighbor)) {
canReachEnd.add(neighbor);
queue.push(neighbor);
}
}
}
return canReachEnd;
}
// For reverse edges, only filter rawData for R === bo.
function getIncomingEdges(bo) {
return rawData.filter(d => d.R === bo);
}
/** All unique BOs for search suggestions */
let allBusinessObjects = [];
function buildAllBusinessObjects() {
const allBusinessObjectsSet = new Set();
rawData.forEach(d => {
allBusinessObjectsSet.add(d.B);
allBusinessObjectsSet.add(d.R);
});
allBusinessObjects = Array.from(allBusinessObjectsSet);
}
// Initialize adjacency + allBusinessObjects + reverse Adjacency from rawData
buildAdjacencyList();
buildAllBusinessObjects();
buildReverseAdjacencyList();
// Do this in updateDatalist whenever buildAllBusinessObjects is called
function updateDatalist() {
const dataList = document.getElementById('businessObjects');
dataList.innerHTML = '';
allBusinessObjects.forEach(bo => {
const option = document.createElement('option');
option.value = bo;
dataList.appendChild(option);
});
}
// Call it right away if allBusinessObjects is not empty
if (allBusinessObjects.length > 0) {
updateDatalist();
}
// Modify buildAllBusinessObjects to also call updateDatalist
const oldBuildAllBusinessObjects = buildAllBusinessObjects;
buildAllBusinessObjects = function () {
oldBuildAllBusinessObjects();
updateDatalist();
};
// Depth-limited DFS that enumerates ALL distinct paths from `start` to `end`, up to `maxDepth` edges. (So a path can have up to maxDepth+1 nodes.)
function findAllPathsDFS(start, end, maxDepth) {
if (!start || !end || maxDepth < 1) return [];
const results = [];
const resultsSet = new Set();
// Precompute which nodes can eventually reach `end`.
const canReachEnd = buildReachableFromEndSet(end);
function dfs(currentPath) {
const lastNode = currentPath[currentPath.length - 1];
const edgesUsed = currentPath.length - 1;
// If 'end' is found within the depth limit, record it
if (lastNode === end) {
const pathKey = currentPath.join("->");
if (!resultsSet.has(pathKey)) {
resultsSet.add(pathKey);
results.push([...currentPath]);
}
return;
}
// If depth is used up, stop
if (edgesUsed === maxDepth) {
return;
}
// Expand
const neighbors = adjacencyList[lastNode] || [];
for (const { target } of neighbors) {
// Prune #1: Must not revisit nodes in the same path
if (currentPath.includes(target)) continue;
// Prune #2: Must be in canReachEnd to have a shot at reaching `end`
if (!canReachEnd.has(target)) continue;
currentPath.push(target);
dfs(currentPath);
currentPath.pop();
}
}
// Kick off DFS
if (canReachEnd.has(start)) {
dfs([start]);
}
return results;
}
function plotPathOnChart(idx) {
const pathArray = foundPaths[idx];
if (!pathArray) return;
// Ensure all nodes in path are in graphNodes
pathArray.forEach(nodeId => {
if (!graphNodes.some(n => n.id === nodeId)) {
graphNodes.push({ id: nodeId });
}
});
// Rebuild links & update
syncAllLinksBetweenExistingNodes();
updateGraph();
/**
// Zoom/center to the first node
const firstNode = graphNodes.find(n => n.id === pathArray[0]);
if (firstNode) {
const t = d3.zoomIdentity
.translate(width / 2 - firstNode.x, height / 2 - firstNode.y)
.scale(1.0);
svg.transition().duration(750)
.call(zoomHandler.transform, t);
}
**/
// Show success message
const messageBox = document.getElementById("pathMessage");
messageBox.textContent = "Path plotted successfully.";
messageBox.style.display = "block";
messageBox.style.opacity = "1";
// Hide after 3 seconds
setTimeout(() => {
messageBox.style.opacity = "0";
setTimeout(() => {
messageBox.style.display = "none";
}, 500);
}, 3000);
}
function expandFieldsForBoPath(boPath) {
// start with the first BO
let expansions = [[boPath[0]]];
const uniqueExpansions = new Set();
for (let i = 0; i < boPath.length - 1; i++) {
const B = boPath[i];
const R = boPath[i + 1];
const possibleFields = rawData
.filter(d => d.B === B && d.R === R)
.map(d => d.F);
const fieldsUsed = (possibleFields.length > 0) ? possibleFields : ["???"];
const newExpansions = [];
expansions.forEach(partialPath => {
fieldsUsed.forEach(f => {
const copy = [...partialPath];
copy.push(f);
copy.push(R);
const pathString = copy.join(" -> ");
if (!uniqueExpansions.has(pathString)) {
uniqueExpansions.add(pathString);
newExpansions.push(copy);
}
});
});
expansions = newExpansions;
}
return expansions;
}
// Show the modal when user clicks the map button
const mapBtn = document.getElementById("mapBtn");
mapBtn.addEventListener("click", () => {
const mapModal = new bootstrap.Modal(document.getElementById('mapModal'));
mapModal.show();
});
let foundPaths = []; // store all BO paths
// On "Search" inside the modal, run DFS and display results
const mapSearchBtn = document.getElementById("mapSearchBtn");
const mapSearchResults = document.getElementById("mapSearchResults");
mapSearchBtn.addEventListener("click", () => {
mapSearchResults.innerHTML = '';
const startBO = document.getElementById("startBO").value.trim();
const endBO = document.getElementById("endBO").value.trim();
const depth = parseInt(document.getElementById("depthLevel").value, 10);
if (!startBO || !endBO || isNaN(depth)) {
mapSearchResults.innerHTML = `<div class="alert alert-warning">Please fill out all fields.</div>`;
return;
}
if (startBO === endBO) {
mapSearchResults.innerHTML = `<div class="alert alert-warning">Source and Target can't be the same.</div>`;
return;
}
// Run DFS
const paths = findAllPathsDFS(startBO, endBO, depth);
foundPaths = paths;
// Sort paths alphabetically and by number of elements
paths.sort((a, b) => {
const aStr = a.join(' → ');
const bStr = b.join(' → ');
return aStr.localeCompare(bStr);
});
paths.sort((a, b) => a.length - b.length);
if (paths.length === 0) {
mapSearchResults.innerHTML = `<div class="alert alert-info">No paths found for Depth <= ${depth}.</div>`;
return;
}
// Display each path as a separate line
let html = ``;
html = `
<table class="table table-bordered">
<tbody>
${paths.map((p, idx) => `
<tr>
<td style="vertical-align: middle;">${p.join(" → ")}</td>
<td style="vertical-align: middle;" class="text-end">
<div class="btn-group justify-content-end w-100" role="group" aria-label="Actions">
<button class="btn btn-sm btn-outline-primary me-2"
onclick="plotPathOnChart(${idx})" title="Plot this path on the graph">
Plot Path
</button>
<button class="btn btn-sm btn-outline-primary"
onclick="viewAllFieldCombinations(${idx})" title="View all field level paths">
Field Paths
</button>
</div>
</td>
</tr>
`).join('')}
</tbody>
</table>
`;
mapSearchResults.innerHTML = html;
});
function viewPathDetailsButtonClick(button) {
const path = decodeURIComponent(button.dataset.path);
viewPathDetails(path);
}
function viewAllFieldCombinations(idx) {
const boPath = foundPaths[idx];
if (!boPath) return;
const uniqueCombos = new Set();
const combos = expandFieldsForBoPath(boPath).filter(arr => {
const pathString = arr.join(" → ");
if (uniqueCombos.has(pathString)) {
return false;
} else {
uniqueCombos.add(pathString);
return true;
}
});
// Sort paths alphabetically
combos.sort((a, b) => {
const aStr = a.join(" → ");
const bStr = b.join(" → ");
return aStr.localeCompare(bStr);
});
let html = `
<table class="table table-bordered">
<tbody>
`;
combos.forEach((arr, comboIdx) => {
const pathString = arr.join(" → ");
const displayPathString = arr.map((item, index) => {
if (index % 2 === 1) {
return `<strong>${item}</strong>`;
} else {
return `${item}`;
}
}).join(" → ");
html += `
<tr>
<td style="vertical-align: middle;">${displayPathString}</td>
<td style="vertical-align: middle;" class="text-end">
<div class="btn-group justify-content-end w-100" role="group" aria-label="Actions">
<button class="btn btn-sm btn-outline-primary" data-path="${encodeURIComponent(pathString)}" onclick="viewPathDetailsButtonClick(this)">
Calculated Fields
</button>
</div>
</td>
</tr>
`;
});
html += `</tbody></table>`;
document.getElementById("allFieldCombosContainer").innerHTML = html;
const fieldModal = new bootstrap.Modal(document.getElementById("allFieldCombinationsModal"));
fieldModal.show();
}
function viewPathDetails(pathString) {
// Split the path string back into an array
const pathArray = pathString.split(" → ");
// Calc fields, let's list each step with additional details
function lrvesiCalcFields() {
let detailedHtml = "";
if (pathArray.length > 1) {
detailedHtml = "<table class='table table-hover table-sm table-borderless small'><tr><td colspan='2'><b>Start</b></tr></td>";
let currentField = pathArray[1];
let returnField;
for (let i = 0; i < (pathArray.length - 1) / 2; i++) {
returnField = pathArray[(i * 2) + 3];
if (returnField == undefined) {
returnField = "<i>{Name of your Return Field from '" + pathArray[(i * 2) + 2] + "' BO}</i>";
}
if (currentField.indexOf('(Multi-instance)') > 0) {
detailedHtml = detailedHtml +
"<tr><td colspan='2' style='border: none;'><hr style='border-top: 1px solid grey;'></td></tr>" + "<tr><td>" + "<b>Full Name</b>" + "</td><td>" + "CF_ESI " + currentField.replace('CF_LRV ', '') + "</tr></td>" +
"<tr><td>" + "<b>Business Object</b> " + "</td><td>" + pathArray[0] + "</tr></td>" +
"<tr><td>" + "<b>Function</b>" + "</td><td>" + "Extract Single Instance" + "</tr></td>" +
"<tr><td>" + "<b>Source Field</b>" + "</td><td>" + currentField + "</tr></td>" +
"<tr><td>" + "<b>Related Business Object</b>" + "</td><td>" + pathArray[(i * 2) + 2] + "</tr></td>" +
"<tr><td>" + "<b>Condition</b>" + "</td><td>" + "<i>Use an existing condition or create a condition on '" + pathArray[(i * 2) + 2] + "' BO</i>" + "</tr></td>" +
"<tr><td>" + "<b>Sort Field, Sort Direction</b>" + "</td><td>" + "<i>Enter Sort Field, Sort Direction</i>" + "</tr></td>" +
"<tr><td>" + "<b>Instance to be Returned</b>" + "</td><td>" + "<i>Select First occurrence/Last occurrence/Specific occurrence</i>" + "</tr></td>";
currentField = "CF_ESI " + currentField.replace('CF_LRV ', '');
}
detailedHtml = detailedHtml +
"<tr><td colspan='2' style='border: none;'><hr style='border-top: 1px solid grey;'></td></tr>" + "<tr><td>" + "<b>Full Name</b>" + "</td><td>" + "CF_LRV " + returnField + "</tr></td>" +
"<tr><td>" + "<b>Business Object</b>" + "</td><td>" + pathArray[0] + "</tr></td>" +
"<tr><td>" + "<b>Function</b>" + "</td><td>" + "Lookup Related Value" + "</tr></td>" +
"<tr><td>" + "<b>Lookup Field</b>" + "</td><td>" + currentField + "</tr></td>" +
"<tr><td>" + "<b>Related Business Object</b>" + "</td><td>" + pathArray[(i * 2) + 2] + "</tr></td>" +
"<tr><td>" + "<b>Return Value</b>" + "</td><td>" + returnField + "</tr></td>";
currentField = "CF_LRV " + returnField;
}
detailedHtml = detailedHtml + "<tr><td colspan='2' style='border: none;'><hr style='border-top: 1px solid grey;'></td><tr><td colspan='2'><b>End</b></table></tr></td>";
detailedHtml = detailedHtml.replace(/\(Multi-instance\)|\(Single instance\)|\(Self referencing instance\)/g, '');
document.getElementById("lrvesiDiv").innerHTML = detailedHtml;
}
}
function ariCalcFields() {
let detailedHtml = "";
if (pathArray.length > 1) {
detailedHtml = "<table class='table table-hover table-sm table-borderless small'><tr><td colspan='2'><b>Start</b></tr></td>";
let currentField = pathArray[1];
let returnField;
for (let i = 0; i < (pathArray.length - 1) / 2; i++) {
returnField = pathArray[(i * 2) + 3];
if (returnField == undefined) {
returnField = "<i>{Name of your Return Field from '" + pathArray[(i * 2) + 2] + "' BO}</i>";
}
detailedHtml = detailedHtml +
"<tr><td colspan='2' style='border: none;'><hr style='border-top: 1px solid grey;'></td></tr>" + "<tr><td>" + "<b>Full Name</b>" + "</td><td>" + "CF_ARI " + returnField + "</tr></td>" +
"<tr><td>" + "<b>Business Object</b>" + "</td><td>" + pathArray[0] + "</tr></td>" +
"<tr><td>" + "<b>Function</b>" + "</td><td>" + "Aggregate Related Instances" + "</tr></td>" +
"<tr><td>" + "<b>Source Field</b>" + "</td><td>" + currentField + "</tr></td>" +
"<tr><td>" + "<b>Related Business Object</b>" + "</td><td>" + pathArray[(i * 2) + 2] + "</tr></td>" +
"<tr><td>" + "<b>Condition</b>" + "</td><td>" + "<i>Use an existing condition or create a condition on '" + pathArray[(i * 2) + 2] + "' BO</i>" + "</tr></td>" +
"<tr><td>" + "<b>Fields To Aggregate</b>" + "</td><td>" + returnField + "</tr></td>";
currentField = "CF_ARI " + returnField;
}
detailedHtml = detailedHtml + "<tr><td colspan='2' style='border: none;'><hr style='border-top: 1px solid grey;'></td><tr><td colspan='2'><b>End</b></table></tr></td>";
detailedHtml = detailedHtml.replace(/\(Multi-instance\)|\(Single instance\)|\(Self referencing instance\)/g, '');
document.getElementById("ariDiv").innerHTML = detailedHtml;
}
}
lrvesiCalcFields()
ariCalcFields()
const radioButtons = document.querySelectorAll('input[name="calcFieldsRadio"]');
radioButtons.forEach((radioButton) => {
radioButton.addEventListener('change', (e) => {
const selectedValue = e.target.value;
if (selectedValue === "LRV + ESI") {
document.getElementById("lrvesiDiv").style.display = "block";
document.getElementById("ariDiv").style.display = "none";
} else if (selectedValue === "ARI") {
document.getElementById("lrvesiDiv").style.display = "none";
document.getElementById("ariDiv").style.display = "block";
}
});
});
const detailModal = new bootstrap.Modal(document.getElementById("pathDetailModal"));
detailModal.show();
}
const width = window.innerWidth;
const height = window.innerHeight;
const svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height);
/** Container group for zoom/pan */
const container = svg.append("g").attr("class", "container");
// Sub-groups: links, nodes, labels
const linkGroup = container.append("g").attr("class", "links");
const nodeGroup = container.append("g").attr("class", "nodes");
const labelGroup = container.append("g").attr("class", "labels");
/** Arrow marker definition */
svg.append("defs").append("marker")
.attr("id", "arrow")
.attr("viewBox", "0 -5 10 10")
.attr("refX", 11)
.attr("refY", 0)
.attr("markerWidth", 9)
.attr("markerHeight", 8)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-3L6,0L0,3")
.attr("fill", "#999");