commonMain.jetbrains.datalore.plot.base.geom.HLineGeom.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* 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.base.geom
import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.base.Aesthetics
import jetbrains.datalore.plot.base.CoordinateSystem
import jetbrains.datalore.plot.base.GeomContext
import jetbrains.datalore.plot.base.PositionAdjustment
import jetbrains.datalore.plot.base.aes.AesScaling
import jetbrains.datalore.plot.base.geom.legend.HLineLegendKeyElementFactory
import jetbrains.datalore.plot.base.geom.util.GeomHelper
import jetbrains.datalore.plot.base.geom.util.HintColorUtil
import jetbrains.datalore.plot.base.interact.GeomTargetCollector
import jetbrains.datalore.plot.base.interact.TipLayoutHint
import jetbrains.datalore.plot.base.render.LegendKeyElementFactory
import jetbrains.datalore.plot.base.render.SvgRoot
import jetbrains.datalore.plot.common.data.SeriesUtil
import jetbrains.datalore.vis.svg.SvgLineElement
class HLineGeom : GeomBase() {
override val legendKeyElementFactory: LegendKeyElementFactory
get() = LEGEND_KEY_ELEMENT_FACTORY
override fun buildIntern(
root: SvgRoot,
aesthetics: Aesthetics,
pos: PositionAdjustment,
coord: CoordinateSystem,
ctx: GeomContext
) {
val geomHelper = GeomHelper(pos, coord, ctx)
val helper = geomHelper.createSvgElementHelper()
helper.setStrokeAlphaEnabled(true)
val viewPort = aesViewPort(aesthetics)
val lines = ArrayList()
for (p in aesthetics.dataPoints()) {
val intercept = p.interceptY()
if (SeriesUtil.isFinite(intercept)) {
if (viewPort.yRange().contains(intercept!!)) {
val start = DoubleVector(viewPort.left, intercept)
val end = DoubleVector(viewPort.right, intercept)
val line = helper.createLine(start, end, p)
lines.add(line)
val h = AesScaling.strokeWidth(p)
val origin = DoubleVector(start.x, intercept - h/2 - 2.0)
val dimensions = DoubleVector(viewPort.dimension.x, h + 4.0)
val rect = DoubleRectangle(origin, dimensions)
ctx.targetCollector.addRectangle(
p.index(),
geomHelper.toClient(rect, p),
GeomTargetCollector.TooltipParams.params()
.setColor(HintColorUtil.fromColor(p)),
TipLayoutHint.Kind.CURSOR_TOOLTIP
)
}
}
}
lines.forEach { root.add(it) }
}
companion object {
const val HANDLES_GROUPS = false
val LEGEND_KEY_ELEMENT_FACTORY: LegendKeyElementFactory =
HLineLegendKeyElementFactory()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy