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

Charts won't draw unless initialized with a frame #49

Closed
westerlund opened this issue Apr 24, 2015 · 10 comments
Closed

Charts won't draw unless initialized with a frame #49

westerlund opened this issue Apr 24, 2015 · 10 comments

Comments

@westerlund
Copy link

It took me a while to figure this out, but I couldn't get the charts to draw unless the chart view was initialized with a frame.

There would be two solutions to this, either support changing the frame of the view or do something drastically like putting a fatalError() in the init() method, to prevent using that.

var lineChart = LineChartView() // won't draw any chart
var lineChart = LineChartView(frame: view.bounds) // will draw charts with the specified frame

I might write a pull request with a fix, but at least it is reported now.

Best,
Simon

@AlBirdie
Copy link
Contributor

This probably falls into this as well, I appears as a chart won't accept any other frame than the one it has been initialised with.
For instance, I initialize a chart with a frame of 0,0,50,50. Later in 'layoutSubviews' a new frame with new dimensions will be set. And even after manually calling 'setNeedsLayout / setNeedsDisplay' on the chart, it doesn't accept the new frame.
Anyone else experiencing this as well?

@danielgindi
Copy link
Collaborator

In ChartViewBase.swift there's a bounds override, around line 750.
Could you please see if the viewport is actually updated there while
debugging?
I'm not on a Mac at the moment and perhaps we can make a quick fix now!

@AlBirdie
Copy link
Contributor

Sorry, just read your comment now. Is there a way to debug this from an Objective-C project? I can't look into the variables when I set a breakpoint in the code you've mentioned.

@danielgindi
Copy link
Collaborator

Maybe println?
Or just a breakpoint to make sure it reaches there after resizing?
I know there are still some bugs when debugging Swift...

On Wed, Apr 29, 2015 at 6:40 PM, AlBirdie notifications@github.com wrote:

Sorry, just read your comment now. Is there a way to debug this from an
Objective-C project? I can't look into the variables when I set a
breakpoint in the code you've mentioned.


Reply to this email directly or view it on GitHub
#49 (comment)
.

@AlBirdie
Copy link
Contributor

AlBirdie commented May 4, 2015

Sorry for not getting back to your earlier Daniel, just got back in the office.

I don't think this issue has been fixed by overriding frame instead of bounds. Just run the demo project with the latest source code, open the line chart demo and rotate the device. At first the viewport is getting stretched, but once you click into the chart (so that it reloads), it'll go back to its original frame.

@danielgindi
Copy link
Collaborator

danielgindi commented May 4, 2015 via email

@AlBirdie
Copy link
Contributor

AlBirdie commented May 4, 2015

Yes, somehow mixed up the code bases. :) So it does rotate.
However, setting the frame manually (i.e. in ViewController's layoutSubviews) still won't work. The chart keeps the frame that has been set initially. This time I'm working with the latest code. ;) I've tried to debug this myself, but to be completely honest, I've got no idea why it isn't working.

@danielgindi
Copy link
Collaborator

danielgindi commented May 4, 2015 via email

@AlBirdie
Copy link
Contributor

AlBirdie commented May 5, 2015

Pretty sure, yes. I'm not even using a StoryBoard (nor layout constraints for that matter).
This is just a regular UIViewController with a chart added in code. In the viewcontroller's layoutSubviews I explicitly set the frame to the viewcontroller's frame, which won't have any effect.
You can even set a completely random frame in layoutSubviews (200 x 200 or something like that), and it won't resize the chart.
As a matter of fact, you can quite easily reproduce this bug by adapting the LineChart1ViewController by removing the LineChartView from the xib file and add it manually by code;

_chartView = [[LineChartView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
[self.view addSubview:_chartView];

Then add a layoutSubViews and set a new frame;

-(void) viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_chartView.frame = CGRectMake(20, 20, 500, 500);
}

Rotate the device and you'll see that the chart's frame does not take the new value.

danielgindi added a commit that referenced this issue May 5, 2015
When initializing in IB, it's clear.
But initWithFrame set it as nil - and combined with the default opaque=YES - it was filling the background with black.
@AlBirdie
Copy link
Contributor

AlBirdie commented May 5, 2015

Yes, this finally fixed it. 👍
Thanks Daniel!

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