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

Advanced Cubic Bezier algorithm for prettier line charts #150

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mlnoone
Copy link

@mlnoone mlnoone commented Nov 30, 2023

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Modified LineChart to use the Advanced Cubic Bezier algorithm for line smoothening as given at https://medium.com/mobile-app-development-publication/making-graph-plotting-function-in-jetpack-compose-95c80ee6fc7f

💡 Motivation and Context

The default line chart has a 'staggered' look which is not found in libs like chart.js or SwiftUI charts, so I searched for ways to improve the smoothening algorithm and found the mentioned article, and tried it out.

💚 How did you test it?

Using the library with the modified file in an Android project as module dependency and tested both on emulator and device

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • All linters passing
  • There are no code climate issues

📸 Screenshots / GIFs

Basic Cubic Bezier
Basic Cubic Bezier

Advancd Cubic Bezier
Advance Cubic Bezier

Validation

Run the sample app and check the difference in the Line Charts

Risks

It is computationally more expensive than the basic cubic Bezier

Mohan Noone and others added 6 commits December 1, 2023 04:32
Optimised slope calculation by using a holding FloatArray to avoid recalculation, and using null is also avoided by this
Further optimised slopes array by removing redundant entry of last value
Optimised in-between slope calculation by replacing 'pow' with 'sqrt' and self multiplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant