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

fix display

Browse files
Files changed (1) hide show
  1. charts.js +16 -21
charts.js CHANGED
@@ -279,27 +279,24 @@ function updateScalingCharts(dimension) {
279
  });
280
  });
281
 
 
282
 
283
- // 4. Synchronous Animation: Points Move + Lines Draw
284
-
285
- // A. Hide Lines BEFORE updating data (so new lines start hidden)
286
  const graphDiv = document.getElementById(`scaling-${scenario}`);
 
 
287
  let currentPaths = graphDiv.querySelectorAll('.js-line path');
288
  currentPaths.forEach(path => {
289
- const len = path.getTotalLength() || 10000;
290
- path.style.transition = 'none';
291
- path.style.strokeDasharray = len;
292
- path.style.strokeDashoffset = len; // Hide
293
  });
294
 
295
- // B. Update Ticks (Instant Layout Update)
296
  Plotly.relayout(`scaling-${scenario}`, {
297
  'xaxis.title.text': xLabels[dimension],
298
  'xaxis.tickvals': tickVals,
299
  'xaxis.ticktext': tickText
300
  });
301
 
302
- // C. Animate Points (Data Update with redraw to create new line paths)
303
  Plotly.animate(`scaling-${scenario}`, {
304
  data: newTraces,
305
  traces: models.map((_, i) => i),
@@ -311,25 +308,23 @@ function updateScalingCharts(dimension) {
311
  },
312
  frame: {
313
  duration: 500,
314
- redraw: true // TRUE: Need to redraw to update line paths to new positions
315
  }
316
- });
317
-
318
- // D. Trigger Line Drawing (CSS Animation) - Start immediately
319
- // Wait one frame for Plotly to create the new path elements
320
- requestAnimationFrame(() => {
321
  requestAnimationFrame(() => {
322
  const newPaths = graphDiv.querySelectorAll('.js-line path');
323
  newPaths.forEach(path => {
324
- const len = path.getTotalLength() || 10000;
325
- // Set initial hidden state
 
326
  path.style.transition = 'none';
327
  path.style.strokeDasharray = len;
328
- path.style.strokeDashoffset = len;
329
  path.getBoundingClientRect(); // Force reflow
330
- // Animate to visible
331
- path.style.transition = 'stroke-dashoffset 0.5s ease-out';
332
- path.style.strokeDashoffset = '0';
333
  });
334
  });
335
  });
 
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),
 
308
  },
309
  frame: {
310
  duration: 500,
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
  });