thinkwee commited on
Commit ·
b4db294
1
Parent(s): 26a0d1f
fix display
Browse files
charts.js
CHANGED
|
@@ -161,7 +161,7 @@ function updateScalingCharts(dimension) {
|
|
| 161 |
const models = Object.keys(data);
|
| 162 |
const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
|
| 163 |
|
| 164 |
-
//
|
| 165 |
const newTraces = [];
|
| 166 |
const allXValues = [];
|
| 167 |
|
|
@@ -192,62 +192,68 @@ function updateScalingCharts(dimension) {
|
|
| 192 |
const maxX = Math.max(...allXValues);
|
| 193 |
const minX = Math.min(...allXValues.filter(v => v > 0));
|
| 194 |
|
| 195 |
-
//
|
| 196 |
-
let
|
|
|
|
|
|
|
|
|
|
| 197 |
if (dimension === 'turn') {
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
dtick: 10,
|
| 203 |
-
range: [0, maxX + 5]
|
| 204 |
-
};
|
| 205 |
} else if (dimension === 'token') {
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
...darkLayout.xaxis,
|
| 217 |
-
title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
|
| 218 |
-
type: 'log',
|
| 219 |
-
tickformat: '$.3f',
|
| 220 |
-
exponentformat: 'none',
|
| 221 |
-
range: [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)]
|
| 222 |
-
};
|
| 223 |
}
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
},
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
});
|
| 252 |
});
|
| 253 |
}
|
|
|
|
| 161 |
const models = Object.keys(data);
|
| 162 |
const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
|
| 163 |
|
| 164 |
+
// Prepare new data
|
| 165 |
const newTraces = [];
|
| 166 |
const allXValues = [];
|
| 167 |
|
|
|
|
| 192 |
const maxX = Math.max(...allXValues);
|
| 193 |
const minX = Math.min(...allXValues.filter(v => v > 0));
|
| 194 |
|
| 195 |
+
// Determine final axis settings
|
| 196 |
+
let finalXaxis = {
|
| 197 |
+
'xaxis.title.text': xLabels[dimension]
|
| 198 |
+
};
|
| 199 |
+
|
| 200 |
if (dimension === 'turn') {
|
| 201 |
+
finalXaxis['xaxis.type'] = 'linear';
|
| 202 |
+
finalXaxis['xaxis.dtick'] = 10;
|
| 203 |
+
finalXaxis['xaxis.range'] = [0, maxX + 5];
|
| 204 |
+
finalXaxis['xaxis.tickformat'] = null;
|
|
|
|
|
|
|
|
|
|
| 205 |
} else if (dimension === 'token') {
|
| 206 |
+
finalXaxis['xaxis.type'] = 'linear';
|
| 207 |
+
finalXaxis['xaxis.dtick'] = 10000;
|
| 208 |
+
finalXaxis['xaxis.range'] = [0, maxX * 1.05];
|
| 209 |
+
finalXaxis['xaxis.tickformat'] = ',.0f';
|
| 210 |
+
} else { // cost
|
| 211 |
+
finalXaxis['xaxis.type'] = 'log';
|
| 212 |
+
finalXaxis['xaxis.dtick'] = null;
|
| 213 |
+
finalXaxis['xaxis.range'] = [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)];
|
| 214 |
+
finalXaxis['xaxis.tickformat'] = '$.3f';
|
| 215 |
+
finalXaxis['xaxis.exponentformat'] = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
+
// STEP 1: Unset dtick/tickformat to prevent freezing during animation
|
| 219 |
+
// When switching range 100 -> 30000, if dtick stays 10, it tries to draw 3000 ticks!
|
| 220 |
+
Plotly.relayout(`scaling-${scenario}`, {
|
| 221 |
+
'xaxis.dtick': null,
|
| 222 |
+
'xaxis.tickformat': null
|
| 223 |
+
}).then(() => {
|
| 224 |
+
// STEP 2: Animate data and range together
|
| 225 |
+
// This creates the smooth "morphing" effect as axis scales with data
|
| 226 |
+
Plotly.animate(`scaling-${scenario}`, {
|
| 227 |
+
data: newTraces,
|
| 228 |
+
layout: {
|
| 229 |
+
xaxis: {
|
| 230 |
+
...darkLayout.xaxis,
|
| 231 |
+
title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
|
| 232 |
+
type: finalXaxis['xaxis.type'],
|
| 233 |
+
range: finalXaxis['xaxis.range'],
|
| 234 |
+
dtick: null, // Keep auto-ticks during animation
|
| 235 |
+
tickformat: null
|
| 236 |
+
},
|
| 237 |
+
yaxis: {
|
| 238 |
+
...darkLayout.yaxis,
|
| 239 |
+
title: { text: 'Accuracy (%)', font: { size: 11, color: '#e2e8f0' } },
|
| 240 |
+
dtick: 5,
|
| 241 |
+
range: yRange
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
}, {
|
| 245 |
+
transition: {
|
| 246 |
+
duration: 500,
|
| 247 |
+
easing: 'cubic-in-out'
|
| 248 |
+
},
|
| 249 |
+
frame: {
|
| 250 |
+
duration: 500,
|
| 251 |
+
redraw: true
|
| 252 |
+
}
|
| 253 |
+
}).then(() => {
|
| 254 |
+
// STEP 3: Apply precise ticks after animation finishes
|
| 255 |
+
Plotly.relayout(`scaling-${scenario}`, finalXaxis);
|
| 256 |
+
});
|
| 257 |
});
|
| 258 |
});
|
| 259 |
}
|