From 470b5fbfe8b90e7339f5eb81077f39497aa4967b Mon Sep 17 00:00:00 2001 From: Marco Fracassi Date: Mon, 14 Aug 2023 16:33:05 +0200 Subject: [PATCH] Fix remember state of bars --- JetChart/build.gradle | 2 +- JetChart/src/main/java/io/jetchart/bar/BarChart.kt | 12 ++++++------ README.md | 4 ++-- app/src/main/java/io/jetchart/demo/MainActivity.kt | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/JetChart/build.gradle b/JetChart/build.gradle index 3dd6b23..4b216f6 100644 --- a/JetChart/build.gradle +++ b/JetChart/build.gradle @@ -59,7 +59,7 @@ afterEvaluate { from components.release groupId = 'io.jetchart' artifactId = 'JetChart' - version = '1.3.3' + version = '1.3.4' } } } diff --git a/JetChart/src/main/java/io/jetchart/bar/BarChart.kt b/JetChart/src/main/java/io/jetchart/bar/BarChart.kt index 89d6d05..790ef3a 100644 --- a/JetChart/src/main/java/io/jetchart/bar/BarChart.kt +++ b/JetChart/src/main/java/io/jetchart/bar/BarChart.kt @@ -32,7 +32,7 @@ import io.jetchart.common.animation.fadeInAnimation @Composable fun BarChart( modifier: Modifier = Modifier, - chars: Bars, + bars: Bars, animation: AnimationSpec = fadeInAnimation(), xAxisDrawer: XAxisDrawer = BarXAxisDrawer(), yAxisDrawer: YAxisDrawer = BarYAxisWithValueDrawer(), @@ -40,10 +40,10 @@ fun BarChart( valueDrawer: BarValueDrawer = SimpleBarValueDrawer(), barHorizontalMargin: Dp = 3.dp ) { - val transitionAnimation = remember(chars.bars) { Animatable(initialValue = 0f) } - val rectangles = remember { mutableStateMapOf() } + val transitionAnimation = remember(bars.bars) { Animatable(initialValue = 0f) } + val rectangles = remember(bars.bars) { mutableStateMapOf() } val barDrawer = SimpleBarDrawer() - LaunchedEffect(chars.bars) { + LaunchedEffect(bars.bars) { transitionAnimation.animateTo(1f, animationSpec = animation) } @@ -60,13 +60,13 @@ fun BarChart( val (xAxisArea, yAxisArea) = axisAreas(this, size, xAxisDrawer, yAxisDrawer, valueDrawer) val barDrawableArea = barDrawableArea(xAxisArea) - yAxisDrawer.drawAxisLabels(this, canvas, yAxisArea, chars.minYValue, chars.maxYValue) + yAxisDrawer.drawAxisLabels(this, canvas, yAxisArea, bars.minYValue, bars.maxYValue) yAxisDrawer.drawAxisLine(this, canvas, yAxisArea) xAxisDrawer.drawAxisLine(this, canvas, xAxisArea) - chars.forEachWithArea(this, barDrawableArea, transitionAnimation.value, valueDrawer, barHorizontalMargin) { barArea, bar -> + bars.forEachWithArea(this, barDrawableArea, transitionAnimation.value, valueDrawer, barHorizontalMargin) { barArea, bar -> barDrawer.drawBar(this, canvas, barArea, bar) labelDrawer.draw(this, canvas, bar.label, barArea, xAxisArea) valueDrawer.draw(this, canvas, bar.value, barArea, xAxisArea) diff --git a/README.md b/README.md index df359a5..d8bcc6e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ allprojects { 2. Add the dependency ```groovy dependencies { - implementation 'com.github.fracassi-marco:JetChart:1.3.3' + implementation 'com.github.fracassi-marco:JetChart:1.3.4' } ``` @@ -63,7 +63,7 @@ You can: fun BarChartComposable(text: MutableState) { val numberOfBars = 8 val width = numberOfBars * 80 - BarChart(chars = Bars( + BarChart(bars = Bars( bars = (1..numberOfBars).map { Bar(label = "BAR$it", value = Random.nextFloat(), color = JetGreen) { bar -> text.value = "You clicked on the bar ${bar.label}!" diff --git a/app/src/main/java/io/jetchart/demo/MainActivity.kt b/app/src/main/java/io/jetchart/demo/MainActivity.kt index c049d61..7448ef9 100644 --- a/app/src/main/java/io/jetchart/demo/MainActivity.kt +++ b/app/src/main/java/io/jetchart/demo/MainActivity.kt @@ -86,7 +86,7 @@ class MainActivity : ComponentActivity() { fun BarChartComposable(text: MutableState) { val numberOfBars = 8 val width = numberOfBars * 80 - BarChart(chars = Bars( + BarChart(bars = Bars( bars = (1..numberOfBars).map { Bar(label = "BAR$it", value = Random.nextFloat(), color = if(it % 2 == 0) JetGreen else Red) { bar -> text.value = "You clicked on the bar ${bar.label}!"