Skip to content

Commit

Permalink
fix: fix issue that legend category cannot update shape (#4968)
Browse files Browse the repository at this point in the history
* fix: fix issue that legend category cannot update shape

* test: update test case
  • Loading branch information
Aarebecca authored and hustcc committed May 10, 2023
1 parent 5258a6e commit 152bc18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Binary file modified __tests__/integration/snapshots/api/chartChangeSize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions __tests__/plots/api/chart-change-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function chartChangeSize(context) {
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Infantry', sold: 220 },
{ genre: 'Logistics', sold: 330 },
{ genre: 'Other', sold: 150 },
]);

Expand Down
4 changes: 2 additions & 2 deletions src/component/legendCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useMarker } from '../utils/marker';
import {
adaptor,
domainOf,
G2Layout,
LegendCategoryLayout,
inferComponentLayout,
inferComponentShape,
scaleOf,
Expand Down Expand Up @@ -244,7 +244,7 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
};

const { legend: legendTheme = {} } = theme;
const layoutWrapper = new G2Layout({
const layoutWrapper = new LegendCategoryLayout({
style: {
x: bbox.x,
y: bbox.y,
Expand Down
7 changes: 7 additions & 0 deletions src/component/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export class G2Layout extends Layout {
}
}

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

export function scaleOf(scales: Scale[], type: string): Scale | undefined {
return scales.filter((s) => s.getOptions().name === type)?.[0];
}
Expand Down

0 comments on commit 152bc18

Please sign in to comment.