Skip to content

Commit e251a40

Browse files
committed
fix(custom-chart-web): refactor, updates changelog
1 parent 91492af commit e251a40

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

packages/pluggableWidgets/custom-chart-web/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9-
### Fixed
9+
### Breaking changes
1010

11-
- We fixed an issue where static data and source attribute wouldn't merge properly.
11+
- We changed how "Static" data and "Source attribute" data are merged. Previously, traces were appended as separate chart elements. Now, traces are merged by index, where source attribute values override static values for the same trace position. This enables proper customization of chart traces through dynamic data.
1212

1313
## [1.2.3] - 2025-10-10
1414

packages/pluggableWidgets/custom-chart-web/src/utils/utils.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import deepmerge from "deepmerge";
33
import { Config, Data, Layout } from "plotly.js-dist-min";
44
import { ChartProps } from "../components/PlotlyChart";
55

6-
// Custom merge options: arrays are replaced (not concatenated) to match Plotly expectations
7-
const mergeOptions: deepmerge.Options = {
8-
arrayMerge: (_target, source) => source
9-
};
6+
// Plotly-specific deep merge: arrays are replaced (not concatenated) to match Plotly expectations
7+
const deepmergePlotly = <T extends object>(target: T, source: T): T =>
8+
deepmerge(target, source, { arrayMerge: (_target, src) => src });
109

1110
export function parseData(staticData?: string, attributeData?: string, sampleData?: string): Data[] {
1211
try {
@@ -22,7 +21,7 @@ export function parseData(staticData?: string, attributeData?: string, sampleDat
2221
for (let i = 0; i < maxLen; i++) {
2322
const staticTrace = (staticTraces[i] ?? {}) as Record<string, unknown>;
2423
const dynamicTrace = (dynamicTraces[i] ?? {}) as Record<string, unknown>;
25-
result.push(deepmerge(staticTrace, dynamicTrace, mergeOptions) as Data);
24+
result.push(deepmergePlotly(staticTrace, dynamicTrace));
2625
}
2726

2827
return result;
@@ -38,7 +37,7 @@ export function parseLayout(staticLayout?: string, attributeLayout?: string, sam
3837
const attrObj = attributeLayout ? JSON.parse(attributeLayout) : {};
3938
const dynamicObj = Object.keys(attrObj).length > 0 ? attrObj : sampleLayout ? JSON.parse(sampleLayout) : {};
4039

41-
return deepmerge(staticObj, dynamicObj, mergeOptions);
40+
return deepmergePlotly(staticObj, dynamicObj);
4241
} catch (error) {
4342
console.error("Error parsing chart layout:", error);
4443
return {};
@@ -61,8 +60,8 @@ export function parseConfig(configOptions?: string): Partial<Config> {
6160
export function mergeChartProps(chartProps: ChartProps, editorState: EditorStoreState): ChartProps {
6261
return {
6362
...chartProps,
64-
config: deepmerge(chartProps.config, parseConfig(editorState.config), mergeOptions),
65-
layout: deepmerge(chartProps.layout, parseLayout(editorState.layout), mergeOptions),
63+
config: deepmergePlotly(chartProps.config, parseConfig(editorState.config)),
64+
layout: deepmergePlotly(chartProps.layout, parseLayout(editorState.layout)),
6665
data: chartProps.data.map((trace, index) => {
6766
let stateTrace: Data | null = null;
6867
try {
@@ -78,7 +77,7 @@ export function mergeChartProps(chartProps: ChartProps, editorState: EditorStore
7877
if (stateTrace == null || typeof stateTrace !== "object") {
7978
return trace;
8079
}
81-
return deepmerge(trace as object, stateTrace as object, mergeOptions) as Data;
80+
return deepmergePlotly(trace, stateTrace);
8281
})
8382
};
8483
}

0 commit comments

Comments
 (0)