8000 Fix/update of axis by xile611 · Pull Request #3008 · VisActor/VChart · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix/update of axis #3008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix issue of `updateSpec` when visible of grid in axis change, fix #3004\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
155 changes: 155 additions & 0 deletions packages/vchart/__tests__/unit/core/update-spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,4 +1253,159 @@ describe('vchart updateSpec of different about label', () => {
reTransformSpec: false
});
});

it('should remake when visible of axis grid change', () => {
const spec = {
type: 'area',
data: [
{
id: 'area',
values: [
{ x: '1990', y: 110, from: 'video ad' },
{ x: '1995', y: 160, from: 'video ad' },
{ x: '2000', y: 230, from: 'video ad' },
{ x: '2005', y: 300, from: 'video ad' },
{ x: '2010', y: 448, from: 'video ad' },
{ x: '2015', y: 500, from: 'video ad' },
{ x: '1990', y: 120, from: 'email marketing' },
{ x: '1995', y: 150, from: 'email marketing' },
{ x: '2000', y: 200, from: 'email marketing' },
{ x: '2005', y: 210, from: 'email marketing' },
{ x: '2010', y: 300, from: 'email marketing' },
{ x: '2015', y: 320, from: 'email marketing' }
]
}
],
label: {
visible: true
},
xField: 'x',
yField: 'y',
seriesField: 'from',
axes: [
{
orient: 'bottom',
type: 'band' as const
},
{
orient: 'left',
type: 'linear' as const,
grid: {
visible: true
}
}
]
};
vchart = new VChart(spec, {
< 10000 /td> dom
});
vchart.renderSync();
const updateRes = (vchart as any)._updateSpec(
{
...spec,
axes: [
{
orient: 'bottom',
type: 'band' as const
},
{
orient: 'left',
type: 'linear' as const,
grid: {
visible: false
}
}
]
},
false
);

expect(updateRes).toEqual({
change: false,
changeTheme: false,
reCompile: false,
reMake: true,
reRender: true,
reSize: false,
reTransformSpec: false
});
});

it('should reRender when `alternateColor` of axis grid change', () => {
const spec = {
type: 'area',
data: [
{
id: 'area',
values: [
{ x: '1990', y: 110, from: 'video ad' },
{ x: '1995', y: 160, from: 'video ad' },
{ x: '2000', y: 230, from: 'video ad' },
{ x: '2005', y: 300, from: 'video ad' },
{ x: '2010', y: 448, from: 'video ad' },
{ x: '2015', y: 500, from: 'video ad' },
{ x: '1990', y: 120, from: 'email marketing' },
{ x: '1995', y: 150, from: 'email marketing' },
{ x: '2000', y: 200, from: 'email marketing' },
{ x: '2005', y: 210, from: 'email marketing' },
{ x: '2010', y: 300, from: 'email marketing' },
{ x: '2015', y: 320, from: 'email marketing' }
]
}
],
label: {
visible: true
},
xField: 'x',
yField: 'y',
seriesField: 'from',
axes: [
{
orient: 'bottom',
type: 'band' as const
},
{
orient: 'left',
type: 'linear' as const,
grid: {
visible: true
}
}
]
};
vchart = new VChart(spec, {
dom
});
vchart.renderSync();
const updateRes = (vchart as any)._updateSpec(
{
...spec,
axes: [
{
orient: 'bottom',
type: 'band' as const
},
{
orient: 'left',
type: 'linear' as const,
grid: {
visible: true,
alternateColor: ['pink', 'green']
}
}
]
},
false
);

expect(updateRes).toEqual({
change: false,
changeTheme: false,
reCompile: false,
reMake: false,
reRender: true,
reSize: false,
reTransformSpec: false
});
});
});
9 changes: 9 additions & 0 deletions packages/vchart/src/component/axis/base-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
/** Update API **/
_compareSpec(spec: T, prevSpec: T) {
const result = super._compareSpec(spec, prevSpec);
if (result.reMake) {
return result;
}

result.reRender = true;
/**
* 存在轴同步相关配置的时候,暂时通过`reMake`触发更新
Expand All @@ -414,6 +418,11 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
result.reMake = true;
return result;
}

result.reMake = ['grid', 'subGrid', 'tick', 'subTick', 'label', 'domainLine', 'title'].some(k => {
return prevSpec?.[k]?.visible !== spec?.[k]?.visible;
});

return result;
}

Expand Down
Loading
0