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

Updates in lollipops #768

Merged
merged 12 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -6350,11 +6350,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