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

exact python match

Browse files
Files changed (1) hide show
  1. charts.js +57 -59
charts.js CHANGED
@@ -161,8 +161,10 @@ function updateScalingCharts(dimension) {
161
  const models = Object.keys(data);
162
  const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
163
 
164
- // Collect all X values for this dimension
 
165
  const allXValues = [];
 
166
  models.forEach(model => {
167
  const modelData = data[model];
168
  let xValues;
@@ -172,79 +174,75 @@ function updateScalingCharts(dimension) {
172
  case 'cost': xValues = modelData.costs; break;
173
  }
174
  allXValues.push(...xValues);
175
- });
176
 
177
- const maxX = Math.max(...allXValues);
178
- const minX = Math.min(...allXValues.filter(v => v > 0));
179
 
180
- // Build new data arrays
181
- const newData = models.map(model => {
182
- const modelData = data[model];
183
- let xValues;
184
- switch (dimension) {
185
- case 'turn': xValues = modelData.turns; break;
186
- case 'token': xValues = modelData.tokens; break;
187
- case 'cost': xValues = modelData.costs; break;
188
- }
189
- return { x: xValues, y: modelData.accuracy };
190
  });
191
 
192
- // Determine axis type and settings
193
- const isLog = (dimension === 'cost');
194
- let xRange, xType, xDtick, xTickformat;
195
 
 
 
196
  if (dimension === 'turn') {
197
- xType = 'linear';
198
- xRange = [0, maxX + 5];
199
- xDtick = 10;
200
- xTickformat = null;
 
 
 
201
  } else if (dimension === 'token') {
202
- xType = 'linear';
203
- xRange = [0, maxX * 1.05];
204
- xDtick = 10000;
205
- xTickformat = ',.0f';
206
- } else {
207
- xType = 'log';
208
- xRange = [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)];
209
- xDtick = null;
210
- xTickformat = '$.3f';
 
 
 
 
 
 
 
 
211
  }
212
 
213
- // Step 1: Animate data points with smooth transition
214
- const animData = newData.map((d, i) => ({ x: d.x, y: d.y }));
215
-
216
- Plotly.animate(`scaling-${scenario}`, {
217
- data: animData,
218
- traces: models.map((_, i) => i)
219
- }, {
220
- transition: { duration: 400, easing: 'cubic-in-out' },
221
- frame: { duration: 400, redraw: true }
222
- }).then(() => {
223
- // Step 2: After animation, update axis labels and formatting
224
- Plotly.relayout(`scaling-${scenario}`, {
225
- 'xaxis.title.text': xLabels[dimension],
226
- 'xaxis.type': xType,
227
- 'xaxis.range': xRange,
228
- 'xaxis.dtick': xDtick,
229
- 'xaxis.tickformat': xTickformat,
230
- 'xaxis.exponentformat': 'none'
231
- });
232
-
233
- // Step 3: Update hover templates
234
- const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };
235
- const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');
236
 
237
- models.forEach((model, i) => {
238
- Plotly.restyle(`scaling-${scenario}`, {
239
- hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`
240
- }, [i]);
241
- });
242
- });
243
  });
244
  }
245
 
246
 
247
 
 
248
  // Dimension toggle event listeners
249
  document.querySelectorAll('.dim-btn:not(.probing-dim)').forEach(btn => {
250
  btn.addEventListener('click', () => {
 
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;
 
174
  case 'cost': xValues = modelData.costs; break;
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', () => {