Skip to content

Commit

Permalink
Updates in lollipops (#768)
Browse files Browse the repository at this point in the history
* Add conditional including of zero to the Y-range for the lollipop geometry.

* Increase multiplicative expand for the continuous scale when geometry is lollipop.

* Update the cookbook-notebook for the lollipop geometry.

* Refactor continuous scale expanding for the lollipop geometry.

* Refactor scale expand parameters for the lollipop geometry.

* Fix rangeIncludesZero() for lollipops.

* Rerun cookbook-notebook for the lollipop geometry.

* Change behaviour of the dir parameter for the lollipop geometry.

* Undo expanding scales for lollipops.

* Update API for geom_lollipop() (change behaviour of the dir parameter).

* Fix the future_changes.md file.

* Rebuild the cookbook-notebook for the lollipop geometry.
  • Loading branch information
ASmirnov-HORIS authored Apr 28, 2023
1 parent eb75a50 commit a29e35e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 53 deletions.
54 changes: 30 additions & 24 deletions docs/f-23b/geom_lollipop.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- New geometry `geom_lollipop()`.

See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23b/lollipop_plot.ipynb).
See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23b/geom_lollipop.ipynb).


- `stroke` aesthetic for `geom_point()`, `geom_jitter()`, `geom_qq()`, `geom_qq2()`, `geom_pointrange()`, `geom_dotplot()`, `geom_ydotplot()` and `outlier_stroke` parameter for `geom_boxplot()`.
Expand All @@ -14,7 +14,7 @@

- New aesthetic `linewidth`. Used only for `geom_lollipop()` at the moment.

See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23b/lollipop_plot.ipynb).
See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23b/geom_lollipop.ipynb).


- the 'newline' character (`\n`) now works as `line break` in legend text ([[#726](https://github.com/JetBrains/lets-plot/issues/726)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import jetbrains.datalore.plot.base.data.TransformVar
import jetbrains.datalore.plot.base.geom.GeomBase
import jetbrains.datalore.plot.base.geom.LiveMapGeom
import jetbrains.datalore.plot.base.geom.LiveMapProvider
import jetbrains.datalore.plot.base.geom.LollipopGeom
import jetbrains.datalore.plot.base.interact.ContextualMapping
import jetbrains.datalore.plot.base.interact.GeomTargetLocator.LookupSpec
import jetbrains.datalore.plot.base.interact.MappedDataAccess
Expand Down Expand Up @@ -320,7 +321,12 @@ class GeomLayerBuilder(
override fun rangeIncludesZero(aes: Aes<*>): Boolean {
@Suppress("NAME_SHADOWING")
val aes = aes.afterOrientation(isYOrientation)
return aestheticsDefaults.rangeIncludesZero(aes)
return if (geom is LollipopGeom && aes == Aes.Y) {
// Pin the lollipops to an axis when baseline coincides with this axis and sticks are perpendicular to it
geom.slope == 0.0 && geom.intercept == 0.0 && geom.direction != LollipopGeom.Direction.ALONG_AXIS
} else {
aestheticsDefaults.rangeIncludesZero(aes)
}
}

override fun setLiveMapProvider(liveMapProvider: LiveMapProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,31 +293,11 @@ class GeomProtoClientSide(geomKind: GeomKind) : GeomProto(geomKind) {
}

GeomKind.LOLLIPOP -> return GeomProvider.lollipop {
// As in LayerConfig
val isYOrientation: Boolean = when (opts.hasOwn(Option.Layer.ORIENTATION)) {
true -> opts.getString(Option.Layer.ORIENTATION)?.lowercase()?.let {
when (it) {
"y" -> true
"x" -> false
else -> throw IllegalArgumentException("${Option.Layer.ORIENTATION} expected x|y but was $it")
}
} ?: false

false -> false
}
val directionValue = opts.getString(Lollipop.DIRECTION)?.lowercase()
val direction = directionValue?.let {
when (it) {
"v" -> if (isYOrientation) {
Direction.ALONG_AXIS
} else {
Direction.ORTHOGONAL_TO_AXIS
}
"h" -> if (isYOrientation) {
Direction.ORTHOGONAL_TO_AXIS
} else {
Direction.ALONG_AXIS
}
"v" -> Direction.ORTHOGONAL_TO_AXIS
"h" -> Direction.ALONG_AXIS
"s" -> Direction.SLOPE
else -> throw IllegalArgumentException(
"Unsupported value for ${Lollipop.DIRECTION} parameter: '$it'. " +
Expand All @@ -334,7 +314,6 @@ class GeomProtoClientSide(geomKind: GeomKind) : GeomProto(geomKind) {
throw IllegalArgumentException(
"Incompatible lollipop parameters: " +
"${Lollipop.SLOPE}=$slope, " +
"${Option.Layer.ORIENTATION}='${if (isYOrientation) "y" else "x"}', " +
"${Lollipop.DIRECTION}='${directionValue}'"
)
}
Expand Down
4 changes: 1 addition & 3 deletions python-package/lets_plot/plot/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6256,11 +6256,9 @@ def geom_lollipop(mapping=None, *, data=None, stat=None, position=None, show_leg
orientation : {'x', 'y'}, default='x'
Specify the axis that the baseline should run along.
Possible values: 'x', 'y'.
dir : {'v', 'h', 's'}
dir : {'v', 'h', 's'}, default='v'
Direction of the lollipop stick.
'v' for vertical, 'h' for horizontal, 's' for orthogonal to the baseline.
If `orientation='x'`, default `dir` is 'v'.
If `orientation='y'`, default `dir` is 'h'.
fatten : float, default=2.5
A multiplicative factor applied to size of the point.
slope : float
Expand Down

0 comments on commit a29e35e

Please sign in to comment.