linked dictionary page to data

This commit is contained in:
Timo 2020-11-26 22:18:51 +02:00
parent 7d75292387
commit a3fefef1e0
6 changed files with 47 additions and 17 deletions

View File

@ -2,6 +2,7 @@
<svg attr.height="{{ size }}" attr.width="{{ size }}" attr.viewBox="0 0 {{ size }} {{ size }}" class="donut-chart"> <svg attr.height="{{ size }}" attr.width="{{ size }}" attr.viewBox="0 0 {{ size }} {{ size }}" class="donut-chart">
<g *ngFor="let value of parsedConfig; let i = index"> <g *ngFor="let value of parsedConfig; let i = index">
<circle <circle
*ngIf="exists(i)"
attr.cx="{{ cx }}" attr.cx="{{ cx }}"
attr.cy="{{ cy }}" attr.cy="{{ cy }}"
attr.r="{{ radius }}" attr.r="{{ radius }}"
@ -26,6 +27,7 @@
<div *ngFor="let val of parsedConfig" [class.active]="val.checked" [class.filter-disabled]="!filter" (click)="toggleFilter.emit(val.key)"> <div *ngFor="let val of parsedConfig" [class.active]="val.checked" [class.filter-disabled]="!filter" (click)="toggleFilter.emit(val.key)">
<redaction-status-bar <redaction-status-bar
[small]="true" [small]="true"
[labelClass]="'no-wrap'"
[config]="[ [config]="[
{ {
length: val.value, length: val.value,

View File

@ -58,12 +58,17 @@ export class SimpleDoughnutChartComponent implements OnChanges {
const newData = []; const newData = [];
let angleOffset = -90; let angleOffset = -90;
this.config.forEach((dataVal) => { this.config.forEach((dataVal) => {
const data = { if (dataVal.value > 0) {
degrees: angleOffset const data = {
}; degrees: angleOffset
newData.push(data); };
angleOffset = this.dataPercentage(dataVal.value) * 360 + angleOffset; newData.push(data);
angleOffset = this.dataPercentage(dataVal.value) * 360 + angleOffset;
} else {
newData.push(null);
}
}); });
console.log(newData);
this.chartData = newData; this.chartData = newData;
} }
@ -80,17 +85,18 @@ export class SimpleDoughnutChartComponent implements OnChanges {
return `rotate(${this.chartData[index].degrees}, ${this.cx}, ${this.cy})`; return `rotate(${this.chartData[index].degrees}, ${this.cx}, ${this.cy})`;
} }
// Eliminate items with value = 0
public get parsedConfig() { public get parsedConfig() {
return this.config return this.config.map((el) => ({
.filter((el) => el.value) ...el,
.map((el) => ({ checked: this.filter?.find((f) => f.key === el.key)?.checked
...el, }));
checked: this.filter?.find((f) => f.key === el.key)?.checked
}));
} }
public getLabel(config: DoughnutChartConfig): string { public getLabel(config: DoughnutChartConfig): string {
return this.totalType === 'sum' ? `${config.value} ${config.label}` : `${config.label} (${config.value} ${this.counterText})`; return this.totalType === 'sum' ? `${config.value} ${config.label}` : `${config.label} (${config.value} ${this.counterText})`;
} }
exists(index: number) {
return !!this.chartData[index];
}
} }

View File

@ -57,7 +57,7 @@
<div class="small-label stats-subtitle"> <div class="small-label stats-subtitle">
<div> <div>
<mat-icon svgIcon="red:entries"></mat-icon> <mat-icon svgIcon="red:entries"></mat-icon>
300 {{ dict.entries?.length }}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,9 +1,11 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { DoughnutChartConfig } from '../../../components/simple-doughnut-chart/simple-doughnut-chart.component'; import { DoughnutChartConfig } from '../../../components/simple-doughnut-chart/simple-doughnut-chart.component';
import { TypeValue } from '@redaction/red-ui-http'; import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http';
import { SortingOption, SortingService } from '../../../utils/sorting.service'; import { SortingOption, SortingService } from '../../../utils/sorting.service';
import { DialogService } from '../../../dialogs/dialog.service'; import { DialogService } from '../../../dialogs/dialog.service';
import { AppStateService } from '../../../state/app-state.service'; import { AppStateService } from '../../../state/app-state.service';
import { tap } from 'rxjs/operators';
import { forkJoin } from 'rxjs';
@Component({ @Component({
selector: 'redaction-dictionary-listing-screen', selector: 'redaction-dictionary-listing-screen',
@ -18,13 +20,28 @@ export class DictionaryListingScreenComponent implements OnInit {
constructor( constructor(
private readonly _dialogService: DialogService, private readonly _dialogService: DialogService,
private readonly _sortingService: SortingService, private readonly _sortingService: SortingService,
private readonly _dictionaryControllerService: DictionaryControllerService,
private readonly _appStateService: AppStateService private readonly _appStateService: AppStateService
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
this._appStateService.reset(); this._appStateService.reset();
const dicts = this._appStateService.dictionaryData; const appStateDictionaryData = this._appStateService.dictionaryData;
this.dictionaries = Object.keys(dicts).map((key) => dicts[key]); this.dictionaries = Object.keys(appStateDictionaryData)
.map((key) => appStateDictionaryData[key])
.filter((d) => !d.virtual);
const dataObs = [];
this.dictionaries.forEach((item) => {
const observable = this._dictionaryControllerService.getDictionaryForType(item.type).pipe(
tap((values) => {
item.entries = values.entries ? values.entries : [];
})
);
dataObs.push(observable);
});
forkJoin(dataObs).subscribe(() => {
this._calculateData();
});
this._calculateData(); this._calculateData();
} }
@ -32,7 +49,7 @@ export class DictionaryListingScreenComponent implements OnInit {
this.chartData = []; this.chartData = [];
for (const dict of this.dictionaries) { for (const dict of this.dictionaries) {
this.chartData.push({ this.chartData.push({
value: 100, value: dict.entries ? dict.entries.length : 0,
color: dict.hexColor, color: dict.hexColor,
label: dict.label, label: dict.label,
key: dict.type key: dict.type

View File

@ -70,3 +70,7 @@ a {
color: $primary; color: $primary;
opacity: 1; opacity: 1;
} }
.no-wrap {
white-space: nowrap;
}

View File

@ -34,4 +34,5 @@ export interface TypeValue {
isDefaultFilter?: boolean; isDefaultFilter?: boolean;
virtual?: boolean; virtual?: boolean;
label?: string; label?: string;
entries?: string[];
} }