thinkwee commited on
Commit
bdbe2ad
·
1 Parent(s): 3a90b9e

exact python match

Browse files
Files changed (1) hide show
  1. charts.js +66 -66
charts.js CHANGED
@@ -159,92 +159,92 @@ function updateScalingCharts(dimension) {
159
  if (!data) return;
160
 
161
  const models = Object.keys(data);
162
- const traces = [];
163
 
 
 
164
  models.forEach(model => {
165
  const modelData = data[model];
166
  let xValues;
167
-
168
  switch (dimension) {
169
- case 'turn':
170
- xValues = modelData.turns;
171
- break;
172
- case 'token':
173
- xValues = modelData.tokens;
174
- break;
175
- case 'cost':
176
- xValues = modelData.costs;
177
- break;
178
  }
 
 
179
 
180
- const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };
181
- const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');
182
 
183
- traces.push({
184
- x: xValues,
185
- y: modelData.accuracy,
186
- mode: 'lines+markers',
187
- name: model,
188
- line: { color: DDR_DATA.modelColors[model] || '#888', width: 2 },
189
- marker: { size: 6, color: DDR_DATA.modelColors[model] || '#888' },
190
- hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`
191
- });
 
192
  });
193
 
194
- // Use exact Y-axis range from Python
195
- const yRange = SCALING_Y_RANGES[scenario] || [0, 100];
196
- const allX = traces.flatMap(t => t.x);
197
- const maxX = Math.max(...allX);
198
- const minX = Math.min(...allX.filter(v => v > 0));
199
 
200
- // X-axis settings per dimension
201
- let xaxis;
202
  if (dimension === 'turn') {
203
- xaxis = {
204
- ...darkLayout.xaxis,
205
- title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
206
- type: 'linear',
207
- dtick: 10,
208
- range: [0, maxX + 5]
209
- };
210
  } else if (dimension === 'token') {
211
- xaxis = {
212
- ...darkLayout.xaxis,
213
- title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
214
- type: 'linear',
215
- dtick: 10000,
216
- tickformat: ',.0f',
217
- range: [0, maxX * 1.05]
218
- };
219
- } else { // cost
220
- xaxis = {
221
- ...darkLayout.xaxis,
222
- title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },
223
- type: 'log',
224
- tickformat: '$.3f',
225
- exponentformat: 'none',
226
- range: [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)]
227
- };
228
  }
229
 
230
- const layout = {
231
- ...darkLayout,
232
- xaxis: xaxis,
233
- yaxis: {
234
- ...darkLayout.yaxis,
235
- title: { text: 'Accuracy (%)', font: { size: 11, color: '#e2e8f0' } },
236
- dtick: 5,
237
- range: yRange
238
- },
239
- showlegend: true
240
- };
 
 
 
 
 
 
 
 
241
 
242
- // Use react for smooth update without animation freeze
243
- Plotly.react(`scaling-${scenario}`, traces, layout, plotlyConfig);
 
 
 
 
 
 
 
 
244
  });
245
  }
246
 
247
 
 
248
  // Dimension toggle event listeners
249
  document.querySelectorAll('.dim-btn:not(.probing-dim)').forEach(btn => {
250
  btn.addEventListener('click', () => {
 
159
  if (!data) return;
160
 
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;
 
169
  switch (dimension) {
170
+ case 'turn': xValues = modelData.turns; break;
171
+ case 'token': xValues = modelData.tokens; break;
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', () => {