Skip to content

Commit 824cceb

Browse files
committed
AG-16323 Fix options graph cache to be isolated per chart instance
1 parent dfd04fb commit 824cceb

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

packages/ag-charts-community/src/api/agCharts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class AgChartsInternal {
218218
optionsMetadata,
219219
deltaOptions,
220220
stripSymbols,
221+
chart?.id,
221222
apiStartTime
222223
);
223224

packages/ag-charts-community/src/chart/series/polar/donutSeries.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globa
33
import type { AgChartOptions, AgDonutSeriesOptions, AgPolarChartOptions } from 'ag-charts-types';
44

55
import { AgCharts } from '../../../api/agCharts';
6-
import { OptionsGraph } from '../../../module/optionsGraph';
76
import { Transformable } from '../../../scene/transformable';
87
import type { Chart } from '../../chart';
98
import type { AgChartProxy } from '../../chartProxy';
@@ -587,7 +586,6 @@ describe('DonutSeries', () => {
587586
let donutSeries: DonutSeries;
588587

589588
beforeEach(async () => {
590-
OptionsGraph.clearValueCache();
591589
const transactionOptions = prepareTestOptions({
592590
theme: {
593591
palette: {

packages/ag-charts-community/src/chart/series/polar/pieSeries.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globa
33
import type { AgChartOptions, AgPieSeriesOptions, AgPolarChartOptions } from 'ag-charts-types';
44

55
import { AgCharts } from '../../../api/agCharts';
6-
import { OptionsGraph } from '../../../module/optionsGraph';
76
import { Transformable } from '../../../scene/transformable';
87
import type { Chart } from '../../chart';
98
import type { AgChartProxy } from '../../chartProxy';
@@ -725,7 +724,6 @@ describe('PieSeries', () => {
725724
let pieSeries: PieSeries;
726725

727726
beforeEach(async () => {
728-
OptionsGraph.clearValueCache();
729727
const transactionOptions = prepareTestOptions({
730728
theme: {
731729
palette: {

packages/ag-charts-community/src/module/optionsGraph.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
const debug = Debug.create('opts', 'options-graph');
4444

4545
export const createOptionsGraph = simpleMemorize(createOptionsGraphFn);
46-
export function createOptionsGraphFn(theme: ChartTheme, options: PlainObject) {
46+
export function createOptionsGraphFn(theme: ChartTheme, options: PlainObject, cachePrefix?: string) {
4747
return debug.group(
4848
'OptionsGraph.constructor()',
4949
() =>
@@ -53,7 +53,8 @@ export function createOptionsGraphFn(theme: ChartTheme, options: PlainObject) {
5353
theme.params,
5454
theme.palette,
5555
theme.overrides,
56-
theme.getTemplateParameters()
56+
theme.getTemplateParameters(),
57+
cachePrefix
5758
)
5859
);
5960
}
@@ -92,10 +93,6 @@ export class OptionsGraph extends AdjacencyListGraph<unknown, string> implements
9293
// A cache of values that persists between chart updates, use sparingly.
9394
private static readonly valueCache = new Map();
9495

95-
public static clearValueCache() {
96-
OptionsGraph.valueCache.clear();
97-
}
98-
9996
public readonly paletteType: PaletteType;
10097

10198
// The current priority order in which to resolve options values.
@@ -134,7 +131,8 @@ export class OptionsGraph extends AdjacencyListGraph<unknown, string> implements
134131
params: PlainObject | undefined = undefined,
135132
public readonly palette: PlainObject = {},
136133
private readonly overrides: PlainObject | undefined = undefined,
137-
private readonly internalParams: Map<unknown, unknown> = new Map()
134+
private readonly internalParams: Map<unknown, unknown> = new Map(),
135+
private readonly cachePrefix: string = 'shared'
138136
) {
139137
super(PATH_EDGE, OPERATION_EDGE, new Set([USER_PARTIAL_OPTIONS_EDGE, USER_OPTIONS_EDGE]));
140138

@@ -514,12 +512,12 @@ export class OptionsGraph extends AdjacencyListGraph<unknown, string> implements
514512
}
515513

516514
getCachedValue(path: string[], key: string): unknown {
517-
const cacheKey = [...path, key].join('.');
515+
const cacheKey = [this.cachePrefix, ...path, key].join('.');
518516
return OptionsGraph.valueCache.get(cacheKey);
519517
}
520518

521519
setCachedValue(path: string[], key: string, value: unknown): void {
522-
const cacheKey = [...path, key].join('.');
520+
const cacheKey = [this.cachePrefix, ...path, key].join('.');
523521
OptionsGraph.valueCache.set(cacheKey, value);
524522
}
525523

packages/ag-charts-community/src/module/optionsModule.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
163163
metadata: ChartInternalOptionMetadata,
164164
deltaOptions?: DeepPartial<T> | null,
165165
stripSymbols = false,
166+
cachePrefix?: string,
166167
apiStartTime?: number
167168
) {
168169
this.optionMetadata = metadata ?? {};
@@ -217,7 +218,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
217218
} else {
218219
ChartOptions.perfDebug(`ChartOptions.slowSetup()`);
219220
({ activeTheme, processedOptions, themeParameters, annotationThemes, googleFonts, optionsGraph } =
220-
this.slowSetup(processedOverrides, deltaOptions, stripSymbols));
221+
this.slowSetup(processedOverrides, deltaOptions, stripSymbols, cachePrefix));
221222
}
222223

223224
this.activeTheme = activeTheme;
@@ -274,7 +275,12 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
274275
}
275276
}
276277

277-
private slowSetup(processedOverrides: Partial<T>, deltaOptions?: DeepPartial<T> | null, stripSymbols = false) {
278+
private slowSetup(
279+
processedOverrides: Partial<T>,
280+
deltaOptions?: DeepPartial<T> | null,
281+
stripSymbols = false,
282+
cachePrefix?: string
283+
) {
278284
let options = deepClone(this.userOptions, ChartOptions.OPTIONS_CLONE_OPTS_FAST) as T & { type?: string };
279285

280286
if (deltaOptions) {
@@ -352,7 +358,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
352358
this.processSeriesOptions(options);
353359
this.processAxesOptions(options);
354360

355-
const optionsGraph = createOptionsGraph(activeTheme, options);
361+
const optionsGraph = createOptionsGraph(activeTheme, options, cachePrefix);
356362
const resolvedOptions = optionsGraph.resolve() as any;
357363
const themeParameters = optionsGraph.resolveParams();
358364
const annotationThemes = optionsGraph.resolveAnnotationThemes();

0 commit comments

Comments
 (0)