lets-plot 4.8.0rc1__cp313-cp313-macosx_12_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lets-plot might be problematic. Click here for more details.
- lets_plot/__init__.py +283 -0
- lets_plot/_global_settings.py +192 -0
- lets_plot/_kbridge.py +149 -0
- lets_plot/_type_utils.py +133 -0
- lets_plot/_version.py +6 -0
- lets_plot/bistro/__init__.py +16 -0
- lets_plot/bistro/_plot2d_common.py +106 -0
- lets_plot/bistro/corr.py +448 -0
- lets_plot/bistro/im.py +196 -0
- lets_plot/bistro/joint.py +192 -0
- lets_plot/bistro/qq.py +207 -0
- lets_plot/bistro/residual.py +341 -0
- lets_plot/bistro/waterfall.py +332 -0
- lets_plot/export/__init__.py +6 -0
- lets_plot/export/ggsave_.py +170 -0
- lets_plot/frontend_context/__init__.py +8 -0
- lets_plot/frontend_context/_configuration.py +151 -0
- lets_plot/frontend_context/_frontend_ctx.py +16 -0
- lets_plot/frontend_context/_html_contexts.py +117 -0
- lets_plot/frontend_context/_intellij_python_json_ctx.py +38 -0
- lets_plot/frontend_context/_json_contexts.py +39 -0
- lets_plot/frontend_context/_jupyter_notebook_ctx.py +119 -0
- lets_plot/frontend_context/_mime_types.py +7 -0
- lets_plot/frontend_context/_static_html_page_ctx.py +27 -0
- lets_plot/frontend_context/_static_svg_ctx.py +26 -0
- lets_plot/frontend_context/_webbr_html_page_ctx.py +29 -0
- lets_plot/frontend_context/sandbox.py +5 -0
- lets_plot/geo_data/__init__.py +19 -0
- lets_plot/geo_data/core.py +335 -0
- lets_plot/geo_data/geocoder.py +988 -0
- lets_plot/geo_data/geocodes.py +512 -0
- lets_plot/geo_data/gis/__init__.py +0 -0
- lets_plot/geo_data/gis/fluent_dict.py +201 -0
- lets_plot/geo_data/gis/geocoding_service.py +42 -0
- lets_plot/geo_data/gis/geometry.py +91 -0
- lets_plot/geo_data/gis/json_request.py +232 -0
- lets_plot/geo_data/gis/json_response.py +308 -0
- lets_plot/geo_data/gis/request.py +492 -0
- lets_plot/geo_data/gis/response.py +247 -0
- lets_plot/geo_data/livemap_helper.py +65 -0
- lets_plot/geo_data/to_geo_data_frame.py +141 -0
- lets_plot/geo_data/type_assertion.py +34 -0
- lets_plot/geo_data_internals/__init__.py +4 -0
- lets_plot/geo_data_internals/constants.py +13 -0
- lets_plot/geo_data_internals/utils.py +33 -0
- lets_plot/mapping.py +115 -0
- lets_plot/package_data/lets-plot.min.js +3 -0
- lets_plot/plot/__init__.py +64 -0
- lets_plot/plot/_global_theme.py +14 -0
- lets_plot/plot/annotation.py +290 -0
- lets_plot/plot/coord.py +242 -0
- lets_plot/plot/core.py +1025 -0
- lets_plot/plot/expand_limits_.py +78 -0
- lets_plot/plot/facet.py +210 -0
- lets_plot/plot/font_features.py +71 -0
- lets_plot/plot/geom.py +9144 -0
- lets_plot/plot/geom_extras.py +53 -0
- lets_plot/plot/geom_function_.py +219 -0
- lets_plot/plot/geom_imshow_.py +393 -0
- lets_plot/plot/geom_livemap_.py +343 -0
- lets_plot/plot/ggbunch_.py +96 -0
- lets_plot/plot/gggrid_.py +139 -0
- lets_plot/plot/ggtb_.py +81 -0
- lets_plot/plot/guide.py +231 -0
- lets_plot/plot/label.py +187 -0
- lets_plot/plot/marginal_layer.py +181 -0
- lets_plot/plot/plot.py +245 -0
- lets_plot/plot/pos.py +344 -0
- lets_plot/plot/sampling.py +338 -0
- lets_plot/plot/sandbox_.py +26 -0
- lets_plot/plot/scale.py +3580 -0
- lets_plot/plot/scale_colormap_mpl.py +300 -0
- lets_plot/plot/scale_convenience.py +155 -0
- lets_plot/plot/scale_identity_.py +662 -0
- lets_plot/plot/scale_position.py +1342 -0
- lets_plot/plot/series_meta.py +209 -0
- lets_plot/plot/stat.py +585 -0
- lets_plot/plot/subplots.py +331 -0
- lets_plot/plot/subplots_util.py +24 -0
- lets_plot/plot/theme_.py +795 -0
- lets_plot/plot/theme_set.py +418 -0
- lets_plot/plot/tooltip.py +486 -0
- lets_plot/plot/util.py +267 -0
- lets_plot/settings_utils.py +244 -0
- lets_plot/tilesets.py +429 -0
- lets_plot-4.8.0rc1.dist-info/METADATA +220 -0
- lets_plot-4.8.0rc1.dist-info/RECORD +95 -0
- lets_plot-4.8.0rc1.dist-info/WHEEL +5 -0
- lets_plot-4.8.0rc1.dist-info/licenses/LICENSE +21 -0
- lets_plot-4.8.0rc1.dist-info/licenses/licenses/LICENSE.FreeType +166 -0
- lets_plot-4.8.0rc1.dist-info/licenses/licenses/LICENSE.ImageMagick +106 -0
- lets_plot-4.8.0rc1.dist-info/licenses/licenses/LICENSE.expat +21 -0
- lets_plot-4.8.0rc1.dist-info/licenses/licenses/LICENSE.fontconfig +200 -0
- lets_plot-4.8.0rc1.dist-info/top_level.txt +2 -0
- lets_plot_kotlin_bridge.cpython-313-darwin.so +0 -0
lets_plot/__init__.py
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2019. JetBrains s.r.o.
|
|
3
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
4
|
+
#
|
|
5
|
+
from pkgutil import extend_path
|
|
6
|
+
from typing import Dict, Union
|
|
7
|
+
|
|
8
|
+
# To handle the situation when the 'lets_plot' package is shared by modules in different locations.
|
|
9
|
+
__path__ = extend_path(__path__, __name__)
|
|
10
|
+
|
|
11
|
+
from ._version import __version__
|
|
12
|
+
from ._global_settings import _settings, is_production, get_global_bool
|
|
13
|
+
from ._global_settings import NO_JS, OFFLINE
|
|
14
|
+
|
|
15
|
+
from .plot import *
|
|
16
|
+
from .export import *
|
|
17
|
+
from .frontend_context import *
|
|
18
|
+
from .mapping import *
|
|
19
|
+
from .settings_utils import *
|
|
20
|
+
from .plot._global_theme import _set_global_theme
|
|
21
|
+
|
|
22
|
+
__all__ = (plot.__all__ +
|
|
23
|
+
frontend_context.__all__ +
|
|
24
|
+
mapping.__all__ +
|
|
25
|
+
settings_utils.__all__ +
|
|
26
|
+
export.__all__ +
|
|
27
|
+
['LetsPlot'])
|
|
28
|
+
|
|
29
|
+
from .frontend_context import _configuration as cfg
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class LetsPlot:
|
|
33
|
+
"""
|
|
34
|
+
Initialize the library and its options.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def setup_html(cls, *,
|
|
39
|
+
isolated_frame: bool = None,
|
|
40
|
+
offline: bool = None,
|
|
41
|
+
no_js: bool = None,
|
|
42
|
+
show_status: bool = False) -> None:
|
|
43
|
+
"""
|
|
44
|
+
Configure Lets-Plot HTML output.
|
|
45
|
+
Depending on the usage, LetsPlot generates different HTML to show plots.
|
|
46
|
+
In most cases LetsPlot will detect type of the environment automatically.
|
|
47
|
+
Auto-detection can be overwritten using this method parameters.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
isolated_frame : bool
|
|
52
|
+
True - generate HTML which can be used in iframe or in a standalone HTML document.
|
|
53
|
+
False - pre-load Lets-Plot JS library. Notebook cell output will only consist
|
|
54
|
+
of HTML for the plot rendering. Default: None - auto-detect.
|
|
55
|
+
offline : bool
|
|
56
|
+
True - full Lets-Plot JS bundle will be added to the notebook.
|
|
57
|
+
Use this option if you would like to work with notebook
|
|
58
|
+
without the Internet connection. False - load Lets-Plot JS library from CDN.
|
|
59
|
+
Default (None): 'connected' mode in production environment
|
|
60
|
+
and 'offline' mode in dev environment.
|
|
61
|
+
no_js : bool, default=False
|
|
62
|
+
True - do not generate HTML+JS as an output - just static SVG image.
|
|
63
|
+
Note that without JS interactive maps and tooltips doesn't work!
|
|
64
|
+
show_status : bool, default=False
|
|
65
|
+
Whether to show status of loading of the Lets-Plot JS library.
|
|
66
|
+
Only applicable when the Lets-Plot JS library is preloaded.
|
|
67
|
+
|
|
68
|
+
Examples
|
|
69
|
+
--------
|
|
70
|
+
.. jupyter-execute::
|
|
71
|
+
:linenos:
|
|
72
|
+
:emphasize-lines: 2
|
|
73
|
+
|
|
74
|
+
from lets_plot import *
|
|
75
|
+
LetsPlot.setup_html()
|
|
76
|
+
ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point()
|
|
77
|
+
|
|
78
|
+
|
|
|
79
|
+
|
|
80
|
+
.. jupyter-execute::
|
|
81
|
+
:linenos:
|
|
82
|
+
:emphasize-lines: 2-3
|
|
83
|
+
|
|
84
|
+
from lets_plot import *
|
|
85
|
+
LetsPlot.setup_html(isolated_frame=False, offline=True, \\
|
|
86
|
+
no_js=True, show_status=True)
|
|
87
|
+
ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point()
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
if not (isinstance(isolated_frame, bool) or isolated_frame is None):
|
|
91
|
+
raise ValueError("'isolated' argument is not boolean: {}".format(type(isolated_frame)))
|
|
92
|
+
if not (isinstance(offline, bool) or offline is None):
|
|
93
|
+
raise ValueError("'offline' argument is not boolean: {}".format(type(offline)))
|
|
94
|
+
if not (isinstance(no_js, bool) or no_js is None):
|
|
95
|
+
raise ValueError("'no_js' argument is not boolean: {}".format(type(no_js)))
|
|
96
|
+
if not isinstance(show_status, bool):
|
|
97
|
+
raise ValueError("'show_status' argument is not boolean: {}".format(type(show_status)))
|
|
98
|
+
|
|
99
|
+
offline = offline if offline is not None else get_global_bool(OFFLINE)
|
|
100
|
+
no_js = no_js if no_js is not None else get_global_bool(NO_JS)
|
|
101
|
+
|
|
102
|
+
cfg._setup_html_context(isolated_frame=isolated_frame,
|
|
103
|
+
offline=offline,
|
|
104
|
+
no_js=no_js,
|
|
105
|
+
show_status=show_status)
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def set(cls, settings: Dict):
|
|
109
|
+
"""
|
|
110
|
+
Set up library options.
|
|
111
|
+
For more info see `Configuring Globally <https://lets-plot.org/python/pages/basemap_tiles.html#configuring-globally>`__.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
settings : dict
|
|
116
|
+
Dictionary of settings.
|
|
117
|
+
|
|
118
|
+
Notes
|
|
119
|
+
-----
|
|
120
|
+
List of possible settings:
|
|
121
|
+
|
|
122
|
+
- html_isolated_frame : preload Lets-Plot JS library or not (bool). Do not use this parameter explicitly. Instead you should call `LetsPlot.setup_html() <https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html#lets_plot.LetsPlot.setup_html>`__.
|
|
123
|
+
- offline : to work with notebook without the Internet connection (bool). Do not use this parameter explicitly. Instead you should call `LetsPlot.setup_html() <https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html#lets_plot.LetsPlot.setup_html>`__.
|
|
124
|
+
- no_js : do not generate HTML+JS as an output (bool). Do not use this parameter explicitly. Instead you should call `LetsPlot.setup_html() <https://lets-plot.org/python/pages/api/lets_plot.LetsPlot.html#lets_plot.LetsPlot.setup_html>`__. Also note that without JS interactive maps and tooltips doesn't work!
|
|
125
|
+
|
|
126
|
+
Interactive map settings could also be specified:
|
|
127
|
+
|
|
128
|
+
- maptiles_kind : kind of the tiles, could be 'raster_zxy' or 'vector_lets_plot'. Do not use this parameter explicitly. Instead you should construct it with functions `maptiles_zxy() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_zxy.html>`__ and `maptiles_lets_plot() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_lets_plot.html>`__.
|
|
129
|
+
- maptiles_url : address of the tile server (str). Do not use this parameter explicitly. Instead you should construct it with functions `maptiles_zxy() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_zxy.html>`__ and `maptiles_lets_plot() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_lets_plot.html>`__.
|
|
130
|
+
- maptiles_theme : tiles theme, could be 'color', 'light' or 'dark'. Do not use this parameter explicitly. Instead you should construct it with function `maptiles_lets_plot() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_lets_plot.html>`__.
|
|
131
|
+
- maptiles_attribution : an attribution or a copyright notice to display on the map as required by the tile license (str, supports HTML links). Do not use this parameter explicitly. Instead you should construct it with function `maptiles_zxy() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_zxy.html>`__.
|
|
132
|
+
- maptiles_min_zoom : minimal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function `maptiles_zxy() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_zxy.html>`__.
|
|
133
|
+
- maptiles_max_zoom : maximal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function `maptiles_zxy() <https://lets-plot.org/python/pages/api/lets_plot.maptiles_zxy.html>`__.
|
|
134
|
+
|
|
135
|
+
Examples
|
|
136
|
+
--------
|
|
137
|
+
.. jupyter-execute::
|
|
138
|
+
:linenos:
|
|
139
|
+
:emphasize-lines: 4
|
|
140
|
+
|
|
141
|
+
from lets_plot import *
|
|
142
|
+
from lets_plot import tilesets
|
|
143
|
+
LetsPlot.setup_html()
|
|
144
|
+
LetsPlot.set(tilesets.LETS_PLOT_LIGHT)
|
|
145
|
+
ggplot() + geom_livemap()
|
|
146
|
+
|
|
147
|
+
|
|
|
148
|
+
|
|
149
|
+
.. jupyter-execute::
|
|
150
|
+
:linenos:
|
|
151
|
+
:emphasize-lines: 4
|
|
152
|
+
|
|
153
|
+
from lets_plot import *
|
|
154
|
+
from lets_plot import tilesets
|
|
155
|
+
LetsPlot.setup_html()
|
|
156
|
+
LetsPlot.set(tilesets.LETS_PLOT_BW)
|
|
157
|
+
ggplot() + geom_livemap()
|
|
158
|
+
|
|
159
|
+
"""
|
|
160
|
+
if is_production():
|
|
161
|
+
_settings.update(settings)
|
|
162
|
+
else:
|
|
163
|
+
_settings.update({'dev_' + key: value for key, value in settings.items()})
|
|
164
|
+
|
|
165
|
+
@classmethod
|
|
166
|
+
def set_theme(cls, theme: Union['core.FeatureSpec', 'core.FeatureSpecArray']):
|
|
167
|
+
"""
|
|
168
|
+
Set up global theme.
|
|
169
|
+
|
|
170
|
+
Parameters
|
|
171
|
+
----------
|
|
172
|
+
theme : spec
|
|
173
|
+
Theme spec provided by `theme(...) <https://lets-plot.org/python/pages/api/lets_plot.theme.html>`__, ``theme_xxx()``, ``flavor_xxx()`` functions, or their sum.
|
|
174
|
+
|
|
175
|
+
"""
|
|
176
|
+
if theme is None:
|
|
177
|
+
_set_global_theme(None)
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
if theme.kind != 'theme' and not (theme.kind == 'feature-list' and all(f.kind == 'theme' for f in theme)):
|
|
181
|
+
raise ValueError("Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported")
|
|
182
|
+
|
|
183
|
+
_set_global_theme(theme)
|
|
184
|
+
|
|
185
|
+
@classmethod
|
|
186
|
+
def setup_show_ext(cls, *,
|
|
187
|
+
exec: str = None,
|
|
188
|
+
new: bool = False) -> None:
|
|
189
|
+
"""
|
|
190
|
+
Configure Lets-Plot to show its HTML output in an external browser.
|
|
191
|
+
|
|
192
|
+
When the "show externally" is set up, an invocation of ``figire.show()`` will
|
|
193
|
+
- generate HTML output
|
|
194
|
+
- save it to a temporary file
|
|
195
|
+
- open the file in the default web browser or in a web browser specified by the ``exec`` parameter.
|
|
196
|
+
|
|
197
|
+
Parameters
|
|
198
|
+
----------
|
|
199
|
+
exec : str, optional
|
|
200
|
+
Specify an app to open the generated temporary HTML file.
|
|
201
|
+
If not specified, the default browser will be used.
|
|
202
|
+
new : bool, default=False
|
|
203
|
+
If True, the URL is opened in a new window of the web browser.
|
|
204
|
+
If False, the URL is opened in the already opened web browser window.
|
|
205
|
+
The ``new`` parameter is only applicable when the ``exec`` parameter is not specified.
|
|
206
|
+
Please note that the ``new`` parameter is not supported by all web browsers and all OS-s.
|
|
207
|
+
|
|
208
|
+
Examples
|
|
209
|
+
--------
|
|
210
|
+
.. code-block::
|
|
211
|
+
:linenos:
|
|
212
|
+
:emphasize-lines: 3
|
|
213
|
+
|
|
214
|
+
# Show the plot in the default web browser.
|
|
215
|
+
from lets_plot import *
|
|
216
|
+
LetsPlot.setup_show_ext()
|
|
217
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
218
|
+
p.show()
|
|
219
|
+
|
|
220
|
+
|
|
|
221
|
+
|
|
222
|
+
.. code-block::
|
|
223
|
+
:linenos:
|
|
224
|
+
:emphasize-lines: 3
|
|
225
|
+
|
|
226
|
+
# Show the plot in the new window of the default web browser if possible.
|
|
227
|
+
from lets_plot import *
|
|
228
|
+
LetsPlot.setup_show_ext(new=True)
|
|
229
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
230
|
+
p.show()
|
|
231
|
+
|
|
232
|
+
|
|
|
233
|
+
|
|
234
|
+
.. code-block::
|
|
235
|
+
:linenos:
|
|
236
|
+
:emphasize-lines: 4
|
|
237
|
+
|
|
238
|
+
# Show the plot in the Chrome web browser for Windows.
|
|
239
|
+
# This is the default setup path. Replace the file path with your own if it differs.
|
|
240
|
+
from lets_plot import *
|
|
241
|
+
LetsPlot.setup_show_ext(exec='C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe --app=%s')
|
|
242
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
243
|
+
p.show()
|
|
244
|
+
|
|
245
|
+
|
|
|
246
|
+
|
|
247
|
+
.. code-block::
|
|
248
|
+
:linenos:
|
|
249
|
+
:emphasize-lines: 3
|
|
250
|
+
|
|
251
|
+
# Show the plot in the Safari web browser for macOS.
|
|
252
|
+
from lets_plot import *
|
|
253
|
+
LetsPlot.setup_show_ext(exec='open -a safari %s')
|
|
254
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
255
|
+
p.show()
|
|
256
|
+
|
|
257
|
+
|
|
|
258
|
+
|
|
259
|
+
.. code-block::
|
|
260
|
+
:linenos:
|
|
261
|
+
:emphasize-lines: 4
|
|
262
|
+
|
|
263
|
+
# Show the plot in the Chrome web browser for macOS in the application mode.
|
|
264
|
+
# This is the default setup path. Replace the path with your own if it differs.
|
|
265
|
+
from lets_plot import *
|
|
266
|
+
LetsPlot.setup_show_ext(exec='/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --app=%s')
|
|
267
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
268
|
+
p.show()
|
|
269
|
+
|
|
270
|
+
|
|
|
271
|
+
|
|
272
|
+
.. code-block::
|
|
273
|
+
:linenos:
|
|
274
|
+
:emphasize-lines: 3
|
|
275
|
+
|
|
276
|
+
# Show the plot in the Chrome web browser for Linux.
|
|
277
|
+
from lets_plot import *
|
|
278
|
+
LetsPlot.setup_show_ext(exec='google-chrome --app=%s')
|
|
279
|
+
p = ggplot() + geom_point(x=0, y=0)
|
|
280
|
+
p.show()
|
|
281
|
+
|
|
282
|
+
"""
|
|
283
|
+
cfg._setup_wb_html_context(exec=exec, new=new)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2019. JetBrains s.r.o.
|
|
3
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
4
|
+
#
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ._version import __version__
|
|
9
|
+
|
|
10
|
+
# Supported environment variables.
|
|
11
|
+
# 'bool' variables accept values:
|
|
12
|
+
# True: 'true', '1', 't', 'y', 'yes'
|
|
13
|
+
# False: 'false', '0', 'f', 'n', 'no'
|
|
14
|
+
#
|
|
15
|
+
# Production mode env variables:
|
|
16
|
+
ENV_HTML_ISOLATED_FRAME = 'LETS_PLOT_HTML_ISOLATED_FRAME' # bool
|
|
17
|
+
ENV_OFFLINE = 'LETS_PLOT_OFFLINE' # bool
|
|
18
|
+
ENV_NO_JS = 'LETS_PLOT_NO_JS' # bool
|
|
19
|
+
ENV_MAX_WIDTH = 'LETS_PLOT_MAX_WIDTH'
|
|
20
|
+
ENV_MAX_HEIGHT = 'LETS_PLOT_MAX_HEIGHT'
|
|
21
|
+
ENV_MAPTILES_KIND = 'LETS_PLOT_MAPTILES_KIND'
|
|
22
|
+
ENV_MAPTILES_URL = 'LETS_PLOT_MAPTILES_URL'
|
|
23
|
+
ENV_MAPTILES_THEME = 'LETS_PLOT_MAPTILES_THEME'
|
|
24
|
+
ENV_GEOCODING_URL = 'LETS_PLOT_GEOCODING_URL'
|
|
25
|
+
|
|
26
|
+
# Dev mode env variables have 'LETS_PLOT_DEV_' prefix instead of 'LETS_PLOT_'.
|
|
27
|
+
ENV_DEV_HTML_ISOLATED_FRAME = 'LETS_PLOT_DEV_HTML_ISOLATED_FRAME' # bool
|
|
28
|
+
ENV_DEV_OFFLINE = 'LETS_PLOT_DEV_OFFLINE' # bool
|
|
29
|
+
ENV_DEV_NO_JS = 'LETS_PLOT_DEV_NO_JS' # bool
|
|
30
|
+
ENV_DEV_MAX_WIDTH = 'LETS_PLOT_DEV_MAX_WIDTH'
|
|
31
|
+
ENV_DEV_MAX_HEIGHT = 'LETS_PLOT_DEV_MAX_HEIGHT'
|
|
32
|
+
ENV_DEV_MAGICK_EXPORT = 'LETS_PLOT_DEV_MAGICK_EXPORT' # bool
|
|
33
|
+
ENV_DEV_MAPTILES_KIND = 'LETS_PLOT_DEV_MAPTILES_KIND'
|
|
34
|
+
ENV_DEV_MAPTILES_URL = 'LETS_PLOT_DEV_MAPTILES_URL'
|
|
35
|
+
ENV_DEV_MAPTILES_THEME = 'LETS_PLOT_DEV_MAPTILES_THEME'
|
|
36
|
+
ENV_DEV_GEOCODING_URL = 'LETS_PLOT_DEV_GEOCODING_URL'
|
|
37
|
+
|
|
38
|
+
# Options
|
|
39
|
+
|
|
40
|
+
HTML_ISOLATED_FRAME = 'html_isolated_frame'
|
|
41
|
+
OFFLINE = 'offline'
|
|
42
|
+
NO_JS = 'no_js'
|
|
43
|
+
JS_BASE_URL = 'js_base_url'
|
|
44
|
+
JS_PATH_TO_FILE = 'js_path_to_file'
|
|
45
|
+
JS_NAME = 'js_name'
|
|
46
|
+
JS_URL_MANUAL = 'js_url_manual'
|
|
47
|
+
MAX_WIDTH = 'max_width'
|
|
48
|
+
MAX_HEIGHT = 'max_height'
|
|
49
|
+
|
|
50
|
+
MAPTILES_KIND = 'maptiles_kind'
|
|
51
|
+
MAPTILES_URL = 'maptiles_url'
|
|
52
|
+
MAPTILES_THEME = 'maptiles_theme'
|
|
53
|
+
MAPTILES_ATTRIBUTION = 'maptiles_attribution'
|
|
54
|
+
MAPTILES_MIN_ZOOM = 'maptiles_min_zoom'
|
|
55
|
+
MAPTILES_MAX_ZOOM = 'maptiles_max_zoom'
|
|
56
|
+
MAPTILES_SOLID_FILL_COLOR = 'maptiles_fill_color'
|
|
57
|
+
TILES_VECTOR_LETS_PLOT = 'vector_lets_plot'
|
|
58
|
+
TILES_RASTER_ZXY = 'raster_zxy'
|
|
59
|
+
TILES_SOLID = 'solid'
|
|
60
|
+
TILES_CHESSBOARD = 'chessboard'
|
|
61
|
+
GEOCODING_PROVIDER_URL = 'geocoding_url'
|
|
62
|
+
GEOCODING_ROUTE = '/map_data/geocoding'
|
|
63
|
+
FRAGMENTS_ENABLED = 'fragments_enabled'
|
|
64
|
+
|
|
65
|
+
_DATALORE_TILES_SERVICE = 'wss://tiles.datalore.jetbrains.com'
|
|
66
|
+
_DATALORE_TILES_ATTRIBUTION = '<a href="https://lets-plot.org">\u00a9 Lets-Plot</a>, map data: <a href="https://www.openstreetmap.org/copyright">\u00a9 OpenStreetMap contributors</a>.'
|
|
67
|
+
_DATALORE_TILES_THEME = 'color'
|
|
68
|
+
_DATALORE_TILES_MIN_ZOOM = 1
|
|
69
|
+
_DATALORE_TILES_MAX_ZOOM = 15
|
|
70
|
+
_DATALORE_GEOCODING_SERVICE = 'https://geo2.datalore.jetbrains.com'
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _init_value(actual_name: str, def_val: Any) -> Any:
|
|
74
|
+
env_val = _get_env_val(actual_name)
|
|
75
|
+
return env_val if env_val else def_val
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _get_env_val(actual_name: str) -> Any:
|
|
79
|
+
env_name = "LETS_PLOT_{}".format(actual_name.upper())
|
|
80
|
+
return os.environ.get(env_name)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
_settings = {
|
|
84
|
+
OFFLINE: _init_value(OFFLINE, False), # default: download from CDN
|
|
85
|
+
NO_JS: _init_value(NO_JS, False),
|
|
86
|
+
# JS_BASE_URL: 'https://dl.bintray.com/jetbrains/lets-plot',
|
|
87
|
+
# JS_BASE_URL: "https://cdnjs.cloudflare.com/ajax/libs/lets-plot",
|
|
88
|
+
JS_BASE_URL: "https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v{version}".format(version=__version__),
|
|
89
|
+
JS_PATH_TO_FILE: "js-package/distr",
|
|
90
|
+
JS_NAME: '', # default: lets-plot.min.js
|
|
91
|
+
GEOCODING_PROVIDER_URL: _init_value(GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
|
|
92
|
+
MAPTILES_KIND: _init_value(MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
|
|
93
|
+
MAPTILES_URL: _init_value(MAPTILES_URL, _DATALORE_TILES_SERVICE),
|
|
94
|
+
MAPTILES_ATTRIBUTION: _init_value(MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
|
|
95
|
+
MAPTILES_THEME: _init_value(MAPTILES_THEME, _DATALORE_TILES_THEME),
|
|
96
|
+
MAPTILES_MIN_ZOOM: _init_value(MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
|
|
97
|
+
MAPTILES_MAX_ZOOM: _init_value(MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
|
|
98
|
+
|
|
99
|
+
'dev_' + OFFLINE: _init_value('dev_' + OFFLINE, True), # default: embed js into the notebook
|
|
100
|
+
'dev_' + NO_JS: _init_value('dev_' + NO_JS, False),
|
|
101
|
+
# We don't publish "dev" version, it must be served on localhost:
|
|
102
|
+
# $ cd lets-plot
|
|
103
|
+
# ./gradlew js-package:jsBrowserDevelopmentWebpack
|
|
104
|
+
# $ python -m http.server 8080
|
|
105
|
+
'dev_' + JS_BASE_URL: "http://127.0.0.1:8080",
|
|
106
|
+
'dev_' + JS_PATH_TO_FILE: "js-package/build/dist/js/developmentExecutable",
|
|
107
|
+
'dev_' + JS_NAME: '', # default: lets-plot.js
|
|
108
|
+
'dev_' + GEOCODING_PROVIDER_URL: _init_value('dev_' + GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
|
|
109
|
+
'dev_' + MAPTILES_KIND: _init_value('dev_' + MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
|
|
110
|
+
'dev_' + MAPTILES_URL: _init_value('dev_' + MAPTILES_URL, _DATALORE_TILES_SERVICE),
|
|
111
|
+
'dev_' + MAPTILES_ATTRIBUTION: _init_value('dev_' + MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
|
|
112
|
+
'dev_' + MAPTILES_THEME: _init_value('dev_' + MAPTILES_THEME, _DATALORE_TILES_THEME),
|
|
113
|
+
'dev_' + MAPTILES_MIN_ZOOM: _init_value('dev_' + MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
|
|
114
|
+
'dev_' + MAPTILES_MAX_ZOOM: _init_value('dev_' + MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _to_actual_name(name: str) -> str:
|
|
119
|
+
if name.startswith("dev_"):
|
|
120
|
+
return name
|
|
121
|
+
|
|
122
|
+
return name if is_production() else 'dev_' + name
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _get_global_val_intern(actual_name: str) -> Any:
|
|
126
|
+
# `settings` dict has precedence over environment variables.
|
|
127
|
+
env_val = _get_env_val(actual_name)
|
|
128
|
+
return _settings.get(actual_name, env_val)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def is_production() -> bool:
|
|
132
|
+
return 'dev' not in __version__
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def get_js_cdn_url() -> str:
|
|
136
|
+
if has_global_value(JS_URL_MANUAL):
|
|
137
|
+
return get_global_str(JS_URL_MANUAL)
|
|
138
|
+
|
|
139
|
+
base_url = get_global_str(JS_BASE_URL)
|
|
140
|
+
|
|
141
|
+
js_path_to_file = get_global_str(JS_PATH_TO_FILE)
|
|
142
|
+
|
|
143
|
+
if has_global_value(JS_NAME):
|
|
144
|
+
name = get_global_str(JS_NAME)
|
|
145
|
+
else:
|
|
146
|
+
name = "lets-plot.min.js" if is_production() else "lets-plot.js".format(version=__version__)
|
|
147
|
+
# name = "lets-plot-{version}.{suffix}".format(version=__version__, suffix=suffix)
|
|
148
|
+
# name = "lets-plot.{suffix}".format(suffix=suffix)
|
|
149
|
+
|
|
150
|
+
# url = "{base_url}/{name}".format(base_url=base_url, name=name)
|
|
151
|
+
url = "{base_url}/{js_path_to_file}/{name}".format(base_url=base_url, js_path_to_file=js_path_to_file, name=name)
|
|
152
|
+
return url
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def has_global_value(name: str) -> bool:
|
|
156
|
+
val = _get_global_val_intern(_to_actual_name(name))
|
|
157
|
+
|
|
158
|
+
if isinstance(val, bool):
|
|
159
|
+
return True
|
|
160
|
+
if isinstance(val, str) and not val.strip():
|
|
161
|
+
return False
|
|
162
|
+
return bool(val)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def get_global_val(name: str) -> Any:
|
|
166
|
+
if not has_global_value(name):
|
|
167
|
+
raise ValueError("Not defined '{}'".format(_to_actual_name(name)))
|
|
168
|
+
|
|
169
|
+
return _get_global_val_intern(_to_actual_name(name))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def get_global_str(name: str) -> str:
|
|
173
|
+
val = get_global_val(name)
|
|
174
|
+
if not isinstance(val, str):
|
|
175
|
+
raise ValueError("Not string value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
|
|
176
|
+
return val
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def get_global_bool(name: str) -> bool:
|
|
180
|
+
val = get_global_val(name)
|
|
181
|
+
if isinstance(val, bool):
|
|
182
|
+
return val
|
|
183
|
+
|
|
184
|
+
if isinstance(val, str):
|
|
185
|
+
if val.lower() in ['true', '1', 't', 'y', 'yes']:
|
|
186
|
+
return True
|
|
187
|
+
elif val.lower() in ['false', '0', 'f', 'n', 'no']:
|
|
188
|
+
return False
|
|
189
|
+
else:
|
|
190
|
+
raise ValueError("Can't convert str to boolean : ['{}'] : {}".format(_to_actual_name(name), val))
|
|
191
|
+
|
|
192
|
+
raise ValueError("Not boolean value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
|
lets_plot/_kbridge.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Copyright (c) 2020. JetBrains s.r.o.
|
|
2
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
3
|
+
|
|
4
|
+
# noinspection PyUnresolvedReferences
|
|
5
|
+
from typing import Dict
|
|
6
|
+
|
|
7
|
+
import lets_plot_kotlin_bridge
|
|
8
|
+
|
|
9
|
+
from ._global_settings import get_js_cdn_url
|
|
10
|
+
from ._type_utils import standardize_dict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _generate_dynamic_display_html(plot_spec: Dict) -> str:
|
|
14
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
15
|
+
return lets_plot_kotlin_bridge.generate_html(plot_spec)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _generate_svg(plot_spec: Dict, w: float = None, h: float = None, unit: str = None, use_css_pixelated_image_rendering: bool=True) -> str:
|
|
19
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
20
|
+
w = -1.0 if w is None else float(w)
|
|
21
|
+
h = -1.0 if h is None else float(h)
|
|
22
|
+
unit = '' if unit is None else str(unit) # None is not a valid value for str type - PyArg_ParseTuple will fail
|
|
23
|
+
return lets_plot_kotlin_bridge.export_svg(plot_spec, w, h, unit, use_css_pixelated_image_rendering)
|
|
24
|
+
|
|
25
|
+
def _generate_png(bytestring: Dict, output_width: float, output_height: float, unit: str, dpi: int, scale: float) -> str:
|
|
26
|
+
"""
|
|
27
|
+
Export a plot to PNG format. Returns base64 encoded string of the PNG image.
|
|
28
|
+
"""
|
|
29
|
+
plot_spec = _standardize_plot_spec(bytestring)
|
|
30
|
+
output_width = -1.0 if output_width is None else float(output_width)
|
|
31
|
+
output_height = -1.0 if output_height is None else float(output_height)
|
|
32
|
+
unit = '' if unit is None else str(unit) # None is not a valid value for str type - PyArg_ParseTuple will fail
|
|
33
|
+
dpi = -1 if dpi is None else int(dpi)
|
|
34
|
+
scale = -1.0 if scale is None else float(scale)
|
|
35
|
+
return lets_plot_kotlin_bridge.export_png(plot_spec, output_width, output_height, unit, dpi, scale)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _generate_static_html_page(plot_spec: Dict, iframe: bool) -> str:
|
|
39
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
40
|
+
scriptUrl = get_js_cdn_url()
|
|
41
|
+
return lets_plot_kotlin_bridge.export_html(plot_spec, scriptUrl, iframe)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _standardize_plot_spec(plot_spec: Dict) -> Dict:
|
|
45
|
+
"""
|
|
46
|
+
:param plot_spec: dict
|
|
47
|
+
"""
|
|
48
|
+
if not isinstance(plot_spec, dict):
|
|
49
|
+
raise ValueError("dict expected but was {}".format(type(plot_spec)))
|
|
50
|
+
|
|
51
|
+
return standardize_dict(plot_spec)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _generate_static_configure_html() -> str:
|
|
55
|
+
"""
|
|
56
|
+
Generate static HTML configuration.
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
str
|
|
61
|
+
HTML string containing the static configuration with the script URL from global settings.
|
|
62
|
+
"""
|
|
63
|
+
scriptUrl = get_js_cdn_url()
|
|
64
|
+
return lets_plot_kotlin_bridge.get_static_configure_html(scriptUrl)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _generate_display_html_for_raw_spec(
|
|
68
|
+
plot_spec: Dict,
|
|
69
|
+
sizing_options: Dict,
|
|
70
|
+
*,
|
|
71
|
+
dynamic_script_loading: bool = False,
|
|
72
|
+
force_immediate_render: bool = False,
|
|
73
|
+
responsive: bool = False
|
|
74
|
+
) -> str:
|
|
75
|
+
"""
|
|
76
|
+
Generate HTML for displaying a plot from 'raw' specification (not processed by plot backend)
|
|
77
|
+
with customizable options.
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
plot_spec : Dict
|
|
82
|
+
Dict containing the plot specification.
|
|
83
|
+
sizing_options : Dict
|
|
84
|
+
Dict containing sizing policy options (width_mode, height_mode, width, height).
|
|
85
|
+
dynamic_script_loading : bool, default=False
|
|
86
|
+
Controls how the generated JS code interacts with the lets-plot JS library.
|
|
87
|
+
If True, assumes the library will be loaded dynamically.
|
|
88
|
+
If False, assumes the library is already present in the page header (static loading).
|
|
89
|
+
force_immediate_render : bool, default=False
|
|
90
|
+
Controls the timing of plot rendering.
|
|
91
|
+
If True, forces immediate plot rendering.
|
|
92
|
+
If False, waits for ResizeObserver(JS) event and renders the plot after the plot
|
|
93
|
+
container is properly layouted in DOM.
|
|
94
|
+
responsive : bool, default=False
|
|
95
|
+
If True, makes the plot responsive to container size changes.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
str
|
|
100
|
+
HTML string containing the plot with specified options.
|
|
101
|
+
|
|
102
|
+
Notes
|
|
103
|
+
-----
|
|
104
|
+
The sizing_options dict supports the following structure:
|
|
105
|
+
{
|
|
106
|
+
'width_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
|
|
107
|
+
'height_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
|
|
108
|
+
'width': number, # optional
|
|
109
|
+
'height': number # optional
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Sizing modes determine how the plot dimensions are calculated:
|
|
113
|
+
|
|
114
|
+
1. FIXED mode:
|
|
115
|
+
- Uses the explicitly provided width/height values
|
|
116
|
+
- Falls back to the default figure size if no values provided
|
|
117
|
+
- Not responsive to container size
|
|
118
|
+
|
|
119
|
+
2. MIN mode:
|
|
120
|
+
Applies the smallest dimension among:
|
|
121
|
+
- The default figure size
|
|
122
|
+
- The specified width/height (if provided)
|
|
123
|
+
- The container size (if available)
|
|
124
|
+
|
|
125
|
+
3. FIT mode:
|
|
126
|
+
Uses either:
|
|
127
|
+
- The specified width/height if provided
|
|
128
|
+
- Otherwise uses container size if available
|
|
129
|
+
- Falls back to default figure size if neither is available
|
|
130
|
+
|
|
131
|
+
4. SCALED mode:
|
|
132
|
+
- Always preserves the figure's aspect ratio
|
|
133
|
+
- Typical usage: one dimension (usually width) uses FIXED/MIN/FIT mode
|
|
134
|
+
and SCALED height adjusts to maintain aspect ratio
|
|
135
|
+
- Special case: when both width and height are SCALED:
|
|
136
|
+
* Requires container size to be available
|
|
137
|
+
* Fits figure within container while preserving aspect ratio
|
|
138
|
+
* Neither dimension is predetermined
|
|
139
|
+
|
|
140
|
+
"""
|
|
141
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
142
|
+
sizing_options = standardize_dict(sizing_options)
|
|
143
|
+
return lets_plot_kotlin_bridge.get_display_html_for_raw_spec(
|
|
144
|
+
plot_spec,
|
|
145
|
+
sizing_options,
|
|
146
|
+
dynamic_script_loading,
|
|
147
|
+
force_immediate_render,
|
|
148
|
+
responsive
|
|
149
|
+
)
|