Skip to content

Commit

Permalink
Some minor changes to chart loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommatheussen committed Apr 25, 2018
1 parent 44b5b10 commit 8ddde8d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
12 changes: 12 additions & 0 deletions client/src/app/chart/chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@
</div> -->

<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
General
</mat-panel-title>
<mat-panel-description>
<mat-progress-bar mode="determinate" [value]="totalProgress"></mat-progress-bar>
</mat-panel-description>
</mat-expansion-panel-header>
<canvas id="general">{{ generalChart }}</canvas>
</mat-expansion-panel>

<pokemon-series-chart *ngFor="let set of charts" [series]="set"></pokemon-series-chart>
</mat-accordion>
8 changes: 8 additions & 0 deletions client/src/app/chart/chart.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
display: block;
height: 100%;
}

.mat-expansion-panel-header-description {
max-width: calc(50% - 17px);
}

.mat-expansion-panel-header-title {
max-width: calc(50% - 17px);
}
15 changes: 1 addition & 14 deletions client/src/app/chart/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AfterViewInit, Component } from '@angular/core';
import { Chart } from 'chart.js';
import { IpcService } from '../ipc.service';


@Component({
selector: 'pokemon-charts',
templateUrl: './chart.component.html',
Expand Down Expand Up @@ -55,7 +54,7 @@ export class ChartsComponent implements AfterViewInit {
];
chartData = {};

chart: Chart[];
generalChart: Chart;

series: string[];

Expand All @@ -69,18 +68,6 @@ export class ChartsComponent implements AfterViewInit {

// this._setupSeriesDataHandler();
// this._ipcService.sendMessage('chart:load:series');

// this.chart = new Chart('canvas', {
// type: 'polarArea',
// data: {
// labels: ['Series 1', 'Series 2', 'Series 3', 'Series 4', 'Series 5'],
// datasets: [
// {
// data: [15, 52, 17, 93, 100]
// }
// ]
// }
// });
}

private _setupChartingHandler() {
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/chart/series-chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ series }}
</mat-panel-title>
<mat-panel-description>
<mat-progress-bar mode="determinate" value="40"></mat-progress-bar>
<mat-progress-bar mode="determinate" [value]="progress"></mat-progress-bar>
</mat-panel-description>
</mat-expansion-panel-header>
<canvas [id]="series">{{ chart }}</canvas>
Expand Down
13 changes: 10 additions & 3 deletions client/src/app/chart/series-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AfterViewInit, Component, Input } from '@angular/core';
import { Chart } from 'chart.js';
import { IpcService } from '../ipc.service';


@Component({
selector: 'pokemon-series-chart',
templateUrl: './series-chart.component.html',
Expand All @@ -13,16 +12,18 @@ export class SeriesChartComponent implements AfterViewInit {

chart;

progress = 0;

constructor(private _ipcService: IpcService) {}

ngAfterViewInit(): void {
this._setupSeriesChartHandler();
this._ipcService.sendMessage(`series:data:load`, this.series);
this._ipcService.sendMessage(`chart:series:load`, this.series);
}

private _setupSeriesChartHandler() {
this._ipcService.setupIpcListenerOnce(
`series:data:${this.series}`,
`chart:series:data:${this.series}`,
(event, data) => {
let seriesData = data.reduce(
(accumulator, currentValue) => {
Expand All @@ -45,6 +46,12 @@ export class SeriesChartComponent implements AfterViewInit {
]
}
});

this.progress =
seriesData.values.reduce((accumulator, currentValue) => {
accumulator += parseFloat(currentValue);
return accumulator;
}, 0) / seriesData.values.length;
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions electron/database/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ handler('chart:load', async () => {
});
});

handler('series:data:load', async (event, args) => {
handler('chart:series:load', async (event, args) => {
let sets = await loadSets(args);

let setCodes = sets.map(set => {
Expand All @@ -35,7 +35,7 @@ handler('series:data:load', async (event, args) => {
};
});

notify(`series:data:${args}`, seriesInfo);
notify(`chart:series:data:${args}`, seriesInfo);
});

handler('chart:load:series', async () => {
Expand Down

0 comments on commit 8ddde8d

Please sign in to comment.