Skip to content

Commit

Permalink
Fix #610 Tooltip is not shown when configured for 'const' value (#732)
Browse files Browse the repository at this point in the history
* VLineGeom: move tooltip target point inside the plot.

* Update future_changes.md.

* Fix for vline tooltip for non flipped coords only.

* Refactoring: new fun `extend(clientRect, flipped, widthExpand, heightExpand)`.
  • Loading branch information
OLarionova-HORIS authored Mar 29, 2023
1 parent de85838 commit fb5094c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 40 deletions.
3 changes: 2 additions & 1 deletion future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
- Quantile should be shown in tooltip if the variable `..quantile..` is mapped to geom aesthetic.
- Bad default formatting for stat variables [[#654](https://github.com/JetBrains/lets-plot/issues/654)].
- The scale name does not apply with `as_discrete()` [[#653](https://github.com/JetBrains/lets-plot/issues/653)].
- Batik: geom_imshow() fail with an error: "The attribute "xlink:href" of the element <image> is required"
- Batik: geom_imshow() fail with an error: "The attribute "xlink:href" of the element <image> is required"
- Tooltip is not shown when configured for 'const' value [[#610](https://github.com/JetBrains/lets-plot/issues/610)].
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.base.*
import jetbrains.datalore.plot.base.geom.util.BarTooltipHelper
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueWidth
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendWidth
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.geom.util.RectanglesHelper
import jetbrains.datalore.plot.base.render.SvgRoot
Expand Down Expand Up @@ -73,7 +73,7 @@ open class BarGeom : GeomBase() {
DoubleRectangle(origin, dimensions)
}
geomHelper.toClient(rect, p)?.let { clientRect ->
if (clientRect.width < 2.0) extendTrueWidth(clientRect, 2.0, ctx) else clientRect
if (clientRect.width < 2.0) extendWidth(clientRect, 2.0, ctx.flipped) else clientRect
}
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import jetbrains.datalore.base.values.Color
import jetbrains.datalore.plot.base.*
import jetbrains.datalore.plot.base.aes.AestheticsDefaults
import jetbrains.datalore.plot.base.geom.util.*
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueHeight
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendHeight
import jetbrains.datalore.plot.base.geom.util.HintColorUtil.colorWithAlpha
import jetbrains.datalore.plot.base.interact.NullGeomTargetCollector
import jetbrains.datalore.plot.base.interact.TipLayoutHint
Expand Down Expand Up @@ -193,7 +193,7 @@ class BoxplotGeom : GeomBase() {
)?.let {
if (isHintRect && upper == lower) {
// Add tooltips for geom_boxplot with zero height (issue #563)
extendTrueHeight(it, 2.0, ctx)
extendHeight(it, 2.0, ctx.flipped)
} else {
it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import jetbrains.datalore.plot.base.aes.AesScaling
import jetbrains.datalore.plot.base.geom.legend.HLineLegendKeyElementFactory
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.GeomUtil
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueHeight
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendHeight
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.interact.GeomTargetCollector
import jetbrains.datalore.plot.base.interact.TipLayoutHint
Expand Down Expand Up @@ -55,7 +55,7 @@ class HLineGeom : GeomBase() {
// tooltip
val rect = geomHelper.toClient(DoubleRectangle.span(start, end), p)!!
val h = AesScaling.strokeWidth(p) + 4.0
val targetRect = extendTrueHeight(rect, h, ctx)
val targetRect = extendHeight(rect, h, ctx.flipped)

ctx.targetCollector.addRectangle(
p.index(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import jetbrains.datalore.plot.base.aes.AesScaling
import jetbrains.datalore.plot.base.geom.util.BarTooltipHelper
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.GeomUtil
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueWidth
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendWidth
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.render.LegendKeyElementFactory
import jetbrains.datalore.plot.base.render.SvgRoot
Expand Down Expand Up @@ -74,7 +74,7 @@ class LineRangeGeom : GeomBase() {
p
)!!
val width = max(AesScaling.strokeWidth(p), 2.0)
extendTrueWidth(rect, width, ctx)
extendWidth(rect, width, ctx.flipped)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import jetbrains.datalore.plot.base.geom.legend.VLineLegendKeyElementFactory
import jetbrains.datalore.plot.base.geom.util.BarTooltipHelper
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.GeomUtil
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueWidth
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendWidth
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.render.LegendKeyElementFactory
import jetbrains.datalore.plot.base.render.SvgRoot
Expand Down Expand Up @@ -102,7 +102,7 @@ class PointRangeGeom : GeomBase() {
val shapeSize = shape.size(p) * fatten / 2
val strokeWidth = shape.strokeWidth(p)
val width = shapeSize + strokeWidth
extendTrueWidth(rect, width, ctx)
extendWidth(rect, width, ctx.flipped)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import jetbrains.datalore.plot.base.aes.AesScaling
import jetbrains.datalore.plot.base.geom.legend.VLineLegendKeyElementFactory
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.GeomUtil
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extendTrueWidth
import jetbrains.datalore.plot.base.geom.util.GeomUtil.extend
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.interact.GeomTargetCollector
import jetbrains.datalore.plot.base.render.LegendKeyElementFactory
Expand Down Expand Up @@ -51,8 +51,12 @@ class VLineGeom : GeomBase() {

// tooltip
val rect = geomHelper.toClient(DoubleRectangle.span(start, end), p)!!
val w = AesScaling.strokeWidth(p) + 4.0
val targetRect = extendTrueWidth(rect, w, ctx)
val widthExpand = AesScaling.strokeWidth(p) + 4.0
// The tooltip point is on the top of the rectangle = on the plot border.
// To ensure that it will be displayed, move the rectangle a little inside the plot
// https://github.com/JetBrains/lets-plot/issues/610
val heightExpand = -2.0
val targetRect = extend(rect, ctx.flipped, widthExpand, heightExpand)

ctx.targetCollector.addRectangle(
p.index(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.base.DataPointAesthetics
import jetbrains.datalore.plot.base.GeomContext
import jetbrains.datalore.plot.common.data.SeriesUtil


Expand Down Expand Up @@ -167,39 +166,33 @@ object GeomUtil {
)
}

internal fun extendTrueWidth(clientRect: DoubleRectangle, delta: Double, ctx: GeomContext): DoubleRectangle {
val unflipped = if (ctx.flipped) {
internal fun extend(
clientRect: DoubleRectangle,
flipped: Boolean,
widthExpand: Double = 0.0,
heightExpand: Double = 0.0
): DoubleRectangle {
val unflipped = if (flipped) {
clientRect.flip()
} else {
clientRect
}
val unflippedNewWidth = DoubleRectangle.LTRB(
unflipped.left - delta / 2, unflipped.top,
unflipped.right + delta / 2, unflipped.bottom
val unflippedNewRect = DoubleRectangle.LTRB(
unflipped.left - widthExpand / 2,
unflipped.top - heightExpand / 2,
unflipped.right + widthExpand / 2,
unflipped.bottom + heightExpand / 2
)
return if (ctx.flipped) {
unflippedNewWidth.flip()
return if (flipped) {
unflippedNewRect.flip()
} else {
unflippedNewWidth
unflippedNewRect
}
}

internal fun extendTrueHeight(clientRect: DoubleRectangle, delta: Double, ctx: GeomContext): DoubleRectangle {
val unflipped = if (ctx.flipped) {
clientRect.flip()
} else {
clientRect
}
internal fun extendWidth(clientRect: DoubleRectangle, delta: Double, flipped: Boolean) =
extend(clientRect, flipped, widthExpand = delta)

val unflippedNewHeight = DoubleRectangle.LTRB(
unflipped.left, unflipped.top - delta / 2,
unflipped.right, unflipped.bottom + delta / 2
)

return if (ctx.flipped) {
unflippedNewHeight.flip()
} else {
unflippedNewHeight
}
}
internal fun extendHeight(clientRect: DoubleRectangle, delta: Double, flipped: Boolean) =
extend(clientRect, flipped, heightExpand = delta)
}

0 comments on commit fb5094c

Please sign in to comment.