-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize large image rendering performance
- Loading branch information
Showing
19 changed files
with
870 additions
and
87 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,9 @@ | ||
--- | ||
'@antv/g-plugin-canvaskit-renderer': patch | ||
'@antv/g-plugin-canvas-renderer': patch | ||
'@antv/g-plugin-device-renderer': patch | ||
'@antv/g-plugin-image-loader': patch | ||
'@antv/g-lite': patch | ||
--- | ||
|
||
perf: optimize large image rendering performance |
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,59 @@ | ||
import { Canvas, Image as GImage } from '@antv/g'; | ||
|
||
export async function image(context: { canvas: Canvas }) { | ||
const { canvas } = context; | ||
await canvas.ready; | ||
console.log(canvas); | ||
|
||
const $dom = canvas.getContextService().getDomElement() as HTMLCanvasElement; | ||
$dom.style.border = '1px solid gray'; | ||
|
||
// --- | ||
$dom.addEventListener('wheel', (event) => { | ||
event.preventDefault(); | ||
|
||
const { deltaX, deltaY } = event; | ||
const d = -(deltaX ?? deltaY); | ||
|
||
const ratio = 1 + (Math.min(Math.max(d, -50), 50) * 1) / 100; | ||
const zoom = canvas.getCamera().getZoom(); | ||
|
||
canvas | ||
.getCamera() | ||
.setZoomByViewportPoint(zoom * ratio, [event.offsetX, event.offsetY]); | ||
}); | ||
|
||
let isDragging = false; | ||
let lastX, lastY; | ||
$dom.addEventListener('mousedown', (e) => { | ||
isDragging = true; | ||
lastX = e.clientX; | ||
lastY = e.clientY; | ||
}); | ||
$dom.addEventListener('mousemove', (e) => { | ||
if (isDragging) { | ||
const dx = e.clientX - lastX; | ||
const dy = e.clientY - lastY; | ||
canvas.getCamera().pan(-dx, -dy); | ||
lastX = e.clientX; | ||
lastY = e.clientY; | ||
} | ||
}); | ||
$dom.addEventListener('mouseup', () => { | ||
isDragging = false; | ||
}); | ||
|
||
// --- | ||
|
||
let image = new GImage({ | ||
style: { | ||
x: 0, | ||
y: 0, | ||
// width: 100, | ||
// height: 400, | ||
// src: 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*N4ZMS7gHsUIAAAAAAAAAAABkARQnAQ', | ||
src: 'http://mmtcdp.stable.alipay.net/cto_designhubcore/afts/img/g1a5QYkvbcMAAAAAAAAAAAAADgLVAQBr/original', | ||
}, | ||
}); | ||
canvas.appendChild(image); | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { circles } from './circles'; | ||
export { rects } from './rect'; | ||
export { image } from './image'; |
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
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
Oops, something went wrong.