mirror of
https://gitee.com/antv/g6.git
synced 2024-11-29 18:28:19 +08:00
fix: fix error when manipulate data (#5899)
* fix: fix error when delete node data in tree graph * test: add case to test combo change * fix: fix error when collapse combo with only one child
This commit is contained in:
parent
c42c27475e
commit
79bb790299
30
packages/g6/__tests__/bugs/render-change-combo.spec.ts
Normal file
30
packages/g6/__tests__/bugs/render-change-combo.spec.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { createGraph } from '@@/utils';
|
||||
|
||||
describe('render change combo', () => {
|
||||
it('bug', async () => {
|
||||
const graph = createGraph({});
|
||||
await graph.render();
|
||||
|
||||
let count = 1;
|
||||
const operation = async () => {
|
||||
graph.setData({
|
||||
nodes: [
|
||||
{ id: 'node1', combo: `${count}A`, style: { x: 250, y: 150 } },
|
||||
{ id: 'node2', combo: `${count}b`, style: { x: 350, y: 150 } },
|
||||
{ id: 'node3', style: { x: 250, y: 300 } },
|
||||
],
|
||||
edges: [],
|
||||
combos: [
|
||||
{ id: `${count}A`, style: { labelText: `${count}A` } },
|
||||
{ id: `${count}b`, style: { labelText: `${count}B` } },
|
||||
],
|
||||
});
|
||||
await graph.render();
|
||||
count++;
|
||||
};
|
||||
|
||||
await operation();
|
||||
|
||||
await operation();
|
||||
});
|
||||
});
|
15
packages/g6/__tests__/bugs/render-deleted-data.spec.ts
Normal file
15
packages/g6/__tests__/bugs/render-deleted-data.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { layoutCompactBoxBasic } from '@/__tests__/demos';
|
||||
import { createDemoGraph } from '@@/utils';
|
||||
|
||||
describe('render deleted data', () => {
|
||||
it('bug', async () => {
|
||||
const graph = await createDemoGraph(layoutCompactBoxBasic);
|
||||
|
||||
const render = jest.fn(async () => {
|
||||
graph.removeNodeData(['Classification']);
|
||||
await graph.render();
|
||||
});
|
||||
|
||||
expect(render).not.toThrow();
|
||||
});
|
||||
});
|
@ -137,9 +137,16 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
|
||||
|
||||
protected getContentBBox(attributes: Required<S>): AABB {
|
||||
const { context, childrenNode = [], padding } = attributes;
|
||||
const childrenBBox = getCombinedBBox(
|
||||
childrenNode.map((id) => context!.element!.getElement(id)).map((child) => child!.getBounds()),
|
||||
);
|
||||
const children = childrenNode.map((id) => context!.element!.getElement(id)).filter(Boolean);
|
||||
if (children.length === 0) {
|
||||
const bbox = new AABB();
|
||||
const { x = 0, y = 0, size } = attributes;
|
||||
const [width, height] = parseSize(size);
|
||||
bbox.setMinMax([x - width / 2, y - height / 2, 0], [x + width / 2, y + height / 2, 0]);
|
||||
return bbox;
|
||||
}
|
||||
|
||||
const childrenBBox = getCombinedBBox(children.map((child) => child!.getBounds()));
|
||||
|
||||
if (!padding) return childrenBBox;
|
||||
|
||||
|
@ -378,9 +378,13 @@ export class DataController {
|
||||
const children = (datum as NodeData).children;
|
||||
if (children !== undefined) {
|
||||
model.attachTreeStructure(TREE_KEY);
|
||||
children.forEach((child) => {
|
||||
this.setParent(child, id, TREE_KEY);
|
||||
});
|
||||
const _children = children.filter((child) => model.hasNode(child));
|
||||
_children.forEach((child) => this.setParent(child, id, TREE_KEY));
|
||||
if (_children.length !== children.length) {
|
||||
// 从数据中移除不存在的子节点
|
||||
// Remove non-existent child nodes from the data
|
||||
this.updateNodeData([{ id, children: _children }]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user