|
6 | 6 | package jetbrains.datalore.plot.builder.tooltip.layout
|
7 | 7 |
|
8 | 8 | import jetbrains.datalore.base.geometry.DoubleRectangle
|
| 9 | +import jetbrains.datalore.base.geometry.DoubleVector |
9 | 10 | import jetbrains.datalore.plot.builder.interact.TestUtil.coord
|
10 | 11 | import jetbrains.datalore.plot.builder.interact.TestUtil.size
|
11 | 12 | import jetbrains.datalore.plot.builder.tooltip.layout.LayoutManager.HorizontalAlignment
|
12 | 13 | import jetbrains.datalore.plot.builder.tooltip.layout.LayoutManager.HorizontalAlignment.LEFT
|
| 14 | +import jetbrains.datalore.plot.builder.tooltip.layout.LayoutManager.HorizontalAlignment.RIGHT |
13 | 15 | import jetbrains.datalore.plot.builder.tooltip.layout.MeasuredTooltipBuilder.MeasuredTooltipBuilderFactory
|
14 | 16 | import kotlin.test.Test
|
15 | 17 |
|
@@ -197,6 +199,50 @@ internal class HorizontalTooltipLayoutTest : TooltipLayoutTestBase() {
|
197 | 199 | )
|
198 | 200 | }
|
199 | 201 |
|
| 202 | + @Test |
| 203 | + fun whenThereIsNotEnoughHorizontalSpaceFromBothSides_AndHorizontalAlignmentIsLeft_ShouldAlignTooltipToRightOfTheLeftBorder() { |
| 204 | + val objectRadius = 200.0 |
| 205 | + val tooltipBuilder = MeasuredTooltipBuilderFactory() |
| 206 | + .defaultObjectRadius(objectRadius) |
| 207 | + .defaultTipSize(size(80.0, 80.0)) |
| 208 | + |
| 209 | + val layoutManagerController = createTipLayoutManagerBuilder(VIEWPORT) |
| 210 | + .addTooltip(tooltipBuilder.horizontal(TOOLTIP_KEY, VIEWPORT.center).buildTooltip()) |
| 211 | + .build() |
| 212 | + |
| 213 | + arrange(layoutManagerController) |
| 214 | + |
| 215 | + val stemX = VIEWPORT.center.x - objectRadius |
| 216 | + assertAllTooltips( |
| 217 | + expect() |
| 218 | + .tooltipX(stemX + NORMAL_STEM_LENGTH) |
| 219 | + .stemCoord(DoubleVector(stemX, VIEWPORT.center.y)) |
| 220 | + ) |
| 221 | + } |
| 222 | + |
| 223 | + @Test |
| 224 | + fun whenThereIsNotEnoughHorizontalSpaceFromBothSides_AndHorizontalAlignmentIsRight_ShouldAlignTooltipToLeftOfTheRightBorder() { |
| 225 | + val objectRadius = 200.0 |
| 226 | + val tipSize = size(80.0, 80.0) |
| 227 | + val tooltipBuilder = MeasuredTooltipBuilderFactory() |
| 228 | + .defaultObjectRadius(objectRadius) |
| 229 | + .defaultTipSize(tipSize) |
| 230 | + |
| 231 | + val layoutManagerController = createTipLayoutManagerBuilder(VIEWPORT) |
| 232 | + .preferredHorizontalAlignment(RIGHT) |
| 233 | + .addTooltip(tooltipBuilder.horizontal(TOOLTIP_KEY, VIEWPORT.center).buildTooltip()) |
| 234 | + .build() |
| 235 | + |
| 236 | + arrange(layoutManagerController) |
| 237 | + |
| 238 | + val stemX = VIEWPORT.center.x + objectRadius |
| 239 | + assertAllTooltips( |
| 240 | + expect() |
| 241 | + .tooltipX(stemX - tipSize.x - NORMAL_STEM_LENGTH) |
| 242 | + .stemCoord(DoubleVector(stemX, VIEWPORT.center.y)) |
| 243 | + ) |
| 244 | + } |
| 245 | + |
200 | 246 | companion object {
|
201 | 247 | private const val IGNORED_KEY = "ignored"
|
202 | 248 | private const val TOOLTIP_KEY = "tooltip"
|
|
0 commit comments