Skip to content

Commit cab3da0

Browse files
committed
Setting global theme: add checking of single feature value, other code improvements.
1 parent 921a250 commit cab3da0

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

demo/jvm-batik/src/main/kotlin/frontendContextDemo/scripts/Boxplot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Boxplot {
4040
// Y-orientation
4141
(letsPlot(data) { y = "cat"; x = "val" } + ggtitle("Boxplot Y-orientation") +
4242
geomBoxplot(
43-
orientation = "y",
43+
// orientation = "y", // auto-detected
4444
outlierColor = "red", outlierSize = 2, outlierShape = 21
4545
)).show()
4646
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ object LetsPlot {
2121
set(value) {
2222
field = when (value) {
2323
null -> null
24-
is OptionsMap -> value
2524
is FeatureList -> {
26-
val optionsMap = value.elements.map { it as? OptionsMap ?: error("theme: unsupported feature $it") }
27-
optionsMap.forEach {
28-
require(it.kind == Option.Plot.THEME) {
29-
"theme: wrong options type, expected `${Option.Plot.THEME}` but was `${it.kind}`"
30-
}
31-
}
32-
ThemeOptionsUtil.toSpec(optionsMap)?.let { mergedOptions ->
25+
val optionsMapList = value.elements.map(::toThemeOptionsMap)
26+
ThemeOptionsUtil.toSpec(optionsMapList)?.let { mergedOptions ->
3327
OptionsMap(Option.Plot.THEME, mergedOptions)
3428
}
3529
}
36-
else -> throw IllegalArgumentException("Only `theme(...)`, `themeXxx()`, `flavorXxx()`, or a sum of them are supported")
30+
31+
else -> toThemeOptionsMap(value)
3732
}
3833
}
3934

@@ -53,4 +48,12 @@ object LetsPlot {
5348
frontendContext = NotebookFrontendContext(jsVersion, isolatedFrameContext, htmlRenderer)
5449
return frontendContext as NotebookFrontendContext
5550
}
51+
52+
private fun toThemeOptionsMap(feature: Feature): OptionsMap {
53+
require(feature is OptionsMap && feature.kind == Option.Plot.THEME) {
54+
"'theme' expected but was: $feature"
55+
}
56+
57+
return feature
58+
}
5659
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fun gggrid(
108108
@Suppress("NAME_SHADOWING")
109109
val plots = (plots.toList() + List(ncol - 1) { null }).take(len)
110110

111-
val features = listOfNotNull(LetsPlot.theme?.let { it as OptionsMap })
111+
val features = listOfNotNull(LetsPlot.theme as? OptionsMap)
112112

113113
return SubPlotsFigure(
114114
figures = plots,

0 commit comments

Comments
 (0)