Skip to content

Commit

Permalink
Support line type in geom_tile()
Browse files Browse the repository at this point in the history
  • Loading branch information
RYangazov committed Apr 23, 2024
1 parent 6e94092 commit 79cb104
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ internal abstract class SlimBase protected constructor(val elementName: String)
internal const val width = 17
internal const val pathData = 18
internal const val transform = 19
internal const val strokeDashArray = 20

internal val ATTR_KEYS = arrayOf("fill", "fill-opacity", "stroke", "stroke-opacity", "stroke-width", "transform", "classes", "x1", "y1", "x2", "y2", "cx", "cy", "r", "x", "y", "height", "width", "d", "transform")
internal val ATTR_KEYS = arrayOf("fill", "fill-opacity", "stroke", "stroke-opacity", "stroke-width", "transform", "classes", "x1", "y1", "x2", "y2", "cx", "cy", "r", "x", "y", "height", "width", "d", "transform", "stroke-dasharray")
internal val ATTR_COUNT = ATTR_KEYS.size
}

Expand All @@ -56,6 +57,10 @@ internal abstract class SlimBase protected constructor(val elementName: String)
setAttribute(strokeWidth, v.toString())
}

override fun setStrokeDashArray(v: String) {
setAttribute(strokeDashArray, v)
}

internal fun setAttribute(index: Int, v: Double) {
setAttribute(index, v.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface SvgSlimShape : SvgSlimObject {
fun setFill(c: Color, alpha: Double)
fun setStroke(c: Color, alpha: Double)
fun setStrokeWidth(v: Double)
fun setStrokeDashArray(v: String)
}
252 changes: 252 additions & 0 deletions docs/dev/notebooks/tile_linetype.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
### Changed
### Fixed
- `to_svg()`, `to_html()`: return the content as string if no "path" is given. [[#1067](https://github.com/JetBrains/lets-plot/issues/1067)].
- Regression of issue [[#966](https://github.com/JetBrains/lets-plot/issues/966)].
- `to_svg()`, `to_html()`: return the content as string if no "path" is given [[#1067](https://github.com/JetBrains/lets-plot/issues/1067)].
- Regression of issue [[#966](https://github.com/JetBrains/lets-plot/issues/966)].
- Linetype doesn't work for `geom_tile()` [[#241](https://github.com/JetBrains/lets-plot-kotlin/issues/241)].
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ open class GeomHelper(
shape.setFill(fill, fillAlpha)
shape.setStroke(stroke, strokeAlpha)
shape.setStrokeWidth(AesScaling.strokeWidth(p))
StrokeDashArraySupport.apply(shape, AesScaling.strokeWidth(p), p.lineType())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.letsPlot.core.plot.base.render.svg

import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType
import org.jetbrains.letsPlot.datamodel.svg.dom.SvgShape
import org.jetbrains.letsPlot.datamodel.svg.dom.slim.SvgSlimShape

/**
* The counterpart of SVG 'stroke-dasharray' attribute but
Expand All @@ -21,6 +22,13 @@ object StrokeDashArraySupport {
}
}

fun apply(element: SvgSlimShape, strokeWidth: Double, lineType: LineType) {
val dashArray = toStrokeDashArray(strokeWidth, lineType)
if (dashArray != null) {
element.setStrokeDashArray(dashArray)
}
}

private fun toStrokeDashArray(strokeWidth: Double, lineType: LineType): String? {
if (lineType.isBlank || lineType.isSolid) {
return null
Expand Down

0 comments on commit 79cb104

Please sign in to comment.