-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradsugiyamaPage.html
199 lines (170 loc) · 5.44 KB
/
radsugiyamaPage.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Radial Sugiyama Layout</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
/* Style for nodes */
.node {
fill: purple;
stroke: #fff;
stroke-width: 2px;
cursor: pointer;
}
/* Style for edges */
.link {
stroke: #660066;
stroke-width: 1.5px;
}
.node:hover {
fill: #DDA0DD;
}
/* Style for labels */
.label {
fill: white;
font-family: 'Arial', sans-serif;
font-size: 12px;
text-anchor: middle;
}
button {
outline: none;
color: #f2f2f2;
font-size: 14px;
font-weight: 500;
border-radius: 8px;
padding: 10px 16px; /* Adjust the padding as needed */
border: none;
margin: 8px 12px; /* Adjust the margin between buttons */
cursor: pointer;
transition: all 0.3s ease;
background-image: linear-gradient(135deg, #b4aee8 10%, #9370DB 100%);
}
button:hover {
transform: scale(0.95);
background-image: linear-gradient(135deg, #9370DB 10%, #b4aee8 100%);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<input type="file" id="fileInput" />
<button onclick="createSugiyama()">Create Radial Sugiyama</button>
<div id="visualization"></div>
<script>
// Function to generate radial Sugiyama layout
function generateRadialSugiyama(adjacencyMatrix) {
const width = 600;
const height = 600;
// Create an SVG container
const svg = d3.select('#visualization').append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', `translate(${width / 2},${height / 2})`);
// Number of nodes
const n = adjacencyMatrix.length;
// Compute angles for each node
const levels = 4; // Number of circular levels
const angleStep = (2 * Math.PI) / n;
// Create nodes
const nodes = [];
for (let level = 0; level < levels; level++) {
for (let i = 0; i < n; i++) {
const angle = i * angleStep;
const radius = level * 50 + 50; // Adjust the radius as needed
nodes.push({ x: radius * Math.cos(angle), y: radius * Math.sin(angle) });
}
}
// Central root node
nodes.push({ x: 0, y: 0 });
// Create links based on the adjacency matrix
const links = [];
for (let i = 0; i < n; i++) {
for (let j = i + 1; j < n; j++) {
if (adjacencyMatrix[i][j] === 1) {
links.push({ source: i, target: j });
}
}
}
// Connect all nodes to the central root node
for (let i = 0; i < n; i++) {
links.push({ source: n, target: i });
}
// Create links for additional connectivity between layers
for (let level = 1; level < levels; level++) {
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (adjacencyMatrix[i][j] === 1) {
links.push({ source: i + (level - 1) * n, target: j + level * n });
}
}
}
}
// Create links
const link = svg.selectAll('.link')
.data(links)
.enter().append('line')
.attr('class', 'link')
.attr('x1', d => nodes[d.source].x)
.attr('y1', d => nodes[d.source].y)
.attr('x2', d => nodes[d.target].x)
.attr('y2', d => nodes[d.target].y)
.attr('marker-end', 'url(#arrowhead)');
// Create nodes
const node = svg.selectAll('.node')
.data(nodes)
.enter().append('circle')
.attr('class', 'node')
.attr('cx', d => d.x)
.attr('cy', d => d.y)
.attr('r', 20);
// Optional: Add labels to nodes
const labels = svg.selectAll('.label')
.data(nodes)
.enter().append('text')
.attr('class', 'label')
.attr('x', d => d.x)
.attr('y', d => d.y + 5)
.text((d, i) => i + 1);
// Define arrowhead marker
svg.append('defs').append('marker')
.attr('id', 'arrowhead')
.attr('refX', 6)
.attr('refY', 2)
.attr('markerWidth', 6)
.attr('markerHeight', 4)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M0,0 L6,2 L0,4');
}
function createSugiyama() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
const csvText = e.target.result;
const adjacencyMatrix = parseCSV(csvText);
generateRadialSugiyama(adjacencyMatrix);
};
reader.readAsText(file);
} else {
alert('Please select a file.');
}
}
function parseCSV(csvText) {
// Assuming CSV format with rows and columns separated by commas
const rows = csvText.split('\n');
const adjacencyMatrix = [];
for (let i = 0; i < rows.length; i++) {
const cols = rows[i].split(',');
const rowValues = cols.map(value => parseInt(value.trim(), 10));
adjacencyMatrix.push(rowValues);
}
return adjacencyMatrix;
}
</script>
</body>
</html>