Skip to content

Commit fb8d620

Browse files
committed
AG-16323 Fix options graph cache to be isolated per chart instance
1 parent 88a9800 commit fb8d620

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
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/module/optionsGraph.ts

Lines changed: 7 additions & 5 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
}
@@ -134,7 +135,8 @@ export class OptionsGraph extends AdjacencyListGraph<unknown, string> implements
134135
params: PlainObject | undefined = undefined,
135136
public readonly palette: PlainObject = {},
136137
private readonly overrides: PlainObject | undefined = undefined,
137-
private readonly internalParams: Map<unknown, unknown> = new Map()
138+
private readonly internalParams: Map<unknown, unknown> = new Map(),
139+
private readonly cachePrefix: string = 'shared'
138140
) {
139141
super(PATH_EDGE, OPERATION_EDGE, new Set([USER_PARTIAL_OPTIONS_EDGE, USER_OPTIONS_EDGE]));
140142

@@ -516,12 +518,12 @@ export class OptionsGraph extends AdjacencyListGraph<unknown, string> implements
516518
}
517519

518520
getCachedValue(path: string[], key: string): unknown {
519-
const cacheKey = [...path, key].join('.');
521+
const cacheKey = [this.cachePrefix, ...path, key].join('.');
520522
return OptionsGraph.valueCache.get(cacheKey);
521523
}
522524

523525
setCachedValue(path: string[], key: string, value: unknown): void {
524-
const cacheKey = [...path, key].join('.');
526+
const cacheKey = [this.cachePrefix, ...path, key].join('.');
525527
OptionsGraph.valueCache.set(cacheKey, value);
526528
}
527529

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
165165
metadata: ChartInternalOptionMetadata,
166166
deltaOptions?: DeepPartial<T> | null,
167167
stripSymbols = false,
168+
cachePrefix?: string,
168169
apiStartTime?: number
169170
) {
170171
this.optionMetadata = metadata ?? {};
@@ -219,7 +220,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
219220
} else {
220221
ChartOptions.perfDebug(`ChartOptions.slowSetup()`);
221222
({ activeTheme, processedOptions, themeParameters, annotationThemes, googleFonts, optionsGraph } =
222-
this.slowSetup(processedOverrides, deltaOptions, stripSymbols));
223+
this.slowSetup(processedOverrides, deltaOptions, stripSymbols, cachePrefix));
223224
}
224225

225226
this.activeTheme = activeTheme;
@@ -276,7 +277,12 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
276277
}
277278
}
278279

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

282288
if (deltaOptions) {
@@ -354,7 +360,7 @@ export class ChartOptions<T extends AgChartOptions = AgChartOptions> {
354360
this.processSeriesOptions(options);
355361
this.processAxesOptions(options, chartType);
356362

357-
const optionsGraph = createOptionsGraph(activeTheme, options);
363+
const optionsGraph = createOptionsGraph(activeTheme, options, cachePrefix);
358364
const resolvedOptions = optionsGraph.resolve() as any;
359365
const themeParameters = optionsGraph.resolveParams();
360366
const annotationThemes = optionsGraph.resolveAnnotationThemes();

0 commit comments

Comments
 (0)