diff --git a/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/style/CustomStyle.kt b/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/style/CustomStyle.kt index 35ed03bcd..783003a8b 100644 --- a/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/style/CustomStyle.kt +++ b/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/style/CustomStyle.kt @@ -70,6 +70,27 @@ public interface WithMargin { } } +public typealias Inset = Margin + +public interface WithInset { + public var inset: Inset? + public fun inset(all: Double) { + inset = Inset(all, all, all, all) + } + + public fun inset(vertical: Double, horizontal: Double) { + inset = Inset(vertical, horizontal, vertical, horizontal) + } + + public fun inset(top: Double, horizontal: Double, bottom: Double) { + inset = Inset(top, horizontal, bottom, horizontal) + } + + public fun inset(top: Double, right: Double, bottom: Double, left: Double) { + inset = Inset(top, right, bottom, left) + } +} + public data class LineParameters internal constructor( var color: Color? = null, var width: Double? = null, @@ -322,8 +343,9 @@ public data class PlotCanvas internal constructor( override var title: TextParameters? = null, var subtitle: TextParameters? = null, var caption: TextParameters? = null, - override var margin: Margin? = null -) : SelfInvocationContext, WithBackground, WithTitle, WithMargin { + override var margin: Margin? = null, + override var inset: Inset? = null, +) : SelfInvocationContext, WithBackground, WithTitle, WithMargin, WithInset { public fun subtitle(block: TextParameters.() -> Unit) { subtitle = TextParameters().apply(block) } diff --git a/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/translator/style.kt b/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/translator/style.kt index f417f613e..eb5dcd7e3 100644 --- a/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/translator/style.kt +++ b/kandy-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/translator/style.kt @@ -89,6 +89,7 @@ internal fun CustomStyle.wrap(): theme { plotSubtitle = plotCanvas.subtitle?.wrap(), plotTitle = plotCanvas.title?.wrap(), plotMargin = plotCanvas.margin?.wrap(), + plotInset = plotCanvas.inset?.wrap(), stripBackground = strip.background?.wrap(), stripText = strip.text?.wrap(), axisTooltip = axis.tooltip.background?.wrap(), @@ -100,8 +101,6 @@ internal fun CustomStyle.wrap(): theme { tooltip = layerTooltips.background?.wrap(), tooltipText = layerTooltips.text?.wrap(), tooltipTitleText = layerTooltips.title?.wrap() - /* - */ ) when (val justification = this@wrap.legend.justification) {