diff --git a/docs/examples/jupyter-notebooks/f-4.9.0/waterfall_plot_base.ipynb b/docs/examples/jupyter-notebooks/f-4.9.0/waterfall_plot_base.ipynb new file mode 100644 index 000000000..65d01f510 --- /dev/null +++ b/docs/examples/jupyter-notebooks/f-4.9.0/waterfall_plot_base.ipynb @@ -0,0 +1,519 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "63396492-2899-4862-8cfb-84e812a844cc", + "metadata": {}, + "source": [ + "# Parameter `base` of the Waterfall Plot" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b1b75d26-0fde-4591-af27-677b5d807b5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%useLatestDescriptors\n", + "%use lets-plot" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7137dd20-92ce-4b54-87d1-a1088285f1d0", + "metadata": {}, + "outputs": [], + "source": [ + "val dataMap = mapOf(\n", + " \"Accounts\" to listOf(\"Product revenue\", \"Services revenue\", \"Fixed costs\", \"Variable costs\"),\n", + " \"Values\" to listOf(830_000, 290_000, -360_000, -150_000),\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "1f861d4a-b5df-429e-b4e0-a2a925c4cb28", + "metadata": {}, + "source": [ + "## Default View" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "201f8210-dfc1-4df2-b1eb-3e6c5cc1a92b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "waterfallPlot(dataMap, \"Accounts\", \"Values\", hline = elementLine()) + themeMinimal()" + ] + }, + { + "cell_type": "markdown", + "id": "0f428414-25a3-49ec-b358-b04c89c80586", + "metadata": {}, + "source": [ + "## Change Base" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "30a03d80-e4c6-4e42-8467-a4f3e1e33778", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "val prevPeriodTotal = 400_000\n", + "waterfallPlot(dataMap, \"Accounts\", \"Values\", base = prevPeriodTotal, hline = elementLine()) + themeMinimal()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Kotlin", + "language": "kotlin", + "name": "kotlin" + }, + "language_info": { + "codemirror_mode": "text/x-kotlin", + "file_extension": ".kt", + "mimetype": "text/x-kotlin", + "name": "kotlin", + "nbconvert_exporter": "", + "pygments_lexer": "kotlin", + "version": "1.9.23" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/future_changes.md b/future_changes.md index 2c3be4c39..87b6f35d5 100644 --- a/future_changes.md +++ b/future_changes.md @@ -46,9 +46,9 @@ This release is 100% compatible with Lets-Plot [v 4.5.1](https://github.com/JetB - Geometries: - `geomBlank()` [[#831](https://github.com/JetBrains/lets-plot/issues/831)]. - - ToDo: `base` parameter in `waterfallPlot()` [[#1159](https://github.com/JetBrains/lets-plot/issues/1159)]. + - `base` parameter in `waterfallPlot()` [[#1159](https://github.com/JetBrains/lets-plot/issues/1159)]. - ToDo: See [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-24g/waterfall_plot_base.ipynb). + See [example notebook](https://nbviewer.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/f-4.9.0/waterfall_plot_base.ipynb). - `checkOverlap` parameter in `geomText()` and `geomLabel()`. diff --git a/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlot.kt b/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlot.kt index 77475dd3a..06a1c22f8 100644 --- a/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlot.kt +++ b/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlot.kt @@ -62,6 +62,8 @@ package org.jetbrains.letsPlot.bistro.waterfall * Specifies appearance, style and content. * When "none", tooltips are not shown. * When "detailed", a more detailed (compared to the default) version of the tooltips is shown. + * @param base default = 0.0. + * Values with measure "absolute" or "total" are relative to this value. * @param sortedValue default = false. * Sorts categories by absolute value of the changes. * @param threshold Groups all categories under a certain threshold value into "Other" category. @@ -109,6 +111,7 @@ fun waterfallPlot( showLegend: Boolean? = null, relativeTooltips: Any? = null, absoluteTooltips: Any? = null, + base: Number? = null, calcTotal: Boolean? = null, totalTitle: String? = null, sortedValue: Boolean? = null, @@ -134,6 +137,7 @@ fun waterfallPlot( showLegend = showLegend, relativeTooltips = relativeTooltips, absoluteTooltips = absoluteTooltips, + base = base, calcTotal = calcTotal, totalTitle = totalTitle, sortedValue = sortedValue, diff --git a/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlotBuilder.kt b/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlotBuilder.kt index 791de24c2..a47b87c27 100644 --- a/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlotBuilder.kt +++ b/plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/bistro/waterfall/WaterfallPlotBuilder.kt @@ -21,6 +21,7 @@ internal class WaterfallPlotBuilder( private val showLegend: Boolean?, private val relativeTooltips: Any?, private val absoluteTooltips: Any?, + private val base: Number?, private val calcTotal: Boolean?, private val totalTitle: String?, private val sortedValue: Boolean?, @@ -56,6 +57,7 @@ internal class WaterfallPlotBuilder( is TooltipOptions -> absoluteTooltips.options else -> absoluteTooltips }, + Waterfall.BASE to base, Waterfall.CALCULATE_TOTAL to calcTotal, Waterfall.TOTAL_TITLE to totalTitle, Waterfall.SORTED_VALUE to sortedValue,