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

Padding/spacing when rotating X-axis labels 90 degree #2414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Padding/spacing when rotating X-axis labels 90 degree #2414

wants to merge 1 commit into from

Conversation

thierryH91200
Copy link
Contributor

This is an old bug
The problem is that the height is calculated 2 times

This is to avoid this kind of problem

Before
capture d ecran 2017-05-05 a 11 48 32

After
capture d ecran 2017-05-05 a 11 47 21

func calculateLegendOffsets 
offsetTop += xAxis.labelRotatedHeight`

and i resume

func calculateOffsets()
 let xlabelheight = xAxis.labelRotatedHeight + xAxis.yOffset
 offsetTop += xlabelheight

@liuxuan30
Copy link
Member

liuxuan30 commented May 8, 2017

eh oh, the tests failed. where 'the height is calculated 2 times'?

@thierryH91200
Copy link
Contributor Author

Why the test fails I do not know

   internal override func calculateOffsets()
    {
        if !_customViewPortEnabled
        {
            var offsetLeft = CGFloat(0.0)
            var offsetRight = CGFloat(0.0)
            var offsetTop = CGFloat(0.0)
            var offsetBottom = CGFloat(0.0)
            
            **calculateLegendOffsets**(offsetLeft: &offsetLeft,
                                   offsetTop: &offsetTop,
                                   offsetRight: &offsetRight,
                                   offsetBottom: &offsetBottom)         <-----first time here in this function
            
            // offsets for y-labels
            if leftAxis.needsOffset
            {
                offsetLeft += leftAxis.requiredSize().width
            }
            
            if rightAxis.needsOffset
            {
                offsetRight += rightAxis.requiredSize().width
            }
            
            if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
            {
                **let xlabelheight = xAxis.labelRotatedHeight + xAxis.yOffset**
                
                // offsets for x-labels
                if xAxis.labelPosition == .bottom
                {
                    **offsetBottom += xlabelheight**         <-----and still here
                }
                else if xAxis.labelPosition == .top
                {
                    offsetTop += **xlabelheight**              <-----and still here
                }
                else if xAxis.labelPosition == .bothSided
                {
                    offsetBottom += xlabelheight
                    offsetTop += xlabelheight
                }
            }
            
  .......
    }

    internal func calculateLegendOffsets(offsetLeft: inout CGFloat, offsetTop: inout CGFloat, offsetRight: inout CGFloat, offsetBottom: inout CGFloat)
    {
.......
            case .horizontal:
                
                switch _legend.verticalAlignment
                {
                case .top:
                    offsetTop += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
                    if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
                    {
                        **offsetTop += xAxis.labelRotatedHeight**       <-----here first time
                    }
                    
                case .bottom:
                    offsetBottom += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
                    if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
                    {
                        **offsetBottom += xAxis.labelRotatedHeight**      <-----here first time
                    }
                    
                    
                default:
                    break
                }
            }
        }
    }

@liuxuan30
Copy link
Member

@thierryH91200 the image can't match, so it failed.. Not having time to look into yet

@thierryH91200
Copy link
Contributor Author

see PhilJay/MPAndroidChart@3dfa56b
this is the same problem and soluce

@SvenMuc
Copy link
Contributor

SvenMuc commented Oct 10, 2017

See also pull request #2214

@semireg
Copy link

semireg commented Oct 16, 2017

👍

@jjatie
Copy link
Collaborator

jjatie commented Jan 11, 2018

@thierryH91200 Looks like you need to update the test. Previously the tests assumed that the double padding was correct. Since it is being compared to a snapshot, that snapshot needs to be updated accordingly.

@jjatie jjatie self-assigned this Jan 11, 2018
@jjatie jjatie added the bug label Jan 11, 2018
@jjatie
Copy link
Collaborator

jjatie commented Jan 11, 2018

I would say this can also target 4.0.0. @liuxuan30 ?

@thierryH91200
Copy link
Contributor Author

see PhilJay/MPAndroidChart@3dfa56b
this is the same problem and soluce

@jjatie
Copy link
Collaborator

jjatie commented Jan 12, 2018

@thierryH91200 I'm not saying your solution is wrong, I'm saying our tests are outdated. In order for this PR to be accepted you need to update the failing tests for the new implementation.

@jjatie jjatie added this to the 3.1 milestone Jan 12, 2018
@liuxuan30
Copy link
Member

I think for bug fixes, master is usually the branch to merge. We need to look at #2214 with this one, to determine if they are same/similar issues.

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 23, 2018

@thierryH91200 are you able to check why tests fail? Do you forgot to update the test, if your commit will change some of the demo chart.
I'm triggering a new CI anyway.

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 30, 2018

Seems we cannot get this done before 3.1. removing. However this is still a high priority fix.

@liuxuan30 liuxuan30 removed this from the 3.1 milestone Jan 30, 2018
@liuxuan30
Copy link
Member

liuxuan30 commented Jan 30, 2018

@jjatie do you think we can finish test and review this for 3.1? I checked the code change is quite small. But we need to understand the fix and test it, which takes descent time. As tomorrow is the deadline, I'm not sure if we can still solve this PR

@jjatie
Copy link
Collaborator

jjatie commented Jan 30, 2018

Yes, this will need to be 4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants