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 panel_background, panel_border, panel_grid_major/minor.
  • Loading branch information
OLarionova-HORIS committed Apr 2, 2024
commit ac65c213b538f4bad28cd74347238dc0210b6d41
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.letsPlot.core.plot.base.theme

import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType

interface PanelGridTheme {
fun isOntop(): Boolean
Expand All @@ -21,4 +22,8 @@ interface PanelGridTheme {
fun majorLineColor(): Color

fun minorLineColor(): Color

fun majorLineType(): LineType

fun minorLineType(): LineType
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.letsPlot.core.plot.base.theme

import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.layout.Thickness
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType

/**
* Plotting area, drawn underneath plot.
Expand All @@ -16,11 +17,13 @@ interface PanelTheme {
fun rectColor(): Color
fun rectFill(): Color
fun rectStrokeWidth(): Double
fun rectLineType(): LineType

fun showBorder(): Boolean
fun borderColor(): Color
fun borderWidth(): Double
fun borderIsOntop(): Boolean
fun borderLineType(): LineType

fun gridX(flipAxis: Boolean = false): PanelGridTheme
fun gridY(flipAxis: Boolean = false): PanelGridTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ internal class DefaultPanelGridTheme(
override fun minorLineColor(): Color {
return getColor(getElemValue(minorLineKey), Elem.COLOR)
}

override fun majorLineType() = getLineType(getElemValue(majorLineKey))

override fun minorLineType() = getLineType(getElemValue(minorLineKey))
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal class DefaultPanelTheme(
return getNumber(getElemValue(rectKey), Elem.SIZE)
}

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

override fun showBorder() = !isElemBlank(borderKey)

override fun borderColor() = getColor(getElemValue(borderKey), Elem.COLOR)
Expand All @@ -53,6 +55,8 @@ internal class DefaultPanelTheme(

override fun borderIsOntop(): Boolean = getBoolean(borderOntopKey)

override fun borderLineType() = getLineType(getElemValue(borderKey))

override fun gridX(flipAxis: Boolean): PanelGridTheme = if (flipAxis) gridY else gridX

override fun gridY(flipAxis: Boolean): PanelGridTheme = if (flipAxis) gridX else gridY
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.frame
import org.jetbrains.letsPlot.commons.geometry.DoubleRectangle
import org.jetbrains.letsPlot.core.plot.base.CoordinateSystem
import org.jetbrains.letsPlot.core.plot.base.PlotContext
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.scale.ScaleBreaks
import org.jetbrains.letsPlot.core.plot.base.theme.PanelGridTheme
Expand Down Expand Up @@ -133,7 +134,9 @@ internal class PolarFrameOfReference(
override fun doStrokeBkgr(parent: SvgComponent) {
val strokeBkgr = createPanelElement() {
it.strokeColor().set(theme.panel().rectColor())
it.strokeWidth().set(theme.panel().rectStrokeWidth())
val width = theme.panel().rectStrokeWidth()
it.strokeWidth().set(width)
StrokeDashArraySupport.apply(it, width, theme.panel().rectLineType())
it.fillOpacity().set(0.0)
}

Expand All @@ -143,7 +146,9 @@ internal class PolarFrameOfReference(
override fun doDrawPanelBorder(parent: SvgComponent) {
val border = createPanelElement() {
it.strokeColor().set(theme.panel().borderColor())
it.strokeWidth().set(theme.panel().borderWidth())
val width = theme.panel().borderWidth()
it.strokeWidth().set(width)
StrokeDashArraySupport.apply(it, width, theme.panel().borderLineType())
it.fillOpacity().set(0.0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.CoordinateSystem
import org.jetbrains.letsPlot.core.plot.base.PlotContext
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.scale.ScaleBreaks
import org.jetbrains.letsPlot.core.plot.base.theme.AxisTheme
Expand Down Expand Up @@ -107,7 +108,9 @@ internal open class SquareFrameOfReference(
protected open fun doDrawPanelBorder(parent: SvgComponent) {
val panelBorder = SvgRectElement(layoutInfo.geomContentBounds).apply {
strokeColor().set(theme.panel().borderColor())
strokeWidth().set(theme.panel().borderWidth())
val width = theme.panel().borderWidth()
strokeWidth().set(width)
StrokeDashArraySupport.apply(this, width, theme.panel().borderLineType())
fillOpacity().set(0.0)
}
parent.add(panelBorder)
Expand Down Expand Up @@ -195,7 +198,9 @@ internal open class SquareFrameOfReference(
protected open fun doStrokeBkgr(parent: SvgComponent) {
val panelRectStroke = SvgRectElement(layoutInfo.geomContentBounds).apply {
strokeColor().set(theme.panel().rectColor())
strokeWidth().set(theme.panel().rectStrokeWidth())
val width = theme.panel().rectStrokeWidth()
strokeWidth().set(width)
StrokeDashArraySupport.apply(this, width, theme.panel().rectLineType())
fillOpacity().set(0.0)
}
parent.add(panelRectStroke)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package org.jetbrains.letsPlot.core.plot.builder.guide

import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType
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.lineString
import org.jetbrains.letsPlot.core.plot.base.theme.PanelGridTheme
Expand All @@ -21,21 +23,31 @@ class GridComponent(

if (gridTheme.showMinor()) {
for (lineString in minorGrid) {
val elem = buildGridLine(lineString, gridTheme.minorLineWidth(), gridTheme.minorLineColor())
val elem = buildGridLine(
lineString,
gridTheme.minorLineWidth(),
gridTheme.minorLineColor(),
gridTheme.minorLineType()
)
rootGroup.children().add(elem)
}
}

// Major grid.
if (gridTheme.showMajor()) {
for (lineString in majorGrid) {
val elem = buildGridLine(lineString, gridTheme.majorLineWidth(), gridTheme.majorLineColor())
val elem = buildGridLine(
lineString,
gridTheme.majorLineWidth(),
gridTheme.majorLineColor(),
gridTheme.majorLineType()
)
rootGroup.children().add(elem)
}
}
}

private fun buildGridLine(lineString: List<DoubleVector>, width: Double, color: Color): SvgNode {
private fun buildGridLine(lineString: List<DoubleVector>, width: Double, color: Color, lineType: LineType): SvgNode {
val shapeElem: SvgShape = when {
lineString.size == 2 -> SvgLineElement(lineString[0].x, lineString[0].y, lineString[1].x, lineString[1].y )
lineString.size < 2 -> SvgPathElement()
Expand All @@ -44,6 +56,7 @@ class GridComponent(

shapeElem.strokeColor().set(color)
shapeElem.strokeWidth().set(width)
StrokeDashArraySupport.apply(shapeElem, width, lineType)
shapeElem.fill().set(SvgColors.NONE)
return shapeElem as SvgNode
}
Expand Down