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

commonMain.jetbrains.datalore.plot.builder.interact.GeomTooltipSetup.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * Copyright (c) 2022. 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.GeomTargetLocator

class GeomTooltipSetup private constructor(
    val locatorLookupSpace: GeomTargetLocator.LookupSpace,
    val locatorLookupStrategy: GeomTargetLocator.LookupStrategy,
    val axisAesFromFunctionKind: List>,// = emptyList()
    val axisTooltipVisibilityFromFunctionKind: Boolean, // = false
    val axisTooltipEnabled: Boolean,// = true
) {

    fun toMultilayerLookupStrategy(): GeomTooltipSetup {
        return GeomTooltipSetup(
            locatorLookupStrategy = GeomTargetLocator.LookupStrategy.NEAREST,
            locatorLookupSpace = GeomTargetLocator.LookupSpace.XY,
            axisAesFromFunctionKind = axisAesFromFunctionKind,
            axisTooltipVisibilityFromFunctionKind = axisTooltipVisibilityFromFunctionKind,
            axisTooltipEnabled = axisTooltipEnabled
        )
    }

    companion object {
        const val AREA_GEOM = true
        const val NON_AREA_GEOM = false

        private val AES_X = listOf(Aes.X)
        private val AES_XY = listOf(Aes.X, Aes.Y)

        fun univariateFunction(
            lookupStrategy: GeomTargetLocator.LookupStrategy,
            axisTooltipVisibilityFromConfig: Boolean? = null
        ): GeomTooltipSetup {
            val axisTooltipVisibilityFromFunctionKind = true
            return GeomTooltipSetup(
                locatorLookupStrategy = lookupStrategy,
                locatorLookupSpace = GeomTargetLocator.LookupSpace.X,
                axisAesFromFunctionKind = AES_X,
                axisTooltipVisibilityFromFunctionKind = axisTooltipVisibilityFromFunctionKind,
                axisTooltipEnabled = isAxisTooltipEnabled(
                    axisTooltipVisibilityFromConfig,
                    axisTooltipVisibilityFromFunctionKind
                )
            )
        }

        fun bivariateFunction(
            area: Boolean,
            axisTooltipVisibilityFromConfig: Boolean? = null
        ): GeomTooltipSetup {
            val axisTooltipVisibilityFromFunctionKind = !area
            val locatorLookupStrategy = if (area) {
                GeomTargetLocator.LookupStrategy.HOVER
            } else {
                GeomTargetLocator.LookupStrategy.NEAREST
            }

            return GeomTooltipSetup(
                locatorLookupStrategy = locatorLookupStrategy,
                locatorLookupSpace = GeomTargetLocator.LookupSpace.XY,
                axisAesFromFunctionKind = AES_XY,
                axisTooltipVisibilityFromFunctionKind = axisTooltipVisibilityFromFunctionKind,
                axisTooltipEnabled = isAxisTooltipEnabled(
                    axisTooltipVisibilityFromConfig,
                    axisTooltipVisibilityFromFunctionKind
                )
            )
        }

        fun none(): GeomTooltipSetup {
            val axisTooltipVisibilityFromFunctionKind = true
            return GeomTooltipSetup(
                locatorLookupStrategy = GeomTargetLocator.LookupStrategy.NONE,
                locatorLookupSpace = GeomTargetLocator.LookupSpace.NONE,
                axisAesFromFunctionKind = emptyList(),
                axisTooltipVisibilityFromFunctionKind = axisTooltipVisibilityFromFunctionKind,
                axisTooltipEnabled = isAxisTooltipEnabled(
                    axisTooltipVisibilityFromConfig = null,
                    axisTooltipVisibilityFromFunctionKind
                )
            )
        }

        private fun isAxisTooltipEnabled(
            axisTooltipVisibilityFromConfig: Boolean?,
            axisTooltipVisibilityFromFunctionKind: Boolean
        ): Boolean {
            return axisTooltipVisibilityFromConfig ?: axisTooltipVisibilityFromFunctionKind
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy