-
Notifications
You must be signed in to change notification settings - Fork 18
PanZoom
Marshall Peterson edited this page May 16, 2024
·
1 revision
Pan and zoom work by updating the domain for the x and/or y scales. Instead of having the scale domain set by the extent of the data that it is bound to, the domain is set using a signal which calculates the current domain based on user interaction.
-
width: number
– Width of the charting area in pixels -
height: number
– Height of the charting area in pixels
-
initialXDomain: [number, number]
– Start and end of thex
domain at the beginning of the pan interaction -
initialYDomain: [number, number]
– Start and end of they
domain at the beginning of the pan interaction -
panDelta: [number, number]
–x
andy
difference in pixels from the beginning of the pan to the current position
-
zoomAnchor: [number, number]
–x
andy
domain coordinates to zoom in/out from -
zoomRatio: number
: zoom ratio
-
xDomain: [number, number]
– Start and end of thex
domain -
yDomain: [number, number]
– Start and end of they
domain
const initialXSpan = initialXDomain[1] - initialXDomain[0];
const xPanRatio = panDelta[0] / width;
const xDomainOffset = initialXSpan * xPanRatio;
const initialYSpan = initialYDomain[1] - initialYDomain[0];
const yPanRatio = panDelta[1] / height;
const yDomainOffset = initialYSpan * yPanRatio;
const xDomain = [
initialXDomain[0] + xDomainOffset,
initialXDomain[1] + xDomainOffset,
]
const yDomain = [
initialYDomain[0] + yDomainOffset,
initialYDomain[1] + yDomainOffset,
]
return {xDomain, yDomain}
const xDomain = [
zoomAnchor[0] + (xDomain[0] - zoomAnchor[0]) * zoomRatio,
zoomAnchor[0] + (xDomain[1] - zoomAnchor[0]) * zoomRatio,
]
@adobe/react-spectrum-charts - Adobe 2024
Chart Components
Supplemental Chart Components
Layout Components