Skip to content

Commit 7147c89

Browse files
Add geomSina() and statSina() classes.
1 parent 3769ce6 commit 7147c89

File tree

13 files changed

+324
-0
lines changed

13 files changed

+324
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package frontendContextDemo.scripts
2+
3+
import demoData.AutoMpg
4+
import frontendContextDemo.ScriptInBatikContext
5+
import org.jetbrains.letsPlot.asDiscrete
6+
import org.jetbrains.letsPlot.geom.geomSina
7+
import org.jetbrains.letsPlot.geom.geomViolin
8+
import org.jetbrains.letsPlot.letsPlot
9+
10+
object Sina {
11+
@JvmStatic
12+
fun main(args: Array<String>) {
13+
ScriptInBatikContext.eval("Sina plot") {
14+
val mpgData = AutoMpg.map()
15+
16+
run {
17+
(letsPlot(mpgData) { x = "origin of car"; y = "miles per gallon" }
18+
+ geomViolin()
19+
+ geomSina(seed = 42)).show()
20+
}
21+
22+
run {
23+
(letsPlot(mpgData) { x = "origin of car"; y = "miles per gallon" }
24+
+ geomViolin(showHalf = -1) { fill = "origin of car" }
25+
+ geomSina(showHalf = 1, seed = 42) { color = "origin of car" }).show()
26+
}
27+
28+
run {
29+
(letsPlot(mpgData) { x = asDiscrete("number of cylinders"); y = "miles per gallon" }
30+
+ geomViolin(alpha = .25) { fill = "origin of car" }
31+
+ geomSina(shape = 21, size = 1.2, stroke = .4, color = "black", seed = 42) { fill = "origin of car" }).show()
32+
}
33+
}
34+
}
35+
}

plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/Stat.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,26 @@ object Stat {
256256
override val parameters = this.seal()
257257
}
258258

