-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiciclePage.html
121 lines (105 loc) · 3.82 KB
/
iciclePage.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Icicle Layout</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
<style>
/* Your existing CSS styles */
rect {
stroke: #DF73FF;
stroke-width: 2;
rx: 60;
}
text {
font-size: 12px;
fill: #333;
pointer-events: none;
}
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" accept=".csv">
<button onclick="createIciclePlot()">Create Icicle Plot</button>
<svg id="icicle-layout"></svg>
<script>
function createIciclePlot() {
// Read the CSV file
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
const csvData = d3.csvParse(e.target.result);
generateIcicleLayout(csvData);
};
reader.readAsText(file);
} else {
alert('Please select a CSV file.');
}
}
function generateIcicleLayout(adjacencyMatrix) {
// Constants
const width = 680;
const height = 400;
const colorScheme = ["#660066", "#E0B0FF"];
const rowSpacing = 5; // Adjust this value to control the spacing between rectangles
function setupSvg() {
return d3.select("#icicle-layout")
.attr("width", width)
.attr("height", height);
}
function createRectangles(svg, root) {
svg.selectAll("rect")
.data(root.descendants())
.enter().append("rect")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("width", d => d.x1 - d.x0 - (d.children ? 0 : rowSpacing))
.attr("height", d => d.y1 - d.y0)
.attr("fill", d => colorScheme[d.depth % colorScheme.length]);
}
function addText(svg, root) {
svg.append("g")
.selectAll("text")
.data(root.descendants())
.enter()
.filter(d => !d.children)
.append("text")
.attr("x", d => (d.x0 + d.x1) / 2)
.attr("y", d => (d.y0 + d.y1) / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.attr("fill", "black")
.text((d, i) => `Node ${i + 2}`);
}
const svg = setupSvg();
const root = d3.hierarchy({ children: adjacencyMatrix }).sum(d => d.children ? 0 : 1);
const partition = d3.partition().size([width, height]);
partition(root);
createRectangles(svg, root);
addText(svg, root);
return svg.node();
}
</script>
</body>
</html>