Charts-kt manages zooming and panning of the visuals.
This is not a "GPU" transformation: it's not just the visuals that are zoomed or panned, but the whole chart that is refreshed, and everything is recomputed.
To enable zoom and pan you have access to these properties of a the chart config
:
//run highlight-only
chart(data) {
config {
events {
zoomMode = ZoomMode.XY // enable zooming on X and Y directions
panMode = PanMode.None // disable panning
}
}
(...)
}
Note that this enables or disables user interactions, however, you can always "force" them by code with chart.zoom()
or chart.pan()
.
Your Chart
contains a public Zoom
instance that holds your "zoom information".
This Zoom
contains 2 DirectedZoom
classes, one for each direction, and each of these classes stores the ratio
and the offset
of your zoom.
The more you zoom-in, the higher your ratio, a chart.zoom.xZoom.ratio
of 2.0 for example means that your actual chart X-axis is two times larger than the initial one.
When you move your chart around, the offset
is updated to reflect this panning.
But when you zoom in and out, the offset is also updated so the visual elements you are zooming on stay on screen just where you expect them to be.
The ZoomEvent
data class contains all changes that reflect a zooming action.
The zoom origin (zoomOriginX
, zoomOriginY
) is relative to the main charting zone:
For example if you zoom-in at the top-right corner the zoomOriginX
value is 100% and the
zoomOriginY
value is 0%.