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

Height of Half Pie Chart (white space in the chart where the removed bottom half from pie chart should be) #4033

Closed
ratala1 opened this issue Jun 20, 2019 · 7 comments
Assignees

Comments

@ratala1
Copy link

ratala1 commented Jun 20, 2019

I am using Half Pie Chart in my project. When I reduce the height component of the pieChart, the chart size also goes down. attaching screenshots for reference. How do I use HalfPieChart without the extra space below the chart?

Screenshot 1:
Height = Width
Simulator Screen Shot - iPhone Xʀ - 2019-06-20 at 15 31 10

Screenshot 2:
Height = Width/2
Simulator Screen Shot - iPhone Xʀ - 2019-06-20 at 15 28 20

Thanks

@ratala1 ratala1 changed the title Height of Half Pie Chart (white space in the chart where the removed half from pie chart should be) Height of Half Pie Chart (white space in the chart where the removed bottom half from pie chart should be) Jun 20, 2019
@kamokaizen
Copy link

did you solve it? same problem i have and can not resolved yet.

@ratala1
Copy link
Author

ratala1 commented Oct 14, 2019

@kamokaizen no

@kamokaizen
Copy link

to solve with workaround; give below item of chart a minus top padding. i m using snapkit;
make.top.equalTo(chartView.snp.bottom).offset(-100) // 100 mean height/2

@JMSerruya
Copy link

Hi @ratala1 , did you found a fix to this issue? facing the same problem.

@liuxuan30
Copy link
Member

I'm feeling it's kind of a defect, that it still counts as a full pie chart view and reserves the bottom half. The workaround seems correct by @kamokaizen, which is to reduce the offset. However, a true solution is not that easy - and we might need someone to look into it.

@liuxuan30 liuxuan30 added the bug label Jan 19, 2020
@liuxuan30
Copy link
Member

liuxuan30 commented Jan 19, 2020

The tricky part here is if you want the radius to be larger, you have to calculate the radius properly;

for example, I faked the radius with ChartsDemo half pie chart:

    internal override func calculateOffsets()
    {
        super.calculateOffsets()
        
        // prevent nullpointer when no data set
        if _data === nil
        {
            return
        }
        
        let radius = maxAngle > 180 ? diameter / 2.0 : (_viewPortHandler.contentRect.size.width > _viewPortHandler.contentRect.size.height ? diameter : diameter / 2)
        
        let c = self.centerOffsets
        
        let shift = (data as? PieChartData)?.dataSet?.selectionShift ?? 0.0
        
        // create the circle box that will contain the pie-chart (the bounds of the pie-chart)
        _circleBox.origin.x = maxAngle > 180 ? (c.x - radius) + shift : (c.x - radius) + shift
        _circleBox.origin.y = maxAngle > 180 ? (c.y - radius) + shift : (_viewPortHandler.contentRect.size.width > _viewPortHandler.contentRect.size.height ? (c.y - radius / 2) + shift : (c.y - radius) + shift)  
        _circleBox.size.width = radius * 2 - shift * 2.0
        _circleBox.size.height = radius * 2 - shift * 2.0

    }

The key idea is to fake the radius and adjust the circle box.

when screen width <= height, it should be the same as a full pie chart, since the radius should be diameter(min(width, height) / 2) anyway;

but when screen width > height, the radius is min(width, height) to use the maximum space:
image

Currently the highlight is partial broken in this state. If you don't mind the highlight, you can use the code directly. The touch point calculation and mapping to slice is more complex than I can fix right now. I hope someone can carry on if interested. So far it seems distanceToCenter is wrong.

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 19, 2020

after the last retry today, it seems the highlight is fixed in #4266

can you guys give a try? I didn't plan to merge this any time soon before we thoroughly test and review it.

any suggestions and review are welcome.

liuxuan30 added a commit that referenced this issue Jan 19, 2020
liuxuan30 added a commit that referenced this issue Jan 19, 2020
liuxuan30 added a commit that referenced this issue Jan 19, 2020
liuxuan30 added a commit to liuxuan30/Charts that referenced this issue Mar 30, 2020
mosaic-engineering pushed a commit to mosaic-io/Charts that referenced this issue Apr 17, 2020
)

* resolve ChartsOrg#4033. when it's half pie and width is larger than height, draw bigger pie chart.

* use enum orientation for widthLarger
merge with master and solve conficts

* fix macOS error, move extension to Platform+CoreGraphics
mosaic-engineering pushed a commit to mosaic-io/Charts that referenced this issue Jun 17, 2020
)

* resolve ChartsOrg#4033. when it's half pie and width is larger than height, draw bigger pie chart.

* use enum orientation for widthLarger
merge with master and solve conficts

* fix macOS error, move extension to Platform+CoreGraphics
SwiftPolar pushed a commit to SwiftPolar/Charts that referenced this issue Mar 20, 2023
)

* resolve ChartsOrg#4033. when it's half pie and width is larger than height, draw bigger pie chart.

* use enum orientation for widthLarger
merge with master and solve conficts

* fix macOS error, move extension to Platform+CoreGraphics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants