Skip to content

Commit

Permalink
Fixed #10452 - Update Chart.js to 3.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Jul 27, 2021
1 parent 96fc1ce commit c07677f
Show file tree
Hide file tree
Showing 16 changed files with 1,432 additions and 598 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@fullcalendar/timegrid": "^5.8.0",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"chart.js": "2.7.3",
"chart.js": "3.3.2",
"codelyzer": "^6.0.0",
"del": "^2.2.0",
"file-saver": "^2.0.2",
Expand Down
40 changes: 22 additions & 18 deletions src/app/components/chart/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ export class UIChart implements AfterViewInit, OnDestroy {
@Input() type: string;

@Input() plugins: any[] = [];

@Input() width: string;

@Input() height: string;

@Input() responsive: boolean = true;

@Output() onDataSelect: EventEmitter<any> = new EventEmitter();

initialized: boolean;

_data: any;

_options: any = {};

chart: any;

constructor(public el: ElementRef) {}

@Input() get data(): any {
return this._data;
}
Expand All @@ -61,8 +61,9 @@ export class UIChart implements AfterViewInit, OnDestroy {

onCanvasClick(event) {
if (this.chart) {
let element = this.chart.getElementAtEvent(event);
let dataset = this.chart.getDatasetAtEvent(event);
const element = this.chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);
const dataset = this.chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);

if (element && element[0] && dataset) {
this.onDataSelect.emit({originalEvent: event, element: element[0], dataset: dataset});
}
Expand All @@ -78,41 +79,44 @@ export class UIChart implements AfterViewInit, OnDestroy {
opts.maintainAspectRatio = false;
}

this.chart = new Chart(this.el.nativeElement.children[0].children[0], {
type: this.type,
data: this.data,
options: this.options,
plugins: this.plugins
import('chart.js/auto').then((module) => {
if (module && module.default) {
this.chart = new module.default(this.el.nativeElement.children[0].children[0], {
type: this.type,
data: this.data,
options: this.options
});

This comment has been minimized.

Copy link
@flexadecimal

flexadecimal Oct 6, 2021

Did you forget to implement the plugin databinding here? Old constructor takes the plugins Input, and constructor in chart.js 3.3.2 hasn't changed. https://www.chartjs.org/docs/3.3.2/developers/plugins.html#using-plugins

Effectively this means that <p-chart [plugins]='somePlugins'></p-chart> is broken.

Please fix 🥺👉👈

This comment has been minimized.

Copy link
@s4m0r4m4

s4m0r4m4 Oct 7, 2021

Contributor

Linking the PR that fixes this just to maintain visibility: #10706

This comment has been minimized.

Copy link
@yigitfindikli

yigitfindikli Oct 13, 2021

Author Contributor

Thanks for your responses! Will be fixed in v12.2.1! @flexadecimal @s4m0r4m4

}
});
}

getCanvas() {
return this.el.nativeElement.children[0].children[0];
}

getBase64Image() {
return this.chart.toBase64Image();
}

generateLegend() {
if (this.chart) {
return this.chart.generateLegend();
}
}

refresh() {
if (this.chart) {
this.chart.update();
}
}

reinit() {
if (this.chart) {
this.chart.destroy();
this.initChart();
}
}

ngOnDestroy() {
if (this.chart) {
this.chart.destroy();
Expand Down
Loading

0 comments on commit c07677f

Please sign in to comment.