thinkwee commited on
Commit ·
3a90b9e
1
Parent(s): 3d06da8
exact python match
Browse files158 unmodified lines15916016116216316416516611 unmodified lines178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246158 unmodified linesif (!data) return;const models = Object.keys(data);const newX = [];const newY = [];models.forEach(model => {const modelData = data[model];11 unmodified linesbreak;}newX.push(xValues);newY.push(modelData.accuracy);});const maxX = Math.max(...newX.flat());// Calculate proper axis settings for each dimensionconst xAxisSettings = {'turn': {type: 'linear',dtick: 10,tickformat: null,range: [0, maxX + 5],tick0: 0},'token': {type: 'linear',dtick: 10000,tickformat: ',.0f',range: [0, maxX * 1.05],tick0: 0},'cost': {type: 'log',dtick: null, // auto for log scaletickformat: '$.3f',range: null, // auto for log scaletick0: null}};const settings = xAxisSettings[dimension];// Animate the transitionPlotly.animate(`scaling-${scenario}`, {data: newX.map((x, i) => ({ x, y: newY[i] })),traces: models.map((_, i) => i),layout: {xaxis: {title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },type: settings.type,dtick: settings.dtick,tickformat: settings.tickformat,range: settings.range,tick0: settings.tick0,exponentformat: 'none'}}}, animationSettings);// Update hover templatesconst hoverLabels = {'turn': 'Turns','token': 'Total Tokens','cost': 'Cost'};models.forEach((model, i) => {const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');Plotly.restyle(`scaling-${scenario}`, {hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`}, [i]);});});}158 unmodified lines15916016116216316416511 unmodified lines177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246158 unmodified linesif (!data) return;const models = Object.keys(data);const traces = [];models.forEach(model => {const modelData = data[model];11 unmodified linesbreak;}const hoverLabels = { 'turn': 'Turns', 'token': 'Tokens', 'cost': 'Cost' };const hoverFormat = dimension === 'token' ? '%{x:,.0f}' : (dimension === 'cost' ? '$%{x:.4f}' : '%{x}');traces.push({x: xValues,y: modelData.accuracy,mode: 'lines+markers',name: model,line: { color: DDR_DATA.modelColors[model] || '#888', width: 2 },marker: { size: 6, color: DDR_DATA.modelColors[model] || '#888' },hovertemplate: `<b>${model}</b><br>${hoverLabels[dimension]}: ${hoverFormat}<br>Accuracy: %{y:.2f}%<extra></extra>`});});// Use exact Y-axis range from Pythonconst yRange = SCALING_Y_RANGES[scenario] || [0, 100];const allX = traces.flatMap(t => t.x);const maxX = Math.max(...allX);const minX = Math.min(...allX.filter(v => v > 0));// X-axis settings per dimensionlet xaxis;if (dimension === 'turn') {xaxis = {...darkLayout.xaxis,title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },type: 'linear',dtick: 10,range: [0, maxX + 5]};} else if (dimension === 'token') {xaxis = {...darkLayout.xaxis,title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },type: 'linear',dtick: 10000,tickformat: ',.0f',range: [0, maxX * 1.05]};} else { // costxaxis = {...darkLayout.xaxis,title: { text: xLabels[dimension], font: { size: 11, color: '#e2e8f0' } },type: 'log',tickformat: '$.3f',exponentformat: 'none',range: [Math.log10(minX * 0.5), Math.log10(maxX * 1.5)]};}const layout = {...darkLayout,xaxis: xaxis,yaxis: {...darkLayout.yaxis,title: { text: 'Accuracy (%)', font: { size: 11, color: '#e2e8f0' } },dtick: 5,range: yRange},showlegend: true};// Use react for smooth update without animation freezePlotly.react(`scaling-${scenario}`, traces, layout, plotlyConfig);});}
charts.js+53-53