All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmTest.plot.builder.interact.TooltipSpecFactoryTest.kt Maven / Gradle / Ivy

/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.plot.builder.interact

import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.base.interact.TipLayoutHint
import jetbrains.datalore.plot.builder.interact.MappedDataAccessMock.Companion.variable
import jetbrains.datalore.plot.builder.tooltip.MappingValue
import kotlin.test.BeforeTest
import kotlin.test.Test

class TooltipSpecFactoryTest : jetbrains.datalore.plot.builder.interact.TooltipSpecTestHelper() {

    @BeforeTest
    fun setUp() {
        init()
    }

    @Test
    fun whenAesFromTooltipListIsNotMapped_ShouldNotThrowException() {
        createTooltipSpecs(geomTargetBuilder.withPointHitShape(TARGET_HIT_COORD, 0.0).build())
    }

    @Test
    fun shouldNotDuplicateAesFromHintsToBigTooltip() {
        val widthMapping = addMappedData(variable().name("type").value("sedan").mapping(AES_WIDTH))
        val colorMapping = addMappedData(variable().name("cyl").value("4").mapping(Aes.COLOR))

        createTooltipSpecs(geomTargetBuilder.withPathHitShape()
                .withLayoutHint(
                    AES_WIDTH, TipLayoutHint.verticalTooltip(
                        TARGET_HIT_COORD,
                        OBJECT_RADIUS,
                        markerColors = emptyList()
                    ))
                .build())

        assertLines(0, widthMapping.shortTooltipText())
        assertLines(1, colorMapping.longTooltipText())
    }

    @Test
    fun shouldNotAddSemicolonIfLabelIsEmpty() {
        val widthMapping = addMappedData(variable().value("sedan").mapping(AES_WIDTH))

        buildTooltipSpecs()

        assertTooltipsCount(1)
        assertLines(0, widthMapping.shortTooltipText())
    }

    @Test
    fun checkIfTooltipIsOutlier() {
        val widthMapping = addMappedData(variable().name("type").value("sedan").mapping(AES_WIDTH))
        createTooltipSpecs(
            geomTargetBuilder.withPathHitShape()
                .withLayoutHint(
                    AES_WIDTH, TipLayoutHint.verticalTooltip(
                        TARGET_HIT_COORD,
                        OBJECT_RADIUS,
                        markerColors = emptyList()
                    )
                )
                .build()
        )
        assertLines(listOf(widthMapping.shortTooltipText()), isOutlier = true)
    }

    @Test
    fun shouldNotAddSemicolonIfLineFormatterIsSet() {
        val widthMapping = addMappedData(variable().name("type").value("sedan").mapping(AES_WIDTH))
        // set line format -> short text will be used
        val widthAes = MappingValue(
            AES_WIDTH,
            format = "{}"
        )
        createTooltipSpecWithValueSources(
            geomTargetBuilder.withPathHitShape()
                .withLayoutHint(
                    AES_WIDTH, TipLayoutHint.verticalTooltip(
                        TARGET_HIT_COORD,
                        OBJECT_RADIUS,
                        markerColors = emptyList()
                    )
                )
                .build(),
            valueSources = listOf(widthAes)
        )
        assertLines(listOf(widthMapping.shortTooltipText()), isOutlier = true)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy