All files / components/chart-examples-bar chart-examples-bar.component.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 7/7
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                            1x 2x                                             2x   15x     2x   3x 3x   2x          
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { first, map, switchMap, timer } from 'rxjs';
 
import { IBarChartOptions, TBarChartData } from '../../interfaces/bar-chart.interface';
 
/** Bar chart example. */
@Component({
  selector: 'app-chart-examples-bar',
  templateUrl: './chart-examples-bar.component.html',
  styleUrls: ['./chart-examples-bar.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  standalone: false,
})
export class AppChartExamplesBarComponent {
  private readonly breakpointObserver = inject(BreakpointObserver);
 
  /** The chart data. */
  private get chartData() {
    return [
      { title: 'one', value: 1 },
      { title: 'two', value: 2 },
      { title: 'three', value: 3 },
      { title: 'four', value: 4 },
      { title: 'five', value: 5 },
    ] as TBarChartData;
  }
 
  /** The chart options. */
  private get chartOptions() {
    return {
      chartTitle: 'Example bar chart',
      xAxisTitle: 'long x axis title',
      yAxisTitle: 'long y axis title',
    } as Partial<IBarChartOptions>;
  }
 
  /** The breakpoint observer stream. */
  private readonly breakpoint$ = this.breakpointObserver
    .observe([Breakpoints.XSmall, Breakpoints.Small, Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
    .pipe(map(result => Object.keys(result.breakpoints).find(item => result.breakpoints[item]) ?? 'unknown'));
 
  /** The chart configuration stream. */
  public readonly chartConfig$ = this.breakpoint$.pipe(
    switchMap(() => {
      const timeout = 100;
      return timer(timeout).pipe(
        first(),
        map(() => ({ data: this.chartData, options: this.chartOptions })),
      );
    }),
  );
}