-
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(plugins): fix tooltip with incorrect position after graph resize
- Loading branch information
antv
committed
Aug 28, 2024
1 parent
c9ba7fc
commit b85182e
Showing
6 changed files
with
98 additions
and
17 deletions.
There are no files selected for viewing
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,53 @@ | ||
import { Graph } from '@antv/g6'; | ||
|
||
export const bugTooltipResize: TestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data: { | ||
nodes: [{ id: 'node1' }, { id: 'node2' }, { id: 'node3' }, { id: 'node4' }, { id: 'node5' }], | ||
edges: [ | ||
{ source: 'node1', target: 'node2' }, | ||
{ source: 'node1', target: 'node3' }, | ||
{ source: 'node1', target: 'node4' }, | ||
{ source: 'node2', target: 'node3' }, | ||
{ source: 'node3', target: 'node4' }, | ||
{ source: 'node4', target: 'node5' }, | ||
], | ||
}, | ||
layout: { | ||
type: 'grid', | ||
}, | ||
plugins: [ | ||
{ | ||
type: 'tooltip', | ||
style: { | ||
['.tooltip']: { | ||
transition: 'none', | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
bugTooltipResize.form = (panel) => { | ||
let width = 500; | ||
return [ | ||
panel.add( | ||
{ | ||
resize: () => { | ||
const newWidth = width === 500 ? 300 : 500; | ||
width = newWidth; | ||
document.querySelector<HTMLDivElement>('#container')!.style.width = `${newWidth}px`; | ||
graph.resize(); | ||
graph.fitView(); | ||
}, | ||
}, | ||
'resize', | ||
), | ||
]; | ||
}; | ||
|
||
return graph; | ||
}; |
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
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
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,26 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('plugin tooltip', () => { | ||
test('bug: tooltip should has correct position after graph resize', async ({ page }) => { | ||
page.goto('/?Demo=bugTooltipResize&Renderer=canvas&GridLine=true&Theme=light&Animation=false'); | ||
|
||
await page.waitForSelector('.tooltip'); | ||
|
||
const clip = { x: 0, y: 0, width: 500, height: 500 }; | ||
|
||
await page.mouse.move(375, 250); | ||
|
||
await expect(page).toHaveScreenshot({ clip }); | ||
|
||
await page.mouse.move(250, 250); | ||
|
||
// wait for div content is 'resize' | ||
const resize = page.getByRole('button', { name: 'resize' }); | ||
|
||
await resize?.click(); | ||
|
||
await page.mouse.move(285, 250); | ||
|
||
await expect(page).toHaveScreenshot({ clip }); | ||
}); | ||
}); |
Binary file added
BIN
+10.6 KB
...ug-tooltip-should-has-correct-position-after-graph-resize-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...ug-tooltip-should-has-correct-position-after-graph-resize-2-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.