Skip to content

Adding 2 concave/convex shape implementations for bar charts#128

Merged
gsteckman merged 8 commits into
KoalaPlot:mainfrom
postfixNotation:contribution/barchartshapes-roundedbars
Oct 26, 2025
Merged

Adding 2 concave/convex shape implementations for bar charts#128
gsteckman merged 8 commits into
KoalaPlot:mainfrom
postfixNotation:contribution/barchartshapes-roundedbars

Conversation

@postfixNotation
Copy link
Copy Markdown
Contributor

Description

Adding two bar chart shape implementations with concave/convex endings (see screenshots below).

  • 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

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's createOutline method gets a Size object 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 corresponding Shape implementation.

Solution

To solve this issue in a standardized way, the existing typealias public typealias VerticalBarComposable<E> = @Composable BarScope.(series: Int, index: Int, value: E) -> Unit has been utilized in the codebase. An additional typealias public 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.() -> Unit or @Composable BarScope.(index: Int) -> Unit have been replaced with either VerticalBarComposable<E> or DefaultVerticalBarComposable<X, Y>.

  • 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

Potentially required adjustments in client code:

  • expressions like bar = { DefaultVerticalBar(SolidColor(Color.Blue)) } must be changed to bar = { _,_,_ -> DefaultVerticalBar(SolidColor(Color.Blue)) }
  • however use of factory functions is uneffected

grouped_barchart
stacked_barchart
waterfall_chart
single_barchart

- 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
Copy link
Copy Markdown
Member

@gsteckman gsteckman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/GroupedVerticalBarPlot.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt
@postfixNotation
Copy link
Copy Markdown
Contributor Author

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)
@postfixNotation
Copy link
Copy Markdown
Contributor Author

This is how the custom shapes look applied to horizontal bar charts.

grouped_horizontal_barchart stacked_horizontal_barchart single_horizontal_barchart

Copy link
Copy Markdown
Member

@gsteckman gsteckman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, wanted to clarify a few comments to be sure they align with the actual implementation & function names.

Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/Bar.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/Bar.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/Bar.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/Bar.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
Comment thread src/commonMain/kotlin/io/github/koalaplot/core/bar/BarPlotShapes.kt Outdated
@postfixNotation
Copy link
Copy Markdown
Contributor Author

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.

@gsteckman gsteckman merged commit 47f9c7e into KoalaPlot:main Oct 26, 2025
1 check passed
@postfixNotation postfixNotation deleted the contribution/barchartshapes-roundedbars branch October 29, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants