@@ -13,6 +13,9 @@ const FEATURED_COMPARISON_PROVIDER_IDS = ['anthropic', 'openai', 'google']
1313
1414/** Max latest models pulled from each featured provider. */
1515const MAX_MODELS_PER_PROVIDER = 4
16+ const CHART_BAR_HEIGHT = 1
17+ const CHART_BAR_END_RADIUS_X = 1
18+ const CHART_BAR_END_RADIUS_Y = 3 / 28
1619
1720const PROVIDER_ICON_MAP : Record < string , ComponentType < { className ?: string } > > = ( ( ) => {
1821 const map : Record < string , ComponentType < { className ?: string } > > = { }
@@ -24,6 +27,14 @@ const PROVIDER_ICON_MAP: Record<string, ComponentType<{ className?: string }>> =
2427 return map
2528} ) ( )
2629
30+ function getRoundedRightBarPath ( x : number , width : number ) : string {
31+ const right = x + width
32+ const radiusX = Math . min ( CHART_BAR_END_RADIUS_X , width / 2 )
33+ const radiusY = CHART_BAR_END_RADIUS_Y
34+
35+ return `M ${ x } 0 H ${ right - radiusX } Q ${ right } 0 ${ right } ${ radiusY } V ${ CHART_BAR_HEIGHT - radiusY } Q ${ right } ${ CHART_BAR_HEIGHT } ${ right - radiusX } ${ CHART_BAR_HEIGHT } H ${ x } Z`
36+ }
37+
2738function selectComparisonModels ( models : CatalogModel [ ] ) : CatalogModel [ ] {
2839 const seen = new Set < string > ( )
2940 const result : CatalogModel [ ] = [ ]
@@ -104,6 +115,9 @@ function StackedCostChart({ models }: ChartProps) {
104115 { data . entries . map ( ( { model, input, output, total } ) => {
105116 const totalPct = data . maxTotal > 0 ? ( total / data . maxTotal ) * 100 : 0
106117 const inputPct = total > 0 ? ( input / total ) * 100 : 0
118+ const plottedTotalPct = Math . max ( totalPct , 3 )
119+ const plottedInputPct = ( plottedTotalPct * inputPct ) / 100
120+ const plottedOutputPct = plottedTotalPct - plottedInputPct
107121 const color = getProviderColor ( model . providerId )
108122
109123 return (
@@ -115,27 +129,30 @@ function StackedCostChart({ models }: ChartProps) {
115129 < ModelLabel model = { model } />
116130 < div className = 'flex h-7 min-w-0 flex-1 items-center gap-2.5' >
117131 < div className = 'hidden h-full min-w-0 flex-1 sm:block' >
118- < div
119- className = 'flex h-full overflow-hidden rounded-r-[3px]'
120- style = { { width : `${ Math . max ( totalPct , 3 ) } %` } }
132+ < svg
133+ aria-hidden = 'true'
134+ className = 'size-full'
135+ preserveAspectRatio = 'none'
136+ viewBox = '0 0 100 1'
121137 >
122- < div
123- className = 'h-full'
124- style = { {
125- width : `${ inputPct } %` ,
126- backgroundColor : color ,
127- opacity : 0.8 ,
128- } }
129- />
130- < div
131- className = 'h-full'
132- style = { {
133- width : `${ 100 - inputPct } %` ,
134- backgroundColor : color ,
135- opacity : 0.35 ,
136- } }
137- />
138- </ div >
138+ { plottedInputPct > 0 &&
139+ ( plottedOutputPct > 0 ? (
140+ < rect fill = { color } fillOpacity = { 0.8 } height = '1' width = { plottedInputPct } />
141+ ) : (
142+ < path
143+ d = { getRoundedRightBarPath ( 0 , plottedInputPct ) }
144+ fill = { color }
145+ fillOpacity = { 0.8 }
146+ />
147+ ) ) }
148+ { plottedOutputPct > 0 && (
149+ < path
150+ d = { getRoundedRightBarPath ( plottedInputPct , plottedOutputPct ) }
151+ fill = { color }
152+ fillOpacity = { 0.35 }
153+ />
154+ ) }
155+ </ svg >
139156 </ div >
140157 < span className = 'shrink-0 text-[11px] text-[var(--text-muted)] sm:w-[148px] sm:text-xs' >
141158 { formatPrice ( input ) } input / { formatPrice ( output ) } output
@@ -188,14 +205,18 @@ function ContextWindowChart({ models }: ChartProps) {
188205 < ModelLabel model = { model } />
189206 < div className = 'flex h-7 min-w-0 flex-1 items-center gap-2.5' >
190207 < div className = 'h-full min-w-0 flex-1' >
191- < div
192- className = 'h-full rounded-r-[3px]'
193- style = { {
194- width : `${ Math . max ( pct , 3 ) } %` ,
195- backgroundColor : color ,
196- opacity : 0.8 ,
197- } }
198- />
208+ < svg
209+ aria-hidden = 'true'
210+ className = 'size-full'
211+ preserveAspectRatio = 'none'
212+ viewBox = '0 0 100 1'
213+ >
214+ < path
215+ d = { getRoundedRightBarPath ( 0 , Math . max ( pct , 3 ) ) }
216+ fill = { color }
217+ fillOpacity = { 0.8 }
218+ />
219+ </ svg >
199220 </ div >
200221 < span className = 'w-10 shrink-0 text-right text-[11px] text-[var(--text-muted)] tabular-nums sm:text-xs' >
201222 { formatTokenCount ( value ) }
@@ -232,11 +253,11 @@ export function ModelComparisonCharts({ models }: ModelComparisonChartsProps) {
232253
233254 < div className = 'h-px w-full bg-[var(--border)]' />
234255
235- < div className = 'flex flex-col sm :flex-row' >
256+ < div className = 'flex flex-col lg :flex-row' >
236257 < div className = 'flex-1 p-6' >
237258 < StackedCostChart models = { comparisonModels } />
238259 </ div >
239- < div className = 'h-px w-full bg-[var(--border)] sm :h-auto sm :w-px' />
260+ < div className = 'h-px w-full bg-[var(--border)] lg :h-auto lg :w-px' />
240261 < div className = 'flex-1 p-6' >
241262 < ContextWindowChart models = { comparisonModels } />
242263 </ div >
0 commit comments