Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render animation misaligned #1949

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export class BarHorizontal2DComponent extends BaseChartComponent {
barOrientation = BarOrientation;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class BarHorizontalNormalizedComponent extends BaseChartComponent {
isSSR = false;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class BarHorizontalStackedComponent extends BaseChartComponent {
isSSR = false;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class BarVertical2DComponent extends BaseChartComponent {
barOrientation = BarOrientation;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class BarVerticalNormalizedComponent extends BaseChartComponent {
barChartType = BarChartType;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class BarVerticalStackedComponent extends BaseChartComponent {
barChartType = BarChartType;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
27 changes: 21 additions & 6 deletions projects/swimlane/ngx-charts/src/lib/bar-chart/bar.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Expand Down Expand Up @@ -65,16 +66,23 @@ export class BarComponent implements OnChanges {
gradientStops: Gradient[];
hasGradient: boolean = false;
hideBar: boolean = false;
pathAnimationDebounceTimer = null;

constructor(element: ElementRef) {
constructor(private cdf: ChangeDetectorRef, element: ElementRef) {
this.element = element.nativeElement;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.roundEdges) {
if (
changes.roundEdges ||
/* fix: appears to render animation misaligned */
changes.x ||
changes.y ||
changes.height ||
changes.width
) {
this.loadAnimation();
}
this.update();
} else this.update();
}

update(): void {
Expand All @@ -88,13 +96,20 @@ export class BarComponent implements OnChanges {
this.hasGradient = false;
}

this.updatePathEl();
this.checkToHideBar();
if (this.pathAnimationDebounceTimer) {
clearTimeout(this.pathAnimationDebounceTimer);
}
this.pathAnimationDebounceTimer = setTimeout(() => {
this.updatePathEl();
this.pathAnimationDebounceTimer = null;
}, 100);
}

loadAnimation(): void {
this.path = this.getStartingPath();
setTimeout(this.update.bind(this), 100);
this.cdf.markForCheck();
this.update();
}

updatePathEl(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class BubbleChartComponent extends BaseChartComponent {
isSSR = false;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class BaseChartComponent implements OnChanges, AfterViewInit, OnDestroy,
if (isPlatformServer(this.platformId)) {
this.animations = false;
}
this.update();
}

ngAfterViewInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export class LineChartComponent extends BaseChartComponent implements OnInit {
isSSR = false;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export class PolarChartComponent extends BaseChartComponent implements OnInit {
isSSR = false;

ngOnInit() {
super.ngOnInit();
if (isPlatformServer(this.platformId)) {
this.isSSR = true;
}
Expand Down