Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'linetype' for theme elements #1072

Merged
merged 14 commits into from
Apr 3, 2024
Merged
Prev Previous commit
Next Next commit
For legend_background, strip_background.
  • Loading branch information
OLarionova-HORIS committed Apr 2, 2024
commit 79e10db1880aaea92c9034d2dc69d79c92eade91
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.letsPlot.core.plot.base.theme
import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification
import org.jetbrains.letsPlot.core.plot.base.layout.Thickness
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType

interface FacetsTheme {
fun showStrip(): Boolean
Expand All @@ -16,6 +17,7 @@ interface FacetsTheme {
fun stripFill(): Color
fun stripColor(): Color
fun stripStrokeWidth(): Double
fun stripLineType(): LineType
fun stripTextStyle(): ThemeTextStyle
fun stripMargins(): Thickness
fun stripTextJustification(): TextJustification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.letsPlot.core.plot.base.guide.LegendDirection
import org.jetbrains.letsPlot.core.plot.base.guide.LegendJustification
import org.jetbrains.letsPlot.core.plot.base.guide.LegendPosition
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType

interface LegendTheme {
fun keySize(): Double
Expand Down Expand Up @@ -40,4 +41,5 @@ interface LegendTheme {
fun backgroundColor(): Color
fun backgroundFill(): Color
fun backgroundStrokeWidth(): Double
fun backgroundRectLineType(): LineType
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.letsPlot.core.plot.base.geom.LiveMapProvider
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification.Companion.TextRotation
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification.Companion.applyJustification
import org.jetbrains.letsPlot.core.plot.base.render.svg.MultilineLabel
import org.jetbrains.letsPlot.core.plot.base.render.svg.StrokeDashArraySupport
import org.jetbrains.letsPlot.core.plot.base.render.svg.SvgComponent
import org.jetbrains.letsPlot.core.plot.base.theme.FacetsTheme
import org.jetbrains.letsPlot.core.plot.base.theme.Theme
Expand Down Expand Up @@ -156,9 +157,11 @@ internal class PlotTile(
private fun addFacetLabBackground(labelBounds: DoubleRectangle, facetTheme: FacetsTheme) {
if (facetTheme.showStripBackground()) {
val rect = SvgRectElement(labelBounds).apply {
strokeWidth().set(facetTheme.stripStrokeWidth())
val width = facetTheme.stripStrokeWidth()
strokeWidth().set(width)
fillColor().set(facetTheme.stripFill())
strokeColor().set(facetTheme.stripColor())
StrokeDashArraySupport.apply(this, width, facetTheme.stripLineType())
}
add(rect)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal class DefaultFacetsTheme(
return getNumber(getElemValue(rectKey), Elem.SIZE)
}

override fun stripLineType() = getLineType(getElemValue(rectKey))

override fun stripTextStyle(): ThemeTextStyle {
return getTextStyle(getElemValue(textKey))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ internal class DefaultLegendTheme(
override fun backgroundStrokeWidth(): Double {
return getNumber(getElemValue(backgroundKey), ThemeOption.Elem.SIZE)
}

override fun backgroundRectLineType() = getLineType(getElemValue(backgroundKey))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification
import org.jetbrains.letsPlot.core.plot.base.layout.TextJustification.Companion.applyJustification
import org.jetbrains.letsPlot.core.plot.base.render.svg.MultilineLabel
import org.jetbrains.letsPlot.core.plot.base.render.svg.StrokeDashArraySupport
import org.jetbrains.letsPlot.core.plot.base.render.svg.SvgComponent
import org.jetbrains.letsPlot.core.plot.base.theme.LegendTheme
import org.jetbrains.letsPlot.core.plot.builder.layout.PlotLabelSpecFactory
Expand Down Expand Up @@ -42,7 +43,9 @@ abstract class LegendBox : SvgComponent() {
if (theme.showBackground()) {
add(SvgRectElement(spec.innerBounds).apply {
strokeColor().set(theme.backgroundColor())
strokeWidth().set(theme.backgroundStrokeWidth())
val width = theme.backgroundStrokeWidth()
strokeWidth().set(width)
StrokeDashArraySupport.apply(this, width, theme.backgroundRectLineType())
fillColor().set(theme.backgroundFill())
})
}
Expand Down