thinkwee commited on
Commit
40e7624
·
1 Parent(s): af678b1

fix display

Browse files
Files changed (1) hide show
  1. charts.js +41 -21
charts.js CHANGED
@@ -311,35 +311,55 @@ function updateScalingCharts(dimension) {
311
  }
312
  }).then(() => {
313
  // Phase 2: Add lines back and animate them drawing
314
- // First, update to lines+markers mode
315
  const linesAndMarkersTraces = newTraces.map(trace => ({
316
  ...trace,
317
  mode: 'lines+markers'
318
  }));
319
 
 
320
  Plotly.react(`scaling-${scenario}`, linesAndMarkersTraces, {
321
  ...graphDiv.layout
322
- }, plotlyConfig);
323
-
324
- // Now animate the newly created line paths
325
- setTimeout(() => {
326
- const paths = graphDiv.querySelectorAll('.js-line path');
327
- paths.forEach(path => {
328
- const len = path.getTotalLength();
329
- if (len > 0) {
330
- // Set up for drawing animation
331
- path.style.strokeDasharray = `${len}`;
332
- path.style.strokeDashoffset = `${len}`;
333
-
334
- // Force browser to register the initial state
335
- void path.offsetWidth;
336
-
337
- // Trigger animation
338
- path.style.transition = 'stroke-dashoffset 2s ease-out';
339
- path.style.strokeDashoffset = '0';
340
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  });
342
- }, 50); // Small delay to ensure DOM is ready
343
  });
344
  });
345
  }
 
311
  }
312
  }).then(() => {
313
  // Phase 2: Add lines back and animate them drawing
 
314
  const linesAndMarkersTraces = newTraces.map(trace => ({
315
  ...trace,
316
  mode: 'lines+markers'
317
  }));
318
 
319
+ // Use Plotly.react and wait for it to complete
320
  Plotly.react(`scaling-${scenario}`, linesAndMarkersTraces, {
321
  ...graphDiv.layout
322
+ }, plotlyConfig).then(() => {
323
+ // Give browser time to render
324
+ requestAnimationFrame(() => {
325
+ requestAnimationFrame(() => {
326
+ // Try multiple selectors to find the line paths
327
+ let paths = graphDiv.querySelectorAll('.scatterlayer .js-line path');
328
+ if (paths.length === 0) {
329
+ paths = graphDiv.querySelectorAll('.js-line path');
330
+ }
331
+ if (paths.length === 0) {
332
+ paths = graphDiv.querySelectorAll('path.js-line');
333
+ }
334
+ if (paths.length === 0) {
335
+ paths = graphDiv.querySelectorAll('.scatter path');
336
+ }
337
+
338
+ console.log(`Found ${paths.length} paths for ${scenario}`);
339
+
340
+ paths.forEach((path, idx) => {
341
+ const len = path.getTotalLength();
342
+ console.log(`Path ${idx}: length = ${len}`);
343
+
344
+ if (len > 0) {
345
+ // Reset any previous animation
346
+ path.style.transition = 'none';
347
+ path.style.strokeDasharray = len + ' ' + len;
348
+ path.style.strokeDashoffset = len;
349
+
350
+ // Force reflow
351
+ path.getBoundingClientRect();
352
+
353
+ // Start animation after a tiny delay
354
+ setTimeout(() => {
355
+ path.style.transition = 'stroke-dashoffset 2s ease-out';
356
+ path.style.strokeDashoffset = '0';
357
+ }, 10);
358
+ }
359
+ });
360
+ });
361
  });
362
+ });
363
  });
364
  });
365
  }