thinkwee commited on
Commit
b4db294
·
1 Parent(s): 26a0d1f

fix display

Browse files
Files changed (1) hide show
  1. charts.js +59 -53
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
- // Build new traces with all properties
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
- // Build complete new layout
196
- let xaxisConfig;
 
 
 
197
  if (dimension === 'turn') {
198
- xaxisConfig = {
199
- ...darkLayout.xaxis,
200
- title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
201
- type: 'linear',
202
- dtick: 10,
203
- range: [0, maxX + 5]
204
- };
205
  } else if (dimension === 'token') {
206
- xaxisConfig = {
207
- ...darkLayout.xaxis,
208
- title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
209
- type: 'linear',
210
- dtick: 10000,
211
- tickformat: ',.0f',
212
- range: [0, maxX * 1.05]
213
- };
214
- } else {
215
- xaxisConfig = {
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
- const newLayout = {
226
- ...darkLayout,
227
- xaxis: xaxisConfig,
228
- yaxis: {
229
- ...darkLayout.yaxis,
230
- title: { text: 'Accuracy (%)', font: { size: 11, color: '#e2e8f0' } },
231
- dtick: 5,
232
- range: yRange
233
- },
234
- showlegend: true
235
- };
236
-
237
- // Use Plotly.animate with BOTH data AND layout in single frame
238
- // This ensures points, lines, and axis all animate together
239
- Plotly.animate(`scaling-${scenario}`, {
240
- data: newTraces,
241
- layout: newLayout
242
- }, {
243
- transition: {
244
- duration: 500,
245
- easing: 'cubic-in-out'
246
- },
247
- frame: {
248
- duration: 500,
249
- redraw: true // Important: redraw ensures lines update, not just markers
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
  }