From 7e119c2dc4d607124413b3a0fb9453d91604819e Mon Sep 17 00:00:00 2001 From: agent-polyblank Date: Mon, 5 Jan 2026 20:16:04 +0000 Subject: [PATCH 1/2] fix docs where DefaultVerticalBar was used --- content/en/docs/xygraphs/bar_plots/index.md | 6 +-- .../github/koalaplot/example/VerticalBar1.kt | 21 +++++---- .../github/koalaplot/example/VerticalBar2.kt | 45 ++++++++++++------- mise.toml | 2 + 4 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 mise.toml diff --git a/content/en/docs/xygraphs/bar_plots/index.md b/content/en/docs/xygraphs/bar_plots/index.md index 93cbd9a..942f5e3 100644 --- a/content/en/docs/xygraphs/bar_plots/index.md +++ b/content/en/docs/xygraphs/bar_plots/index.md @@ -10,19 +10,19 @@ Bar Plots are also 2-D plots and are therefore plotted within an ```XYGraph``` p The simplest type of vertical bar plot has a single series of data, and there is a ```VerticalBarPlot``` overload to make this use case easy when using Float values for the y-axis. The below example demonstrates this to plot the population of each New York City burrough. -{{% example "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt" 16 31 %}} +{{% example "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt" 14 35 %}} ![Vertical bars](VerticalBar1.png) {{% /example %}} In the above example, all bars were automatically extended to the origin of the y-axis, 0. In some cases it is desirable to plot vertical bars with starting positions that are not at 0. To support this use case, there is a second form of ```VerticalBarPlot``` that allows specifying the starting and ending coordinates of each bar. The below example demonstrates using this flexibility to create a waterfall chart: -{{% example "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt" 17 39 %}} +{{% example "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt" 17 53 %}} ![Waterfall](VerticalBar2.png) {{% /example %}} There is also a builder DSL for vertical bar plots, that slightly improves on the syntax. The previous example can also be implemented as follows: -{{% code "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar3.kt" 15 29 %}} +{{% code "/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar3.kt" 17 29 %}} {{% alert title="Tip" color="info" %}} For improved type safety, consider using an enumeration for the ```CategoryAxisModel``` categories. If an item is added with a category value that is not a member of the list provided to the ```CategoryAxisModel``` constructor, a runtime exception will be thrown. diff --git a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt index 5c7fafa..062e087 100644 --- a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt +++ b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar1.kt @@ -4,7 +4,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.window.singleWindowApplication -import io.github.koalaplot.core.bar.DefaultVerticalBar +import io.github.koalaplot.core.bar.DefaultBar import io.github.koalaplot.core.bar.VerticalBarPlot import io.github.koalaplot.core.util.ExperimentalKoalaPlotApi import io.github.koalaplot.core.xygraph.CategoryAxisModel @@ -17,16 +17,19 @@ fun main() = singleWindowApplication { val population = listOf(1.446788f, 2.648452f, 1.638281f, 2.330295f, 0.487155f) XYGraph( - xAxisModel = remember { CategoryAxisModel(boroughs) }, - yAxisModel = rememberFloatLinearAxisModel(0f..3f, minorTickCount = 0), - yAxisTitle = "Population (Millions)" + xAxisModel = remember { CategoryAxisModel(boroughs) }, + yAxisModel = rememberFloatLinearAxisModel(0f..3f, minorTickCount = 0), + yAxisTitle = "Population (Millions)" ) { VerticalBarPlot( - xData = boroughs, - yData = population, - bar = { - DefaultVerticalBar(SolidColor(Color.Blue)) - } + xData = boroughs, + yData = population, + bar = { _, _, _ -> + DefaultBar( + brush = SolidColor(Color.Blue), + modifier = Modifier.fillMaxWidth(), + ) + } ) } } diff --git a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt index c9d4ec6..c8837da 100644 --- a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt +++ b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt @@ -5,7 +5,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.window.singleWindowApplication -import io.github.koalaplot.core.bar.DefaultVerticalBar +import io.github.koalaplot.core.bar.DefaultBar import io.github.koalaplot.core.bar.VerticalBarPlot import io.github.koalaplot.core.bar.verticalBarPlotEntry import io.github.koalaplot.core.util.ExperimentalKoalaPlotApi @@ -17,26 +17,37 @@ import io.github.koalaplot.core.xygraph.rememberFloatLinearAxisModel @OptIn(ExperimentalKoalaPlotApi::class) fun main() = singleWindowApplication { val categories = listOf("Initial Cash", "Q1", "Q2", "Q3", "Q4", "Final Cash") - val colors = listOf( - Color.DarkGray, Color(0xFF00498F), Color(0xFFED7D31), - Color(0xFF00498F), Color(0xFF00498F), Color.DarkGray, - ) - val data = listOf( - verticalBarPlotEntry(categories[0], 0f, 100f), - verticalBarPlotEntry(categories[1], 100f, 120f), - verticalBarPlotEntry(categories[2], 120f, 90f), - verticalBarPlotEntry(categories[3], 90f, 110f), - verticalBarPlotEntry(categories[4], 110f, 130f), - verticalBarPlotEntry(categories[5], 0f, 130f), - ) + val colors = + listOf( + Color.DarkGray, + Color(0xFF00498F), + Color(0xFFED7D31), + Color(0xFF00498F), + Color(0xFF00498F), + Color.DarkGray, + ) + val data = + listOf( + verticalBarPlotEntry(categories[0], 0f, 100f), + verticalBarPlotEntry(categories[1], 100f, 120f), + verticalBarPlotEntry(categories[2], 120f, 90f), + verticalBarPlotEntry(categories[3], 90f, 110f), + verticalBarPlotEntry(categories[4], 110f, 130f), + verticalBarPlotEntry(categories[5], 0f, 130f), + ) XYGraph( - xAxisModel = remember { CategoryAxisModel(categories) }, - yAxisModel = rememberFloatLinearAxisModel(0f..150f, minorTickCount = 0), + xAxisModel = remember { CategoryAxisModel(categories) }, + yAxisModel = rememberFloatLinearAxisModel(0f..150f, minorTickCount = 0), ) { VerticalBarPlot( - data, - bar = { DefaultVerticalBar(SolidColor(colors[it])) } + data, + bar = { index, _, _ -> + DefaultBar( + brush = SolidColor(colors[index]), + modifier = Modifier.fillMaxWidth(), + ) + } ) } } diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..a15969e --- /dev/null +++ b/mise.toml @@ -0,0 +1,2 @@ +[tools] +hugo-extended = "0.120.4" From 38f5a8f67312698a57eb10247bd40a61eed21156 Mon Sep 17 00:00:00 2001 From: agent-polyblank Date: Mon, 5 Jan 2026 20:21:56 +0000 Subject: [PATCH 2/2] fix the ones in VerticalBar2 XYGraphScope --- .../io/github/koalaplot/example/VerticalBar2.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt index c8837da..f0667be 100644 --- a/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt +++ b/examples/src/jvmMain/kotlin/io/github/koalaplot/example/VerticalBar2.kt @@ -55,11 +55,11 @@ fun main() = singleWindowApplication { @Composable private fun XYGraphScope.x() { VerticalBarPlot { - item("Initial Cash", 0f, 100f) { DefaultVerticalBar(SolidColor(Color.DarkGray)) } - item("Q1", 100f, 120f) { DefaultVerticalBar(SolidColor(Color(0xFF00498F))) } - item("Q2", 120f, 90f) { DefaultVerticalBar(SolidColor(Color(0xFFED7D31))) } - item("Q3", 90f, 110f) { DefaultVerticalBar(SolidColor(Color(0xFF00498F))) } - item("Q4", 110f, 130f) { DefaultVerticalBar(SolidColor(Color(0xFF00498F))) } - item("Final Cash", 0f, 130f) { DefaultVerticalBar(SolidColor(Color.DarkGray)) } + item("Initial Cash", 0f, 100f) { _, _, _ -> DefaultBar(SolidColor(Color.DarkGray)) } + item("Q1", 100f, 120f) { _, _, _ -> DefaultBar(SolidColor(Color(0xFF00498F))) } + item("Q2", 120f, 90f) { _, _, _ -> DefaultBar(SolidColor(Color(0xFFED7D31))) } + item("Q3", 90f, 110f) { _, _, _ -> DefaultBar(SolidColor(Color(0xFF00498F))) } + item("Q4", 110f, 130f) { _, _, _ -> DefaultBar(SolidColor(Color(0xFF00498F))) } + item("Final Cash", 0f, 130f) { _, _, _ -> DefaultBar(SolidColor(Color.DarkGray)) } } }