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

commonMain.jetbrains.datalore.plot.builder.guide.LegendBoxSpec.kt Maven / Gradle / Ivy

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

import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.builder.theme.LegendTheme

abstract class LegendBoxSpec(
    val title: String,
    val theme: LegendTheme,
    val reverse: Boolean
) {

    abstract val layout: LegendBoxLayout
    val contentOrigin: DoubleVector

    private val fullContentExtend: DoubleVector
    private val innerOrigin: DoubleVector
    private val innerContentExtend: DoubleVector

    private val contentSize: DoubleVector
        get() = layout.size

    val size: DoubleVector
        get() = contentSize.add(fullContentExtend)

    val innerBounds: DoubleRectangle
        get() = DoubleRectangle(innerOrigin, contentSize.add(innerContentExtend))

    val contentBounds: DoubleRectangle
        get() = DoubleRectangle(contentOrigin, contentSize)

    init {
        val contentExpand = theme.margin() + theme.padding()
        contentOrigin = DoubleVector(contentExpand, contentExpand)
        fullContentExtend = DoubleVector(contentExpand * 2, contentExpand * 2)

        innerOrigin = DoubleVector(theme.margin(), theme.margin())
        innerContentExtend = DoubleVector(theme.padding() * 2, theme.padding() * 2)
    }

    fun hasTitle(): Boolean {
        return title.isNotBlank() && theme.showTitle()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy