2020 * the selected window so bars always fill the chart even on sparse data.
2121 */
2222
23- import { useMemo , useState , useRef , useCallback } from 'react' ;
23+ import { useMemo , useState , useRef , useCallback , useId } from 'react' ;
2424import useSWR from 'swr' ;
2525import {
2626 getUsageSummary ,
@@ -99,7 +99,7 @@ function buildSeries(
9999 const hourMap = new Map ( byHour . map ( ( h ) => [ h . hour , h ] ) ) ;
100100 const now = new Date ( ) ;
101101
102- if ( windowKey === '24h' && byHour . length > 0 ) {
102+ if ( windowKey === '24h' ) {
103103 const out : ChartPoint [ ] = [ ] ;
104104 for ( let i = 23 ; i >= 0 ; i -- ) {
105105 const d = new Date ( now ) ;
@@ -135,9 +135,8 @@ function buildSeries(
135135 return { points : out , granularity : 'hour' } ;
136136 }
137137
138- // Daily granularity for 24h/7d fallback, 30d, all.
139- const count =
140- windowKey === '24h' ? 1 : windowKey === '7d' ? 7 : windowKey === '30d' ? 30 : 60 ;
138+ // Daily granularity for 7d fallback, 30d, all.
139+ const count = windowKey === '7d' ? 7 : windowKey === '30d' ? 30 : 60 ;
141140 if ( windowKey === 'all' && byDay . length > 0 ) {
142141 const slice = byDay . slice ( - count ) ;
143142 return {
@@ -271,6 +270,7 @@ function CostAreaChart({
271270 [ points ]
272271 ) ;
273272 const rangeLabel = windowKey === 'all' ? 'All' : windowKey ;
273+ const fillGradientId = `usage-fill-${ useId ( ) . replace ( / : / g, '' ) } ` ;
274274
275275 // Internal SVG coordinates; preserveAspectRatio="none" stretches them.
276276 const W = 600 ;
@@ -365,7 +365,7 @@ function CostAreaChart({
365365 onMouseLeave = { onLeave }
366366 >
367367 < defs >
368- < linearGradient id = "usage-fill" x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
368+ < linearGradient id = { fillGradientId } x1 = "0" y1 = "0" x2 = "0" y2 = "1" >
369369 < stop offset = "0%" stopColor = "rgb(99,102,241)" stopOpacity = "0.45" />
370370 < stop offset = "100%" stopColor = "rgb(99,102,241)" stopOpacity = "0" />
371371 </ linearGradient >
@@ -386,7 +386,7 @@ function CostAreaChart({
386386
387387 { maxCost > 0 && (
388388 < >
389- < path d = { fillPath } fill = " url(#usage-fill)" />
389+ < path d = { fillPath } fill = { ` url(#${ fillGradientId } )` } />
390390 < path
391391 d = { linePath }
392392 fill = "none"
0 commit comments