thinkwee commited on
Commit
b356dc8
·
1 Parent(s): 1159d13

fix display

Browse files
Files changed (1) hide show
  1. charts.js +38 -25
charts.js CHANGED
@@ -279,28 +279,27 @@ function updateScalingCharts(dimension) {
279
  });
280
  });
281
 
282
- // 4. Animation Strategy: Hide Lines -> Move Points -> Draw Lines
283
 
284
  const graphDiv = document.getElementById(`scaling-${scenario}`);
285
 
286
- // A. Hide lines via opacity (keep DOM elements)
287
- let currentPaths = graphDiv.querySelectorAll('.js-line path');
288
- currentPaths.forEach(path => {
289
- path.style.opacity = '0';
290
- });
291
 
292
- // B. Update Ticks
293
  Plotly.relayout(`scaling-${scenario}`, {
294
  'xaxis.title.text': xLabels[dimension],
295
  'xaxis.tickvals': tickVals,
296
  'xaxis.ticktext': tickText
297
  });
298
 
299
- // C. Animate Points (with lines hidden)
300
  Plotly.animate(`scaling-${scenario}`, {
301
- data: newTraces,
302
- traces: models.map((_, i) => i),
303
- layout: {}
304
  }, {
305
  transition: {
306
  duration: 500,
@@ -311,22 +310,36 @@ function updateScalingCharts(dimension) {
311
  redraw: true
312
  }
313
  }).then(() => {
314
- // D. After points arrive, draw lines from left to right
315
- requestAnimationFrame(() => {
316
- const newPaths = graphDiv.querySelectorAll('.js-line path');
317
- newPaths.forEach(path => {
 
 
 
 
 
 
 
 
 
 
 
318
  const len = path.getTotalLength();
319
- // Setup for drawing animation
320
- path.style.opacity = '1';
321
- path.style.transition = 'none';
322
- path.style.strokeDasharray = len;
323
- path.style.strokeDashoffset = len; // Start hidden
324
- path.getBoundingClientRect(); // Force reflow
325
- // Animate: draw from left to right
326
- path.style.transition = 'stroke-dashoffset 0.6s ease-out';
327
- path.style.strokeDashoffset = '0'; // Reveal
 
 
 
328
  });
329
- });
330
  });
331
  });
332
  }
 
279
  });
280
  });
281
 
282
+ // 4. Two-Phase Animation: Points Only -> Add Lines with Drawing Effect
283
 
284
  const graphDiv = document.getElementById(`scaling-${scenario}`);
285
 
286
+ // Phase 1: Update to markers-only mode and animate points
287
+ const markersOnlyTraces = newTraces.map(trace => ({
288
+ ...trace,
289
+ mode: 'markers' // Remove lines completely
290
+ }));
291
 
292
+ // Update ticks
293
  Plotly.relayout(`scaling-${scenario}`, {
294
  'xaxis.title.text': xLabels[dimension],
295
  'xaxis.tickvals': tickVals,
296
  'xaxis.ticktext': tickText
297
  });
298
 
299
+ // Animate points to new positions (no lines)
300
  Plotly.animate(`scaling-${scenario}`, {
301
+ data: markersOnlyTraces,
302
+ traces: models.map((_, i) => i)
 
303
  }, {
304
  transition: {
305
  duration: 500,
 
310
  redraw: true
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 0.8s ease-out';
339
+ path.style.strokeDashoffset = '0';
340
+ }
341
  });
342
+ }, 50); // Small delay to ensure DOM is ready
343
  });
344
  });
345
  }