lets-plot 4.5.0__cp313-cp313-macosx_11_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 +191 -0
- lets_plot/_kbridge.py +36 -0
- lets_plot/_type_utils.py +110 -0
- lets_plot/_version.py +6 -0
- lets_plot/bistro/__init__.py +16 -0
- lets_plot/bistro/_plot2d_common.py +93 -0
- lets_plot/bistro/corr.py +447 -0
- lets_plot/bistro/im.py +165 -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 +250 -0
- lets_plot/export/__init__.py +6 -0
- lets_plot/export/ggsave_.py +133 -0
- lets_plot/frontend_context/__init__.py +8 -0
- lets_plot/frontend_context/_configuration.py +144 -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 +18 -0
- lets_plot/geo_data/core.py +331 -0
- lets_plot/geo_data/geocoder.py +977 -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 +2 -0
- lets_plot/plot/__init__.py +62 -0
- lets_plot/plot/_global_theme.py +14 -0
- lets_plot/plot/annotation.py +233 -0
- lets_plot/plot/coord.py +242 -0
- lets_plot/plot/core.py +943 -0
- lets_plot/plot/expand_limits_.py +78 -0
- lets_plot/plot/facet.py +206 -0
- lets_plot/plot/font_features.py +71 -0
- lets_plot/plot/geom.py +7897 -0
- lets_plot/plot/geom_extras.py +53 -0
- lets_plot/plot/geom_function_.py +216 -0
- lets_plot/plot/geom_imshow_.py +401 -0
- lets_plot/plot/geom_livemap_.py +330 -0
- lets_plot/plot/gggrid_.py +141 -0
- lets_plot/plot/ggtb_.py +56 -0
- lets_plot/plot/guide.py +229 -0
- lets_plot/plot/label.py +187 -0
- lets_plot/plot/marginal_layer.py +181 -0
- lets_plot/plot/plot.py +237 -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 +3552 -0
- lets_plot/plot/scale_colormap_mpl.py +297 -0
- lets_plot/plot/scale_convenience.py +155 -0
- lets_plot/plot/scale_identity_.py +658 -0
- lets_plot/plot/scale_position.py +1336 -0
- lets_plot/plot/series_meta.py +123 -0
- lets_plot/plot/stat.py +581 -0
- lets_plot/plot/subplots.py +322 -0
- lets_plot/plot/theme_.py +681 -0
- lets_plot/plot/theme_set.py +393 -0
- lets_plot/plot/tooltip.py +486 -0
- lets_plot/plot/util.py +226 -0
- lets_plot/settings_utils.py +244 -0
- lets_plot/tilesets.py +364 -0
- lets_plot-4.5.0.dist-info/LICENSE +21 -0
- lets_plot-4.5.0.dist-info/METADATA +186 -0
- lets_plot-4.5.0.dist-info/RECORD +89 -0
- lets_plot-4.5.0.dist-info/WHEEL +5 -0
- lets_plot-4.5.0.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 HTLM 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()`.
|
|
123
|
+
- offline : to work with notebook without the Internet connection (bool). Do not use this parameter explicitly. Instead you should call `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()`. 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()` and `maptiles_lets_plot()`.
|
|
129
|
+
- maptiles_url : address of the tile server (str). Do not use this parameter explicitly. Instead you should construct it with functions `maptiles_zxy()` and `maptiles_lets_plot()`.
|
|
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()`.
|
|
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()`.
|
|
132
|
+
- maptiles_min_zoom : minimal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function `maptiles_zxy()`.
|
|
133
|
+
- maptiles_max_zoom : maximal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function `maptiles_zxy()`.
|
|
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(...)`, `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,191 @@
|
|
|
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_MAPTILES_KIND = 'LETS_PLOT_DEV_MAPTILES_KIND'
|
|
33
|
+
ENV_DEV_MAPTILES_URL = 'LETS_PLOT_DEV_MAPTILES_URL'
|
|
34
|
+
ENV_DEV_MAPTILES_THEME = 'LETS_PLOT_DEV_MAPTILES_THEME'
|
|
35
|
+
ENV_DEV_GEOCODING_URL = 'LETS_PLOT_DEV_GEOCODING_URL'
|
|
36
|
+
|
|
37
|
+
# Options
|
|
38
|
+
|
|
39
|
+
HTML_ISOLATED_FRAME = 'html_isolated_frame'
|
|
40
|
+
OFFLINE = 'offline'
|
|
41
|
+
NO_JS = 'no_js'
|
|
42
|
+
JS_BASE_URL = 'js_base_url'
|
|
43
|
+
JS_PATH_TO_FILE = 'js_path_to_file'
|
|
44
|
+
JS_NAME = 'js_name'
|
|
45
|
+
JS_URL_MANUAL = 'js_url_manual'
|
|
46
|
+
MAX_WIDTH = 'max_width'
|
|
47
|
+
MAX_HEIGHT = 'max_height'
|
|
48
|
+
|
|
49
|
+
MAPTILES_KIND = 'maptiles_kind'
|
|
50
|
+
MAPTILES_URL = 'maptiles_url'
|
|
51
|
+
MAPTILES_THEME = 'maptiles_theme'
|
|
52
|
+
MAPTILES_ATTRIBUTION = 'maptiles_attribution'
|
|
53
|
+
MAPTILES_MIN_ZOOM = 'maptiles_min_zoom'
|
|
54
|
+
MAPTILES_MAX_ZOOM = 'maptiles_max_zoom'
|
|
55
|
+
MAPTILES_SOLID_FILL_COLOR = 'maptiles_fill_color'
|
|
56
|
+
TILES_VECTOR_LETS_PLOT = 'vector_lets_plot'
|
|
57
|
+
TILES_RASTER_ZXY = 'raster_zxy'
|
|
58
|
+
TILES_SOLID = 'solid'
|
|
59
|
+
TILES_CHESSBOARD = 'chessboard'
|
|
60
|
+
GEOCODING_PROVIDER_URL = 'geocoding_url'
|
|
61
|
+
GEOCODING_ROUTE = '/map_data/geocoding'
|
|
62
|
+
FRAGMENTS_ENABLED = 'fragments_enabled'
|
|
63
|
+
|
|
64
|
+
_DATALORE_TILES_SERVICE = 'wss://tiles.datalore.jetbrains.com'
|
|
65
|
+
_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>.'
|
|
66
|
+
_DATALORE_TILES_THEME = 'color'
|
|
67
|
+
_DATALORE_TILES_MIN_ZOOM = 1
|
|
68
|
+
_DATALORE_TILES_MAX_ZOOM = 15
|
|
69
|
+
_DATALORE_GEOCODING_SERVICE = 'https://geo2.datalore.jetbrains.com'
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _init_value(actual_name: str, def_val: Any) -> Any:
|
|
73
|
+
env_val = _get_env_val(actual_name)
|
|
74
|
+
return env_val if env_val else def_val
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _get_env_val(actual_name: str) -> Any:
|
|
78
|
+
env_name = "LETS_PLOT_{}".format(actual_name.upper())
|
|
79
|
+
return os.environ.get(env_name)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
_settings = {
|
|
83
|
+
OFFLINE: _init_value(OFFLINE, False), # default: download from CDN
|
|
84
|
+
NO_JS: _init_value(NO_JS, False),
|
|
85
|
+
# JS_BASE_URL: 'https://dl.bintray.com/jetbrains/lets-plot',
|
|
86
|
+
# JS_BASE_URL: "https://cdnjs.cloudflare.com/ajax/libs/lets-plot",
|
|
87
|
+
JS_BASE_URL: "https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v{version}".format(version=__version__),
|
|
88
|
+
JS_PATH_TO_FILE: "js-package/distr",
|
|
89
|
+
JS_NAME: '', # default: lets-plot.min.js
|
|
90
|
+
GEOCODING_PROVIDER_URL: _init_value(GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
|
|
91
|
+
MAPTILES_KIND: _init_value(MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
|
|
92
|
+
MAPTILES_URL: _init_value(MAPTILES_URL, _DATALORE_TILES_SERVICE),
|
|
93
|
+
MAPTILES_ATTRIBUTION: _init_value(MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
|
|
94
|
+
MAPTILES_THEME: _init_value(MAPTILES_THEME, _DATALORE_TILES_THEME),
|
|
95
|
+
MAPTILES_MIN_ZOOM: _init_value(MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
|
|
96
|
+
MAPTILES_MAX_ZOOM: _init_value(MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
|
|
97
|
+
|
|
98
|
+
'dev_' + OFFLINE: _init_value('dev_' + OFFLINE, True), # default: embed js into the notebook
|
|
99
|
+
'dev_' + NO_JS: _init_value('dev_' + NO_JS, False),
|
|
100
|
+
# We don't publish "dev" version, it must be served on localhost:
|
|
101
|
+
# $ cd lets-plot
|
|
102
|
+
# ./gradlew js-package:jsBrowserDevelopmentWebpack
|
|
103
|
+
# $ python -m http.server 8080
|
|
104
|
+
'dev_' + JS_BASE_URL: "http://127.0.0.1:8080",
|
|
105
|
+
'dev_' + JS_PATH_TO_FILE: "js-package/build/dist/js/developmentExecutable",
|
|
106
|
+
'dev_' + JS_NAME: '', # default: lets-plot.js
|
|
107
|
+
'dev_' + GEOCODING_PROVIDER_URL: _init_value('dev_' + GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
|
|
108
|
+
'dev_' + MAPTILES_KIND: _init_value('dev_' + MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
|
|
109
|
+
'dev_' + MAPTILES_URL: _init_value('dev_' + MAPTILES_URL, _DATALORE_TILES_SERVICE),
|
|
110
|
+
'dev_' + MAPTILES_ATTRIBUTION: _init_value('dev_' + MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
|
|
111
|
+
'dev_' + MAPTILES_THEME: _init_value('dev_' + MAPTILES_THEME, _DATALORE_TILES_THEME),
|
|
112
|
+
'dev_' + MAPTILES_MIN_ZOOM: _init_value('dev_' + MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
|
|
113
|
+
'dev_' + MAPTILES_MAX_ZOOM: _init_value('dev_' + MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _to_actual_name(name: str) -> str:
|
|
118
|
+
if name.startswith("dev_"):
|
|
119
|
+
return name
|
|
120
|
+
|
|
121
|
+
return name if is_production() else 'dev_' + name
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _get_global_val_intern(actual_name: str) -> Any:
|
|
125
|
+
# `settings` dict has precedence over environment variables.
|
|
126
|
+
env_val = _get_env_val(actual_name)
|
|
127
|
+
return _settings.get(actual_name, env_val)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def is_production() -> bool:
|
|
131
|
+
return 'dev' not in __version__
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def get_js_cdn_url() -> str:
|
|
135
|
+
if has_global_value(JS_URL_MANUAL):
|
|
136
|
+
return get_global_str(JS_URL_MANUAL)
|
|
137
|
+
|
|
138
|
+
base_url = get_global_str(JS_BASE_URL)
|
|
139
|
+
|
|
140
|
+
js_path_to_file = get_global_str(JS_PATH_TO_FILE)
|
|
141
|
+
|
|
142
|
+
if has_global_value(JS_NAME):
|
|
143
|
+
name = get_global_str(JS_NAME)
|
|
144
|
+
else:
|
|
145
|
+
name = "lets-plot.min.js" if is_production() else "lets-plot.js".format(version=__version__)
|
|
146
|
+
# name = "lets-plot-{version}.{suffix}".format(version=__version__, suffix=suffix)
|
|
147
|
+
# name = "lets-plot.{suffix}".format(suffix=suffix)
|
|
148
|
+
|
|
149
|
+
# url = "{base_url}/{name}".format(base_url=base_url, name=name)
|
|
150
|
+
url = "{base_url}/{js_path_to_file}/{name}".format(base_url=base_url, js_path_to_file=js_path_to_file, name=name)
|
|
151
|
+
return url
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def has_global_value(name: str) -> bool:
|
|
155
|
+
val = _get_global_val_intern(_to_actual_name(name))
|
|
156
|
+
|
|
157
|
+
if isinstance(val, bool):
|
|
158
|
+
return True
|
|
159
|
+
if isinstance(val, str) and not val.strip():
|
|
160
|
+
return False
|
|
161
|
+
return bool(val)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def get_global_val(name: str) -> Any:
|
|
165
|
+
if not has_global_value(name):
|
|
166
|
+
raise ValueError("Not defined '{}'".format(_to_actual_name(name)))
|
|
167
|
+
|
|
168
|
+
return _get_global_val_intern(_to_actual_name(name))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def get_global_str(name: str) -> str:
|
|
172
|
+
val = get_global_val(name)
|
|
173
|
+
if not isinstance(val, str):
|
|
174
|
+
raise ValueError("Not string value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
|
|
175
|
+
return val
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def get_global_bool(name: str) -> bool:
|
|
179
|
+
val = get_global_val(name)
|
|
180
|
+
if isinstance(val, bool):
|
|
181
|
+
return val
|
|
182
|
+
|
|
183
|
+
if isinstance(val, str):
|
|
184
|
+
if val.lower() in ['true', '1', 't', 'y', 'yes']:
|
|
185
|
+
return True
|
|
186
|
+
elif val.lower() in ['false', '0', 'f', 'n', 'no']:
|
|
187
|
+
return False
|
|
188
|
+
else:
|
|
189
|
+
raise ValueError("Can't convert str to boolean : ['{}'] : {}".format(_to_actual_name(name), val))
|
|
190
|
+
|
|
191
|
+
raise ValueError("Not boolean value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
|
lets_plot/_kbridge.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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 ._type_utils import standardize_dict
|
|
10
|
+
from ._global_settings import get_js_cdn_url
|
|
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, use_css_pixelated_image_rendering: bool = True) -> str:
|
|
19
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
20
|
+
return lets_plot_kotlin_bridge.export_svg(plot_spec, use_css_pixelated_image_rendering)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _generate_static_html_page(plot_spec: Dict, iframe: bool) -> str:
|
|
24
|
+
plot_spec = _standardize_plot_spec(plot_spec)
|
|
25
|
+
scriptUrl = get_js_cdn_url()
|
|
26
|
+
return lets_plot_kotlin_bridge.export_html(plot_spec, scriptUrl, iframe)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _standardize_plot_spec(plot_spec: Dict) -> Dict:
|
|
30
|
+
"""
|
|
31
|
+
:param plot_spec: dict
|
|
32
|
+
"""
|
|
33
|
+
if not isinstance(plot_spec, dict):
|
|
34
|
+
raise ValueError("dict expected but was {}".format(type(plot_spec)))
|
|
35
|
+
|
|
36
|
+
return standardize_dict(plot_spec)
|
lets_plot/_type_utils.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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 json
|
|
6
|
+
import math
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
|
|
9
|
+
from typing import Dict
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
import numpy
|
|
13
|
+
except ImportError:
|
|
14
|
+
numpy = None
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
import pandas
|
|
18
|
+
except ImportError:
|
|
19
|
+
pandas = None
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
import polars
|
|
23
|
+
except ImportError:
|
|
24
|
+
polars = None
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
import shapely
|
|
28
|
+
import shapely.geometry
|
|
29
|
+
except ImportError:
|
|
30
|
+
shapely = None
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
import jax.numpy as jnp
|
|
34
|
+
except ImportError:
|
|
35
|
+
jnp = None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Parameter 'value' can also be pandas.DataFrame
|
|
39
|
+
def standardize_dict(value: Dict) -> Dict:
|
|
40
|
+
result = {}
|
|
41
|
+
for k, v in value.items():
|
|
42
|
+
result[_standardize_value(k)] = _standardize_value(v)
|
|
43
|
+
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_pandas_data_frame(v) -> bool:
|
|
48
|
+
return pandas and isinstance(v, pandas.DataFrame)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def is_polars_dataframe(v):
|
|
52
|
+
return polars and isinstance(v, polars.DataFrame)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def is_dict_or_dataframe(v):
|
|
56
|
+
return isinstance(v, dict) or (pandas and isinstance(v, pandas.DataFrame))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def is_int(v):
|
|
60
|
+
return isinstance(v, int) or (numpy and isinstance(v, numpy.integer)) or (jnp and isinstance(v, jnp.integer))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def is_float(v):
|
|
64
|
+
return isinstance(v, float) or (numpy and isinstance(v, numpy.floating)) or (jnp and isinstance(v, jnp.floating))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def is_ndarray(data) -> bool:
|
|
68
|
+
return (numpy and isinstance(data, numpy.ndarray)) or (jnp and isinstance(data, jnp.ndarray))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def is_number(v):
|
|
72
|
+
return is_int(v) or is_float(v)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _standardize_value(v):
|
|
76
|
+
if v is None:
|
|
77
|
+
return v
|
|
78
|
+
if isinstance(v, bool):
|
|
79
|
+
return bool(v)
|
|
80
|
+
if isinstance(v, str):
|
|
81
|
+
return str(v)
|
|
82
|
+
if is_float(v):
|
|
83
|
+
if math.isfinite(v):
|
|
84
|
+
return float(v)
|
|
85
|
+
# None for special values like 'nan' etc. because
|
|
86
|
+
# some json parsers (like com.google.gson.Gson) do not handle them well.
|
|
87
|
+
return None
|
|
88
|
+
if is_int(v):
|
|
89
|
+
return float(v)
|
|
90
|
+
if is_dict_or_dataframe(v):
|
|
91
|
+
return standardize_dict(v)
|
|
92
|
+
if is_polars_dataframe(v):
|
|
93
|
+
return standardize_dict(v.to_dict(as_series=False))
|
|
94
|
+
if isinstance(v, list):
|
|
95
|
+
return [_standardize_value(elem) for elem in v]
|
|
96
|
+
if isinstance(v, tuple):
|
|
97
|
+
return tuple(_standardize_value(elem) for elem in v)
|
|
98
|
+
if (numpy and isinstance(v, numpy.ndarray)) or (pandas and isinstance(v, pandas.Series)) or (jnp and isinstance(v, jnp.ndarray)):
|
|
99
|
+
return _standardize_value(v.tolist())
|
|
100
|
+
if isinstance(v, datetime):
|
|
101
|
+
if pandas and v is pandas.NaT:
|
|
102
|
+
return None
|
|
103
|
+
else:
|
|
104
|
+
return v.timestamp() * 1000 # convert from second to millisecond
|
|
105
|
+
if shapely and isinstance(v, shapely.geometry.base.BaseGeometry):
|
|
106
|
+
return json.dumps(shapely.geometry.mapping(v))
|
|
107
|
+
try:
|
|
108
|
+
return repr(v)
|
|
109
|
+
except Exception:
|
|
110
|
+
raise Exception('Unsupported type: {0}({1})'.format(v, type(v)))
|
lets_plot/_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
from .corr import *
|
|
5
|
+
from .im import *
|
|
6
|
+
from .qq import *
|
|
7
|
+
from .residual import *
|
|
8
|
+
from .joint import *
|
|
9
|
+
from .waterfall import *
|
|
10
|
+
|
|
11
|
+
__all__ = (im.__all__ +
|
|
12
|
+
corr.__all__ +
|
|
13
|
+
qq.__all__ +
|
|
14
|
+
residual.__all__ +
|
|
15
|
+
joint.__all__ +
|
|
16
|
+
waterfall.__all__)
|