thinkwee
commited on
Commit
·
b356dc8
1
Parent(s):
1159d13
fix display
Browse files
charts.js
CHANGED
|
@@ -279,28 +279,27 @@ function updateScalingCharts(dimension) {
|
|
| 279 |
});
|
| 280 |
});
|
| 281 |
|
| 282 |
-
// 4. Animation
|
| 283 |
|
| 284 |
const graphDiv = document.getElementById(`scaling-${scenario}`);
|
| 285 |
|
| 286 |
-
//
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
});
|
| 291 |
|
| 292 |
-
//
|
| 293 |
Plotly.relayout(`scaling-${scenario}`, {
|
| 294 |
'xaxis.title.text': xLabels[dimension],
|
| 295 |
'xaxis.tickvals': tickVals,
|
| 296 |
'xaxis.ticktext': tickText
|
| 297 |
});
|
| 298 |
|
| 299 |
-
//
|
| 300 |
Plotly.animate(`scaling-${scenario}`, {
|
| 301 |
-
data:
|
| 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 |
-
//
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
const len = path.getTotalLength();
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
}
|