@@ -105,10 +105,11 @@ export const CHART_OPTIONS_DATA_TRANSFORM: SelectValue<ChartDataTransform>[] = [
105
105
} ,
106
106
] ;
107
107
108
- export enum SeriesTypes {
108
+ const enum SeriesTypes {
109
109
ACCEPTED = 'Accepted' ,
110
110
DROPPED = 'Dropped' ,
111
111
PROJECTED = 'Projected' ,
112
+ RESERVED = 'Reserved' ,
112
113
FILTERED = 'Filtered' ,
113
114
}
114
115
@@ -166,6 +167,7 @@ export type UsageChartProps = {
166
167
* Display datetime in UTC
167
168
*/
168
169
usageDateShowUtc ?: boolean ;
170
+ yAxisFormatter ?: ( val : number ) => string ;
169
171
} ;
170
172
171
173
/**
@@ -181,6 +183,8 @@ const cumulativeTotalDataTransformation: UsageChartProps['handleDataTransformati
181
183
dropped : [ ] ,
182
184
projected : [ ] ,
183
185
filtered : [ ] ,
186
+ reserved : [ ] ,
187
+ onDemand : [ ] ,
184
188
} ;
185
189
const isCumulative = transform === ChartDataTransform . CUMULATIVE ;
186
190
@@ -201,11 +205,20 @@ const cumulativeTotalDataTransformation: UsageChartProps['handleDataTransformati
201
205
return chartData ;
202
206
} ;
203
207
208
+ const getUnitYaxisFormatter =
209
+ ( dataCategory : UsageChartProps [ 'dataCategory' ] ) => ( val : number ) =>
210
+ formatUsageWithUnits ( val , dataCategory , {
211
+ isAbbreviated : true ,
212
+ useUnitScaling : true ,
213
+ } ) ;
214
+
204
215
export type ChartStats = {
205
216
accepted : NonNullable < BarSeriesOption [ 'data' ] > ;
206
217
dropped : NonNullable < BarSeriesOption [ 'data' ] > ;
207
218
projected : NonNullable < BarSeriesOption [ 'data' ] > ;
208
219
filtered ?: NonNullable < BarSeriesOption [ 'data' ] > ;
220
+ onDemand ?: NonNullable < BarSeriesOption [ 'data' ] > ;
221
+ reserved ?: NonNullable < BarSeriesOption [ 'data' ] > ;
209
222
} ;
210
223
211
224
function chartMetadata ( {
@@ -238,7 +251,6 @@ function chartMetadata({
238
251
xAxisData : string [ ] ;
239
252
xAxisLabelInterval : number ;
240
253
xAxisTickInterval : number ;
241
- yAxisFormatter : ( val : number ) => string ;
242
254
yAxisMinInterval : number ;
243
255
} {
244
256
const selectDataCategory = categoryOptions . find ( o => o . value === dataCategory ) ;
@@ -299,11 +311,6 @@ function chartMetadata({
299
311
xAxisTickInterval,
300
312
xAxisLabelInterval,
301
313
yAxisMinInterval,
302
- yAxisFormatter : ( val : number ) =>
303
- formatUsageWithUnits ( val , dataCategory , {
304
- isAbbreviated : true ,
305
- useUnitScaling : true ,
306
- } ) ,
307
314
tooltipValueFormatter : getTooltipFormatter ( dataCategory ) ,
308
315
} ;
309
316
}
@@ -337,6 +344,7 @@ function UsageChartBody({
337
344
categoryOptions = CHART_OPTIONS_DATACATEGORY ,
338
345
usageDateInterval = '1d' ,
339
346
usageDateShowUtc = true ,
347
+ yAxisFormatter,
340
348
handleDataTransformation = cumulativeTotalDataTransformation ,
341
349
} : UsageChartProps ) {
342
350
const theme = useTheme ( ) ;
@@ -361,14 +369,15 @@ function UsageChartBody({
361
369
) ;
362
370
}
363
371
372
+ const yAxisLabelFormatter = yAxisFormatter ?? getUnitYaxisFormatter ( dataCategory ) ;
373
+
364
374
const {
365
375
chartData,
366
376
tooltipValueFormatter,
367
377
xAxisData,
368
378
xAxisTickInterval,
369
379
xAxisLabelInterval,
370
380
yAxisMinInterval,
371
- yAxisFormatter,
372
381
} = chartMetadata ( {
373
382
categoryOptions,
374
383
dataCategory,
@@ -383,9 +392,13 @@ function UsageChartBody({
383
392
384
393
function chartLegendData ( ) {
385
394
const legend : LegendComponentOption [ 'data' ] = [
386
- {
387
- name : SeriesTypes . ACCEPTED ,
388
- } ,
395
+ chartData . reserved && chartData . reserved . length > 0
396
+ ? {
397
+ name : SeriesTypes . RESERVED ,
398
+ }
399
+ : {
400
+ name : SeriesTypes . ACCEPTED ,
401
+ } ,
389
402
] ;
390
403
391
404
if ( chartData . filtered && chartData . filtered . length > 0 ) {
@@ -454,7 +467,7 @@ function UsageChartBody({
454
467
return (
455
468
< BaseChart
456
469
colors = { colors }
457
- grid = { { bottom : '3px' , left : '0px ' , right : '10px' , top : '40px' } }
470
+ grid = { { bottom : '3px' , left : '3px ' , right : '10px' , top : '40px' } }
458
471
xAxis = { xAxis ( {
459
472
show : true ,
460
473
type : 'category' ,
@@ -474,7 +487,7 @@ function UsageChartBody({
474
487
min : 0 ,
475
488
minInterval : yAxisMinInterval ,
476
489
axisLabel : {
477
- formatter : yAxisFormatter ,
490
+ formatter : yAxisLabelFormatter ,
478
491
color : theme . chartLabel ,
479
492
} ,
480
493
} }
0 commit comments