-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy.vue
755 lines (730 loc) · 31.8 KB
/
copy.vue
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
<template>
<div id="app">
<div class="menu">
Current Supported Skema Version:
<span style="white-space:pre; color: tomato; font-weight: bold;">0.1.7 </span>
<select v-model="selectedOption" @change="fetchData" class="my-select" placeholder="Select">
<option v-for="option in options" :value="option.value" :key="option.value">
{{ option.text }}
</option>
</select>
<input type="text" v-model="url" class="url-input"
placeholder="Input URL of JSON file here."/>
<!-- <button @click="changeSvgContent">Draw</button> -->
<button @click="submitUrl">Submit</button>
<input
type="file"
ref="fileInput"
@change="handleFileChange"
style="display: none;"
/>
<button
:style="{ margin: '0 30px', backgroundColor: 'tomato', color: 'white', border: 'none' }"
class="btn btn-primary" @click="triggerFileInput">
Choose File
</button>
<button class="btn btn-primary download-button" @click="downloadSVG" >downloadSVG</button>
<button
:style="{ margin: '0 30px', backgroundColor: 'green', color: 'white', border: 'none' }"
class="btn btn-primary" @click="showPreviousBox">
Previous Box
</button>
<!-- <button
:style="{ margin: '0 30px', backgroundColor: 'purple', color: 'white', border: 'none' }"
class="btn btn-primary" @click="toggleDraggable">Toggle Draggable
</button> -->
</div>
<div class="content">
<div class="editor-box">
<!-- <textarea v-model="inputText" placeholder="Input Gromet JSON here..."
@input="validateJson">
</textarea> -->
<!-- <p v-if="!isValidJson" class="error">Invalid JSON format!</p> -->
<!-- <pre contenteditable="true"
v-html="highlightedJson" ref="jsonEditor"></pre> -->
<label for="deep-select">Select Display Depth: </label>
<select id="deep-select" v-model="selectedDeep">
<option v-for="num in possibleDepths" :key="num" :value="num">
{{ num }}
</option>
</select>
<!-- -->
<!-- <button @click="isExpandClicked = !isExpandClicked">Select Node to View</button> -->
<vue-json-pretty
:data="highlightedJson"
:editable="true"
:highlight-array="highlightNode"
:deep="selectedDeep"
@click.native="jsonClick">
</vue-json-pretty>
</div>
<div class="svg-container">
<div id="tooltip" class="tooltip" style="opacity: 0;"></div>
<!-- <svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" :fill="svgColor"/>
</svg> -->
<label for="startingFN">Initial #(Entry): </label>
<input v-model="startingFN" @keyup.enter="drawMoviz">
<svg id="mainsvg" width="1200" height="1000" overflow="visible" ref="svgMoviz">
<g id="sumGroup"></g>
</svg>
</div>
</div>
</div>
</template>
<script>
/* eslint-disable */
import * as d3 from 'd3';
import axios from 'axios';
import VueJsonPretty from 'vue-json-pretty-highlight-row';
import 'vue-json-pretty-highlight-row/lib/styles.css';
import { getBoxLayout } from './utils/layout';
import { drawBox } from './utils/drawBox';
import { setGromet } from './utils/global.js';
// import Vue from 'vue';
// Vue.prototype.$gromet = { data: null };
export default {
name: 'App',
components: {
VueJsonPretty,
},
data() {
return {
skemaVersion: '',
url: '',
selectedDeep: 3,
possibleDepths: [1, 2, 3, 4, 5, 6, 7],
startingFN: 0,
blockStyle: {
backgroundColor: 'rgba(255, 255, 120, 0)',
height: '90vh',
width: '100%',
},
selectedFile: null,
selectedOption: null,
gromet: null,
path: 'res',
highlightedJson: null,
selectedNode: null,
// selectedBoxIdNum:null,
highlightNode: null,
routePair: {0:"0"},
routePairC: {0:"0"},
boxTypePair: {},
options: [
{ text: 'Clay1', value: 'https://raw.githubusercontent.com/hconhisway/webcrawler/master/get_beta--Gromet-FN-auto2.json' },
{ text: 'core_dynamics', value: 'https://raw.githubusercontent.com/hconhisway/webcrawler/master/core_dynamics_pack2.json' },
{ text: 'while1', value: 'https://raw.githubusercontent.com/ml4ai/skema/adarshp/nom_error_handling/data/gromet/python/while1/FN_0.1.6/while1--Gromet-FN-auto.json' },
{ text: 'cond1', value: 'https://raw.githubusercontent.com/ml4ai/skema/adarshp/nom_error_handling/data/gromet/python/cond1/FN_0.1.6/cond1--Gromet-FN-auto.json' },
{ text: 'fun1', value: 'https://raw.githubusercontent.com/ml4ai/skema/main/data/gromet/python/fun1/FN_0.1.6/fun1--Gromet-FN-auto.json' },
{ text: 'fun4', value: 'https://raw.githubusercontent.com/ml4ai/skema/adarshp/nom_error_handling/data/gromet/python/fun4/FN_0.1.6/fun4--Gromet-FN-auto.json' },
{ text: 'exp1', value: 'https://raw.githubusercontent.com/ml4ai/skema/main/data/gromet/python/exp1/FN_0.1.6/exp1--Gromet-FN-auto.json' },
{ text: 'exp2', value: 'https://gist.githubusercontent.com/jastier/76f7566ac44265707d892a252d8f85ab/raw/2be498c5fb369635725e9e6b493732a5c181ac65/first_matlab.json' },
{ text: 'exp3', value: 'https://raw.githubusercontent.com/ml4ai/skema/main/data/gromet/python/exp3/FN_0.1.6/exp3--Gromet-FN-auto.json' },
{ text: 'fun_default1', value: 'https://raw.githubusercontent.com/ml4ai/skema/adarshp/nom_error_handling/data/gromet/python/fun_default1/FN_0.1.6/fun_default1--Gromet-FN-auto.json' },
{ text: 'assign_operator1', value: 'https://raw.githubusercontent.com/ml4ai/skema/main/data/gromet/python/assign_operator1/FN_0.1.6/assign_operator1--Gromet-FN-auto.json' },
],
};
},
mounted() {
this.$refs.svgMoviz.addEventListener('mouseover', this.handleMouseOverDelegate);
},
beforeDestroy() {
this.$refs.svgMoviz.removeEventListener('mouseover', this.handleMouseOverDelegate);
},
async created() {
const grometUrl = this.$route.query.gromet_url;
if (grometUrl) {
try {
const response = await axios.get(grometUrl);
this.gromet = response.data;
this.skemaVersion = this.gromet.schema_version;
this.processJson();
this.drawMoviz();
} catch (error) {
console.error(error);
}
}
},
methods: {
drawMoviz() {
d3.selectAll('g').remove();
function handleZoom(e) {
d3.select('svg g')
.attr('transform', e.transform);
}
const svg = d3.select('svg');
svg.append('g').attr('id', 'sumGroup');
const zoom = d3.zoom()
.on('zoom', handleZoom);
svg.call(zoom);
const graphData = this.gromet.modules[0];
setGromet(graphData);
const fn0 = graphData.fn;
const fnS = graphData.fn_array;
let currentFN = fn0;
console.log(this.routePair)
if (this.startingFN !== 0){
let prefix = "--- Click <HERE> to visualize this FN --- ";
let numbersString = fnS[this.startingFN-1].hi_there.replace(prefix, "").trim();
let trimmedNum = numbersString.replace(/^['"]+|['"]+$/g, '');
let routeNumbers = trimmedNum.split('-').map(Number);
let altRouteNumbers = this.routePair[trimmedNum].split('-').map(Number);
let currentBox = "0";
const layout = getBoxLayout(currentFN);
drawBox(layout, fnS, 0);
for (let i=0;i<routeNumbers.length;i++) {
if (i===0) {
continue;
} else {
let boxId = "boxid" + currentBox;
const nodeId = "bf-" + String(routeNumbers[i]);
this.triggerClickEvent(boxId, nodeId);
currentBox = currentBox + "-" + String(altRouteNumbers[i]);
}
}
const target = d3.select('#mainsvg').select("#sumGroup").select("#boxid"+currentBox).select("#frame"+currentBox);
const svgContainer = d3.select('#mainsvg');
svgContainer.selectAll("#highlightRect").remove();
this.selectedNode = altRouteNumbers[altRouteNumbers.length - 1];
if (this.selectedNode === 0 || this.selectedNode === '0') {
this.highlightNode = ['res.fn'];
} else {
this.highlightNode = [`res.fn_array[${this.selectedNode - 1}]`];
}
if (this.selectedNode !== null) {
const increasedWidth = Number(target.attr("width")) + 7;
const increasedHeight = Number(target.attr("height")) + 7;
const parentD3Selection = d3.select('#mainsvg').select("#boxid"+currentBox);
const rectSelection = parentD3Selection.append('rect');
rectSelection
.attr('id', 'highlightRect')
.attr('x', Number(target.attr("x")) - 3.5)
.attr('y', Number(target.attr("y")) - 3.5)
.attr('rx', 5)
.attr('ry', 5)
.attr('width', increasedWidth)
.attr('height', increasedHeight)
.style("fill", "none")
.style("stroke", "red")
.style("stroke-width", 38)
.style("stroke-opacity", 0.2);
}
const selectedBoxId = "boxid" + this.routePair[trimmedNum];
d3.select("#sumGroup").selectChildren().each(function() {
if (this.id !== selectedBoxId) {
d3.select(this).style('display', 'none');
}
})
// console.log(trimmedNum2)
// const layout = getBoxLayout(currentFN);
// drawBox(layout, fnS, this.routePair[trimmedNum]);
} else {
const layout = getBoxLayout(currentFN);
drawBox(layout, fnS, 0);
}
// console.log(graphData)
// const layout = getBoxLayout(currentFN);
// drawBox(layout, fnS, 0);
// test
// drawBox(getBoxLayout(fnS[104]), fnS, 0);
// console.log(fnS[104]);
},
processJson() {
this.highlightedJson = this.gromet.modules[0];
this.highlightedJson.fn = {
hi_there: "--- Click <HERE> to visualize this FN --- 0",
...this.highlightedJson.fn
};
this.getAllChildBody(this.highlightedJson.fn, "0", "0");
for (let i=0; i<this.highlightedJson.metadata_collection.length;i++) {
const currentNum = i+1;
this.highlightedJson.metadata_collection[i] = {
// num: "#" + currentNum,
...this.highlightedJson.metadata_collection[i]
};
if (this.highlightedJson.metadata_collection[i].hasOwnProperty("0")) {
delete this.highlightedJson.metadata_collection[i]["0"].metadata_type;
delete this.highlightedJson.metadata_collection[i]["0"].source_language;
delete this.highlightedJson.metadata_collection[i]["0"].source_language_version;
delete this.highlightedJson.metadata_collection[i]["0"].data_type;
delete this.highlightedJson.metadata_collection[i]["0"].provenance;
delete this.highlightedJson.metadata_collection[i]["0"].col_begin;
delete this.highlightedJson.metadata_collection[i]["0"].col_end;
delete this.highlightedJson.metadata_collection[i]["0"].code_file_reference_uid;
}
if (this.highlightedJson.metadata_collection[i].hasOwnProperty("1")) {
delete this.highlightedJson.metadata_collection[i]["1"].metadata_type;
delete this.highlightedJson.metadata_collection[i]["1"].source_language;
delete this.highlightedJson.metadata_collection[i]["1"].source_language_version;
delete this.highlightedJson.metadata_collection[i]["1"].data_type;
delete this.highlightedJson.metadata_collection[i]["1"].provenance;
delete this.highlightedJson.metadata_collection[i]["1"].col_begin;
delete this.highlightedJson.metadata_collection[i]["1"].col_end;
delete this.highlightedJson.metadata_collection[i]["1"].code_file_reference_uid;
}
if (this.highlightedJson.metadata_collection[i].hasOwnProperty("2")) {
delete this.highlightedJson.metadata_collection[i]["2"].metadata_type;
delete this.highlightedJson.metadata_collection[i]["2"].source_language;
delete this.highlightedJson.metadata_collection[i]["2"].source_language_version;
delete this.highlightedJson.metadata_collection[i]["2"].data_type;
delete this.highlightedJson.metadata_collection[i]["2"].provenance;
delete this.highlightedJson.metadata_collection[i]["2"].col_begin;
delete this.highlightedJson.metadata_collection[i]["2"].col_end;
delete this.highlightedJson.metadata_collection[i]["2"].code_file_reference_uid;
}
}
// delete this.highlightedJson.metadata_collection;
// delete this.highlightedJson.metadata;
// for (let i=0; i<this.highlightedJson.metadata_collection.length;i++) {
// }
for (let i=0; i<this.highlightedJson.fn_array.length;i++) {
const currentEntry = i+1;
this.highlightedJson.fn_array[i] = {
body_num: currentEntry,
...this.highlightedJson.fn_array[i]
};
}
},
getAllChildBody(objJson, currentRoute, altRoute) {
if ("bf" in objJson) {
for (let i=0; i<objJson.bf.length; i++) {
if ("body" in objJson.bf[i]) {
let currentNodeNum = objJson.bf[i].body - 1;
let newRoute = currentRoute + `-${currentNodeNum + 1}`;
let newAltRoute = altRoute + `-${i}`
const clickPrompt = "--- Click <HERE> to visualize this FN --- " + newAltRoute;
this.routePair[newAltRoute] = newRoute;
this.highlightedJson.fn_array[currentNodeNum] = {
hi_there: clickPrompt,
...this.highlightedJson.fn_array[currentNodeNum]
};
this.getAllChildBody(this.highlightedJson.fn_array[currentNodeNum], newRoute, newAltRoute);
}
}
}
// if ("bc" in objJson) {
// for (let i=0; i<objJson.bc.length; i++) {
// if ("body_if" in objJson.bc[i]) {
// let currentNodeNum = objJson.bc[i].body_if - 1;
// let newRoute = currentRoute + `-${currentNodeNum + 1}`;
// let newAltRoute = altRoute + `-${i}`;
// console.log(newAltRoute);
// const clickPrompt = "--- Click <HERE> to visualize this FN --- " + newAltRoute;
// // this.routePairC[newAltRoute] = newRoute;
// this.highlightedJson.fn_array[currentNodeNum] = {
// hi_there: clickPrompt,
// ...this.highlightedJson.fn_array[currentNodeNum]
// };
// this.getAllChildBody(this.highlightedJson.fn_array[currentNodeNum], newRoute, newAltRoute);
// }
// if ("body_else" in objJson.bc[i]) {
// let currentNodeNum = objJson.bc[i].body_else - 1;
// let newRoute = currentRoute + `-${currentNodeNum + 1}`;
// let newAltRoute = altRoute + `-${i}`;
// const clickPrompt = "--- Click <HERE> to visualize this FN --- " + newAltRoute;
// // this.routePairC[newAltRoute] = newRoute;
// this.highlightedJson.fn_array[currentNodeNum] = {
// hi_there: clickPrompt,
// ...this.highlightedJson.fn_array[currentNodeNum]
// };
// this.getAllChildBody(this.highlightedJson.fn_array[currentNodeNum], newRoute, newAltRoute);
// }
// if ("condition" in objJson.bc[i]) {
// let currentNodeNum = objJson.bc[i].condition - 1;
// let newRoute = currentRoute + `-${currentNodeNum + 1}`;
// let newAltRoute = altRoute + `-${i}`;
// const clickPrompt = "--- Click <HERE> to visualize this FN --- " + newAltRoute;
// this.routePairC[newAltRoute] = newRoute;
// this.highlightedJson.fn_array[currentNodeNum] = {
// hi_there: clickPrompt,
// ...this.highlightedJson.fn_array[currentNodeNum]
// };
// this.getAllChildBody(this.highlightedJson.fn_array[currentNodeNum], newRoute, newAltRoute);
// }
// }
// }
},
async fetchData() {
try {
const response = await axios.get(this.selectedOption);
this.gromet = response.data;
this.skemaVersion = this.gromet.schema_version;
this.processJson();
this.drawMoviz();
} catch (error) {
// eslint-disable-next-line
console.error(error);
}
},
triggerFileInput() {
this.$refs.fileInput.click();
},
handleFileChange(event) {
this.selectedFile = event.target.files[0];
if (this.selectedFile) {
const reader = new FileReader();
reader.onload = (e) => {
try {
this.gromet = JSON.parse(e.target.result);
this.skemaVersion = this.gromet.schema_version;
this.processJson();
this.drawMoviz();
} catch (error) {
// eslint-disable-next-line
console.error('Error parsing JSON:', error);
}
};
reader.readAsText(this.selectedFile); // 读取文件内容为文本
}
},
// handleMouseOver(event) {
// if (event.target.tagName === 'g' && event.target.id.startsWith('boxid')) {
// const parts = event.target.id.split('-');
// const lastPart = parts.pop();
// const numberMatch = lastPart.match(/\d+$/); // Matches the last number in a string
// if (numberMatch) {
// this.selectedNode = numberMatch[0];
// } else {
// this.selectedNode = null;
// }
// }
// },
handleMouseOverDelegate(event) {
const target = event.target;
if (target.id && target.id.startsWith('frame')) {
const parts = target.id.split('-');
const lastPart = parts.pop();
const numberMatch = lastPart.match(/\d+$/);
const svgContainer = d3.select('#mainsvg');
svgContainer.selectAll("#highlightRect").remove();
if (numberMatch) {
this.selectedNode = numberMatch[0];
} else {
this.selectedNode = null;
}
if (this.selectedNode === 0 || this.selectedNode === '0') {
this.highlightNode = ['res.fn'];
} else {
this.highlightNode = [`res.fn_array[${this.selectedNode - 1}]`];
}
if (this.selectedNode !== null) {
const increasedWidth = target.width.baseVal.value + 7;
const increasedHeight = target.height.baseVal.value + 7;
const parentD3Selection = d3.select(target.parentNode);
const rectSelection = parentD3Selection.append('rect');
rectSelection
.attr('id', 'highlightRect')
.attr('x', target.x.baseVal.value - 3.5)
.attr('y', target.y.baseVal.value - 3.5)
.attr('rx', 5)
.attr('ry', 5)
.attr('width', increasedWidth)
.attr('height', increasedHeight)
.style("fill", "none")
.style("stroke", "red")
.style("stroke-width", 38)
.style("stroke-opacity", 0.2);
// Add event listener to remove the rectangle on mouseout using D3
// d3.select(target).on('mouseout', () => {
// parentD3Selection.select('#highlightRect').remove();
// });
}
}
if (event.target.id !== "mainsvg") {
// 查找或创建floating-tag div
let floatingTag = document.getElementById("floating-tag");
if (!floatingTag) {
floatingTag = document.createElement("div");
floatingTag.id = "floating-tag";
document.body.appendChild(floatingTag);
}
// 设置floating-tag div的样式
floatingTag.style.position = "absolute";
floatingTag.style.zIndex = "10000"; // 高z-index确保不被遮挡
floatingTag.style.background = "white"; // 白色背景
floatingTag.style.padding = "2px 8px";
floatingTag.style.borderRadius = "4px";
floatingTag.innerHTML = `<span style="color: blue;">${event.target.tagName}</span>#<span style="color: red;">${event.target.id}</span>`;
floatingTag.style.boxShadow = "0 0 7px -2px #0000008f";
floatingTag.style.fontWeight = "bold";
// 获取元素的相对视口的位置
const rect = event.target.getBoundingClientRect();
// 计算元素的绝对位置
const absoluteX = rect.left + window.scrollX;
const absoluteY = rect.top + window.scrollY;
// 调整floating-tag的位置
floatingTag.style.left = `${absoluteX}px`;
floatingTag.style.top = `${absoluteY - 36}px`;
}
if (target.id && this.highlightNode && this.highlightNode.length) {
if (this.selectedNode === 0 || this.selectedNode === "0") {
this.highlightNode = ["res.fn"];
} else {
this.highlightNode = [`res.fn_array[${this.selectedNode - 1}]`];
}
this.highlightNode = [
this.highlightNode[0],
`${this.highlightNode[0]}.${target.id.split("-")[0]}`
];
}
},
jsonClick() {
let spanText = event.target.textContent;
let prefix = "--- Click <HERE> to visualize this FN --- ";
if (spanText.startsWith('\"--- Click <HERE> to visualize this FN ---')) {
if (Object.keys(this.routePair).length>1){
let numbersString = spanText.replace(prefix, "").trim();
let trimmedNum = numbersString.replace(/^['"]+|['"]+$/g, '');
let routeNumbers = trimmedNum.split('-').map(Number);
let altRouteNumbers = this.routePair[trimmedNum].split('-').map(Number);
let currentBox = "0";
for (let i=0;i<routeNumbers.length;i++) {
if (i===0) {
continue;
} else {
let boxId = "boxid" + currentBox;
const nodeId = "bf-" + String(routeNumbers[i]);
this.triggerClickEvent(boxId, nodeId);
currentBox = currentBox + "-" + String(altRouteNumbers[i]);
}
}
const target = d3.select('#mainsvg').select("#sumGroup").select("#boxid"+currentBox).select("#frame"+currentBox);
const svgContainer = d3.select('#mainsvg');
svgContainer.selectAll("#highlightRect").remove();
this.selectedNode = altRouteNumbers[altRouteNumbers.length - 1];
if (this.selectedNode === 0 || this.selectedNode === '0') {
this.highlightNode = ['res.fn'];
} else {
this.highlightNode = [`res.fn_array[${this.selectedNode - 1}]`];
}
if (this.selectedNode !== null) {
const increasedWidth = Number(target.attr("width")) + 7;
const increasedHeight = Number(target.attr("height")) + 7;
const parentD3Selection = d3.select('#mainsvg').select("#boxid"+currentBox);
const rectSelection = parentD3Selection.append('rect');
rectSelection
.attr('id', 'highlightRect')
.attr('x', Number(target.attr("x")) - 3.5)
.attr('y', Number(target.attr("y")) - 3.5)
.attr('rx', 5)
.attr('ry', 5)
.attr('width', increasedWidth)
.attr('height', increasedHeight)
.style("fill", "none")
.style("stroke", "red")
.style("stroke-width", 38)
.style("stroke-opacity", 0.2);
// Add event listener to remove the rectangle on mouseout using D3
// d3.select(target).on('mouseout', () => {
// parentD3Selection.select('#highlightRect').remove();
// });
}
}
// if (Object.keys(this.routePair).length>1) {
// let numbersString = spanText.replace(prefix, "").trim();
// let trimmedNum = numbersString.replace(/^['"]+|['"]+$/g, '');
// let routeNumbers = trimmedNum.split('-').map(Number);
// let altRouteNumbers = this.routePairC[trimmedNum].split('-').map(Number);
// let currentBox = "0";
// for (let i=0;i<routeNumbers.length;i++) {
// if (i===0) {
// continue;
// } else {
// let boxId = "boxid" + currentBox;
// const nodeId = "bc-" + String(routeNumbers[i]);
// this.triggerClickEvent(boxId, nodeId);
// currentBox = currentBox + "-" + String(altRouteNumbers[i]);
// }
// }
// const target = d3.select('#mainsvg').select("#sumGroup").select("#boxid"+currentBox).select("#frame"+currentBox);
// const svgContainer = d3.select('#mainsvg');
// svgContainer.selectAll("#highlightRect").remove();
// this.selectedNode = altRouteNumbers[altRouteNumbers.length - 1];
// if (this.selectedNode === 0 || this.selectedNode === '0') {
// this.highlightNode = ['res.fn'];
// } else {
// this.highlightNode = [`res.fn_array[${this.selectedNode - 1}]`];
// }
// if (this.selectedNode !== null) {
// const increasedWidth = Number(target.attr("width")) + 7;
// const increasedHeight = Number(target.attr("height")) + 7;
// const parentD3Selection = d3.select('#mainsvg').select("#boxid"+currentBox);
// const rectSelection = parentD3Selection.append('rect');
// rectSelection
// .attr('id', 'highlightRect')
// .attr('x', Number(target.attr("x")) - 3.5)
// .attr('y', Number(target.attr("y")) - 3.5)
// .attr('rx', 5)
// .attr('ry', 5)
// .attr('width', increasedWidth)
// .attr('height', increasedHeight)
// .style("fill", "none")
// .style("stroke", "red")
// .style("stroke-width", 38)
// .style("stroke-opacity", 0.2);
// }
// }
}
},
triggerClickEvent(boxId, nodeId) {
const element = d3.select("#sumGroup").select("#" + boxId).select("#" + nodeId);
if (element && element.attr("data-clicked") === "false") {
element.dispatch('click');
}
},
downloadSVG() {
const svgElement = document.getElementById('mainsvg');
const svgData = new XMLSerializer().serializeToString(svgElement);
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
const svgUrl = URL.createObjectURL(svgBlob);
const downloadLink = document.createElement('a');
downloadLink.href = svgUrl;
downloadLink.download = 'mainsvg.svg';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
},
showPreviousBox() {
if(this.selectedNode !== null && this.selectedNode !== 0 && this.selectedNode !== 1) {
let prefix = "--- Click <HERE> to visualize this FN --- ";
let numbersString = this.gromet.modules[0].fn_array[this.selectedNode-1].hi_there.replace(prefix, "").trim();
let trimmedNum = this.routePair[numbersString.replace(/^['"]+|['"]+$/g, '')];
let partsNum = trimmedNum.split('-');
partsNum.pop();
let newTrimmedNum = partsNum.join('-');
let selectedBoxId = "boxid" + trimmedNum;
let PreSelectedBoxId = "boxid" + newTrimmedNum;
let selectedLineId = "line" + newTrimmedNum + "_" + trimmedNum;
console.log(selectedLineId)
d3.select("#sumGroup").selectChildren().each(function() {
if (this.id === PreSelectedBoxId) {
d3.select(this).style('display', null);
} else if (this.id === selectedLineId) {
d3.select(this).style('display', null);
}
})
} else if (this.selectedNode === 1) {
let prefix = "--- Click <HERE> to visualize this FN --- ";
let numbersString = this.gromet.modules[0].fn.hi_there.replace(prefix, "").trim();
let trimmedNum = this.routePair[numbersString.replace(/^['"]+|['"]+$/g, '')];
let partsNum = trimmedNum.split('-');
partsNum.pop();
let newTrimmedNum = partsNum.join('-');
let selectedBoxId = "boxid" + trimmedNum;
let PreSelectedBoxId = "boxid" + newTrimmedNum;
let selectedLineId = "line" + newTrimmedNum + "_" + trimmedNum;
console.log(selectedLineId)
d3.select("#sumGroup").selectChildren().each(function() {
if (this.id === PreSelectedBoxId) {
d3.select(this).style('display', null);
} else if (this.id === selectedLineId) {
d3.select(this).style('display', null);
}
})
}
},
async submitUrl() {
try {
const response = await axios.get(this.url);
this.gromet = response.data;
this.skemaVersion = this.gromet.schema_version;
this.processJson();
this.drawMoviz();
} catch (error) {
// eslint-disable-next-line
console.error(error);
}
},
},
};
</script>
<style scoped>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.menu {
margin-bottom: 20px;
}
.content {
display: flex;
justify-content: space-around;
height: 90vh;
}
.editor-box {
border: 5px solid #4b4a4a;
padding: 20px;
margin: 10px;
width: 35%;
border-radius: 10px;
height: 80vh;
/* overflow: hidden; */
overflow: auto;
text-align: left;
}
.svg-container {
border: 5px solid #4b4a4a;
padding: 20px;
margin: 10px;
width: 60%;
border-radius: 10px;
height: 80vh;
overflow: hidden;
position: relative;
}
.error {
color: red;
margin-top: 10px;
}
.my-select {
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid #ccc;
margin-right: 20px;
}
.url-input {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
width: 400px;
overflow-x: auto;
margin-left: 20px;
}
pre {
overflow-x: auto;
overflow-y: auto;
height: 100%;
width: 100%;
white-space: nowrap;
}
.svg-container input {
position: absolute; /* input使用绝对定位 */
top: 10px; /* 定位到顶部 */
left: 140px; /* 定位到左侧 */
}
.svg-container label {
font-weight: bold;
position: absolute; /* input使用绝对定位 */
top: 14px; /* 定位到顶部 */
left: 20px; /* 定位到左侧 */
}
span {
text-align: left !important;
}
.tooltip {
position: absolute;
text-align: left;
width: auto;
height: auto;
padding: 5px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none; /* 确保用户可以与下面的元素交互 */
}
</style>