Skip to content

Commit

Permalink
Code improvements and examples in expand_limits().
Browse files Browse the repository at this point in the history
Minor improvements in docs.
  • Loading branch information
alshan committed Sep 13, 2024
1 parent 226e421 commit fd41708
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ val letsPlotTaskGroup by extra { "lets-plot" }
allprojects {
group = "org.jetbrains.lets-plot"
version = "4.4.2-SNAPSHOT" // see also: python-package/lets_plot/_version.py
// version = "0.0.0-SNAPSHOT" // for local publishing only

// Generate JVM 1.8 bytecode
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
Expand Down
5 changes: 4 additions & 1 deletion devdocs/SNAPSHOT_publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### 1. Prepare for publishing:

- Check `version` in the root `build.gradle` file: version must be like `X.X.X-SNAPSHOT`.
- Check `version` in the root `build.gradle.kts` file: version must be like `X.X.X-SNAPSHOT`.
- Add token to the `sonatype` section of the `local.properties` file.

### 2. Publish:
Expand All @@ -23,3 +23,6 @@ Run tne next gradle tasks from the project root:
Check uploaded artifacts here:

https://oss.sonatype.org/content/repositories/snapshots/org/jetbrains/lets-plot/


TBD: Snapshot vertsion of JS artifacts.
6 changes: 3 additions & 3 deletions js-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
> If you want run them from this folder, remove `js-package:` from the task name.

- `./gradlew js-package:jsBrowserProductionWebpack` - builds minified JS package `lets-plot.min.js` for embedding;
- `./gradlew js-package:jsBrowserDevelopmentWebpack` - builds full-size JS package `lets-plot.js` for develop purpose;
- `$ ./gradlew js-package:jsBrowserProductionWebpack` - builds minified JS package `lets-plot.min.js` for embedding;
- `$ ./gradlew js-package:jsBrowserDevelopmentWebpack` - builds full-size JS package `lets-plot.js` for develop purpose;

> **Note**: For more details about debugging JS demos check [JS debugging.md](../devdocs/misc/JS_debugging.md).
After build artifacts can be found inside `build` directory: `js-package/build/distributions`.

- `./gradlew js-package:copyForPublish` - copies minified JS package for release.
- `$ ./gradlew js-package:copyForPublish` - copies minified JS package for release.

Release artifacts are located inside `distr` directory: `js-package/distr`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object PlotHtmlHelper {
return if (dev) {
// We don't publish "dev" version, it must be served on localhost:
// $ cd lets-plot
// - Build "dev" JS package (see js-package/README.md)
// - Activate env containing Python.
// $ python -m http.server 8080
"http://127.0.0.1:8080/js-package/build/dist/js/developmentExecutable/js-package.js"
} else {
Expand Down
46 changes: 38 additions & 8 deletions python-package/lets_plot/plot/expand_limits_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,53 @@ def expand_limits(*, x=None, y=None, size=None, color=None, fill=None, alpha=Non
Examples
--------
.. jupyter-execute::
:linenos:
:emphasize-lines: 10
from lets_plot import *
LetsPlot.setup_html()
data = {
'x': [-3, 0, 1],
'y': [2, 3, -1],
}
# Include the value -10 along the x-axis
ggplot(data, aes('x', 'y')) + geom_point() + \
expand_limits(x=-10)
|
.. jupyter-execute::
:linenos:
:emphasize-lines: 10
from lets_plot import *
LetsPlot.setup_html()
data = {
'x': [-3, 0, 1],
'y': [2, 3, -1],
}
# Expand Limits Along the y-axis
ggplot(data, aes('x', 'y')) + geom_point() + \
expand_limits(y=range(-10, 10))
"""
params = locals()

def standardize(value):
if value is None:
return [None]
elif isinstance(value, (list, tuple, range)):
if isinstance(value, (list, tuple, range)):
return list(value)
else:
return [value]

standardized = {k: standardize(v) for k, v in params.items()}

max_length = max(len(v) for v in standardized.values())
raw_data = {k: v + [None] * (max_length - len(v)) for k, v in standardized.items()}
# Drop all undefined but keep x and y even if undefined.
cleaned = {k: v for k, v in standardized.items() if k in ['x', 'y'] or not all(e is None for e in v)}

max_length = max(len(v) for v in cleaned.values())
data = {k: v + [None] * (max_length - len(v)) for k, v in cleaned.items()}

# remove all undefined but keep x and y even if undefined.
filtered_data = {k: v for k, v in raw_data.items() if k in ['x', 'y'] or not all(e is None for e in v)}
return geom_blank(mapping=aes(**filtered_data))
return geom_blank(mapping=aes(**data))
2 changes: 1 addition & 1 deletion python-package/lets_plot/plot/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7539,7 +7539,7 @@ def geom_blank(mapping=None, *, data=None, stat=None, position=None, show_legend
**other_args):
"""
Draw nothing, but can be a useful way of ensuring common scales between different plots (see `expand_limits()`).
Also, can help to avoid the "No layers in plot" error when buildling plots using automated tools.
Also, can help to avoid the "No layers in plot" error when building plots using automated tools.
Parameters
----------
Expand Down

0 comments on commit fd41708

Please sign in to comment.