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

Extending lines between data points when zoomed and panning #330

Closed
micnguyen opened this issue Aug 31, 2015 · 6 comments
Closed

Extending lines between data points when zoomed and panning #330

micnguyen opened this issue Aug 31, 2015 · 6 comments

Comments

@micnguyen
Copy link

Hi,

I've implemented a "time-series" graph by basically creating a chartview with lots of intervals (where each interval is 1 minute) ie: there is a data point at interval 1 and interval 61 if they are 1 hour apart.

I've noticed when I zoom into some points and panned across that the line connecting 2 data points will extend out beyond the limits of the start/end points of the line even if the data-points have disappeared form the view port.

I have made a recording of the bug in action: http://gfycat.com/SarcasticCarefreeGalapagostortoise

@liuxuan30
Copy link
Member

Did you modify drawLinear or drawCubic? If not, could you help debugging it? Should be an issue that if the interval is wider than screen width, it cannot find proper data point to connect and leads to weird behaviour.

@kwoylie
Copy link

kwoylie commented Aug 31, 2015

Hey,

I have fixed the issue, I haven't checked it into github, since I'm not too sure what the ramifications are. But below is the description of my fix:

BEFORE:
drawLinear function was getting chart entries that is inside the bounds of the view by doing the following:

internal func drawLinear(#context: CGContext, dataSet: LineChartDataSet, entries: [ChartDataEntry]) {
        ...
        var entryFrom = dataSet.entryForXIndex(_minX)
        var entryTo = dataSet.entryForXIndex(_maxX)
        ....
}
AFTER: So I added the follow functions to ChartDataSet class to give me the entry before the first visible entry and the entry after the last visible entry.
public func entryForBeforeXIndex(x: Int) -> ChartDataEntry?
{
        var index = self.entryIndex(xIndex: x)
        if (index > -1)
        {
            return _yVals[max(0,index-1)];
        }
        return nil
}

public func entryForAfterXIndex(x: Int) -> ChartDataEntry?
{
        var index = self.entryIndex(xIndex: x)
        if (index > -1)
        {

            return _yVals[min(index+1, _yVals.count-1)];
        }
        return nil
}
Then I changed the drawLinear function to this instead:
internal func drawLinear(#context: CGContext, dataSet: LineChartDataSet, entries: [ChartDataEntry]) {
        ...
        var entryFrom = dataSet.entryForBeforeXIndex(_minX)
        var entryTo = dataSet.entryForAfterXIndex(_maxX)
        ....
}

It'll be great, if you guys can apply the changes the library if it doesn't break anything else.

@liuxuan30
Copy link
Member

@micnguyen try it out! @kwoylie you could raise a PR and let @danielgindi has a review.

@micnguyen
Copy link
Author

@liuxuan30 @kwoylie fix does indeed fix this issue as well as #130. The core problem at hand is when the viewport changes, the data points no longer exist and there is funny rendering issues that come with that. Admittedly, this does come at a performance hit as it's looking at a much larger range of values, but the hit is temporarily worth the frequent and visible visual glitch.

@liuxuan30
Copy link
Member

I saw another issue is the line is broke when scrolling in my project :( today Seems we need a enhancement.

@danielgindi
Copy link
Collaborator

Well I don't see this anymore, so I guess we fixed it in a commit somewhere :-)

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

4 participants