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

Radar chart radius is still affected by label size when label drawing is disabled #153

Closed
liuxuan30 opened this issue Jun 16, 2015 · 10 comments
Labels

Comments

@liuxuan30
Copy link
Member

radardiff

I have setup two radar chart as shown in the screen shot. I am confused why the left one is smaller than right one. I just feed the same frame for both of them, only data is different. What I want is the same size for radar chart.

I found that _viewPortHandler.contentRect is giving different rect at diffrent phase. In init function, _viewPortHandler.contentRect is giving the right size.

I disabled the legend like this:

self.radarChart.legend.enabled = NO;
self.radarChart.data = radarData; // after set legend disabled

and checking stack trace, it shows the stack is notifyDataSetChanged() -> calculateOffsets(),

in calculateOffsets(),

        legendTop += self.extraTopOffset;
        legendRight += self.extraRightOffset;
        legendBottom += self.extraBottomOffset;
        legendLeft += self.extraLeftOffset;

        var minOffset = CGFloat(10.0);

        if (self.isKindOfClass(RadarChartView))
        {
            let x = (self as! RadarChartView).xAxis;

            if (x.isEnabled)
            {
                minOffset = max(10.0, x.labelWidth);
            }
        }
        var offsetLeft = max(minOffset, legendLeft);
        var offsetTop = max(minOffset, legendTop);
        var offsetRight = max(minOffset, legendRight);
        var offsetBottom = max(minOffset, max(self.requiredBaseOffset, legendBottom));

        _viewPortHandler.restrainViewPort(offsetLeft: offsetLeft, offsetTop: offsetTop, offsetRight: offsetRight, offsetBottom: offsetBottom);

the minOffset depends on the xAxis label width, the left radar is 11.56 whilte the right radar is 40. then it leads to diffrent size and even the factor is somewhat weird.

    /// Returns the factor that is needed to transform values into pixels.
    public var factor: CGFloat
    {
        var content = _viewPortHandler.contentRect;
        return min(content.width / 2.0, content.height / 2.0)
                / CGFloat(_yAxis.axisRange);
    }

The factor depends on the axisRange as well, and my left radar range is 120.0 while the left one is 140000000.0.

I am not sure if this a bug. but if false, how can I fix it? I need the left one and right one is equal radius.

@liuxuan30
Copy link
Member Author

More frame info:

my chart bound is (0,0,157,40)

but after calculateOffsets(),

the left radar contentRect is
(11.56, 11.56, 133.88, 16.88)

the right one is:
(40.46, 40.46, 76.08, -40.92)
Seems it messed up. the factor is also weird, but under this situation, the right radar is giving a fair size, but the left one is not.

@danielgindi
Copy link
Collaborator

Does this happen on Android version too?

On Tue, Jun 16, 2015 at 11:56 AM, Xuan [email protected] wrote:

More frame info:

my chart bound is (0,0,157,40)

but after calculateOffsets(),

the left radar contentRect is
(11.56, 11.56, 133.88, 16.88)

the right one is:
(40.46, 40.46, 76.08, -40.92)
Seems it messed up. the factor is also weird, but under this situation,
the right radar is giving a fair size, but the left one is not.
It seems it messed up,


Reply to this email directly or view it on GitHub
#153 (comment)
.

@liuxuan30
Copy link
Member Author

I am not android developer, thus I am no sure...

@liuxuan30
Copy link
Member Author

@danielgindi could you elaberate what's the viewport purpose for radar chart?

also, I am struggling with

 public var factor: CGFloat
    {
        var content = _viewPortHandler.contentRect;
        return min(content.width / 2.0, content.height / 2.0)
                / CGFloat(_yAxis.axisRange);
    }

It reads the _yAxis.axisRange, however, this could vary from 120 to 14000000. This can cause factor to be a large number, if the _yAxis.axisRange is small and factor could be also very small. Is this a bug or by design?

@liuxuan30
Copy link
Member Author

@danielgindi With further investigation, I think a very small view frame can easily be impacted. for exmaple, what I am doing is create a thumb view, the height is only 40. and ios-charts is doing calculations, leads to the viewPortHandler.contentRect has a very small height or even negative height.

even I manually set the offset like this:

    self.thumbView.data = radarData;
    [self.thumbView.viewPortHandler restrainViewPortWithOffsetLeft:0 offsetTop:0 offsetRight:0 offsetBottom:0];

However, in ChartViewBase: drawRect,

        if (!_offsetsCalculated)
        {
            calculateOffsets();
            _offsetsCalculated = true;
        }

This overwrite my changes again while drawing.

I think this part should be enhanced to be able to fit in small view frame? What do you think?

@liuxuan30
Copy link
Member Author

besides,

        var offsetLeft = max(minOffset, legendLeft);
        var offsetTop = max(minOffset, legendTop);
        var offsetRight = max(minOffset, legendRight);
        var offsetBottom = max(minOffset, max(self.requiredBaseOffset, legendBottom));

this will make the radar chart not center aligned vertically.

I don't understand why offsetTop is set to either minOffset or legendTop. There should be a standalone yRequiredBaseOffset and xRequiredBaseOffset. using single RequiredBaseOffset and set it to xAxis.labelWidth is not good

@davecom
Copy link

davecom commented Jul 19, 2015

I'm seeing the same bug. Did you find a workaround?

@liuxuan30
Copy link
Member Author

@davecom I don't have the issue recently, and I forget what I changed... But based on the comments, I guess it's about to change:

if (!_offsetsCalculated)
        {
            calculateOffsets();
            _offsetsCalculated = true;
        }

I add a Bool property, if it's a thumb view, don't caculate:

        if (!_offsetsCalculated)
        {
            if (!isSmallView)
            {
                calculateOffsets()
            }
            _offsetsCalculated = true
        }

@davecom
Copy link

davecom commented Jul 20, 2015

I actually think this issue may be the same as #205

@liuxuan30
Copy link
Member Author

@davecom I guess not, because I have disabled draw labels for small size charts. Unless it indeed has bug even I disabled it it still count it.

@danielgindi danielgindi changed the title radar chart radius is diffrent for two different data Radar chart radius is still affected by label size when label drawing is disabled Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants