Skip to content

Commit

Permalink
Fix calculation of XY-ranges for geom_errorbar (#770)
Browse files Browse the repository at this point in the history
* Fix XY-ranges calculation, use height/width expansion for errorbar depend on its representation.

* Separate logic to identify renderedAes for errobar.

* Remove unused import directive.

* Code cleanup.

* Fix requirements for the specified aesthetics for the errorbar.

* Update demo notebook.
  • Loading branch information
OLarionova-HORIS committed May 2, 2023
1 parent ec2e2a8 commit 7a2383f
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 44 deletions.
300 changes: 264 additions & 36 deletions docs/f-23b/horizontal_error_bars.ipynb

Large diffs are not rendered by default.

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 @@ -268,8 +268,8 @@ class GeomLayerBuilder(
override val geomKind: GeomKind = geomProvider.geomKind
override val aestheticsDefaults: AestheticsDefaults = geomProvider.aestheticsDefaults()

private val myConstantByAes: TypedKeyHashMap = TypedKeyHashMap()
private val myRenderedAes: List<Aes<*>>
private val myConstantByAes: TypedKeyHashMap

override val legendKeyElementFactory: LegendKeyElementFactory
get() = geom.legendKeyElementFactory
Expand All @@ -278,13 +278,31 @@ class GeomLayerBuilder(
get() = geom is LiveMapGeom

init {
myRenderedAes = GeomMeta.renders(geomProvider.geomKind, colorByAes, fillByAes)

// constant value by aes (default + specified)
myConstantByAes = TypedKeyHashMap()
for (key in constantByAes.keys<Any>()) {
myConstantByAes.put(key, constantByAes[key])
}

myRenderedAes = GeomMeta.renders(geomProvider.geomKind, colorByAes, fillByAes).let { allRenderedAes ->
if (geomKind == GeomKind.ERROR_BAR) {
// ToDo Need refactoring...
// This geometry supports a dual set of aesthetics (vertical and horizontal representation).
// Check that the settings are consistent
// and set the aesthetics needed for that geometry.
val definedAes = allRenderedAes.filter { aes -> hasBinding(aes) || hasConstant(aes) }
val isVertical = setOf(Aes.YMIN, Aes.YMAX).all { aes -> aes in definedAes }
val isHorizontal = setOf(Aes.XMIN, Aes.XMAX).all { aes -> aes in definedAes }
require(!(isVertical && isHorizontal)) {
"Either ymin, ymax or xmin, xmax must be specified for the errorbar."
}
allRenderedAes - when (isVertical) {
true -> setOf(Aes.Y, Aes.XMIN, Aes.XMAX, Aes.HEIGHT)
false -> setOf(Aes.X, Aes.YMIN, Aes.YMAX, Aes.WIDTH)
}
} else {
allRenderedAes
}
}
}

override fun renderedAes(): List<Aes<*>> {
Expand Down

0 comments on commit 7a2383f

Please sign in to comment.