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

fix display

Browse files
Files changed (1) hide show
  1. charts.js +37 -26
charts.js CHANGED
@@ -274,50 +274,61 @@ function updateScalingCharts(dimension) {
274
  x: modelNormX,
275
  y: data[model].accuracy,
276
  customdata: rawValues,
277
- mode: 'markers', // Hide lines during transition
278
  hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: %{customdata}<br>Accuracy: %{y:.2f}%<extra></extra>`
279
  });
280
  });
281
 
282
- // 4. Animate Points (Lines Hidden)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  Plotly.animate(`scaling-${scenario}`, {
284
  data: newTraces,
285
- layout: {
286
- 'xaxis.title.text': xLabels[dimension],
287
- 'xaxis.tickvals': tickVals,
288
- 'xaxis.ticktext': tickText
289
- }
290
  }, {
291
  transition: {
292
- duration: 800,
293
  easing: 'cubic-in-out'
294
  },
295
  frame: {
296
- duration: 800,
297
- redraw: true
298
  }
299
- }).then(() => {
300
- // 5. After points arrive, Draw Lines
301
- // First, enable lines mode
302
- Plotly.restyle(`scaling-${scenario}`, { mode: 'lines+markers' });
303
 
304
- // Then, animate the SVG paths
 
 
305
  requestAnimationFrame(() => {
306
- const graphDiv = document.getElementById(`scaling-${scenario}`);
307
- const paths = graphDiv.querySelectorAll('.js-line path');
308
-
309
- paths.forEach(path => {
310
- const len = path.getTotalLength();
311
- // Set initial state (hidden)
312
  path.style.transition = 'none';
313
  path.style.strokeDasharray = len;
314
  path.style.strokeDashoffset = len;
315
-
316
- // Force reflow
317
- path.getBoundingClientRect();
318
-
319
  // Animate to visible
320
- path.style.transition = 'stroke-dashoffset 1s ease-out';
321
  path.style.strokeDashoffset = '0';
322
  });
323
  });
 
274
  x: modelNormX,
275
  y: data[model].accuracy,
276
  customdata: rawValues,
277
+ mode: 'lines+markers', // KEEP LINES - we'll hide them via CSS
278
  hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: %{customdata}<br>Accuracy: %{y:.2f}%<extra></extra>`
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),
306
+ layout: {}
 
 
 
307
  }, {
308
  transition: {
309
+ duration: 500,
310
  easing: 'cubic-in-out'
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
  });