WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 43255f1

Browse files
authored
Merge pull request #5760 from ag-grid/ag-16407/fix-fc-performance
AG-16407 - Fix Financial Charts performance.
2 parents 51959f2 + d73bddf commit 43255f1

File tree

22 files changed

+195
-102
lines changed

22 files changed

+195
-102
lines changed

packages/ag-charts-community/src/chart/axis/axis.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,18 +547,21 @@ export abstract class Axis<
547547

548548
protected animatable = true;
549549
setDomains(...domains: DomainWithMetadata<D>[]) {
550-
let domain: D[];
550+
let normalizedDomain: DomainWithMetadata<D>;
551551
let animatable: boolean;
552552
if (domains.length > 0) {
553-
({ domain, animatable } = this.scale.normalizeDomains(...domains));
553+
const result = this.scale.normalizeDomains(...domains);
554+
// After normalization, ordinal time domains are always sorted ascending
555+
normalizedDomain = { domain: result.domain, sortMetadata: { sortOrder: 1 } };
556+
animatable = result.animatable;
554557
} else {
555558
// Series (or all series in a group) hidden
556559
// There could be multiple axes, so we still consider this to be animatable
557-
domain = [];
560+
normalizedDomain = { domain: [] };
558561
animatable = true;
559562
}
560563

561-
this.dataDomain = this.normaliseDataDomain(domain);
564+
this.dataDomain = this.normaliseDataDomain(normalizedDomain);
562565

563566
if (this.reverse) {
564567
this.dataDomain.domain.reverse();
@@ -964,8 +967,8 @@ export abstract class Axis<
964967
return { domain, direction, boundSeries, defaultValue: this.title?.text };
965968
}
966969

967-
protected normaliseDataDomain(d: D[]): { domain: D[]; clipped: boolean } {
968-
return { domain: [...d], clipped: false };
970+
protected normaliseDataDomain(d: DomainWithMetadata<D>): { domain: D[]; clipped: boolean } {
971+
return { domain: [...d.domain], clipped: false };
969972
}
970973

971974
getLayoutState(): AxisLayout {

packages/ag-charts-community/src/chart/axis/categoryAxis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DomainWithMetadata } from 'ag-charts-core';
12
import { Property, isFiniteNumber } from 'ag-charts-core';
23
import type { AgTimeInterval, AgTimeIntervalUnit, DateFormatterStyle, FormatterParams } from 'ag-charts-types';
34

@@ -49,8 +50,8 @@ export class CategoryAxis<
4950
return false;
5051
}
5152

52-
override normaliseDataDomain(domain: Array<string | object>) {
53-
return { domain, clipped: false };
53+
override normaliseDataDomain(d: DomainWithMetadata<string | object>) {
54+
return { domain: d.domain, clipped: false };
5455
}
5556

5657
protected override updateScale() {

packages/ag-charts-community/src/chart/axis/logAxis.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DomainWithMetadata } from 'ag-charts-core';
12
import { Logger, normalisedExtentWithMetadata } from 'ag-charts-core';
23

34
import type { ModuleContext } from '../../module/moduleContext';
@@ -8,16 +9,24 @@ export class LogAxis extends NumberAxis {
89
static override readonly className = 'LogAxis';
910
static override readonly type = 'log' as const;
1011

11-
override normaliseDataDomain(d: number[]) {
12+
override normaliseDataDomain(d: DomainWithMetadata<number>) {
1213
const { min, max, preferredMin, preferredMax } = this;
13-
const { extent, clipped } = normalisedExtentWithMetadata(d, min, max, preferredMin, preferredMax);
14+
const { extent, clipped } = normalisedExtentWithMetadata(
15+
d.domain,
16+
min,
17+
max,
18+
preferredMin,
19+
preferredMax,
20+
undefined,
21+
d.sortMetadata?.sortOrder
22+
);
1423

15-
if ((extent[0] < 0 && extent[1] > 0) || (d[0] < 0 && d[1] > 0)) {
24+
if ((extent[0] < 0 && extent[1] > 0) || (d.domain[0] < 0 && d.domain[1] > 0)) {
1625
Logger.warn(
1726
`The log axis domain crosses zero, the chart data cannot be rendered. See log axis documentation for more information.`
1827
);
1928
return { domain: [], clipped };
20-
} else if (extent[0] === 0 || extent[1] === 0 || d[0] === 0 || d[1] === 0) {
29+
} else if (extent[0] === 0 || extent[1] === 0 || d.domain[0] === 0 || d.domain[1] === 0) {
2130
Logger.warn(
2231
`The log axis domain contains a value of 0, the chart data cannot be rendered. See log axis documentation for more information.`
2332
);

packages/ag-charts-community/src/chart/axis/numberAxis.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DomainWithMetadata } from 'ag-charts-core';
12
import { Property, normalisedExtentWithMetadata } from 'ag-charts-core';
23
import type { FormatterParams } from 'ag-charts-types';
34

@@ -33,9 +34,17 @@ export class NumberAxis extends CartesianAxis<LinearScale | LogScale, number> {
3334
return min != null && max != null && min < max;
3435
}
3536

36-
override normaliseDataDomain(d: number[]) {
37+
override normaliseDataDomain(d: DomainWithMetadata<number>) {
3738
const { min, max, preferredMin, preferredMax } = this;
38-
const { extent, clipped } = normalisedExtentWithMetadata(d, min, max, preferredMin, preferredMax);
39+
const { extent, clipped } = normalisedExtentWithMetadata(
40+
d.domain,
41+
min,
42+
max,
43+
preferredMin,
44+
preferredMax,
45+
undefined,
46+
d.sortMetadata?.sortOrder
47+
);
3948

4049
return { domain: extent, clipped };
4150
}

packages/ag-charts-community/src/chart/axis/timeAxis.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { ChartAxisDirection } from 'ag-charts-core';
1+
import type { ChartAxisDirection, DomainWithMetadata } from 'ag-charts-core';
22
import {
33
BaseProperties,
44
Logger,
55
Property,
66
ProxyPropertyOnWrite,
77
dateTruncationForDomain,
8-
extractDomain,
98
intervalEpoch,
109
intervalFloor,
1110
intervalMilliseconds,
@@ -90,9 +89,9 @@ export class TimeAxis extends CartesianAxis<TimeScale, number | Date> {
9089
return this.parentLevel.enabled ? this.parentLevel.tick : undefined;
9190
}
9291

93-
override normaliseDataDomain(domain: Date[]) {
92+
override normaliseDataDomain(d: DomainWithMetadata<Date>) {
9493
const { extent, clipped } = normalisedTimeExtentWithMetadata(
95-
domain,
94+
d,
9695
this.min,
9796
this.max,
9897
this.preferredMin,
@@ -199,7 +198,7 @@ export function calculateDefaultUnit(
199198
for (const series of boundSeries) {
200199
if (!series.visible) continue;
201200

202-
const { extent: domain } = normalisedTimeExtentWithMetadata(extractDomain(series.getDomain(direction)));
201+
const { extent: domain } = normalisedTimeExtentWithMetadata(series.getDomain(direction));
203202
if (domain.length === 0) continue;
204203

205204
const d0 = domain[0].valueOf();

packages/ag-charts-community/src/chart/axis/unitTimeAxis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DomainWithMetadata } from 'ag-charts-core';
12
import {
23
Property,
34
dateTruncationForDomain,
@@ -91,9 +92,9 @@ export class UnitTimeAxis extends DiscreteTimeAxis<UnitTimeScale> {
9192
this.scale.interval = this.unit ?? this.defaultUnit;
9293
}
9394

94-
override normaliseDataDomain(domain: Date[]) {
95+
override normaliseDataDomain(d: DomainWithMetadata<Date>) {
9596
const { extent, clipped } = normalisedTimeExtentWithMetadata(
96-
domain,
97+
d,
9798
this.min,
9899
this.max,
99100
this.preferredMin,

packages/ag-charts-community/src/chart/series/cartesian/barSeries.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,21 @@ export class BarSeries extends AbstractBarSeries<
13141314
highlightState?: HighlightState
13151315
): Required<AgBarSeriesStyle> {
13161316
const { properties, dataModel, processedData } = this;
1317-
const { itemStyler } = properties;
1317+
const { itemStyler, simpleItemStyler } = properties;
13181318

13191319
const highlightStyle = this.getHighlightStyle(isHighlight, datumIndex, highlightState);
1320+
1321+
// Fast path: simpleItemStyler bypasses options graph resolution
1322+
if (simpleItemStyler && processedData != null && datumIndex != null) {
1323+
const datum = processedData.dataSources.get(this.id)?.data?.[datumIndex];
1324+
const overrides = simpleItemStyler(datum);
1325+
return mergeDefaults(
1326+
overrides,
1327+
highlightStyle,
1328+
this.getStyle(false, highlightState)
1329+
) as Required<AgBarSeriesStyle>;
1330+
}
1331+
13201332
let style = mergeDefaults(highlightStyle, this.getStyle(datumIndex === undefined, highlightState));
13211333

13221334
if (itemStyler && dataModel != null && processedData != null && datumIndex != null) {
@@ -1616,6 +1628,7 @@ export class BarSeries extends AbstractBarSeries<
16161628
return (
16171629
this.properties.styler != null ||
16181630
this.properties.itemStyler != null ||
1631+
this.properties.simpleItemStyler != null ||
16191632
this.properties.label.itemStyler != null
16201633
);
16211634
}

packages/ag-charts-community/src/chart/series/cartesian/barSeriesOptionsDef.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type OptionsDefs,
33
barHighlightOptionsDef,
44
boolean,
5+
callback,
56
callbackDefs,
67
commonSeriesOptionsDefs,
78
commonSeriesThemeableOptionsDefs,
@@ -86,3 +87,5 @@ barSeriesOptionsDef.yFilterKey = undocumented(string);
8687
barSeriesOptionsDef.pickOutsideVisibleMinorAxis = undocumented(boolean);
8788
// @ts-expect-error undocumented option
8889
barSeriesOptionsDef.focusPriority = undocumented(number);
90+
// @ts-expect-error undocumented option
91+
barSeriesOptionsDef.simpleItemStyler = undocumented(callback);

packages/ag-charts-community/src/chart/series/cartesian/barSeriesProperties.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export class BarSeriesProperties extends AbstractBarSeriesProperties<AgBarSeries
8080
@Property
8181
itemStyler?: Styler<AgBarSeriesItemStylerParams<unknown>, AgBarSeriesStyle>;
8282

83+
@Property
84+
simpleItemStyler?: (datum: unknown) => AgBarSeriesStyle | undefined;
85+
8386
@Property
8487
readonly shadow = new DropShadow();
8588

packages/ag-charts-community/src/scale/ordinalTimeScale.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ export class OrdinalTimeScale extends DiscreteTimeScale {
7676

7777
if (nonEmptyDomains.length === 0) {
7878
return { domain: [], animatable: false };
79-
} else if (nonEmptyDomains.length === 1) {
79+
}
80+
81+
// Check if all domains are the same array reference (common in Financial Charts)
82+
const firstDomain = nonEmptyDomains[0].domain;
83+
const allSame = nonEmptyDomains.every((d) => d.domain === firstDomain);
84+
85+
if (nonEmptyDomains.length === 1 || allSame) {
8086
const input = nonEmptyDomains[0];
8187
let domain = input.domain;
8288

0 commit comments

Comments
 (0)