mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 03:38:20 +08:00
fix: fix issue for null values in the alignFields util (#6152)
This commit is contained in:
parent
117d4513bf
commit
3aa9bbbfa2
@ -0,0 +1,42 @@
|
|||||||
|
import { createGraph } from '@@/utils';
|
||||||
|
|
||||||
|
describe('bug: plugin-history-align-fields', () => {
|
||||||
|
it('fix alignFields util', async () => {
|
||||||
|
const graph = createGraph({
|
||||||
|
plugins: [{ type: 'history', key: 'history' }],
|
||||||
|
data: {
|
||||||
|
nodes: [
|
||||||
|
{
|
||||||
|
id: 'node-1',
|
||||||
|
type: 'rect',
|
||||||
|
style: { x: 50, y: 100 },
|
||||||
|
data: {
|
||||||
|
aaa: {
|
||||||
|
bbb: false,
|
||||||
|
ccc: true,
|
||||||
|
ddd: '1234',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await graph.render();
|
||||||
|
|
||||||
|
expect(graph.getNodeData('node-1').style).toEqual({ x: 50, y: 100 });
|
||||||
|
expect(graph.getNodeData('node-1').data!.aaa).toEqual({
|
||||||
|
bbb: false,
|
||||||
|
ccc: true,
|
||||||
|
ddd: '1234',
|
||||||
|
});
|
||||||
|
|
||||||
|
await graph.translateElementBy('node-1', [100, 100]);
|
||||||
|
expect(graph.getNodeData('node-1').style).toEqual({ x: 150, y: 200, z: 0 });
|
||||||
|
expect(graph.getNodeData('node-1').data!.aaa).toEqual({
|
||||||
|
bbb: false,
|
||||||
|
ccc: true,
|
||||||
|
ddd: '1234',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -18,7 +18,7 @@ export function alignFields(refObject: Record<string, any>, targetObject: Record
|
|||||||
if (isObject(refObject[key]) && !Array.isArray(refObject[key]) && refObject[key] !== null) {
|
if (isObject(refObject[key]) && !Array.isArray(refObject[key]) && refObject[key] !== null) {
|
||||||
if (!targetObject[key]) targetObject[key] = {};
|
if (!targetObject[key]) targetObject[key] = {};
|
||||||
alignFields(refObject[key], targetObject[key]);
|
alignFields(refObject[key], targetObject[key]);
|
||||||
} else if (!targetObject[key]) {
|
} else if (targetObject[key] === undefined) {
|
||||||
targetObject[key] = inferDefaultValue(key);
|
targetObject[key] = inferDefaultValue(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user