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 d791150d93ac33ae1f63b08402414dfa939d0697
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.jetbrains.letsPlot.core.plot.builder.presentation.Style.TOOLTIP_LABEL
import org.jetbrains.letsPlot.core.plot.builder.presentation.Style.TOOLTIP_TITLE
import org.jetbrains.letsPlot.core.plot.builder.tooltip.component.TooltipBox
import demo.plot.common.model.SimpleDemoBase
import org.jetbrains.letsPlot.core.plot.base.render.linetype.LineType
import org.jetbrains.letsPlot.core.plot.base.render.linetype.NamedLineType

class TooltipBoxDemo : SimpleDemoBase(DEMO_BOX_SIZE) {

Expand Down Expand Up @@ -59,6 +61,7 @@ class TooltipBoxDemo : SimpleDemoBase(DEMO_BOX_SIZE) {
textColor,
borderColor,
strokeWidth,
lineType,
lines,
title,
textClassName,
Expand Down Expand Up @@ -90,6 +93,7 @@ class TooltipBoxDemo : SimpleDemoBase(DEMO_BOX_SIZE) {
val textColor: Color? = Color.BLACK,
val borderColor: Color = Color.BLACK,
val strokeWidth: Double = 2.0,
val lineType: LineType = NamedLineType.SOLID,
val lines: List<TooltipSpec.Line>,
val title: String? = null,
val textClassName: String = TOOLTIP_TEXT_CLASS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ interface AxisTheme {
fun tooltipFill(): Color
fun tooltipColor(): Color
fun tooltipStrokeWidth(): Double
fun tooltipLineType(): LineType

fun tooltipTextStyle(): ThemeTextStyle
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
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 TooltipsTheme {
fun tooltipColor(): Color
fun tooltipFill(): Color
fun tooltipStrokeWidth(): Double
fun tooltipLineType(): LineType

fun textStyle(): ThemeTextStyle
fun titleStyle(): ThemeTextStyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ internal class DefaultAxisTheme(
return getNumber(getElemValue(tooltipKey), Elem.SIZE)
}

override fun tooltipLineType() = getLineType(getElemValue(tooltipKey))

override fun tooltipTextStyle(): ThemeTextStyle {
val tooltipTextColor = getColor(getElemValue(tooltipTextColorKey), Elem.COLOR)
val textStyle = getTextStyle(getElemValue(tooltipTextKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal class DefaultTooltipsTheme(

override fun tooltipStrokeWidth() = getNumber(getElemValue(tooltipKey), Elem.SIZE)

override fun tooltipLineType() = getLineType(getElemValue(tooltipKey))

override fun textStyle(): ThemeTextStyle = getTextStyle(getElemValue(textKey))

override fun titleStyle(): ThemeTextStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ internal class LiveMapAxisTheme : AxisTheme {

override fun tooltipStrokeWidth() = 1.0

override fun tooltipLineType() = NamedLineType.SOLID

override fun tooltipTextStyle(): ThemeTextStyle = ThemeTextStyle(
family = FontFamily.SERIF,
face = FontFace.NORMAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.letsPlot.commons.values.Color.Companion.WHITE
import org.jetbrains.letsPlot.commons.values.Colors
import org.jetbrains.letsPlot.commons.values.Colors.mimicTransparency
import org.jetbrains.letsPlot.core.plot.base.PlotContext
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.TooltipsTheme
import org.jetbrains.letsPlot.core.plot.base.tooltip.GeomTargetLocator
Expand Down Expand Up @@ -128,6 +129,13 @@ internal class TooltipRenderer constructor(
else -> tooltipsTheme.tooltipStrokeWidth()
}

val lineType = when {
spec.layoutHint.kind == X_AXIS_TOOLTIP -> xAxisTheme.tooltipLineType()
spec.layoutHint.kind == Y_AXIS_TOOLTIP -> yAxisTheme.tooltipLineType()
spec.isSide -> NamedLineType.SOLID
else -> tooltipsTheme.tooltipLineType()
}

val borderRadius = when (spec.layoutHint.kind) {
X_AXIS_TOOLTIP, Y_AXIS_TOOLTIP -> 0.0
else -> BORDER_RADIUS
Expand All @@ -142,6 +150,7 @@ internal class TooltipRenderer constructor(
textColor = textColor,
borderColor = borderColor,
strokeWidth = strokeWidth,
lineType = lineType,
lines = spec.lines,
title = spec.title,
textClassName = spec.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import org.jetbrains.letsPlot.commons.geometry.DoubleRectangle
import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.intern.math.toRadians
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.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.render.svg.Text
import org.jetbrains.letsPlot.core.plot.builder.presentation.Defaults.Common.Tooltip.COLOR_BAR_STROKE_WIDTH
Expand Down Expand Up @@ -78,6 +80,7 @@ class TooltipBox : SvgComponent() {
textColor: Color?,
borderColor: Color,
strokeWidth: Double,
lineType: LineType,
lines: List<TooltipSpec.Line>,
title: String?,
textClassName: String,
Expand All @@ -101,7 +104,7 @@ class TooltipBox : SvgComponent() {
markerColors,
textClassName
)
myPointerBox.updateStyle(fillColor, borderColor, strokeWidth, borderRadius, pointMarkerStrokeColor)
myPointerBox.updateStyle(fillColor, borderColor, strokeWidth, lineType, borderRadius, pointMarkerStrokeColor)
}

fun setPosition(
Expand Down Expand Up @@ -141,6 +144,7 @@ class TooltipBox : SvgComponent() {
fillColor: Color,
borderColor: Color,
strokeWidth: Double,
lineType: LineType,
borderRadius: Double,
pointMarkerStrokeColor: Color
) {
Expand All @@ -150,6 +154,7 @@ class TooltipBox : SvgComponent() {
strokeColor().set(borderColor)
strokeWidth().set(strokeWidth)
fillColor().set(fillColor)
StrokeDashArraySupport.apply(this, strokeWidth, lineType)
}

myHighlightPoint.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object TestUtil {
override fun tooltipFill() = AXIS_TOOLTIP_COLOR
override fun tooltipColor() = AXIS_TOOLTIP_COLOR
override fun tooltipStrokeWidth() = 1.0
override fun tooltipLineType() = NamedLineType.SOLID
override fun tooltipTextStyle(): ThemeTextStyle = ThemeTextStyle(
// Defaults.FONT_FAMILY_NORMAL,
FontFamily.SERIF,
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.geometry.DoubleVector.Companion.ZERO
import org.jetbrains.letsPlot.commons.unsupported.UNSUPPORTED
import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.render.linetype.NamedLineType
import org.jetbrains.letsPlot.core.plot.builder.tooltip.component.TooltipBox
import org.jetbrains.letsPlot.core.plot.builder.tooltip.component.TooltipBox.Orientation.HORIZONTAL
import org.jetbrains.letsPlot.core.plot.builder.tooltip.component.TooltipBox.Orientation.VERTICAL
Expand Down Expand Up @@ -45,6 +46,7 @@ class TooltipBoxTest {
textColor = Color.WHITE,
borderColor = Color.BLACK,
strokeWidth = 1.0,
lineType = NamedLineType.SOLID,
lines = listOf(TooltipSpec.Line.withValue(wordText)),
title = null,
textClassName = "anyStyle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object TooltipTestUtil {
override fun tooltipFill() = Color.WHITE
override fun tooltipColor() = Color.BLACK
override fun tooltipStrokeWidth() = 1.0
override fun tooltipLineType() = NamedLineType.SOLID
override fun tooltipTextStyle(): ThemeTextStyle =
ThemeTextStyle(
// Defaults.FONT_FAMILY_NORMAL,
Expand Down