Skip to content
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

Positioning on changing of the screen orientation #786

Closed
oxodpavel opened this issue Mar 2, 2016 · 5 comments
Closed

Positioning on changing of the screen orientation #786

oxodpavel opened this issue Mar 2, 2016 · 5 comments

Comments

@oxodpavel
Copy link

Hi!

There is a minor drawback, that when screen orientation changes, the vertical scale loses its position and goes to some range around original (previous).

Conditions:

  • occurs only when some scaling has been performed
  • occurs only on positions which are not aligned to the horizontal and vertical axes (to thier zero values)
  • changing screen orientation back restores graph position to the original state (seems like, horiz and vert orientations have independent positioning parameters, am I write)
    test_app_land
    test_app_port
@leoMehlig
Copy link
Contributor

I had the same problem and solved it by overriding this method in my Chart-Class:

public override func observeValueForKeyPath(
keyPath: String?,
ofObject object: AnyObject?, 
change: [String : AnyObject]?, 
context: UnsafeMutablePointer<Void>) {     

        var oldPoint: CGPoint?
        if keyPath == "frame" || keyPath == "bounds" {
            oldPoint = viewPortHandler.contentRect.origin
            getTransformer(.Left).pixelToValue(&oldPoint!)
        }
        super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
        if var p = oldPoint {
            getTransformer(.Left).pointValueToPixel(&p)
            viewPortHandler.centerViewPort(pt: p, chart: self)
        }
} 

@liuxuan30
Copy link
Member

I fixed the md in your comment @leoMehlig, nice solution btw
@oxodpavel will it solve your issue, or you can override to get what you want?

@oxodpavel
Copy link
Author

Yes, thank you! This patch works fine

@leoMehlig
Copy link
Contributor

@liuxuan30 is this a feature that should be implemented internally?

@liuxuan30
Copy link
Member

@leoMehlig I'm not sure if everyone has such requirements, some may want keep centered, while some want nothing changed :) If you think it's useful, than add a switch to turn it on and a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants