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 axis_line, axis_ticks.
  • Loading branch information
OLarionova-HORIS committed Apr 2, 2024
commit 3898e7f577135fe229180ecf0406a94c1eb16f77
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 AxisTheme {
val axis: String
Expand Down Expand Up @@ -36,6 +37,10 @@ interface AxisTheme {

fun tickMarkColor(): Color

fun lineType(): LineType

fun tickMarkLineType(): LineType

fun labelStyle(): ThemeTextStyle

fun rotateLabels(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ internal class DefaultAxisTheme(
return getColor(getElemValue(lineKey), Elem.COLOR)
}

override fun lineType() = getLineType(getElemValue(lineKey))

override fun tickMarkWidth(): Double {
return getNumber(getElemValue(tickKey), Elem.SIZE)
}
Expand All @@ -100,6 +102,8 @@ internal class DefaultAxisTheme(
return getColor(getElemValue(tickKey), Elem.COLOR)
}

override fun tickMarkLineType() = getLineType(getElemValue(tickKey))

override fun tickLabelMargins() = getMargins(getElemValue(textKey))

override fun labelStyle(): ThemeTextStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.letsPlot.core.plot.builder.guide

import org.jetbrains.letsPlot.commons.geometry.DoubleVector
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.render.svg.Text
import org.jetbrains.letsPlot.core.plot.base.render.svg.Text.HorizontalAnchor.*
Expand Down Expand Up @@ -68,8 +69,10 @@ class AxisComponent(
// Axis line
if (!hideAxisBreaks && axisTheme.showLine()) {
val axisLine = SvgLineElement(x1, y1, x2, y2).apply {
strokeWidth().set(axisTheme.lineWidth())
val width = axisTheme.lineWidth()
strokeWidth().set(width)
strokeColor().set(axisTheme.lineColor())
StrokeDashArraySupport.apply(this, width, axisTheme.lineType())
}
rootElement.children().add(axisLine)
}
Expand All @@ -85,8 +88,10 @@ class AxisComponent(
var tickMark: SvgLineElement? = null
if (axisTheme.showTickMarks()) {
tickMark = SvgLineElement()
tickMark.strokeWidth().set(axisTheme.tickMarkWidth())
val width = axisTheme.tickMarkWidth()
tickMark.strokeWidth().set(width)
tickMark.strokeColor().set(axisTheme.tickMarkColor())
StrokeDashArraySupport.apply(tickMark, width, axisTheme.tickMarkLineType())
}

var tickLabel: TextLabel? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.letsPlot.core.plot.builder.guide
import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.intern.math.toDegrees
import org.jetbrains.letsPlot.commons.values.Color
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.render.svg.Text.HorizontalAnchor
import org.jetbrains.letsPlot.core.plot.base.render.svg.Text.VerticalAnchor
Expand Down Expand Up @@ -63,17 +64,21 @@ class PolarAxisComponent(
.lineString(breaksData.axisLine)
.build()
)
strokeWidth().set(axisTheme.lineWidth())
val width = axisTheme.lineWidth()
strokeWidth().set(width)
strokeColor().set(axisTheme.lineColor())
StrokeDashArraySupport.apply(this, width, axisTheme.lineType())
fillColor().set(Color.TRANSPARENT)
}
rootElement.children().add(axisLine)
} else {
val axisLine = SvgLineElement().apply {
y1().set(breaksData.center.y)
y2().set(breaksData.center.y - length / 2.0)
strokeWidth().set(axisTheme.lineWidth())
val width = axisTheme.lineWidth()
strokeWidth().set(width)
strokeColor().set(axisTheme.lineColor())
StrokeDashArraySupport.apply(this, width, axisTheme.lineType())
}
rootElement.children().add(axisLine)
}
Expand All @@ -91,8 +96,10 @@ class PolarAxisComponent(

val tickMark: SvgLineElement? = if (axisTheme.showTickMarks()) {
val tickMark = SvgLineElement()
tickMark.strokeWidth().set(axisTheme.tickMarkWidth())
val width = axisTheme.tickMarkWidth()
tickMark.strokeWidth().set(width)
tickMark.strokeColor().set(axisTheme.tickMarkColor())
StrokeDashArraySupport.apply(tickMark, width, axisTheme.tickMarkLineType())
val markLength = axisTheme.tickMarkLength()

when (orientation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.letsPlot.commons.values.FontFace
import org.jetbrains.letsPlot.commons.values.FontFamily
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.NamedLineType
import org.jetbrains.letsPlot.core.plot.base.theme.AxisTheme
import org.jetbrains.letsPlot.core.plot.base.theme.ThemeTextStyle
import org.jetbrains.letsPlot.core.plot.builder.presentation.Defaults
Expand Down Expand Up @@ -45,6 +46,10 @@ internal class LiveMapAxisTheme : AxisTheme {

override fun tickMarkColor() = Defaults.Plot.Axis.LINE_COLOR

override fun lineType() = NamedLineType.SOLID

override fun tickMarkLineType() = NamedLineType.SOLID

override fun labelStyle(): ThemeTextStyle = ThemeTextStyle(
family = FontFamily.SERIF,
face = FontFace.NORMAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.letsPlot.core.plot.base.Aes
import org.jetbrains.letsPlot.core.plot.base.GeomKind
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.NamedLineType
import org.jetbrains.letsPlot.core.plot.base.theme.AxisTheme
import org.jetbrains.letsPlot.core.plot.base.theme.ThemeTextStyle
import org.jetbrains.letsPlot.core.plot.base.tooltip.*
Expand Down Expand Up @@ -48,6 +49,8 @@ object TestUtil {
override fun lineWidth() = TODO("Not yet implemented")
override fun lineColor() = TODO("Not yet implemented")
override fun tickMarkColor() = TODO("Not yet implemented")
override fun lineType() = NamedLineType.SOLID
override fun tickMarkLineType() = NamedLineType.SOLID
override fun labelStyle(): ThemeTextStyle = TODO("Not yet implemented")
override fun rotateLabels() = TODO("Not yet implemented")
override fun labelAngle(): Double = TODO("Not yet implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.letsPlot.commons.values.FontFamily
import org.jetbrains.letsPlot.core.plot.base.PlotContext
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.NamedLineType
import org.jetbrains.letsPlot.core.plot.base.theme.AxisTheme
import org.jetbrains.letsPlot.core.plot.base.theme.ThemeTextStyle
import org.jetbrains.letsPlot.core.plot.base.tooltip.ContextualMapping
Expand Down Expand Up @@ -41,6 +42,8 @@ object TooltipTestUtil {
override fun lineWidth() = TODO("Not yet implemented")
override fun lineColor() = TODO("Not yet implemented")
override fun tickMarkColor() = TODO("Not yet implemented")
override fun lineType() = NamedLineType.SOLID
override fun tickMarkLineType() = NamedLineType.SOLID
override fun labelStyle(): ThemeTextStyle = TODO("Not yet implemented")
override fun rotateLabels() = TODO("Not yet implemented")
override fun labelAngle() = TODO("Not yet implemented")
Expand Down