thinkwee
commited on
Commit
·
37f473d
1
Parent(s):
bdbe2ad
exact python match
Browse files
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 |
-
//
|
|
|
|
| 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 |
-
|
| 178 |
-
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
}
|
| 189 |
-
return { x: xValues, y: modelData.accuracy };
|
| 190 |
});
|
| 191 |
|
| 192 |
-
|
| 193 |
-
const
|
| 194 |
-
let xRange, xType, xDtick, xTickformat;
|
| 195 |
|
|
|
|
|
|
|
| 196 |
if (dimension === 'turn') {
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
| 201 |
} else if (dimension === 'token') {
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 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 |
-
|
| 238 |
-
|
| 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', () => {
|