Adding 2 concave/convex shape implementations for bar charts#128
Conversation
- first shape starts with flat and ends with convex shaped side
- second shape starts and ends with convex shaped side
- intermediary stacked bars start with concave shaped side
potentially breaking changes:
- using standardized Composable function typealias for emitting vertical bar since it contains fundamental data required for sophisticated bar rendering
- introducing default Composable function typealias using `VerticalBarPlotEntry` type parameter
- applying `roundToInt` only to range expression; removing from height calculation, since rounding results in up to 2.47% of error
client side adjustments due to breaking changes:
- expressions like `bar = { DefaultVerticalBar(SolidColor(Color.Blue)) }` must be changed to `bar = { _,_,_ -> DefaultVerticalBar(SolidColor(Color.Blue)) }`
- use of factory functions is uneffected
gsteckman
left a comment
There was a problem hiding this comment.
Thanks again for contributing. Just a couple comments on this. Also, I've started working on a horizontal bar implementation. I'll try to get it committed soon so you can pull it into your changes.
Thanks a lot for implementing a horizontal bar chart! Saves me tons of time. I've pulled and merged it locally, now I'm adding the respective shape implementations for the horizontal bar chart. Shouldn't take too long. |
…to be compatible with custom shape rendering adding shapes and factory functions for horizontal barcharts with concave/convex endings, equivalent to vertical barchart variants standardizing barchart shape and factory function names (vertical/horizontal distinction)
gsteckman
left a comment
There was a problem hiding this comment.
Hi, wanted to clarify a few comments to be sure they align with the actual implementation & function names.
Thanks for checking the comments. Indeed, these were sloppy copy/paste errors. I think I fixed them all. |



Description
Adding two bar chart shape implementations with concave/convex endings (see screenshots below).
Motivation
While migrating to Koalaplot, I needed to maintain UI style related requirements such as having rounded corners in UI elements. While looking for a library, I didn't find a single one which satisfied these kind of needs. However Koalaplot was by far the best option. Once this pull request, hopefully, gets accepted I'll move on to implementing horizontal barcharts.
Challenges
Shape'screateOutlinemethod gets aSizeobject which however doesn't have any information about the positioning/layout of the corresponding bar, so in simple terms the bar doesn't know anything about it's surrounding and it's neighbors. To solve this issue the corresponding value of the bar and it's index in the series get passed to the correspondingShapeimplementation.Solution
To solve this issue in a standardized way, the existing typealias
public typealias VerticalBarComposable<E> = @Composable BarScope.(series: Int, index: Int, value: E) -> Unithas been utilized in the codebase. An additional typealiaspublic typealias DefaultVerticalBarComposable<X, Y> = VerticalBarComposable<VerticalBarPlotEntry<X, Y>>has been added for better readability.So effectively unstandardized expressions such as
@Composable BarScope.(dataIndex: Int, groupIndex: Int, entry: E) -> Unit,@Composable BarScope.() -> Unitor@Composable BarScope.(index: Int) -> Unithave been replaced with eitherVerticalBarComposable<E>orDefaultVerticalBarComposable<X, Y>.VerticalBarPlotEntrytype parameterroundToIntonly to range expression; removing from height calculation, since rounding results in up to 2.47% of errorPotentially required adjustments in client code:
bar = { DefaultVerticalBar(SolidColor(Color.Blue)) }must be changed tobar = { _,_,_ -> DefaultVerticalBar(SolidColor(Color.Blue)) }