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

hide values under 10% #959

Closed
marcomonanto opened this issue Apr 19, 2016 · 4 comments
Closed

hide values under 10% #959

marcomonanto opened this issue Apr 19, 2016 · 4 comments

Comments

@marcomonanto
Copy link

Hi, I want to hide the values in my barchart that are under 10%, i've already override drawValues but I need to overide DrawRect from BarLineChartViewBase.

I've already overrided some methods from the library but how can I override if some methods are internal?

@liuxuan30
Copy link
Member

if you could override drawValues why you have to override DrawRect? and even so overriding drawRect seems also fine. I don't know why you cannot override internal.

@marcomonanto
Copy link
Author

marcomonanto commented Apr 20, 2016

I need to override the drawRect to change a line: "renderer!.drawValues(context: context)" to "myRenderer!.drawValues(context: context)" but some methods of drawRect are internal so I cant call them.
Cant call the internal methods since they are from another target so how could I do that?

the drawRect is this one:

` public override func drawRect(rect: CGRect)
{
super.drawRect(rect)

    if _data === nil
    {
        return
    }

    let optionalContext = NSUIGraphicsGetCurrentContext()
    guard let context = optionalContext else { return }

    calcModulus()

    if (_xAxisRenderer !== nil)
    {
        _xAxisRenderer!.calcXBounds(chart: self, xAxisModulus: _xAxis.axisLabelModulus)
    }
    if (renderer !== nil)
    {
        renderer!.calcXBounds(chart: self, xAxisModulus: _xAxis.axisLabelModulus)
    }

    // execute all drawing commands
    drawGridBackground(context: context)

    if (_leftAxis.isEnabled)
    {
        _leftYAxisRenderer?.computeAxis(yMin: _leftAxis._axisMinimum, yMax: _leftAxis._axisMaximum)
    }
    if (_rightAxis.isEnabled)
    {
        _rightYAxisRenderer?.computeAxis(yMin: _rightAxis._axisMinimum, yMax: _rightAxis._axisMaximum)
    }

    _xAxisRenderer?.renderAxisLine(context: context)
    _leftYAxisRenderer?.renderAxisLine(context: context)
    _rightYAxisRenderer?.renderAxisLine(context: context)

    if (_autoScaleMinMaxEnabled)
    {
        let lowestVisibleXIndex = self.lowestVisibleXIndex,
        highestVisibleXIndex = self.highestVisibleXIndex

        if (_autoScaleLastLowestVisibleXIndex == nil || _autoScaleLastLowestVisibleXIndex != lowestVisibleXIndex ||
            _autoScaleLastHighestVisibleXIndex == nil || _autoScaleLastHighestVisibleXIndex != highestVisibleXIndex)
        {
            calcMinMax()
            calculateOffsets()

            _autoScaleLastLowestVisibleXIndex = lowestVisibleXIndex
            _autoScaleLastHighestVisibleXIndex = highestVisibleXIndex
        }
    }

    // make sure the graph values and grid cannot be drawn outside the content-rect
    CGContextSaveGState(context)

    CGContextClipToRect(context, _viewPortHandler.contentRect)

    _xAxisRenderer?.renderGridLines(context: context)
    _leftYAxisRenderer?.renderGridLines(context: context)
    _rightYAxisRenderer?.renderGridLines(context: context)

    if (_xAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _xAxisRenderer?.renderLimitLines(context: context)
    }
    if (_leftAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _leftYAxisRenderer?.renderLimitLines(context: context)
    }
    if (_rightAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _rightYAxisRenderer?.renderLimitLines(context: context)
    }

    renderer?.drawData(context: context)

    // if highlighting is enabled
    if (valuesToHighlight())
    {
        renderer?.drawHighlighted(context: context, indices: _indicesToHighlight)
    }

    // Removes clipping rectangle
    CGContextRestoreGState(context)

    renderer!.drawExtras(context: context)

    if (!_xAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _xAxisRenderer?.renderLimitLines(context: context)
    }
    if (!_leftAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _leftYAxisRenderer?.renderLimitLines(context: context)
    }
    if (!_rightAxis.isDrawLimitLinesBehindDataEnabled)
    {
        _rightYAxisRenderer?.renderLimitLines(context: context)
    }

    _xAxisRenderer.renderAxisLabels(context: context)
    _leftYAxisRenderer.renderAxisLabels(context: context)
    _rightYAxisRenderer.renderAxisLabels(context: context)

    renderer!.drawValues(context: context)

    _legendRenderer.renderLegend(context: context)
    // drawLegend()

    drawMarkers(context: context)

    drawDescription(context: context)
}`

Thanks in advance

@dxclancy
Copy link

Hi, I'm sure you've thought of this and I don't understand your problem correctly, but I wonder if it might be easier to work around this issue?

You say you want to hide values in your bar chart that are under 10%. I'm not sure precisely what you mean, but could you calculate if they are under 10% yourself and then change the data you pass?

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 21, 2016

regardless of overriding drawRect, I think once you are able to write drawValues, you can achieve "hide values under 10%" already, why bother overriding drawRect? You just initialize "myRenderer" in initialize() so drawRect will call your renderer, right?

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