Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of XY-ranges for geom_errorbar #770

Merged
merged 6 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next Next commit
Fix XY-ranges calculation, use height/width expansion for errorbar de…
…pend on its representation.
  • Loading branch information
OLarionova-HORIS committed Apr 27, 2023
commit b015c099422f9c1b448bdaec7543d1d0aed346ae
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ open class AestheticsDefaults {
.update(Aes.COLOR, Color.BLACK)
}

fun errorBarH(): AestheticsDefaults {
return errorBar()
}

fun crossBar(): AestheticsDefaults {
return AestheticsDefaults()
.update(Aes.WIDTH, 0.9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package jetbrains.datalore.plot.base.geom
import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleSegment
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.base.interval.DoubleSpan
import jetbrains.datalore.base.values.Color
import jetbrains.datalore.plot.base.*
import jetbrains.datalore.plot.base.aes.AesScaling
Expand All @@ -23,7 +24,7 @@ import jetbrains.datalore.plot.base.render.SvgRoot
import jetbrains.datalore.vis.svg.SvgGElement
import jetbrains.datalore.vis.svg.SvgLineElement

class ErrorBarGeom : GeomBase() {
class ErrorBarGeom : GeomBase(), WithWidth, WithHeight {

override val legendKeyElementFactory: LegendKeyElementFactory
get() = ErrorBarLegendKeyElementFactory()
Expand All @@ -38,10 +39,10 @@ class ErrorBarGeom : GeomBase() {
val geomHelper = GeomHelper(pos, coord, ctx)
val colorsByDataPoint = HintColorUtil.createColorMarkerMapper(GeomKind.ERROR_BAR, ctx)

var dataPoints = GeomUtil.withDefined(aesthetics.dataPoints(), Aes.X, Aes.YMIN, Aes.YMAX, Aes.WIDTH)
var dataPoints = GeomUtil.withDefined(aesthetics.dataPoints(), verticalAes())
val isVertical = dataPoints.any()
if (!isVertical) {
dataPoints = GeomUtil.withDefined(aesthetics.dataPoints(), Aes.Y, Aes.XMIN, Aes.XMAX, Aes.HEIGHT)
dataPoints = GeomUtil.withDefined(aesthetics.dataPoints(), horizontalAes())
}

val xAes = if (isVertical) Aes.X else Aes.Y
Expand Down Expand Up @@ -156,6 +157,9 @@ class ErrorBarGeom : GeomBase() {
companion object {
const val HANDLES_GROUPS = false

private fun verticalAes() = listOf(Aes.X, Aes.YMIN, Aes.YMAX, Aes.WIDTH)
private fun horizontalAes() = listOf(Aes.Y, Aes.XMIN, Aes.XMAX, Aes.HEIGHT)

private fun errorBarLegendShape(segments: List<DoubleSegment>, p: DataPointAesthetics): SvgGElement {
val g = SvgGElement()
segments.forEach { segment ->
Expand Down Expand Up @@ -193,4 +197,26 @@ class ErrorBarGeom : GeomBase() {
return g
}
}

override fun heightSpan(
p: DataPointAesthetics,
coordAes: Aes<Double>,
resolution: Double,
isDiscrete: Boolean
): DoubleSpan? {
val isHorizontal = horizontalAes().all(p::defined)
if (!isHorizontal) return null
return PointDimensionsUtil.dimensionSpan(p, coordAes, Aes.HEIGHT, resolution)
}

override fun widthSpan(
p: DataPointAesthetics,
coordAes: Aes<Double>,
resolution: Double,
isDiscrete: Boolean
): DoubleSpan? {
val isVertical = verticalAes().all(p::defined)
if (!isVertical) return null
return PointDimensionsUtil.dimensionSpan(p, coordAes, Aes.WIDTH, resolution)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ object GeomUtil {
return dataPoints.filter { p -> p.defined(aes0) && p.defined(aes1) && p.defined(aes2) && p.defined(aes3) }
}

fun withDefined(
dataPoints: Iterable<DataPointAesthetics>,
aesList: List<Aes<*>>
): Iterable<DataPointAesthetics> {
return dataPoints.filter { p ->
aesList.all { aes -> p.defined(aes) }
}
}

fun createGroups(dataPoints: Iterable<DataPointAesthetics>): Map<Int, List<DataPointAesthetics>> {
val pointsByGroup = HashMap<Int, MutableList<DataPointAesthetics>>()
for (p in dataPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ internal object PositionalScalesUtil {
}

private fun positionalDryRunAesthetics(layer: GeomLayer): Aesthetics {
val aesList = layer.renderedAes().filter {
Aes.affectingScaleX(it) ||
Aes.affectingScaleY(it) ||
it == Aes.HEIGHT ||
it == Aes.WIDTH
}
val aesList = layer.renderedAes()
.filter {
Aes.affectingScaleX(it) ||
Aes.affectingScaleY(it) ||
it == Aes.HEIGHT ||
it == Aes.WIDTH
}
.filter { layer.hasBinding(it) || layer.hasConstant(it) }

val mappers = aesList.associateWith { Mappers.IDENTITY }
return PlotUtil.createLayerAesthetics(layer, aesList, mappers)
Expand Down Expand Up @@ -191,8 +193,8 @@ internal object PositionalScalesUtil {
private fun computeLayerDryRunXYRangesAfterPosAdjustment(
layer: GeomLayer, aes: Aesthetics, geomCtx: GeomContext
): Pair<DoubleSpan?, DoubleSpan?> {
val posAesX = Aes.affectingScaleX(layer.renderedAes())
val posAesY = Aes.affectingScaleY(layer.renderedAes())
val posAesX = Aes.affectingScaleX(layer.renderedAes().filter { layer.hasBinding(it) || layer.hasConstant(it) })
val posAesY = Aes.affectingScaleY(layer.renderedAes().filter { layer.hasBinding(it) || layer.hasConstant(it) })

val pos = PlotUtil.createPositionAdjustment(layer.posProvider, aes)
if (pos.isIdentity) {
Expand Down