Skip to content

Commit

Permalink
Update charts.ts
Browse files Browse the repository at this point in the history
Refresh graph on label/option/chartType/color/legend change
  • Loading branch information
MumblesNZ authored Jan 16, 2019
1 parent 602742b commit bdcaedb
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/charts/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,22 @@ export class BaseChartDirective implements OnDestroy, OnChanges, OnInit {

public ngOnChanges(changes: SimpleChanges): void {
if (this.initFlag) {
// Check if the changes are in the data or datasets
if (changes.hasOwnProperty('data') || changes.hasOwnProperty('datasets')) {
if (changes['data']) {
this.updateChartData(changes['data'].currentValue);
} else {
this.updateChartData(changes['datasets'].currentValue);
}

this.chart.update();
} else {
// otherwise rebuild the chart
this.refresh();
if (changes.hasOwnProperty('labels') || changes.hasOwnProperty('options') || changes.hasOwnProperty('chartType') || changes.hasOwnProperty('colors') || changes.hasOwnProperty('legend')) {
this.refresh();
}
else if (changes.hasOwnProperty('data') || changes.hasOwnProperty('datasets')) {
// Check if the changes are in the data or datasets
if (changes['data']) {
this.updateChartData(changes['data'].currentValue);
}
else {
this.updateChartData(changes['datasets'].currentValue);
}
this.chart.update();
}
else {
// otherwise rebuild the chart
this.refresh();
}
}
}
Expand Down

0 comments on commit bdcaedb

Please sign in to comment.