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

fix display

Browse files
Files changed (1) hide show
  1. charts.js +64 -52
charts.js CHANGED
@@ -161,11 +161,14 @@ function updateScalingCharts(dimension) {
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,66 +178,76 @@ function updateScalingCharts(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
  }
@@ -242,7 +255,6 @@ function updateScalingCharts(dimension) {
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
+ // Build new traces with all properties
165
+ const newTraces = [];
166
  const allXValues = [];
 
167
 
168
+ const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };
169
+ const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');
170
+
171
+ models.forEach(model => {
172
  const modelData = data[model];
173
  let xValues;
174
  switch (dimension) {
 
178
  }
179
  allXValues.push(...xValues);
180
 
181
+ newTraces.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
+ // 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
  }
 
255
 
256
 
257
 
 
258
  // Dimension toggle event listeners
259
  document.querySelectorAll('.dim-btn:not(.probing-dim)').forEach(btn => {
260
  btn.addEventListener('click', () => {