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

why drawValues has some condition which uses break, some uses continue? #611

Closed
liuxuan30 opened this issue Dec 14, 2015 · 6 comments
Closed

Comments

@liuxuan30
Copy link
Member

I am customizing func drawValues, and I found below code:

if (!dataSet.isStacked)
{
    for (var j = 0, count = Int(ceil(CGFloat(valuePoints.count) * _animator.phaseX)); j < count; j++)
    {
        if (!viewPortHandler.isInBoundsRight(valuePoints[j].x))
        {
            break
        }

        if (!viewPortHandler.isInBoundsY(valuePoints[j].y)
            || !viewPortHandler.isInBoundsLeft(valuePoints[j].x))
        {
            continue
        }
}

it will use break for right, continue for left. Why break here? I checked some other charts, it almost has the same pattern, break for right, top, continue for others. I am not sure if this is deliberated to do so?

@ffchung
Copy link

ffchung commented Dec 16, 2015

As I guess from the code you post, it check the point from top left to right bottom , scan by col.

1 4 7
2 5 8
3 6 9

if the visible space is 1, 2, 4, 5

the break is used at 7 , the x is not visible , and all after it will not visible too, so break, quit the loop.

and the continue is used at 3 and 6, the x is visible , but the y is not visible, so it skip it and jump to the other col.

@liuxuan30
Copy link
Member Author

Not sure your meaning of
1 4 7
2 5 8
3 6 9
seems not your case.it will be visible for an entire bar or not, will not have 1,2,4,5 case

@danielgindi
Copy link
Collaborator

Well, this allows us to not draw things that are out of the view, and stop drawing when reached an index that is out of the view.

Or to explain in another way:

We are drawing "from left to right", right?
So for every point on the X axis, we will draw some points...
Some of those points may be outside of the viewport - so we continue, to avoid drawing them. It's not that we don't use clipping masks, it's that drawing stuff like texts is expensive.

Same goes for every point on the X axis that is outside of the viewport, but on the left side. Because those are points that are not to be drawn, but we are still waiting to reach the x index that we start to draw. So at this stage we are actually searching.

And now when we reach the point on the x axis that is out of reach - we break to stop drawing the loop completely.

@liuxuan30
Copy link
Member Author

I get it. It turned out that, I am customizing a new chart type based on horizontal bar chart, and I want to draw the bars from top to bottom, while the default implementation is from bottom to top. What I did is not to reverse the xIndex in data sets, but change the logic inside the rendering. So while zooming, that's why it did not draw anything becaues of break, changing to continue will solve the problem.

@danielgindi
Copy link
Collaborator

This could be done with a flag that swaps transformers, and then a PR ;-)

@liuxuan30
Copy link
Member Author

I totally forgot this way.. I will see if I could do it

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