This is a share your knowledge, Q&A-style question inspired by this question to detect which section of arc segment or degree of touch inside a circle or semi-circle as in gif and image below. Also how stroke width changes are set by default inwards or outwards a Canvas or Composable with draw Modifier.
How to check which arc or pie chart segment clicked in Jetpack Compose?
1k Views Asked by Thracian At
1
There are 1 best solutions below
Related Questions in ANDROID
- Creating global Class holder
- Flutter + Dart: Editing name of a tab shows up a black screen
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Sdk 34 WRITE_EXTERNAL_STORAGE not working
- ussd reader in Recket Native module
- Incorrect display of LinearGradientBrush in IOS
- The Binary Version Of its metadata is 1.8.0, expected Version is 1.6.0 build error
- I can't make TextInput to auto expand properly in Android
- Creating multiple instances of a class with different initializing values in Flutter
- How to create a lottie animation
- making android analyze with coverity sast tool
- Flutter plugin development android src not opening after opening example
- I initialize my ViewModel in the Activity with several fragments as tabs, but the fragments(tabs) return null for the updated livedata
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How I can use the shared preferences class?
Related Questions in ANDROID-JETPACK-COMPOSE
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Inject a class into a composable function using hilt
- preventing duplicate text
- Jetpack compose - how I can hookup LiveData property from ViewModel with TextField in activity?
- MarkerInfoWindow doesn't hold the clicked marker position after list refresh in Compose Map
- How do you import functions from one page to another in Jetpack Compose?
- Jetpack compose ViewModels - should I have one ViewModel for different api calls?
- Change background color of clicked sentence in Text
- How to add and retrive pdf file on firebase in jetpack compose
- Made a widget with glance API in Jetpack Compose. Button filling the whole widget
- Jetpack Compose how to reverse edge-to-edge when leaving composition
- Can Anyone help me to load pdf file from firebase to user app by URL in jetpack compose?
- PullRefreshIndicator circle always displaying on jetpack compose
- Android Studio Using recently added resources in compose preview in multi-module project
- Android compose animations crashing in release builds
Related Questions in ANDROID-JETPACK-COMPOSE-CANVAS
- How to switch movement of object from one path to another smoothly in Jetpack Compose?
- How to know the current Translation, Rotation and Scale that are currently applied to a Compose (or View) Canvas?
- Android Compose Canvas producing unexpected BlendMode results
- How to draw a Ring in Jetpack Compose with Canvas?
- How can I draw a line in jetpack compose and have a custom corner?
- Jetpack Compose drawLine with stampedPathEffect
- Applying a Blur Effect to the Entire Screen Except for a Specific Rectangle in Jetpack Compose
- How can I determine whether a 2D Point is within a Polygon or Complex Path with Jetpack Compose?
- Confusing behaviour by the 'rotate' transformation of Compose Canvas
- Jetpack Compose watermark or write on Bitmap with androidx.compose.ui.graphics.Canvas?
- How to make this triangle indicator to rotate and move in android jetpack compose?
- How to draw one side curve of box in jetpack compose android
- Jetpack Compose Animation skips to target value immediately
- How to create HSL saturation and lightness change gradient or brush editor with Jetpack Compose?
- Jetpack compose BlendMode.Xor different from preview
Related Questions in JETPACK-COMPOSE-ANIMATION
- Infinite color animation sequentially in Jetpack Compose
- How reset detectHorizontalDragGestures
- AnimatedVisibility is not working with weights
- Animate LazyColumn items content size in Compose
- Creating a wave-like text animation in jetpack compose: sequence disruption issue
- Applying Brush Effect to Whole Word While Animating Each Letter Individually in Jetpack Compose
- Jetpack compose Animation handling when new items are created
- How can I determine whether a 2D Point is within a Polygon or Complex Path with Jetpack Compose?
- Jetpack Compose - Animate recomposition on state change
- Animation with increasing sizes in Jetpack Compose
- Compose: Animate 2 composables at the same time without affecting position of siblings
- Dynamically Change Navigation Animation - Jetpack Compose
- How to reduce recompositions when animating text color?
- Jetpack Compose Animation with LinearEasing not working properly with Talkback
- Navigation Compose animation is always using the default transition
Related Questions in JETPACK-COMPOSE-DRAWSCOPE
- Compose - Remove part of background of an image
- how to create a hexagon shape with curved endsin Jetpack composeH
- Can we scale text inside draw scope in compose?
- Only ONE rounded corner on the pentagon in Jetpack Compose, is there any way?
- Draw Image with fixed height and width jetpack compose canvas using drawImage()
- Jetpack Compose: DrawScope: Gradient alpha seems to be multiplied
- How to check which arc or pie chart segment clicked in Jetpack Compose?
- why DrawScope dimensions don't match up with Canvas?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?


By default half of the stroke is drawn inside selected position while the other half of it being is drawn out.
By changing topLeft and Size of the Rect arc is drawn into it's possible to create Arc that grows outwards when clicked or can be animated via an actions. In the image below radius of inner section of arc doesn't change which in the example below green rectangle never touches blue circle.
When drawing a donut chart we need to have an outer radius which is represented with red circle, stroke width and inner radius which is represented with blue circle. I also used inner stroke width to give some depth to donut chart.
To calculate which section of a chart or circle we touch first we need to find out if we touch the section inside the arc by measuring distance from center of arc/circle to touch position since distance should be between inner radius and outer radius to be able to know that we touch the desired region.
If the touch position is inside the region that is desired we can get the angle using arctangent function which gives angle in radians.
https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
After getting angle between center and touch position need to check out which segment this angle is in. I mapped angles in image to data as start and end angles
Mapping is done using start angle top start is -90 degrees in draw coordinate system
Also for darken color based on colors passed i used
And to animate color between unselected color to selected color used
lerpfunction which is the most convenient way to animate color between one to otherFull implementation