Skip to content

Commit 553a4a2

Browse files
Waterfall Plot (#253)
* Waterfall: Prepare first basic version of the new function. * Waterfall: Small fixes in API (parameter names). * Waterfall: Add test notebook. * Waterfall: Add cookbook. * Waterfall: Add KDoc. * Waterfall: Update the future_changes.md file. * Waterfall: Replace Double to Number in API. * Waterfall: Rerun notebooks.
1 parent fd1cd70 commit 553a4a2

File tree

6 files changed

+13556
-0
lines changed

6 files changed

+13556
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package frontendContextDemo.scripts
2+
3+
import frontendContextDemo.ScriptInBatikContext
4+
import org.jetbrains.letsPlot.bistro.waterfall.waterfallPlot
5+
import org.jetbrains.letsPlot.label.ggtitle
6+
import org.jetbrains.letsPlot.themes.elementLine
7+
import org.jetbrains.letsPlot.themes.elementText
8+
import org.jetbrains.letsPlot.tooltips.layerTooltips
9+
10+
object Waterfall {
11+
@JvmStatic
12+
fun main(args: Array<String>) {
13+
ScriptInBatikContext.eval("Waterfall plot") {
14+
run {
15+
val data = mapOf(
16+
"cat" to listOf("A", "B", "C", "D"),
17+
"val" to listOf(1, 3, -2, 1)
18+
)
19+
20+
val p = waterfallPlot(data, "cat", "val") + ggtitle("Basic demo")
21+
p.show()
22+
}
23+
24+
run {
25+
val data = mapOf(
26+
"cat" to listOf("A", "B", "C", "D", "E"),
27+
"val" to listOf(100, 200, -400, 500, -200)
28+
)
29+
30+
val p = waterfallPlot(
31+
data, "cat", "val",
32+
color = "flow_type",
33+
fill = "lightgrey",
34+
size = 3.0,
35+
alpha = 0.75,
36+
linetype = "dotted",
37+
width = 0.4,
38+
showLegend = true,
39+
relativeTooltips = layerTooltips()
40+
.title("Category: @..xlabel.. (#@..x..)")
41+
.minWidth(200)
42+
.anchor("top_center")
43+
.line("ymax|@..ymax..")
44+
.line("ymin|^ymin")
45+
.format("@..x..", "d")
46+
.format("@..ymax..", ".3f")
47+
.format("ymin", "d")
48+
.disableSplitting(),
49+
calcTotal = false,
50+
totalTitle = "result",
51+
sortedValue = true,
52+
maxValues = 3,
53+
hline = elementLine(color = "magenta", size = 5),
54+
hlineOntop = false,
55+
connector = elementLine(color = "cyan", size = 1.5),
56+
label = elementText(color = "flow_type", family = "Times", face = "bold", size = 5, angle = 45),
57+
labelFormat = "d"
58+
) + ggtitle("With parameters")
59+
p.show()
60+
}
61+
62+
run {
63+
val data = mapOf(
64+
"cat" to listOf("A", "B", "C", "D", "T1", "A", "B", "C", null, "E", "T2"),
65+
"val" to listOf(1.2, 2.2, -0.4, 1.5, null, -2.0, 1.3, -0.8, 1.0, 1.0, 0.0),
66+
"m" to listOf("absolute", "relative", "relative", "relative", "total", "relative", "relative", "relative", "relative", null, "total")
67+
)
68+
69+
val p = waterfallPlot(data, "cat", "val", measure = "m", showLegend = true) + ggtitle("With measure")
70+
p.show()
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)