-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add horizontal bar chart component
- Loading branch information
1 parent
38f2786
commit 92ba778
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/app/reports/feature/dashboard/charts/bar-horizontal/bar-horizontal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="container"> | ||
<ngx-charts-bar-horizontal | ||
[results]="results$ | async" | ||
[legend]="true" | ||
[xAxis]="true" | ||
[yAxis]="true" | ||
[showGridLines]="true" | ||
[rotateXAxisTicks]="true" | ||
[noBarWhenZero]="true" | ||
[showXAxisLabel]="true" | ||
[showYAxisLabel]="true" | ||
xAxisLabel="Category" | ||
yAxisLabel="Amount" | ||
> | ||
</ngx-charts-bar-horizontal> | ||
</div> |
81 changes: 81 additions & 0 deletions
81
src/app/reports/feature/dashboard/charts/bar-horizontal/bar-horizontal.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { ChartsBarHorizontalComponent } from './bar-horizontal.component'; | ||
import { provideMockStore, MockStore } from '@ngrx/store/testing'; | ||
import { NgxChartsModule } from '@swimlane/ngx-charts'; | ||
import { CategoryGroup } from '../../../../../shared/services/ynab/interfaces/categories/categoryGroup'; | ||
import { Account } from '../../../../../shared/services/ynab/interfaces/accounts/account'; | ||
import { Transaction } from '../../../../../shared/services/ynab/interfaces/transactions/transaction'; | ||
import { selectReportResults } from '../../../../data-access/report.selectors'; | ||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; | ||
|
||
describe('ChartsBarHorizontalComponent', () => { | ||
let component: ChartsBarHorizontalComponent; | ||
let fixture: ComponentFixture<ChartsBarHorizontalComponent>; | ||
let store: MockStore; | ||
|
||
const initialState: { | ||
categoryGroups: CategoryGroup[]; | ||
accounts: Account[]; | ||
transactions: Transaction[]; | ||
} = { | ||
categoryGroups: [], | ||
accounts: [], | ||
transactions: [], | ||
}; | ||
|
||
afterEach(() => { | ||
store?.resetSelectors(); | ||
}); | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
NgxChartsModule, | ||
provideAnimationsAsync(), | ||
provideMockStore({ | ||
initialState, | ||
selectors: [ | ||
{ | ||
selector: selectReportResults, | ||
value: [ | ||
{ | ||
name: 'Groceries', | ||
value: 100, | ||
}, | ||
{ | ||
name: 'Pet Care', | ||
value: 25, | ||
}, | ||
{ | ||
name: 'Internet', | ||
value: 50, | ||
}, | ||
], | ||
}, | ||
], | ||
}), | ||
], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ChartsBarHorizontalComponent); | ||
component = fixture.componentInstance; | ||
store = TestBed.inject(MockStore); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeDefined(); | ||
}); | ||
|
||
it('should call populate chart on #ngOnInit()', () => { | ||
component.ngOnInit(); | ||
fixture.detectChanges(); | ||
|
||
const legend: HTMLElement = fixture.nativeElement.querySelector('ul.legend-labels'); | ||
expect(legend.textContent).toContain('Groceries'); | ||
expect(legend.textContent).toContain('Pet Care'); | ||
expect(legend.textContent).toContain('Internet'); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/app/reports/feature/dashboard/charts/bar-horizontal/bar-horizontal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AsyncPipe } from '@angular/common'; | ||
import { Component, inject, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { NgxChartsModule } from '@swimlane/ngx-charts'; | ||
import { Store } from '@ngrx/store'; | ||
import { selectReportResults } from '../../../../data-access/report.selectors'; | ||
|
||
@Component({ | ||
selector: 'app-charts-bar-horizontal', | ||
standalone: true, | ||
imports: [AsyncPipe, NgxChartsModule], | ||
templateUrl: './bar-horizontal.component.html', | ||
}) | ||
export class ChartsBarHorizontalComponent implements OnInit { | ||
store = inject(Store); | ||
|
||
results$: Observable<{ value: number; name: string }[]> | undefined; | ||
|
||
ngOnInit(): void { | ||
this.results$ = this.store.select(selectReportResults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Routes } from '@angular/router'; | ||
import { ChartsBarVerticalComponent } from './charts/bar-vertical/bar-vertical.component'; | ||
import { ChartsBarHorizontalComponent } from './charts/bar-horizontal/bar-horizontal.component'; | ||
|
||
export const dashboardRoutes: Routes = [ | ||
{ path: 'bar-vert', component: ChartsBarVerticalComponent }, | ||
{ path: 'bar-horz', component: ChartsBarHorizontalComponent }, | ||
]; |