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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 1x 2x 2x 2x 2x 20x 20x 200x 2x 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 { IGaugeChartDataNode, IGaugeChartOptions } from '../../interfaces/gauge-chart.interface';
/** Gauge chart example. */
@Component({
selector: 'app-chart-examples-gauge',
templateUrl: './chart-examples-gauge.component.html',
styleUrls: ['./chart-examples-gauge.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class AppChartExamplesGaugeComponent {
private readonly breakpointObserver = inject(BreakpointObserver);
/** The chat values. */
public value = {
first: 80,
second: 75,
third: 65,
};
/** The chart data. */
private get chartData() {
const chunks = {
first: 10,
second: 100,
};
const data: {
first: IGaugeChartDataNode[];
second: IGaugeChartDataNode[];
} = {
first: Array.from(Array(chunks.first).keys()).map(item => {
const mod = 10;
return {
key: 'value',
y: (item + 1) * mod,
} as IGaugeChartDataNode;
}),
second: Array.from(Array(chunks.second).keys()).map(item => {
return {
key: 'value',
y: item + 1,
} as IGaugeChartDataNode;
}),
};
return data;
}
/**
* Example gauge chart options.
*/
private get chartOptions() {
const options: {
first: Partial<IGaugeChartOptions>;
second: Partial<IGaugeChartOptions>;
third: Partial<IGaugeChartOptions>;
fourth: Partial<IGaugeChartOptions>;
} = {
first: {
chartTitle: 'Example gauge chart 1',
} as Partial<IGaugeChartOptions>,
second: {
chartTitle: 'Example gauge chart 2',
showLabels: false,
} as Partial<IGaugeChartOptions>,
third: {
chartTitle: 'Example gauge chart 3',
showLabels: false,
showTooltips: false,
defaultColor: 'red',
} as Partial<IGaugeChartOptions>,
fourth: {
chartTitle: 'Example gauge chart 2',
showLabels: false,
valueFontSize: 30,
padRad: 0,
} as Partial<IGaugeChartOptions>,
};
return options;
}
/** 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 })),
);
}),
);
}
|