mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-29 13:22:42 +00:00
Filter lists when donut chart items are clicked
This commit is contained in:
parent
a9b6801b22
commit
915faabe25
@ -2,7 +2,8 @@
|
|||||||
<div class="tui-card-title">{{title | uppercase}}</div>
|
<div class="tui-card-title">{{title | uppercase}}</div>
|
||||||
<div class="tui-card-content">
|
<div class="tui-card-content">
|
||||||
<div fxLayout="row" fxLayoutAlign="space-between stretch">
|
<div fxLayout="row" fxLayoutAlign="space-between stretch">
|
||||||
<app-donut-chart [elementID]="chartID" fxFlex="30" [title]="title"></app-donut-chart>
|
<app-donut-chart [elementID]="chartID" fxFlex="30" [title]="title" (stateEvent)="onItemSelect($event)">
|
||||||
|
</app-donut-chart>
|
||||||
<div class=" items" fxLayout="column" fxLayoutAlign="start end" fxFlex="70">
|
<div class=" items" fxLayout="column" fxLayoutAlign="start end" fxFlex="70">
|
||||||
<app-chart-item *ngFor="let state of states" (click)="onItemSelect(state.label)" [state]="state.label"
|
<app-chart-item *ngFor="let state of states" (click)="onItemSelect(state.label)" [state]="state.label"
|
||||||
[count]="state.count">
|
[count]="state.count">
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
import { Chart } from 'chart.js'
|
import { Chart } from 'chart.js'
|
||||||
import { tooltip } from '../tooltip'
|
import { tooltip } from '../tooltip'
|
||||||
|
import { FilterService } from 'src/app/services/filter.service';
|
||||||
|
import { StType } from 'src/app/type';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-donut-chart',
|
selector: 'app-donut-chart',
|
||||||
@ -10,6 +12,8 @@ import { tooltip } from '../tooltip'
|
|||||||
export class DonutChartComponent {
|
export class DonutChartComponent {
|
||||||
@Input() elementID: string;
|
@Input() elementID: string;
|
||||||
@Input() title: number;
|
@Input() title: number;
|
||||||
|
@Output() stateEvent = new EventEmitter<string>();;
|
||||||
|
|
||||||
_count: number;
|
_count: number;
|
||||||
_countClass = "count-total";
|
_countClass = "count-total";
|
||||||
set count(n: number) {
|
set count(n: number) {
|
||||||
@ -23,7 +27,7 @@ export class DonutChartComponent {
|
|||||||
private ctx: any;
|
private ctx: any;
|
||||||
private chart: Chart;
|
private chart: Chart;
|
||||||
|
|
||||||
constructor() { }
|
constructor(private filterService: FilterService) { }
|
||||||
|
|
||||||
updateData(data: { label: string, count: number, color: string }[]): void {
|
updateData(data: { label: string, count: number, color: string }[]): void {
|
||||||
// Using object destructuring
|
// Using object destructuring
|
||||||
@ -59,6 +63,15 @@ export class DonutChartComponent {
|
|||||||
options: {
|
options: {
|
||||||
cutoutPercentage: 77,
|
cutoutPercentage: 77,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
onClick: (e) => {
|
||||||
|
var activePoints = this.chart.getElementsAtEvent(e);
|
||||||
|
if (activePoints.length > 0) {
|
||||||
|
const index = activePoints[0]["_index"];
|
||||||
|
const label = this.chart.data.labels[index];
|
||||||
|
|
||||||
|
this.stateEvent.emit(label);
|
||||||
|
}
|
||||||
|
},
|
||||||
legend: {
|
legend: {
|
||||||
display: false
|
display: false
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, ViewChild, AfterViewInit } from '@angular/core';
|
import { Component, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core';
|
||||||
import { StType } from '../../type';
|
import { StType } from '../../type';
|
||||||
import { cardElevation } from '../../style';
|
import { cardElevation } from '../../style';
|
||||||
import { FilterService } from 'src/app/services/filter.service';
|
import { FilterService } from 'src/app/services/filter.service';
|
||||||
@ -17,7 +17,10 @@ export class StatusListComponent {
|
|||||||
elevation: string = cardElevation;
|
elevation: string = cardElevation;
|
||||||
title: string = 'Status';
|
title: string = 'Status';
|
||||||
|
|
||||||
constructor(private filterService: FilterService) { }
|
constructor(
|
||||||
|
private filterService: FilterService,
|
||||||
|
private cdr: ChangeDetectorRef,
|
||||||
|
) { }
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
// Listen for filter changes from other components
|
// Listen for filter changes from other components
|
||||||
@ -34,6 +37,8 @@ export class StatusListComponent {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.cdr.detectChanges(); // manually detect changes
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggle(t: StType) {
|
onToggle(t: StType) {
|
||||||
|
Loading…
Reference in New Issue
Block a user