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

Scroll after create Graph #16

Closed
llKoull opened this issue Jun 7, 2016 · 11 comments
Closed

Scroll after create Graph #16

llKoull opened this issue Jun 7, 2016 · 11 comments

Comments

@llKoull
Copy link

llKoull commented Jun 7, 2016

Hello!

First of all I want to thank you about this awesome library! I'm using it in a new project and It's really smooth. I only have one question. Is it posible to automatically scroll to the end of the graph after it appears on the view?

Best regards!

@hdoria
Copy link

hdoria commented Jun 8, 2016

Same problem here.

@hdoria
Copy link

hdoria commented Jun 8, 2016

Just figured it out. You can change the scroll direction:

graphView.direction = ScrollableGraphViewDirection.RightToLeft

RightToLeft will automatically scroll to the end of the graph .

@llKoull
Copy link
Author

llKoull commented Jun 8, 2016

Hi hdoria!

I tried this line of code but It doesn't work for me 😟

`let graphView = ScrollableGraphView(frame: CGRectMake(0.0, 0.0, self.frame.width, self.frame.height))
graphView.topMargin = 80

    graphView.backgroundFillColor = UIColor.colorFromHex("#333333")

    graphView.lineWidth = 1
    graphView.lineColor = UIColor.colorFromHex("#777777")
    graphView.lineStyle = ScrollableGraphViewLineStyle.Smooth

    graphView.shouldFill = true
    graphView.fillType = ScrollableGraphViewFillType.Gradient
    graphView.fillColor = UIColor.colorFromHex("#555555")
    graphView.fillGradientType = ScrollableGraphViewGradientType.Linear
    graphView.fillGradientStartColor = UIColor.colorFromHex("#555555")
    graphView.fillGradientEndColor = UIColor.colorFromHex("#444444")

    graphView.dataPointSpacing = 80
    graphView.dataPointSize = 2
    graphView.dataPointFillColor = UIColor.whiteColor()

    graphView.referenceLineLabelFont = UIFont.boldSystemFontOfSize(8)
    graphView.referenceLineColor = UIColor.whiteColor().colorWithAlphaComponent(0.2)
    graphView.referenceLineLabelColor = UIColor.whiteColor()
    graphView.dataPointLabelColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)

    graphView.shouldAnimateOnStartup = true
    graphView.shouldAdaptRange = true
    graphView.adaptAnimationType = .Elastic
    graphView.animationDuration = 1.5
    graphView.shouldRangeAlwaysStartAtZero = true

    self.graphView?.direction = .RightToLeft

    graphView.setData(values, withLabels: labels)
    self.graphContainerView.addSubview(graphView)`

@philackm
Copy link
Owner

philackm commented Jun 8, 2016

@hdoria Yes! That property can be used to change which end of the graph it starts at.

@llKoull Try changing:

self.graphView?.direction = .RightToLeft

to

self.graphView.direction = .RightToLeft

I don't think you have declared graphView as an optional.

Otherwise I can't see any other major mistakes. Does it not start at the end of the graph even after changing the direction to .RightToLeft? (Note there is no scrolling animation for this property, it will just start at the end of the graph and the user will have to swipe to the left to see the start of the graph.)

@llKoull
Copy link
Author

llKoull commented Jun 8, 2016

Hi @philackm !

I tried to use self.graphView.direction = .RightToLeft but xcode gives me an error and I cant compile. I also tried to declare it as ! and the i can compile but i get

unexpectedly found nil while unwrapping an Optional value

I always have to scroll from left to right no matters which direction i choose :O

Thanks for your help

@llKoull
Copy link
Author

llKoull commented Jun 8, 2016

I finally got this working, It was my fault, I was using self.grapView and i should use graphview instead.

But now i've got another problem, The graph is scrolling, that's nice! ^_^ but the graphic it's not filled with color It seems that only half part of the graphic is filled until i touch It (some lines and the Y-axis values are also hidden. If i touch the graph It fills up with the correct color).

