ehsannarmani / ComposeCharts

Animated & Flexible Practical Charts For Jetpack Compose
Apache License 2.0
272 stars 13 forks source link

Implement indicator position customization #12

Closed LeeWeeder closed 3 months ago

LeeWeeder commented 3 months ago

In this issue #11, I have requested a feature to position the indicators to the start or end of the chart for the line and column charts.

Edit: Now also included RowCharts.

Samples

[!TIP] For old implementations that wanted to retain the position at the start, there is nothing to do as change defaults to the start position.

Column Chart

ColumnChart(
    ...,
    indicatorProperties = IndicatorProperties(
        textStyle = TextStyle(fontSize = 12.sp, fontFamily = ubuntu, color = Color.White),
        count = 4,
        position = IndicatorProperties.Position.End // Define the position, defaults to Start
    ),
    ...
)
Column Chart with indicator positioned at the end

Line Chart

LineChart(
    ...,
    indicatorProperties = IndicatorProperties(
        textStyle = TextStyle(fontSize = 12.sp, fontFamily = ubuntu, color = Color.White),
        count = 4,
        position = IndicatorProperties.Position.End // Define the position, defaults to Start
    ),
    ...
)
Column Chart with indicator positioned at the end

[!NOTE] I only implemented the implementation. I would like to relay the documentation update (README) to the maintainers/owner for uniformity if this ever gets merged.

Thank you!

ehsannarmani commented 3 months ago

Hi @LeeWeeder , thank you for you pr, this is really valuable for us. A reviewed your PR and it seems there is no problem, but now we have this feature, I would like you to add that feature to the row chart as well, so that this feature is complete and available in all charts. πŸ™Œ

Note: the start position for the row chart indicators will be top of chart and end position will be bottom of chart, so by default give end position for row chart indicators

LeeWeeder commented 3 months ago

Working on this.

LeeWeeder commented 3 months ago

Hello @ehsannarmani. I have implemented the feature for RowChart but while doing so, it also introduced major breaking changes.

Instead of

LineChart(
    ...,
    indicatorProperties = IndicatorProperties(
        textStyle = TextStyle(fontSize = 12.sp, fontFamily = ubuntu, color = Color.White),
        count = 4,
        position =  IndicatorProperties.Position.End // Define the position, defaults to Start
    ),
    ...
)

The implementation will be as follows

LineChart(
    ...,
    indicatorProperties = HorizontalIndicatorProperties(
        textStyle = TextStyle(fontSize = 12.sp, fontFamily = ubuntu, color = Color.White),
        count = 4,
        position =  IndicatorPosition.Horizontal.End// Define the position, defaults to Start
    ),
    ...
)

The implementation for LineChart and ColumnChart is the same.

[!NOTE] I refactored the IndicatorProperties.Position to IndicatorPosition for simplicity of usage.

[!NOTE] IndicatorProperties became HorizontalIndicatorProperties

For RowChart, will use

RowChart(
    ...,
    indicatorProperties = VerticalIndicatorProperties(
        textStyle = TextStyle(fontSize = 12.sp, fontFamily = ubuntu, color = Color.White),
        count = 4,
        position = IndicatorPosition.Vertical.Top  // Define the position, defaults to Bottom
    ),
    ...
)
ehsannarmani commented 3 months ago

Hi, cool. @LeeWeeder But why you closed the pr?

LeeWeeder commented 3 months ago

Hello @ehsannarmani. I didn't know renaming the branch would automatically close a PR. I apologize for that. I didn't notice until you pointed it out to me, my bad. I will just restore the branch and reopen the PR. Again, sorry for the inconvenience.

ehsannarmani commented 3 months ago

Hi @LeeWeeder , It's ok i know. Thank you so much for your efforts πŸ™ŒπŸ™Œ