Skip to content

Commit

Permalink
Remove angular animations when SSR on charts with series (swimlane#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsongutidev authored Feb 9, 2022
1 parent f22f9b6 commit ec21b24
Show file tree
Hide file tree
Showing 14 changed files with 629 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TemplateRef,
TrackByFunction
} from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { trigger, style, animate, transition } from '@angular/animations';

import { scaleBand, scaleLinear } from 'd3-scale';
Expand Down Expand Up @@ -74,33 +75,65 @@ import { BarOrientation } from '../common/types/bar-orientation.enum';
[yAxisOffset]="dataLabelMaxWidth.negative"
(dimensionsChanged)="updateYAxisWidth($event)"
></svg:g>
<svg:g
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g *ngIf="!isSSR">
<svg:g
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g
ngx-charts-series-horizontal
[xScale]="valueScale"
[activeEntries]="activeEntries"
[yScale]="innerScale"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[roundEdges]="roundEdges"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
</svg:g>
</svg:g>
<svg:g *ngIf="isSSR">
<svg:g
ngx-charts-series-horizontal
[xScale]="valueScale"
[activeEntries]="activeEntries"
[yScale]="innerScale"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[roundEdges]="roundEdges"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
*ngFor="let group of results; let index = index; trackBy: trackBy"
[attr.transform]="groupTransform(group)"
>
<svg:g
ngx-charts-series-horizontal
[xScale]="valueScale"
[activeEntries]="activeEntries"
[yScale]="innerScale"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[roundEdges]="roundEdges"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
</svg:g>
</svg:g>
</svg:g>
</ngx-charts-chart>
Expand Down Expand Up @@ -172,9 +205,16 @@ export class BarHorizontal2DComponent extends BaseChartComponent {
yAxisWidth: number = 0;
legendOptions: LegendOptions;
dataLabelMaxWidth: any = { negative: 0, positive: 0 };
isSSR = false;

barOrientation = BarOrientation;

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

update(): void {
super.update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { BarChartType } from './types/bar-chart-type.enum';
import { ScaleType } from '../common/types/scale-type.enum';
import { LegendOptions, LegendPosition } from '../common/types/legend.model';
import { ViewDimensions } from '../common/types/view-dimension.interface';
import { isPlatformServer } from '@angular/common';

@Component({
selector: 'ngx-charts-bar-horizontal-normalized',
Expand Down Expand Up @@ -65,30 +66,55 @@ import { ViewDimensions } from '../common/types/view-dimension.interface';
[ticks]="yAxisTicks"
(dimensionsChanged)="updateYAxisWidth($event)"
></svg:g>
<svg:g
*ngFor="let group of results; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g *ngIf="!isSSR">
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Normalized"
[xScale]="xScale"
[yScale]="yScale"
[activeEntries]="activeEntries"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
[noBarWhenZero]="noBarWhenZero"
/>
*ngFor="let group of results; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Normalized"
[xScale]="xScale"
[yScale]="yScale"
[activeEntries]="activeEntries"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
[noBarWhenZero]="noBarWhenZero"
/>
</svg:g>
</svg:g>
<svg:g *ngIf="isSSR">
<svg:g *ngFor="let group of results; trackBy: trackBy" [attr.transform]="groupTransform(group)">
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Normalized"
[xScale]="xScale"
[yScale]="yScale"
[activeEntries]="activeEntries"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
[noBarWhenZero]="noBarWhenZero"
/>
</svg:g>
</svg:g>
</svg:g>
</ngx-charts-chart>
Expand Down Expand Up @@ -154,6 +180,13 @@ export class BarHorizontalNormalizedComponent extends BaseChartComponent {
yAxisWidth: number = 0;
legendOptions: LegendOptions;
barChartType = BarChartType;
isSSR = false;

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

update(): void {
super.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TemplateRef,
TrackByFunction
} from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { trigger, style, animate, transition } from '@angular/animations';

import { scaleBand, scaleLinear } from 'd3-scale';
Expand Down Expand Up @@ -65,33 +66,64 @@ import { ViewDimensions } from '../common/types/view-dimension.interface';
[yAxisOffset]="dataLabelMaxWidth.negative"
(dimensionsChanged)="updateYAxisWidth($event)"
></svg:g>
<svg:g
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g *ngIf="!isSSR">
<svg:g
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
>
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Stacked"
[xScale]="xScale"
[yScale]="yScale"
[colors]="colors"
[series]="group.series"
[activeEntries]="activeEntries"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
</svg:g>
</svg:g>
<svg:g *ngIf="isSSR">
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Stacked"
[xScale]="xScale"
[yScale]="yScale"
[colors]="colors"
[series]="group.series"
[activeEntries]="activeEntries"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
*ngFor="let group of results; let index = index; trackBy: trackBy"
[attr.transform]="groupTransform(group)"
>
<svg:g
ngx-charts-series-horizontal
[type]="barChartType.Stacked"
[xScale]="xScale"
[yScale]="yScale"
[colors]="colors"
[series]="group.series"
[activeEntries]="activeEntries"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[seriesName]="group.name"
[animations]="animations"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelWidthChanged)="onDataLabelMaxWidthChanged($event, index)"
/>
</svg:g>
</svg:g>
</svg:g>
</ngx-charts-chart>
Expand Down Expand Up @@ -162,6 +194,13 @@ export class BarHorizontalStackedComponent extends BaseChartComponent {
dataLabelMaxWidth: any = { negative: 0, positive: 0 };

barChartType = BarChartType;
isSSR = false;

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

update(): void {
super.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { LegendOptions, LegendPosition } from '../common/types/legend.model';
import { ScaleType } from '../common/types/scale-type.enum';
import { ViewDimensions } from '../common/types/view-dimension.interface';
import { BarOrientation } from '../common/types/bar-orientation.enum';
import { isPlatformServer } from '@angular/common';

@Component({
selector: 'ngx-charts-bar-vertical-2d',
Expand Down Expand Up @@ -73,10 +74,38 @@ import { BarOrientation } from '../common/types/bar-orientation.enum';
[ticks]="yAxisTicks"
(dimensionsChanged)="updateYAxisWidth($event)"
></svg:g>
<svg:g *ngIf="!isSSR">
<svg:g
ngx-charts-series-vertical
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
[activeEntries]="activeEntries"
[xScale]="innerScale"
[yScale]="valueScale"
[colors]="colors"
[series]="group.series"
[dims]="dims"
[gradient]="gradient"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
[showDataLabel]="showDataLabel"
[dataLabelFormatting]="dataLabelFormatting"
[seriesName]="group.name"
[roundEdges]="roundEdges"
[animations]="animations"
[noBarWhenZero]="noBarWhenZero"
(select)="onClick($event, group)"
(activate)="onActivate($event, group)"
(deactivate)="onDeactivate($event, group)"
(dataLabelHeightChanged)="onDataLabelMaxHeightChanged($event, index)"
/>
</svg:g>
</svg:g>
<svg:g *ngIf="isSSR">
<svg:g
ngx-charts-series-vertical
*ngFor="let group of results; let index = index; trackBy: trackBy"
[@animationState]="'active'"
[attr.transform]="groupTransform(group)"
[activeEntries]="activeEntries"
[xScale]="innerScale"
Expand Down Expand Up @@ -169,9 +198,16 @@ export class BarVertical2DComponent extends BaseChartComponent {
yAxisWidth: number = 0;
legendOptions: LegendOptions;
dataLabelMaxHeight: any = { negative: 0, positive: 0 };
isSSR = false;

barOrientation = BarOrientation;

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

update(): void {
super.update();

Expand Down
Loading

0 comments on commit ec21b24

Please sign in to comment.