259+
@Suppress("ClassName")
260+
class sina(
261+
override val scale: String? = null,
262+
override val tailsCutoff: Number? = null,
263+
override val bw: Any? = null,
264+
override val kernel: String? = null,
265+
override val n: Int? = null,
266+
override val trim: Boolean? = null,
267+
override val adjust: Number? = null,
268+
override val fullScanMax: Int? = null,
269+
override val quantiles: List<Number>? = null,
270+
mapping: SinaStatMapping.() -> Unit = {}
271+
) : SinaStatParameters,
272+
StatOptions(
273+
StatKind.SINA,
274+
mapping = SinaStatMapping().apply(mapping).seal()
275+
) {
276+
override val parameters = this.seal()
277+
}
278+
259279
@Suppress("ClassName")
260280
class densityRidges(
261281
override val tailsCutoff: Number? = null,
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.jetbrains.letsPlot.geom
2+
3+
import org.jetbrains.letsPlot.Stat
4+
import org.jetbrains.letsPlot.intern.GeomKind
5+
import org.jetbrains.letsPlot.intern.Layer
6+
import org.jetbrains.letsPlot.intern.layer.GeomOptions
7+
import org.jetbrains.letsPlot.intern.layer.PosOptions
8+
import org.jetbrains.letsPlot.intern.layer.SamplingOptions
9+
import org.jetbrains.letsPlot.intern.layer.StatOptions
10+
import org.jetbrains.letsPlot.intern.layer.WithColorOption
11+
import org.jetbrains.letsPlot.intern.layer.WithFillOption
12+
import org.jetbrains.letsPlot.intern.layer.geom.SinaAesthetics
13+
import org.jetbrains.letsPlot.intern.layer.geom.SinaMapping
14+
import org.jetbrains.letsPlot.intern.layer.geom.SinaParameters
15+
import org.jetbrains.letsPlot.intern.layer.stat.SinaStatAesthetics
16+
import org.jetbrains.letsPlot.intern.layer.stat.SinaStatParameters
17+
import org.jetbrains.letsPlot.pos.positionDodge
18+
import org.jetbrains.letsPlot.tooltips.TooltipOptions
19+
20+
/*
21+
TODO
22+
*/
23+
class geomSina(
24+
data: Map<*, *>? = null,
25+
stat: StatOptions = Stat.sina(),
26+
position: PosOptions = positionDodge(),
27+
showLegend: Boolean = true,
28+
inheritAes: Boolean? = null,
29+
manualKey: Any? = null,
30+
sampling: SamplingOptions? = null,
31+
tooltips: TooltipOptions? = null,
32+
orientation: String? = null,
33+
override val x: Number? = null,
34+
override val y: Number? = null,
35+
override val violinWidth: Number? = null,
36+
override val alpha: Number? = null,
37+
override val color: Any? = null,
38+
override val fill: Any? = null,
39+
override val shape: Any? = null,
40+
override val size: Number? = null,
41+
override val stroke: Any? = null,
42+
override val width: Number? = null,
43+
override val weight: Number? = null,
44+
override val scale: String? = null,
45+
override val tailsCutoff: Number? = null,
46+
override val bw: Any? = null,
47+
override val kernel: String? = null,
48+
override val n: Int? = null,
49+
override val trim: Boolean? = null,
50+
override val adjust: Number? = null,
51+
override val fullScanMax: Int? = null,
52+
override val quantiles: List<Number>? = null,
53+
override val showHalf: Number? = null,
54+
override val seed: Int? = null,
55+
override val colorBy: String? = null,
56+
override val fillBy: String? = null,
57+
mapping: SinaMapping.() -> Unit = {}
58+
) : SinaAesthetics,
59+
SinaParameters,
60+
SinaStatAesthetics,
61+
SinaStatParameters,
62+
WithColorOption,
63+
WithFillOption,
64+
Layer(
65+
mapping = SinaMapping().apply(mapping).seal(),
66+
data = data,
67+
geom = GeomOptions(GeomKind.SINA),
68+
stat = stat,
69+
position = position,
70+
showLegend = showLegend,
71+
inheritAes = inheritAes,
72+
manualKey = manualKey,
73+
sampling = sampling,
74+
tooltips = tooltips,
75+
orientation = orientation
76+
) {
77+
78+
override fun seal() = super<SinaAesthetics>.seal() +
79+
super<SinaParameters>.seal() +
80+
super<SinaStatAesthetics>.seal() +
81+
super<SinaStatParameters>.seal() +
82+
super<WithColorOption>.seal() +
83+
super<WithFillOption>.seal()
84+
}

plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/ggmarginal.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private fun toMarginal(side: Char, size: Double?, layer: Layer): Layer {
9191
StatKind.BOXPLOT -> GeomKind.BOX_PLOT
9292
StatKind.BOXPLOT_OUTLIER -> GeomKind.BOX_PLOT
9393
StatKind.YDENSITY -> GeomKind.VIOLIN
94+
StatKind.SINA -> GeomKind.SINA
9495
else -> null
9596
} ?: layer.geom.kind
9697

plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/intern/GeomKind.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum class GeomKind {
5252
},
5353
AREA_RIDGES,
5454
VIOLIN,
55+
SINA,
5556
LIVE_MAP,
5657
POINT,
5758
RIBBON,

plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/intern/StatKind.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum class StatKind {
1515
DENSITY2DF,
1616
DENSITYRIDGES,
1717
YDENSITY,
18+
SINA,
1819
DOTPLOT,
1920
YDOTPLOT,
2021
BIN,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jetbrains.letsPlot.intern.layer.geom
2+
3+
import org.jetbrains.letsPlot.intern.Options
4+
import org.jetbrains.letsPlot.intern.OptionsCapsule
5+
6+
interface SinaAesthetics : OptionsCapsule {
7+
val x: Any?
8+
val y: Any?
9+
val violinWidth: Any?
10+
val alpha: Any?
11+
val color: Any?
12+
val fill: Any?
13+
val shape: Any?
14+
val size: Any?
15+
val stroke: Any?
16+
val width: Any?
17+
18+
override fun seal() = Options.of(
19+
"x" to x,
20+
"y" to y,
21+
"violinwidth" to violinWidth,
22+
"alpha" to alpha,
23+
"color" to color,
24+
"fill" to fill,
25+
"shape" to shape,
26+
"size" to size,
27+
"stroke" to stroke,
28+
"width" to width
29+
)
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.jetbrains.letsPlot.intern.layer.geom
2+
3+
import org.jetbrains.letsPlot.intern.layer.WithGroupOption
4+
5+
class SinaMapping(
6+
override var x: Any? = null,
7+
override var y: Any? = null,
8+
override var violinWidth: Any? = null,
9+
override var alpha: Any? = null,
10+
override var color: Any? = null,
11+
override var fill: Any? = null,
12+
override var shape: Any? = null,
13+
override var size: Any? = null,
14+
override var stroke: Any? = null,
15+
override var width: Any? = null,
16+
override var group: Any? = null,
17+
override var paint_a: Any? = null,
18+
override var paint_b: Any? = null,
19+
override var paint_c: Any? = null
20+
) : SinaAesthetics, WithGroupOption, PaintAesthetics {
21+
override fun seal() = super<SinaAesthetics>.seal() +
22+
groupOption() +
23+
super<PaintAesthetics>.seal()
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jetbrains.letsPlot.intern.layer.geom
2+
3+
import org.jetbrains.letsPlot.core.spec.Option
4+
import org.jetbrains.letsPlot.intern.Options
5+
import org.jetbrains.letsPlot.intern.OptionsCapsule
6+
7+
interface SinaParameters : OptionsCapsule {
8+
val showHalf: Number?
9+
val seed: Int?
10+
11+
override fun seal() = Options.of(
12+
Option.Geom.Sina.SHOW_HALF to showHalf,
13+
Option.Geom.Sina.SEED to seed
14+
)
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.jetbrains.letsPlot.intern.layer.stat
2+
3+
import org.jetbrains.letsPlot.intern.Options
4+
import org.jetbrains.letsPlot.intern.OptionsCapsule
5+
6+
interface SinaStatAesthetics : OptionsCapsule {
7+
val x: Any?
8+
val y: Any?
9+
val weight: Any?
10+
11+
override fun seal() = Options.of(
12+
"x" to x,
13+
"y" to y,
14+
"weight" to weight
15+
)
16+
}

0 commit comments

Comments
 (0)