Skip to content

Commit

Permalink
fix: change data wont update (#5002)
Browse files Browse the repository at this point in the history
* fix: fix issue that change data wont update

* test: update test snapshot
  • Loading branch information
Aarebecca authored and hustcc committed May 13, 2023
1 parent 2e92914 commit 349a9f4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/api/chartOptionsChangeData.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/component/legendCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,27 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
};

const { legend: legendTheme = {} } = theme;

const categoryStyle = adaptor(
Object.assign({}, legendTheme, legendStyle, style),
);

const layoutWrapper = new LegendCategoryLayout({
style: {
x: bbox.x,
y: bbox.y,
width: bbox.width,
height: bbox.height,
...finalLayout,
// @ts-ignore
subOptions: categoryStyle,
},
});

layoutWrapper.appendChild(
new Category({
className: 'legend-category',
style: adaptor(Object.assign({}, legendTheme, legendStyle, style)),
style: categoryStyle,
}),
);
return layoutWrapper;
Expand Down
21 changes: 12 additions & 9 deletions src/component/legendContinuous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,6 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
const { bbox } = value;
const { x, y, width, height } = bbox;
const finalLayout = inferComponentLayout(position, layout);
const layoutWrapper = new G2Layout({
style: {
x,
y,
width,
height,
...finalLayout,
},
});

const { continuousLegend: legendTheme = {} } = theme;
const finalStyle = adaptor(
Expand Down Expand Up @@ -252,6 +243,18 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
),
);

const layoutWrapper = new G2Layout({
style: {
x,
y,
width,
height,
...finalLayout,
// @ts-ignore
subOptions: finalStyle,
},
});

layoutWrapper.appendChild(
new Continuous({
style: finalStyle,
Expand Down
14 changes: 9 additions & 5 deletions src/component/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@ export function inferComponentLayout(
}

export class G2Layout extends Layout {
get child() {
return this.children?.[0] as any;
}

update(options: any) {
this.attr(options);
const { width, height, ...restOptions } = options;
(this.children?.[0] as any)?.update(restOptions);
const { subOptions } = options;
this.child?.update(subOptions);
}
}

export class LegendCategoryLayout extends Layout {
export class LegendCategoryLayout extends G2Layout {
update(options: any) {
this.attr(options);
(this.children?.[0] as any)?.update(options);
const { subOptions } = options;
this.child?.update(subOptions);
}
}

Expand Down

0 comments on commit 349a9f4

Please sign in to comment.