-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(elements): fix element cannot translate to origin point (#6319)
Co-authored-by: antv <antv@antfin.com>
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/g6/__tests__/bugs/element-set-position-to-origin.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ID } from '@/src'; | ||
import { createGraph } from '@@/utils'; | ||
|
||
describe('element set position to origin', () => { | ||
it('suite 1', async () => { | ||
const graph = createGraph({ | ||
data: { | ||
nodes: [{ id: 'node-1' }], | ||
}, | ||
}); | ||
|
||
await graph.draw(); | ||
|
||
// @ts-expect-error Property 'context' is protected | ||
const getElementOf = (id: ID) => graph.context.element!.getElement(id)!; | ||
|
||
expect(graph.getNodeData('node-1').style).toEqual({}); | ||
expect(getElementOf('node-1').style.transform).toBe('translate(0, 0)'); | ||
|
||
graph.translateElementTo('node-1', [100, 100]); | ||
|
||
expect(graph.getNodeData('node-1').style).toEqual({ x: 100, y: 100, z: 0 }); | ||
expect(getElementOf('node-1').style.transform).toBe('translate(100, 100)'); | ||
|
||
graph.translateElementTo('node-1', [0, 0]); | ||
|
||
expect(graph.getNodeData('node-1').style).toEqual({ x: 0, y: 0, z: 0 }); | ||
expect(getElementOf('node-1').style.transform).toBe('translate(0, 0)'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters