-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
viewPortHandler.setMaximumScaleX not working for horizontal bar chart #256
Comments
About As for the gestures - I have no objection to making it internal... |
@danielgindi I was stuck in how to read correct _maxScaleX in ChartViewPortHandler. I have to obtain chart type in ChartViewPortHandler, which I think is not a good design? I want to read matrix.d instead of matrix.a for horizontal bar chart. |
Yes it is, the better way should be that the ViewPort knows that the axis is rotated (x=y, y=x) |
Got you. I will take a look at the subclassing way and 'rotated axis' way. |
@danielgindi Another question, do you have any purpose for the missing |
maxScaleY is just a much more complex issue :-) |
I tried adding property axisRotated and just switch them like this in if (_axisRotated)
{
// min scale-x is 1, max is the max CGFloat
_scaleX = min(max(_minScaleX, matrix.d), _maxScaleX)
// min scale-y is 1
_scaleY = max(_minScaleY, matrix.a)
}
else
{
// min scale-x is 1, max is the max CGFloat
_scaleX = min(max(_minScaleX, matrix.a), _maxScaleX)
// min scale-y is 1
_scaleY = max(_minScaleY, matrix.d)
} Other code in ViewPortHandler not changed. It actually can zoom to correct maxScaleX, but while zooming, the chart is moving like 'shaking' a lot not static. |
You might be encountering the problem of the axis changing its size. You On Thu, Jul 30, 2015 at 11:40 AM, Xuan [email protected] wrote:
|
I improved limitTransAndScale like below. The zooming is working to me, but when it exceeds the maxScaleX, let's say 3, the chart start moving to the top. I am not sure why, as far as I can tell is the I am not sure if below code about the newTransY calculation is correct. This is the current limitTransAndScale: /// limits the maximum scale and X translation of the given matrix
private func limitTransAndScale(inout #matrix: CGAffineTransform, content: CGRect?)
{
if (_axisRotated)
{
// min scale-x is 1, max is the max CGFloat
_scaleX = min(max(_minScaleX, matrix.d), _maxScaleX)
// min scale-y is 1
_scaleY = max(_minScaleY, matrix.a)
}
else
{
// min scale-x is 1, max is the max CGFloat
_scaleX = min(max(_minScaleX, matrix.a), _maxScaleX)
// min scale-y is 1
_scaleY = max(_minScaleY, matrix.d)
}
var width: CGFloat = 0.0
var height: CGFloat = 0.0
if (content != nil)
{
width = content!.width
height = content!.height
}
if (axisRotated)
{
var maxTransX = -width * (_scaleY - 1.0)
var newTransX = min(max(matrix.tx, maxTransX - _transOffsetX), _transOffsetX)
var maxTransY = height * (_scaleX - 1.0)
var newTransY = max(min(matrix.ty, maxTransY + _transOffsetY), -_transOffsetY)
matrix.tx = newTransX
matrix.a = _scaleY
matrix.ty = newTransY
matrix.d = _scaleX
}
else
{
var maxTransX = -width * (_scaleX - 1.0)
var newTransX = min(max(matrix.tx, maxTransX - _transOffsetX), _transOffsetX)
var maxTransY = height * (_scaleY - 1.0)
var newTransY = max(min(matrix.ty, maxTransY + _transOffsetY), -_transOffsetY)
matrix.tx = newTransX
matrix.a = _scaleX
matrix.ty = newTransY
matrix.d = _scaleY
}
} |
Well I spent a lot to figure out what's going on for it. Here's my investigation Let's say we set maxScaleX to 3 for horizontal bar chart. If I apply above code, the zoom in will stop when it reaches 3, however it will have some offset vertically. It is because, in var scaleX = (_gestureScaleAxis == .Both || _gestureScaleAxis == .X) && _scaleXEnabled ? recognizer.scale : 1.0
var scaleY = (_gestureScaleAxis == .Both || _gestureScaleAxis == .Y) && _scaleYEnabled ? recognizer.scale : 1.0
var matrix = CGAffineTransformMakeTranslation(location.x, location.y)
matrix = CGAffineTransformScale(matrix, scaleX, scaleY)
matrix = CGAffineTransformTranslate(matrix, -location.x, -location.y)
matrix = CGAffineTransformConcat(_viewPortHandler.touchMatrix, matrix)
_viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true) When calculating scaleY, once we reaches the max scale 3, the viewPortHandler.touchMatrix.d will be 3, however, the matrix.d will be some value larger than 1, let's say 1.2. Now, the matrix will concat the touchMatrix, so the new matrix.d after concat is 3.6(3*1.2), and matrix.ty is positive value. This matrix.ty is based on scale 3.6, not 3. so when we are trying to calculate it in limitTransAndScale, var maxTransY = height * (_scaleX - 1.0)
var newTransY = max(min(matrix.ty, maxTransY + _transOffsetY), -_transOffsetY) The newTransY will always be matrix.ty until it exceeds maxTransY. That's why I have the offeset vertically. I think it is a tough bug to fix. What I can think about is, we have to calculate the ty when the scale is exactly based on the max scale, and store it somewhere, this will be the correct value to use, after the matrix.d larger than mas scale. |
@danielgindi I suddenly realize am I facing the same maxScaleY issue...? Since horizontal bar is rotated, and then the scaling the X for horizontal bar is just like sacaling Y for normal bars... |
So what you are saying is - all this work and you changed nothing? :-)
|
No, I mean I am stuck at the matrix calculating, and today I feel setting max scaling x scale feature for horizontal bar is just like setting normal charts' max scale on y axis. Currently we don't support setting maxScaleY, and you said it's complicated, and it is the same complexicity for horizontal bar chart... I now trying save the last touchMatrix before it exceeds the maxScale, and try to calculate the translations from this last touchMatrix to get the correct translateX,Y. But still some bugs. Can you share where you are blocked for this feature? Do you have plan for fixing it :-) |
@liuxuan30 does #388 solve this for you? |
@danielgindi I need some clarifications here, for horizontal bar chart, what direction is for maxScaleX and maxScaleY? I just tried play with them, but I found setting maxScaleX for horizontal bar chart's effect is like setting same maxScaleX as normal bar chart, which I think should be maxScaleY effect. Which means, if I use below code in horizontal bar chart in ChartsDemo: [_chartView.viewPortHandler setMaximumScaleX:3.0]; It actually works horizontally, which I think it should be y axis... This seems very different at the time we were talking about this post. I was always thinking the x axis for horizontal bar chart is the y axis for normal bar chart... And [_chartView.viewPortHandler setMaximumScaleY:3.0]; actually could limit the horizontal bar chart's 'x' axis. So I think this issue works for me, only the x and y axis are confusing. BTW, I found another small bug #463: if you reach the max scale level, scroll the chart to the middle, and try zoom in again, it actually starts a scrolling to top, which at first seems zooming. This is also a bug when I tried to implement maxScaleY. So I use another way to solve my problem, meaning saving a touchMatrix everytime and read data from it. |
The bug at #463 is fixed, but X/Y are still flipped for horizontal bar chart, as the axises ARE actually flipped. You are using Y axis component for the axis that shows on the X axis, but it is still called Y axis. |
It works like a charm with b1e9d0b while setting maxScaleX/Y. A old though bug solved finally! Now I have to recall all my changes for this. My misunderstanding is I use |
@danielgindi Yes, the big change is for the transformers and view ports. I tried another sort of scatter chart, and I put one normal bar chart y axis and one horizontal bar chart y axis together to work as x and y axis in the scatter chart. |
I am trying to set max scaleX for horizontal bar chart via
viewPortHandler.setMaximumScaleX
, let's say the maxScaleX to be 3.However when zooming in on xAxis for horizontal bart chart, it can zoom in as much I want.
After the investigation, I found in below function
matrix.a
is always 1, butmatrix.d
is keeping increasing as the correct scale inlimitTransAndScale
. It seems like we forgot to switch them for horizontal bart chart, or do you intend to do so?Also, I want to propose could we change the gestures and their handlers to be 'internal' rather than 'private'?
The pinch gesture handler is private and I cannot override it to adapt for horizontal bar charts, though we could use
is HorizontalBarChartView
in BarLineChartViewBase and make some changes, just likeperformPanChange
I tried to fix it but I found it's more complicated than I thought. I added setMaximumScaleY, and have to change
canZoomInMoreX
and have to get chart type in ChartViewPortHandler in order to read maxScaleY for horizontal bar chart, which seems not a good design pattern.Needs your help how to fix this.
The text was updated successfully, but these errors were encountered: