Skip to content

Commit de9b8dc

Browse files
committed
Fix chart options and update cost calculations in shared storage components
1 parent 7ac8202 commit de9b8dc

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/app/components/usage/shared-storage/charts/line-usage-time/line-usage-time.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class LineUsageTimeComponent implements OnChanges {
5151
series: []
5252
};
5353
updateFromInput: boolean = false;
54-
chartType: 'perRepo' | 'total' = 'total';
54+
chartType: 'perRepo' | 'total' = 'perRepo';
5555

5656
constructor(
5757
private themeService: ThemingService
@@ -81,7 +81,9 @@ export class LineUsageTimeComponent implements OnChanges {
8181
gbs += line.value;
8282
if (acc.find(a => a.name === line.repositorySlug)) {
8383
const existing = acc.find(a => a.name === line.repositorySlug);
84-
existing?.data.push([line.date.getTime(), existing.data[existing.data.length - 1][1] + line.value]);
84+
if (existing && line.value !== 0) {
85+
existing.data.push([line.date.getTime(), line.value]);
86+
}
8587
} else {
8688
acc.push({
8789
name: line.repositorySlug,
@@ -98,6 +100,22 @@ export class LineUsageTimeComponent implements OnChanges {
98100
}).slice(0, 50);
99101
if (this.options.legend) this.options.legend.enabled = true;
100102
}
103+
this.options.title = {
104+
text: this.currency === 'cost' ? 'Shared Storage Cost Per Day' : 'Shared Storage Size'
105+
};
106+
this.options.yAxis = {
107+
...this.options.yAxis,
108+
title: {
109+
text: this.currency === 'cost' ? 'Dollars ($)' : 'Gigabits (Gb)'
110+
},
111+
};
112+
this.options = {
113+
...this.options,
114+
tooltip: {
115+
...this.options.tooltip,
116+
pointFormat: `${this.options.series!.length > 1 ? '<b>{series.name}</b><br>' : ''}${this.currency === 'cost' ? '${point.y:.2f}/day' : '{point.y:.2f} GB/day'}`,
117+
}
118+
}
101119
this.updateFromInput = true;
102120
}
103121

src/app/components/usage/shared-storage/table-shared-storage/table-shared-storage.component.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ type SharedStorageUsageItem = {
1010
count: number;
1111
avgSize: number;
1212
total: number;
13-
cost: number;
13+
totalCost: number;
1414
avgCost: number;
15-
costPerDay: number;
1615
pricePerUnit: number;
16+
costPerDay: number;
1717
};
1818

1919
@Component({
@@ -43,13 +43,12 @@ export class TableSharedStorageComponent implements OnChanges, AfterViewInit {
4343
const workflowEntry = acc.find(a => a.repo === line.repositorySlug);
4444
const date = line.date;
4545
const month: string = date.toLocaleString('default', { month: 'short' });
46-
const cost = line.pricePerUnit * line.quantity;
46+
const cost = line.quantity * line.pricePerUnit;
4747
if (workflowEntry) {
48-
const daysInMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
4948
if ((workflowEntry as any)[month] as any) {
50-
(workflowEntry as any)[month] += this.currency === 'cost' ? line.value * daysInMonth : line.value;
49+
(workflowEntry as any)[month] += line.value;
5150
} else {
52-
(workflowEntry as any)[month] = this.currency === 'cost' ? line.value * daysInMonth : line.value;
51+
(workflowEntry as any)[month] = line.value;
5352
}
5453
if (!this.columns.find(c => c.columnDef === month)) {
5554
this.columns.push({
@@ -63,19 +62,20 @@ export class TableSharedStorageComponent implements OnChanges, AfterViewInit {
6362
});
6463
}
6564
workflowEntry.total += line.quantity;
66-
workflowEntry.cost += cost;
65+
workflowEntry.totalCost += cost;
6766
workflowEntry.count++;
67+
workflowEntry.costPerDay = cost;
6868
} else {
6969
acc.push({
7070
repo: line.repositorySlug,
7171
total: line.quantity,
7272
count: 1,
73-
cost,
73+
totalCost: cost,
7474
avgSize: 0,
7575
avgCost: 0,
7676
[month]: line.value,
7777
pricePerUnit: line.pricePerUnit,
78-
costPerDay: 0,
78+
costPerDay: cost
7979
});
8080
}
8181
return acc;
@@ -87,8 +87,7 @@ export class TableSharedStorageComponent implements OnChanges, AfterViewInit {
8787
(sharedStorageItem as any)[column.columnDef] = 0;
8888
}
8989
sharedStorageItem.avgSize = sharedStorageItem.total / sharedStorageItem.count;
90-
sharedStorageItem.avgCost = sharedStorageItem.cost / sharedStorageItem.count;
91-
sharedStorageItem.costPerDay = sharedStorageItem.total * sharedStorageItem.pricePerUnit;
90+
sharedStorageItem.avgCost = sharedStorageItem.totalCost / sharedStorageItem.count;
9291
});
9392
});
9493

@@ -128,8 +127,8 @@ export class TableSharedStorageComponent implements OnChanges, AfterViewInit {
128127
{
129128
columnDef: 'total',
130129
header: 'Total Cost',
131-
cell: (sharedStorageItem: any) => currencyPipe.transform(sharedStorageItem.cost),
132-
footer: () => currencyPipe.transform(this.dataSource.data.reduce((acc, line) => acc + line.cost, 0))
130+
cell: (sharedStorageItem: any) => currencyPipe.transform(sharedStorageItem.totalCost),
131+
footer: () => currencyPipe.transform(this.dataSource.data.reduce((acc, line) => acc + line.totalCost, 0))
133132
},
134133
{
135134
columnDef: 'costPerDay',

0 commit comments

Comments
 (0)