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

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

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * 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.GeomTargetLocator.LookupSpace
import jetbrains.datalore.plot.base.interact.GeomTargetLocator.LookupStrategy
import jetbrains.datalore.plot.builder.interact.GeomInteractionBuilderUtil.createTooltipLines
import jetbrains.datalore.plot.builder.tooltip.TooltipLine
import jetbrains.datalore.plot.builder.tooltip.TooltipSpecification

class GeomInteractionBuilder constructor(
    val locatorLookupSpace: LookupSpace,
    val locatorLookupStrategy: LookupStrategy,
    private val tooltipAes: List>,
    private val tooltipAxisAes: List>,
    private val tooltipOutlierAes: List>,
) {

    private var myUserTooltipSpec: TooltipSpecification? = null

    var ignoreInvisibleTargets: Boolean = false
        private set

    var tooltipConstants: Map, Any>? = null
        private set

    var isCrosshairEnabled: Boolean = false
        private set

    val tooltipLines: List
        get() = createTooltipLines(
            myUserTooltipSpec,
            tooltipAes = tooltipAes,
            tooltipAxisAes = tooltipAxisAes,
            sideTooltipAes = tooltipOutlierAes,
            tooltipConstantAes = tooltipConstants
        )

    val tooltipProperties: TooltipSpecification.TooltipProperties
        get() = myUserTooltipSpec?.tooltipProperties ?: TooltipSpecification.TooltipProperties.NONE

    val tooltipTitle: TooltipLine?
        get() = myUserTooltipSpec?.tooltipTitle


    fun tooltipConstants(v: Map, Any>): GeomInteractionBuilder {
        tooltipConstants = v
        return this
    }

    fun tooltipLinesSpec(v: TooltipSpecification): GeomInteractionBuilder {
        myUserTooltipSpec = v
        return this
    }

    fun enableCrosshair(v: Boolean): GeomInteractionBuilder {
        isCrosshairEnabled = v
        return this
    }

    fun ignoreInvisibleTargets(v: Boolean): GeomInteractionBuilder {
        ignoreInvisibleTargets = v
        return this
    }

    fun build(): GeomInteraction {
        return GeomInteraction(this)
    }


    class DemoAndTest(
        private val supportedAes: List>,
        private val axisAes: List>? = null,
    ) {
        fun univariateFunction(lookupStrategy: LookupStrategy): GeomInteractionBuilder {
            return createBuilder(GeomTooltipSetup.univariateFunction(lookupStrategy))
        }

        fun bivariateFunction(area: Boolean): GeomInteractionBuilder {
            return createBuilder(GeomTooltipSetup.bivariateFunction(area))
        }

        private fun createBuilder(geomTooltipSetup: GeomTooltipSetup): GeomInteractionBuilder {
            return GeomInteractionBuilder(
                locatorLookupSpace = geomTooltipSetup.locatorLookupSpace,
                locatorLookupStrategy = geomTooltipSetup.locatorLookupStrategy,
                tooltipAes = supportedAes - geomTooltipSetup.axisAesFromFunctionKind,
                tooltipAxisAes = axisAes
                    ?: if (!geomTooltipSetup.axisTooltipEnabled) emptyList()
                    else geomTooltipSetup.axisAesFromFunctionKind,
                tooltipOutlierAes = emptyList()
            )
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy