Skip to content

Commit a183392

Browse files
committed
fix 0 values
1 parent 879837c commit a183392

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/app/shared/forms/planet-stacked-bar.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ export class PlanetStackedBarComponent implements OnChanges {
3737

3838
ngOnChanges() {
3939
const total = this.data.reduce((t, item) => t + item.amount, 0);
40+
if (total === 0) {
41+
this.data = this.data.map((item, index) => ({
42+
...item,
43+
class: index === 0 ? 'bg-light-grey' : item.class,
44+
percent: index === 0 ? 1 : 0
45+
}));
46+
this.barSizes = '1fr';
47+
return;
48+
}
4049
this.data = this.data.map(item => ({ ...item, percent: (item.amount / total) }));
4150
this.barSizes = this.data.reduce((sizes, item) => sizes + (item.percent + 'fr '), '');
4251
this.barSizes.trim();

0 commit comments

Comments
 (0)