Skip to content

Commit

Permalink
update options config change
Browse files Browse the repository at this point in the history
  • Loading branch information
antonin77 committed Feb 6, 2025
1 parent 5d8cdc3 commit bf7aea7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 39 deletions.
3 changes: 3 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,8 @@
}
}
}
},
"cli": {
"analytics": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,23 @@ export class BarChartDirective<X extends XaxisType> implements ChartView<X, numb
this.createElement();
}

private async createElement() {
private createElement() {
this.updateConfig();
this.updateType();
this.updateLoading();
this.updateData();

this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
if(this.chartInstance() != null) {
this.updateOptions(this._options, true, true, false);
} else {
this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
}
}

private render() {
Expand Down Expand Up @@ -167,6 +172,10 @@ export class BarChartDirective<X extends XaxisType> implements ChartView<X, numb
});
}

private updateType() {
mergeDeep(this._options, { chart: { type: this.type } });
}

private updateOptions(
options: any,
redrawPaths?: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class LineChartDirective<X extends XaxisType, Y extends YaxisType> implem
@Output() customEvent: EventEmitter<'previous' | 'next' | 'pivot'> = new EventEmitter();

ngOnChanges(changes: SimpleChanges): void {
console.log("onChanges", changes)
this.ngZone.runOutsideAngular(() => {
asapScheduler.schedule(() => this.hydrate(changes));
});
Expand All @@ -58,6 +59,7 @@ export class LineChartDirective<X extends XaxisType, Y extends YaxisType> implem
const shouldUpdateSeries =
Object.keys(changes).filter((c) => c !== "data" && c!== "isLoading").length === 0;
if (shouldUpdateSeries) {
console.log("shouldUpdateSeries", this.type, this.config, this.data, this.isLoading)
this.updateLoading();
this.updateData();
this.updateOptions(this._options, true, true, false);
Expand All @@ -67,19 +69,23 @@ export class LineChartDirective<X extends XaxisType, Y extends YaxisType> implem
this.createElement();
}

private async createElement() {
private createElement() {
this.updateConfig();
this.updateType();
this.updateLoading();
this.updateData();

this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
if(this.chartInstance() != null) {
this.updateOptions(this._options, true, true, false);
} else {
this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
}
}

private render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,23 @@ export class PieChartDirective implements ChartView<string, number>, OnChanges,
this.createElement();
}

private async createElement() {
private createElement() {
this.updateConfig();
this.updateType();
this.updateLoading();
this.updateData();

this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
if(this.chartInstance() != null) {
this.updateOptions(this._options, true, true, false);
} else {
this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
}
}

private render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ export class RangeChartDirective<X extends XaxisType> implements ChartView<X, nu
this.createElement();
}

private async createElement() {
private createElement() {
this.updateConfig();
this.updateType();
this.updateLoading();
this.updateData();

this.destroy();
if(this.chartInstance() != null) {
this.updateOptions(this._options, true, true, false);
} else {
this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
}
}

private render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ export class TreemapChartDirective implements ChartView<string, number>, OnChang
this.createElement();
}

private async createElement() {
private createElement() {
this.updateConfig();
this.updateType();
this.updateLoading();
this.updateData();

this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
if(this.chartInstance() != null) {
this.updateOptions(this._options, true, true, false);
} else {
this.destroy();

const chartInstance = this.ngZone.runOutsideAngular(
() => new ApexCharts(this.el.nativeElement, this._options)
);
this.chartInstance.set(chartInstance);
this.render();
}
}

private render() {
Expand Down

0 comments on commit bf7aea7

Please sign in to comment.