-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
88 lines (79 loc) · 2.58 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', function() {
const cy1 = createCytoscape('cy1');
const cy2 = createCytoscape('cy2');
document.getElementById('check-homeomorphism').addEventListener('click', function() {
const result = checkHomeomorphism(cy1, cy2);
document.getElementById('result').textContent = result ?
"The graphs are homeomorphic!" :
"The graphs are not homeomorphic.";
});
});
function createCytoscape(containerId) {
return cytoscape({
container: document.getElementById(containerId),
style: [
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle',
'curve-style': 'bezier'
}
}
],
layout: {
name: 'grid',
rows: 1
}
});
}
function setupCytoscapeInteractions(cy) {
let nodeId = 0;
let sourceNode = null;
cy.on('tap', function(event) {
if (event.target === cy) {
const position = event.position;
cy.add({
group: 'nodes',
data: { id: 'n' + nodeId++ },
position: position
});
}
});
cy.on('cxttap', 'node', function(event) {
cy.remove(event.target);
});
cy.on('mousedown', 'node', function(event) {
sourceNode = event.target;
});
cy.on('mouseup', 'node', function(event) {
if (sourceNode && sourceNode !== event.target) {
cy.add({
group: 'edges',
data: {
id: 'e' + sourceNode.id() + '-' + event.target.id(),
source: sourceNode.id(),
target: event.target.id()
}
});
}
sourceNode = null;
});
}
function checkHomeomorphism(cy1, cy2) {
// This is a simplified check that only compares the number of nodes and edges
// A real homeomorphism check would be much more complex
return cy1.nodes().length === cy2.nodes().length &&
cy1.edges().length === cy2.edges().length;
}
setupCytoscapeInteractions(cy1);
setupCytoscapeInteractions(cy2);