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

Can't subclass BarChartRenderer due to 'fileprivate' status of many properties #2731

Closed
cegiela opened this issue Aug 18, 2017 · 7 comments
Closed

Comments

@cegiela
Copy link

cegiela commented Aug 18, 2017

Thank you for your work on this -- I'd like to customize the appearance of the bars, but can't do it by subclassing the renderer cleanly. It has to be initialized with things that are unavailable to me unless I subclass them and their dependancies, and on it goes. I'd like to just feed the existing properties on BarChartView back into the initialization of the renderer. On a broader note: Really almost all properties should be open in open-source software.

@seenoevo
Copy link

seenoevo commented Aug 19, 2017

I am also running into the same issue, I'm trying to subclass BarChartRenderer and override drawValues, but fileprivate class Buffer and fileprivate var _buffers = [Buffer]() are causing issues.

It's most likely we have to change the source code, at least for BarChartRenderer if we want to subclass it, but I like to hear from @danielgindi @PhilJay @liuxuan30 if there's a better way to not touch the source code.

@seenoevo
Copy link

seenoevo commented Aug 19, 2017

@cegiela resolved it

just re-declare all the fileprivate variables/functions in your subclass, and override the functions as normal:

public class CustomBarChartRenderer: BarChartRenderer
{
    fileprivate class Buffer
    {
        var rects = [CGRect]()
    }
   
    fileprivate var buffers = [Buffer]()
    
    fileprivate var barShadowRectBuffer = CGRect()
    
    override public func initBuffers()

   ...
}

@cegiela
Copy link
Author

cegiela commented Aug 19, 2017

Thanks @seenoevo, but then how do you make an instance of CustomBarChartRenderer with all the required parameters? Did you get that figured out?

@seenoevo
Copy link

seenoevo commented Aug 19, 2017

@cegiela I think I realized what you're saying:

here's what you do:

The CustomBarChartRenderer, a subclass of BarChartRenderer has the following in its parameters:

CustomBarChartRenderer(dataProvider: BarChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?)

just pass in your BarChartView's object member variables like so:


var barChartView = BarChartView()
....
let customRenderer = CustomBarChartRenderer(dataProvider: barChartView,
                                                        animator: barChartView.chartAnimator,
                                                        viewPortHandler: barChartView.viewPortHandler)

@aelam
Copy link
Contributor

aelam commented Aug 20, 2017 via email

@seenoevo
Copy link

@aelam yup that is the way to do it since it's declared as fileprivate in the parent class

@liuxuan30
Copy link
Member

liuxuan30 commented Aug 21, 2017

fileprivate is something private if you really need to override, just modify them to interval and build the library on your side. Redeclare in your child class also works (may introduce code duplication)

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