Dynamic value generation when zooming
- Dominant language
- Swift
- Stars
- 28k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I want to make a Function plotter where you set the range of values by just zooming out.
So what I tried is setting the minimum x and y Scale in the viewporthandler to 0.1 and then modify the code in the pinchGestureRecognized of BarLineChartViewBase.swift like the following:
`else if recognizer.state == NSUIGestureRecognizerState.changed
{
let isZoomingOut = (recognizer.nsuiScale < 1)
var canZoomMoreX = isZoomingOut ? _viewPortHandler.canZoomOutMoreX : _viewPortHandler.canZoomInMoreX
var canZoomMoreY = isZoomingOut ? _viewPortHandler.canZoomOutMoreY : _viewPortHandler.canZoomInMoreY
if _isScaling
{
canZoomMoreX = canZoomMoreX && _scaleXEnabled && (_gestureScaleAxis == .both || _gestureScaleAxis == .x)
canZoomMoreY = canZoomMoreY && _scaleYEnabled && (_gestureScaleAxis == .both || _gestureScaleAxis == .y)
//if canZoomMoreX || canZoomMoreY
//{
var location = recognizer.location(in: self)
location.x = location.x - _viewPortHandler.offsetLeft
if isTouchInverted()
{
location.y = -(location.y - _viewPortHandler.offsetTop)
}
else
{
location.y = -(_viewPortHandler.chartHeight - location.y - _viewPortHandler.offsetBottom)
}
let scaleX = /*canZoomMoreX ?*/ recognizer.nsuiScale// : 1.0
let scaleY = /*canZoomMoreY ?*/ recognizer.nsuiScale// : 1.0
var matrix = CGAffineTransform(translationX: location.x, y: location.y)
matrix = matrix.scaledBy(x: scaleX, y: scaleY)
matrix = matrix.translatedBy(x: -location.x, y: -location.y)
matrix = _viewPortHandler.touchMatrix.concatenating(matrix)
delegate?.update?(x: matrix.tx, y: matrix.ty, scaleX: matrix.a, scaleY: matrix.d)
let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)
if delegate !== nil
{
delegate?.chartScaled?(self, scaleX: scaleX, scaleY: scaleY)
}
/*}
else
{
}*/
recognizer.nsuiScale = 1.0
}
}`
Where update does just set the ChartData as it does when initially setting the data but with a different range
`func update(x: CGFloat, y: CGFloat, scaleX: CGFloat, scaleY: CGFloat)
{
setChart(from: Double(CGFloat(_from) / scaleX), to: Double(CGFloat(_to) / scaleY))
}`
But this is not working fine at all the zooming is absolutely wrong a weird. Is there a clever way of doing this that works well ? Thanks a lot in advance =)
Contributor guide
Research direction
Start with BarLineChartViewBase.swift and its pinchGestureRecognized handling, then inspect the viewport handler and the existing setChart path used for initial data. Reproduce the zoom behavior with the proposed update method and compare the viewport transform with the recalculated range. Done means zooming changes the function range without the distorted or incorrect behavior described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- data-visualization, mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100