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

AG-12655 Skip unordered category animations #2947

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions packages/ag-charts-community/src/chart/axis/categoryAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,52 @@ export class CategoryAxis<
@Validate(RATIO, { optional: true })
paddingOuter?: number;

private domainOrderedToNormalizedDomain(seriesDomain: any[], normalizedDomain: any[]) {
let normalizedIndex = -1;
for (let seriesIndex = 0; seriesIndex < seriesDomain.length; seriesIndex += 1) {
const value = seriesDomain[seriesIndex];
const normalizedNextIndex = normalizedDomain.indexOf(value);

if (normalizedNextIndex === -1) {
// All subsequent values must be extending (i.e. appending to) the normalized domain
normalizedIndex = Number.MAX_SAFE_INTEGER;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use Infinity to keep consistent with similar logic in our codebase

jacobp100 marked this conversation as resolved.
Show resolved Hide resolved
} else if (normalizedNextIndex <= normalizedIndex) {
return false;
} else {
normalizedIndex = normalizedNextIndex;
}
}

return true;
}

private categoryAnimatable = true;
protected override calculateDomain() {
let normalizedDomain: any[] = [];

let categoryAnimatable = true;
for (const series of this.boundSeries) {
if (!this.includeInvisibleDomains && !series.isEnabled()) continue;
Copy link
Contributor

@iMoses iMoses Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: includeInvisibleDomains is always true in category axes, so this always returns false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to match the original logic - in case this value ever changes


const seriesDomain = series.getDomain(this.direction);

categoryAnimatable &&= this.domainOrderedToNormalizedDomain(seriesDomain, normalizedDomain);

normalizedDomain = this.normaliseDataDomain([...normalizedDomain, ...seriesDomain]).domain;
}

this.setDomain(normalizedDomain);
this.categoryAnimatable = categoryAnimatable;
}

override update() {
super.update();

if (!this.categoryAnimatable) {
this.moduleCtx.animationManager.skip();
}
}

override normaliseDataDomain(d: Array<string | object>) {
const domain = [];
const uniqueValues = new Set();
Expand Down
Loading