thinkwee commited on
Commit
8b51fca
·
1 Parent(s): 37f473d

fix display

Browse files
Files changed (1) hide show
  1. charts.js +54 -54
charts.js CHANGED
@@ -161,11 +161,11 @@ function updateScalingCharts(dimension) {
161
  const models = Object.keys(data);
162
  const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
163
 
164
- // Build traces with new X values
165
- const traces = [];
166
  const allXValues = [];
 
167
 
168
- models.forEach(model => {
169
  const modelData = data[model];
170
  let xValues;
171
  switch (dimension) {
@@ -175,74 +175,74 @@ function updateScalingCharts(dimension) {
175
  }
176
  allXValues.push(...xValues);
177
 
178
- const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };
179
- const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');
180
-
181
- traces.push({
182
- x: xValues,
183
- y: modelData.accuracy,
184
- mode: 'lines+markers',
185
- name: model,
186
- line: { color: DDR_DATA.modelColors[model] || '#888', width: 2 },
187
- marker: { size: 6, color: DDR_DATA.modelColors[model] || '#888' },
188
- hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`
189
- });
190
  });
191
 
192
  const maxX = Math.max(...allXValues);
193
  const minX = Math.min(...allXValues.filter(v => v > 0));
194
 
195
- // X-axis settings per dimension
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 { // cost
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 layout = {
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
- transition: { duration: 300, easing: 'cubic-in-out' }
236
- };
 
 
 
 
237
 
238
- // Use Plotly.react for complete redraw with transition
239
- Plotly.react(`scaling-${scenario}`, traces, layout, plotlyConfig);
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  });
241
  }
242
 
243
 
244
 
245
 
 
246
  // Dimension toggle event listeners
247
  document.querySelectorAll('.dim-btn:not(.probing-dim)').forEach(btn => {
248
  btn.addEventListener('click', () => {
 
161
  const models = Object.keys(data);
162
  const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
163
 
164
+ // Collect X values and build update data
 
165
  const allXValues = [];
166
+ const updateData = [];
167
 
168
+ models.forEach((model, idx) => {
169
  const modelData = data[model];
170
  let xValues;
171
  switch (dimension) {
 
175
  }
176
  allXValues.push(...xValues);
177
 
178
+ updateData.push({ x: [xValues], y: [modelData.accuracy] });
 
 
 
 
 
 
 
 
 
 
 
179
  });
180
 
181
  const maxX = Math.max(...allXValues);
182
  const minX = Math.min(...allXValues.filter(v => v > 0));
183
 
184
+ // Build X-axis config based on dimension
185
+ let xaxisUpdate = {
186
+ 'xaxis.title.text': xLabels[dimension]
187
+ };
188
+
189
  if (dimension === 'turn') {
190
+ xaxisUpdate['xaxis.type'] = 'linear';
191
+ xaxisUpdate['xaxis.dtick'] = 10;
192
+ xaxisUpdate['xaxis.range'] = [0, maxX + 5];
193
+ xaxisUpdate['xaxis.tickformat'] = null;
 
 
 
194
  } else if (dimension === 'token') {
195
+ xaxisUpdate['xaxis.type'] = 'linear';
196
+ xaxisUpdate['xaxis.dtick'] = 10000;
197
+ xaxisUpdate['xaxis.range'] = [0, maxX * 1.05];
198
+ xaxisUpdate['xaxis.tickformat'] = ',.0f';
 
 
 
 
199
  } else { // cost
200
+ xaxisUpdate['xaxis.type'] = 'log';
201
+ xaxisUpdate['xaxis.dtick'] = null;
202
+ xaxisUpdate['xaxis.range'] = [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)];
203
+ xaxisUpdate['xaxis.tickformat'] = '$.3f';
204
+ xaxisUpdate['xaxis.exponentformat'] = 'none';
 
 
 
205
  }
206
 
207
+ // Update hover templates
208
+ const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };
209
+ const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');
210
+
211
+ // First: Update layout (axis) - this happens instantly
212
+ Plotly.relayout(`scaling-${scenario}`, xaxisUpdate);
213
+
214
+ // Then: Animate data points to new positions
215
+ const xUpdates = models.map(model => {
216
+ const modelData = data[model];
217
+ switch (dimension) {
218
+ case 'turn': return modelData.turns;
219
+ case 'token': return modelData.tokens;
220
+ case 'cost': return modelData.costs;
221
+ }
222
+ });
223
 
224
+ // Use Plotly.animate for smooth data transition
225
+ Plotly.animate(`scaling-${scenario}`, {
226
+ data: xUpdates.map((x, i) => ({ x })),
227
+ traces: models.map((_, i) => i)
228
+ }, {
229
+ transition: { duration: 400, easing: 'cubic-in-out' },
230
+ frame: { duration: 400, redraw: false }
231
+ });
232
+
233
+ // Update hover templates after animation
234
+ models.forEach((model, i) => {
235
+ Plotly.restyle(`scaling-${scenario}`, {
236
+ hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`
237
+ }, [i]);
238
+ });
239
  });
240
  }
241
 
242
 
243
 
244
 
245
+
246
  // Dimension toggle event listeners
247
  document.querySelectorAll('.dim-btn:not(.probing-dim)').forEach(btn => {
248
  btn.addEventListener('click', () => {