Update index.html
Browse files- index.html +41 -23
index.html
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
}
|
14 |
#viz {
|
15 |
width: 100%;
|
16 |
-
height:
|
17 |
position: relative;
|
18 |
overflow: hidden;
|
19 |
}
|
@@ -86,18 +86,26 @@ const labelData = [{"x": 1.7994170188903809, "y": -0.15466168522834778, "label":
|
|
86 |
|
87 |
function createVisualization() {
|
88 |
const container = d3.select("#viz");
|
89 |
-
|
90 |
// Set dynamic width and height for responsiveness
|
91 |
const width = window.innerWidth;
|
92 |
-
const height = window.innerHeight
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
const plot = Plot.plot({
|
95 |
width: width,
|
96 |
height: height,
|
97 |
-
margin: 50,
|
98 |
style: {
|
99 |
background: "white",
|
100 |
-
fontSize: 12,
|
101 |
overflow: "visible"
|
102 |
},
|
103 |
color: {
|
@@ -108,7 +116,7 @@ function createVisualization() {
|
|
108 |
x: "x",
|
109 |
y: "y",
|
110 |
fill: d => `topic${d.topic}`,
|
111 |
-
r:
|
112 |
opacity: 0.6,
|
113 |
stroke: "white",
|
114 |
strokeWidth: 0.5
|
@@ -118,12 +126,12 @@ function createVisualization() {
|
|
118 |
y: "y",
|
119 |
text: "label",
|
120 |
fill: "black",
|
121 |
-
fontSize:
|
122 |
fontWeight: "bold",
|
123 |
dx: 0,
|
124 |
dy: 0,
|
125 |
background: true,
|
126 |
-
backgroundPadding:
|
127 |
backgroundFill: "white",
|
128 |
backgroundOpacity: 0.9
|
129 |
})
|
@@ -140,6 +148,12 @@ function createVisualization() {
|
|
140 |
|
141 |
const popup = d3.select("#popup");
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
// Function to update popup content and position
|
144 |
function updatePopup(circle) {
|
145 |
const index = Array.from(document.querySelectorAll('circle')).indexOf(circle);
|
@@ -166,18 +180,23 @@ function createVisualization() {
|
|
166 |
let leftPos = rect.left - vizRect.left + rect.width/2;
|
167 |
let topPos = rect.top - vizRect.top - popupRect.height - 10;
|
168 |
|
169 |
-
//
|
170 |
-
if (
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
181 |
}
|
182 |
|
183 |
popup
|
@@ -189,7 +208,7 @@ function createVisualization() {
|
|
189 |
d3.selectAll("circle")
|
190 |
.style("cursor", "pointer")
|
191 |
.on("click", function(event) {
|
192 |
-
event.stopPropagation();
|
193 |
updatePopup(this);
|
194 |
});
|
195 |
|
@@ -207,7 +226,6 @@ function createVisualization() {
|
|
207 |
// Wait for everything to be loaded and on window resize to adjust
|
208 |
window.addEventListener('load', createVisualization);
|
209 |
window.addEventListener('resize', function() {
|
210 |
-
// Re-create the visualization on window resize
|
211 |
d3.select("#viz").html('');
|
212 |
createVisualization();
|
213 |
});
|
|
|
13 |
}
|
14 |
#viz {
|
15 |
width: 100%;
|
16 |
+
height: 100vh;
|
17 |
position: relative;
|
18 |
overflow: hidden;
|
19 |
}
|
|
|
86 |
|
87 |
function createVisualization() {
|
88 |
const container = d3.select("#viz");
|
89 |
+
|
90 |
// Set dynamic width and height for responsiveness
|
91 |
const width = window.innerWidth;
|
92 |
+
const height = window.innerHeight;
|
93 |
+
|
94 |
+
// Determine if we're on mobile (width < 768px is a common breakpoint)
|
95 |
+
const isMobile = width < 768;
|
96 |
+
|
97 |
+
// Adjust sizes based on device
|
98 |
+
const pointSize = isMobile ? 8 : 12;
|
99 |
+
const labelSize = isMobile ? 12 : 16;
|
100 |
+
const labelPadding = isMobile ? 4 : 8;
|
101 |
+
|
102 |
const plot = Plot.plot({
|
103 |
width: width,
|
104 |
height: height,
|
105 |
+
margin: isMobile ? 30 : 50,
|
106 |
style: {
|
107 |
background: "white",
|
108 |
+
fontSize: isMobile ? 10 : 12,
|
109 |
overflow: "visible"
|
110 |
},
|
111 |
color: {
|
|
|
116 |
x: "x",
|
117 |
y: "y",
|
118 |
fill: d => `topic${d.topic}`,
|
119 |
+
r: pointSize,
|
120 |
opacity: 0.6,
|
121 |
stroke: "white",
|
122 |
strokeWidth: 0.5
|
|
|
126 |
y: "y",
|
127 |
text: "label",
|
128 |
fill: "black",
|
129 |
+
fontSize: labelSize,
|
130 |
fontWeight: "bold",
|
131 |
dx: 0,
|
132 |
dy: 0,
|
133 |
background: true,
|
134 |
+
backgroundPadding: labelPadding,
|
135 |
backgroundFill: "white",
|
136 |
backgroundOpacity: 0.9
|
137 |
})
|
|
|
148 |
|
149 |
const popup = d3.select("#popup");
|
150 |
|
151 |
+
// Adjust popup styling for mobile
|
152 |
+
if (isMobile) {
|
153 |
+
popup.style("max-width", "280px")
|
154 |
+
.style("font-size", "12px");
|
155 |
+
}
|
156 |
+
|
157 |
// Function to update popup content and position
|
158 |
function updatePopup(circle) {
|
159 |
const index = Array.from(document.querySelectorAll('circle')).indexOf(circle);
|
|
|
180 |
let leftPos = rect.left - vizRect.left + rect.width/2;
|
181 |
let topPos = rect.top - vizRect.top - popupRect.height - 10;
|
182 |
|
183 |
+
// Adjust popup position for mobile
|
184 |
+
if (isMobile) {
|
185 |
+
// Center popup horizontally on mobile
|
186 |
+
leftPos = (windowWidth - popupRect.width) / 2;
|
187 |
+
// Position popup at fixed distance from top
|
188 |
+
topPos = 20;
|
189 |
+
} else {
|
190 |
+
// Desktop positioning logic
|
191 |
+
if (rect.left + popupRect.width > windowWidth) {
|
192 |
+
leftPos = windowWidth - popupRect.width - 20;
|
193 |
+
}
|
194 |
+
if (leftPos < 0) {
|
195 |
+
leftPos = 20;
|
196 |
+
}
|
197 |
+
if (topPos < 0) {
|
198 |
+
topPos = rect.top - vizRect.top + rect.height + 10;
|
199 |
+
}
|
200 |
}
|
201 |
|
202 |
popup
|
|
|
208 |
d3.selectAll("circle")
|
209 |
.style("cursor", "pointer")
|
210 |
.on("click", function(event) {
|
211 |
+
event.stopPropagation();
|
212 |
updatePopup(this);
|
213 |
});
|
214 |
|
|
|
226 |
// Wait for everything to be loaded and on window resize to adjust
|
227 |
window.addEventListener('load', createVisualization);
|
228 |
window.addEventListener('resize', function() {
|
|
|
229 |
d3.select("#viz").html('');
|
230 |
createVisualization();
|
231 |
});
|