GithubHelp home page GithubHelp logo

Rotating the pie chart about piecharts HOT 4 CLOSED

Brandon-316 avatar Brandon-316 commented on May 14, 2024
Rotating the pie chart

from piecharts.

Comments (4)

ivnsch avatar ivnsch commented on May 14, 2024 2

Implemented! You can now rotate the chart after initialization.

Example:

func onSelected(slice: PieSlice, selected: Bool) {
    chartView.referenceAngle = 270 - slice.view.midAngle.radiansToDegrees + chartView.referenceAngle
}

extension FloatingPoint {
    var radiansToDegrees: Self {
        return self * 180 / .pi
    }
}

Where 270 is the top center, the angle you want to rotate the slice to.

While this doesn't affect the calculations, it's worth to note that the slice's mid angle is not necessarily in [0, 2π] range. If you want to have it in this range, e.g. to debug you can do slice.view.midAngle.radiansToDegrees.truncatingRemainder(dividingBy: 360).

You'll have to use 0 as selectedOffset for now. To support both selectedOffset and rotation change it's necessary to do a little more work. You can try to do this if you want! The most simple way to achieve this would be to add a delegate method for termination of rotate animation and also allow to select slices programmatically, such that you can do this when the rotation finishes. Or the other way around, depending on what you need.

The change is in master, to use it:

pod 'PieCharts', :git => 'https://github.com/i-schuetz/PieCharts.git'

from piecharts.

ivnsch avatar ivnsch commented on May 14, 2024

It's not possible right now. I will take a look into this in the next days, thanks!

from piecharts.

Brandon-316 avatar Brandon-316 commented on May 14, 2024

Awesome thanks!

from piecharts.

Brandon-316 avatar Brandon-316 commented on May 14, 2024

Great thank you!

from piecharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.