I attach some pictures!

1
2

Thanks and best regards!

@philackm
Copy link
Owner

philackm commented Jun 9, 2016

Hmmm. Could you post the code you have to a GitHub gist (https://gist.github.com) and then post the link here? I'd like to try reproduce it and find what's causing the bug.

On Jun 9, 2016, at 7:39 AM, Raúl Vidal Muiños notifications@github.com wrote:

I finally got this working, It was my fault, I was using self.grapView and i should use graphview instead.

But now i've got another problem, The graph scroll, that's nice, but the graphic it's not filled with color It seems that only half part of the graphic is filled until i touch It (some lines and the Y-axis values are also hidden. If i touch the graph It fills up with the correct color).

I attach some pictures!

Thanks and best regards!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@llKoull
Copy link
Author

llKoull commented Jun 9, 2016

I'm sorry, but i can't post all the code. Anyways, I can tell you what i've done.

I created a UICollectionView with a custom cell called GraphCollectionViewCell. This is the code of the custom cell:

`import UIKit
import ScrollableGraphView

class GraphCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var graphTitle: UILabel!
@IBOutlet weak var graphContainerView: UIView!
var graphView: ScrollableGraphView?

required init(coder aDecoder: NSCoder)
{
    super.init(coder: aDecoder)!
}

func initializeGraph(values: [Double], labels: [String])
{
    let graphView = ScrollableGraphView(frame: CGRectMake(0.0, 0.0, self.frame.width, self.frame.height))
    graphView.topMargin = 80

    graphView.backgroundFillColor = UIColor.colorFromHex("#333333")

    graphView.lineWidth = 1
    graphView.lineColor = UIColor.colorFromHex("#777777")
    graphView.lineStyle = ScrollableGraphViewLineStyle.Smooth

    graphView.shouldFill = true
    graphView.fillType = ScrollableGraphViewFillType.Gradient
    graphView.fillColor = UIColor.colorFromHex("#555555")
    graphView.fillGradientType = ScrollableGraphViewGradientType.Linear
    graphView.fillGradientStartColor = UIColor.colorFromHex("#555555")
    graphView.fillGradientEndColor = UIColor.colorFromHex("#444444")

    graphView.dataPointSpacing = 80
    graphView.dataPointSize = 2
    graphView.dataPointFillColor = UIColor.whiteColor()

    graphView.referenceLineLabelFont = UIFont.boldSystemFontOfSize(8)
    graphView.referenceLineColor = UIColor.whiteColor().colorWithAlphaComponent(0.2)
    graphView.referenceLineLabelColor = UIColor.whiteColor()
    graphView.dataPointLabelColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)

    graphView.shouldAnimateOnStartup = true
    graphView.shouldAdaptRange = true
    graphView.adaptAnimationType = .Elastic
    graphView.animationDuration = 1.5
    graphView.shouldRangeAlwaysStartAtZero = true

    graphView.setData(values, withLabels: labels)
    graphView.direction = .RightToLeft
    self.graphContainerView.addSubview(graphView)
}

// MARK: Setters



// MARK: Getters

}
`

Then I initialize the cell in the main view using the function

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell

with the following code:

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as! GraphCollectionViewCell cell.initializeGraph(stepsArray, labels: labelsArray) return cell

I think that I autolayout can be affecting to the view.

Thanks for your help!

@hdoria
Copy link

hdoria commented Jun 9, 2016

Same problem here. This only happens when using ScrollableGraphViewDirection.RightToLeft.

@philackm
Copy link
Owner

philackm commented Jun 9, 2016

Okay I just pushed 1.1.1 to cocoapods.

@hdoria, @llKoull Can you please try that version and let me know if it is any better?

@llKoull
Copy link
Author

llKoull commented Jun 9, 2016

Yeah! It's working perfect! ^_^

Thanks @philackm !!!

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