fdaudens HF staff commited on
Commit
15bdd8d
·
verified ·
1 Parent(s): 78cb252

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +19 -20
index.html CHANGED
@@ -117,21 +117,20 @@ const labelData = [{"x": 1.7994170188903809, "y": -0.15466168522834778, "label":
117
 
118
  // Create visualization function
119
  function createVisualization() {
120
- // Clear any existing visualization
121
  const container = d3.select("#viz");
122
- container.html('');
123
 
124
- // Set up responsive variables
125
  const width = window.innerWidth;
126
- const isMobile = width < 768;
127
  const height = isMobile ? window.innerHeight : window.innerHeight * 0.67;
128
 
 
 
 
129
  // Adjust sizes based on device
130
  const pointSize = isMobile ? 8 : 12;
131
  const labelSize = isMobile ? 12 : 16;
132
  const labelPadding = isMobile ? 4 : 8;
133
 
134
- // Create the plot
135
  const plot = Plot.plot({
136
  width: width,
137
  height: height,
@@ -177,10 +176,8 @@ function createVisualization() {
177
  }
178
  });
179
 
180
- // Add plot to container
181
  container.node().appendChild(plot);
182
 
183
- // Set up popup
184
  const popup = d3.select("#popup");
185
 
186
  // Adjust popup styling for mobile
@@ -209,21 +206,20 @@ function createVisualization() {
209
  const vizRect = document.getElementById("viz").getBoundingClientRect();
210
  const popupRect = popup.node().getBoundingClientRect();
211
  const windowWidth = window.innerWidth;
212
-
213
- // Calculate position
214
- let leftPos, topPos;
215
-
 
 
 
216
  if (isMobile) {
217
  // Center popup horizontally on mobile
218
  leftPos = (windowWidth - popupRect.width) / 2;
219
  // Position popup at fixed distance from top
220
  topPos = 20;
221
  } else {
222
- // Desktop positioning
223
- leftPos = rect.left - vizRect.left + rect.width/2;
224
- topPos = rect.top - vizRect.top - popupRect.height - 10;
225
-
226
- // Adjust if popup would go off screen
227
  if (rect.left + popupRect.width > windowWidth) {
228
  leftPos = windowWidth - popupRect.width - 20;
229
  }
@@ -240,7 +236,7 @@ function createVisualization() {
240
  .style("top", topPos + "px");
241
  }
242
 
243
- // Set up event listeners
244
  d3.selectAll("circle")
245
  .style("cursor", "pointer")
246
  .on("click", function(event) {
@@ -248,7 +244,7 @@ function createVisualization() {
248
  updatePopup(this);
249
  });
250
 
251
- // Close popup when clicking outside
252
  document.addEventListener("click", function() {
253
  popup.style("display", "none");
254
  });
@@ -259,9 +255,12 @@ function createVisualization() {
259
  });
260
  }
261
 
262
- // Initialize visualization on load and resize
263
  window.addEventListener('load', createVisualization);
264
- window.addEventListener('resize', createVisualization);
 
 
 
265
  </script>
266
  </body>
267
  </html>
 
117
 
118
  // Create visualization function
119
  function createVisualization() {
 
120
  const container = d3.select("#viz");
 
121
 
122
+ // Set dynamic width and height for responsiveness
123
  const width = window.innerWidth;
 
124
  const height = isMobile ? window.innerHeight : window.innerHeight * 0.67;
125
 
126
+ // Determine if we're on mobile (width < 768px is a common breakpoint)
127
+ const isMobile = width < 768;
128
+
129
  // Adjust sizes based on device
130
  const pointSize = isMobile ? 8 : 12;
131
  const labelSize = isMobile ? 12 : 16;
132
  const labelPadding = isMobile ? 4 : 8;
133
 
 
134
  const plot = Plot.plot({
135
  width: width,
136
  height: height,
 
176
  }
177
  });
178
 
 
179
  container.node().appendChild(plot);
180
 
 
181
  const popup = d3.select("#popup");
182
 
183
  // Adjust popup styling for mobile
 
206
  const vizRect = document.getElementById("viz").getBoundingClientRect();
207
  const popupRect = popup.node().getBoundingClientRect();
208
  const windowWidth = window.innerWidth;
209
+ const windowHeight = window.innerHeight;
210
+
211
+ // Calculate initial position
212
+ let leftPos = rect.left - vizRect.left + rect.width/2;
213
+ let topPos = rect.top - vizRect.top - popupRect.height - 10;
214
+
215
+ // Adjust popup position for mobile
216
  if (isMobile) {
217
  // Center popup horizontally on mobile
218
  leftPos = (windowWidth - popupRect.width) / 2;
219
  // Position popup at fixed distance from top
220
  topPos = 20;
221
  } else {
222
+ // Desktop positioning logic
 
 
 
 
223
  if (rect.left + popupRect.width > windowWidth) {
224
  leftPos = windowWidth - popupRect.width - 20;
225
  }
 
236
  .style("top", topPos + "px");
237
  }
238
 
239
+ // Handle clicks on points
240
  d3.selectAll("circle")
241
  .style("cursor", "pointer")
242
  .on("click", function(event) {
 
244
  updatePopup(this);
245
  });
246
 
247
+ // Click anywhere else to close popup
248
  document.addEventListener("click", function() {
249
  popup.style("display", "none");
250
  });
 
255
  });
256
  }
257
 
258
+ // Wait for everything to be loaded and on window resize to adjust
259
  window.addEventListener('load', createVisualization);
260
+ window.addEventListener('resize', function() {
261
+ d3.select("#viz").html('');
262
+ createVisualization();
263
+ });
264
  </script>
265
  </body>
266
  </html>