lets-plot 4.6.0rc1__cp39-cp39-macosx_10_15_x86_64.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.

Files changed (91) hide show
  1. lets_plot/__init__.py +283 -0
  2. lets_plot/_global_settings.py +191 -0
  3. lets_plot/_kbridge.py +134 -0
  4. lets_plot/_type_utils.py +110 -0
  5. lets_plot/_version.py +6 -0
  6. lets_plot/bistro/__init__.py +16 -0
  7. lets_plot/bistro/_plot2d_common.py +100 -0
  8. lets_plot/bistro/corr.py +447 -0
  9. lets_plot/bistro/im.py +196 -0
  10. lets_plot/bistro/joint.py +192 -0
  11. lets_plot/bistro/qq.py +207 -0
  12. lets_plot/bistro/residual.py +341 -0
  13. lets_plot/bistro/waterfall.py +252 -0
  14. lets_plot/export/__init__.py +6 -0
  15. lets_plot/export/ggsave_.py +133 -0
  16. lets_plot/frontend_context/__init__.py +8 -0
  17. lets_plot/frontend_context/_configuration.py +144 -0
  18. lets_plot/frontend_context/_frontend_ctx.py +16 -0
  19. lets_plot/frontend_context/_html_contexts.py +117 -0
  20. lets_plot/frontend_context/_intellij_python_json_ctx.py +38 -0
  21. lets_plot/frontend_context/_json_contexts.py +39 -0
  22. lets_plot/frontend_context/_jupyter_notebook_ctx.py +119 -0
  23. lets_plot/frontend_context/_mime_types.py +7 -0
  24. lets_plot/frontend_context/_static_html_page_ctx.py +27 -0
  25. lets_plot/frontend_context/_static_svg_ctx.py +26 -0
  26. lets_plot/frontend_context/_webbr_html_page_ctx.py +29 -0
  27. lets_plot/frontend_context/sandbox.py +5 -0
  28. lets_plot/geo_data/__init__.py +18 -0
  29. lets_plot/geo_data/core.py +331 -0
  30. lets_plot/geo_data/geocoder.py +977 -0
  31. lets_plot/geo_data/geocodes.py +512 -0
  32. lets_plot/geo_data/gis/__init__.py +0 -0
  33. lets_plot/geo_data/gis/fluent_dict.py +201 -0
  34. lets_plot/geo_data/gis/geocoding_service.py +42 -0
  35. lets_plot/geo_data/gis/geometry.py +91 -0
  36. lets_plot/geo_data/gis/json_request.py +232 -0
  37. lets_plot/geo_data/gis/json_response.py +308 -0
  38. lets_plot/geo_data/gis/request.py +492 -0
  39. lets_plot/geo_data/gis/response.py +247 -0
  40. lets_plot/geo_data/livemap_helper.py +65 -0
  41. lets_plot/geo_data/to_geo_data_frame.py +141 -0
  42. lets_plot/geo_data/type_assertion.py +34 -0
  43. lets_plot/geo_data_internals/__init__.py +4 -0
  44. lets_plot/geo_data_internals/constants.py +13 -0
  45. lets_plot/geo_data_internals/utils.py +33 -0
  46. lets_plot/mapping.py +115 -0
  47. lets_plot/package_data/lets-plot.min.js +2 -0
  48. lets_plot/plot/__init__.py +64 -0
  49. lets_plot/plot/_global_theme.py +14 -0
  50. lets_plot/plot/annotation.py +233 -0
  51. lets_plot/plot/coord.py +242 -0
  52. lets_plot/plot/core.py +943 -0
  53. lets_plot/plot/expand_limits_.py +78 -0
  54. lets_plot/plot/facet.py +206 -0
  55. lets_plot/plot/font_features.py +71 -0
  56. lets_plot/plot/geom.py +8160 -0
  57. lets_plot/plot/geom_extras.py +53 -0
  58. lets_plot/plot/geom_function_.py +216 -0
  59. lets_plot/plot/geom_imshow_.py +401 -0
  60. lets_plot/plot/geom_livemap_.py +330 -0
  61. lets_plot/plot/ggbunch_.py +96 -0
  62. lets_plot/plot/gggrid_.py +126 -0
  63. lets_plot/plot/ggtb_.py +56 -0
  64. lets_plot/plot/guide.py +229 -0
  65. lets_plot/plot/label.py +187 -0
  66. lets_plot/plot/marginal_layer.py +181 -0
  67. lets_plot/plot/plot.py +244 -0
  68. lets_plot/plot/pos.py +346 -0
  69. lets_plot/plot/sampling.py +338 -0
  70. lets_plot/plot/sandbox_.py +26 -0
  71. lets_plot/plot/scale.py +3577 -0
  72. lets_plot/plot/scale_colormap_mpl.py +297 -0
  73. lets_plot/plot/scale_convenience.py +155 -0
  74. lets_plot/plot/scale_identity_.py +658 -0
  75. lets_plot/plot/scale_position.py +1336 -0
  76. lets_plot/plot/series_meta.py +129 -0
  77. lets_plot/plot/stat.py +581 -0
  78. lets_plot/plot/subplots.py +322 -0
  79. lets_plot/plot/subplots_util.py +24 -0
  80. lets_plot/plot/theme_.py +766 -0
  81. lets_plot/plot/theme_set.py +393 -0
  82. lets_plot/plot/tooltip.py +486 -0
  83. lets_plot/plot/util.py +226 -0
  84. lets_plot/settings_utils.py +244 -0
  85. lets_plot/tilesets.py +364 -0
  86. lets_plot-4.6.0rc1.dist-info/LICENSE +21 -0
  87. lets_plot-4.6.0rc1.dist-info/METADATA +199 -0
  88. lets_plot-4.6.0rc1.dist-info/RECORD +91 -0
  89. lets_plot-4.6.0rc1.dist-info/WHEEL +5 -0
  90. lets_plot-4.6.0rc1.dist-info/top_level.txt +2 -0
  91. lets_plot_kotlin_bridge.cpython-39-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,134 @@
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, 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)
37
+
38
+
39
+ def _generate_static_configure_html() -> str:
40
+ """
41
+ Generate static HTML configuration.
42
+
43
+ Returns
44
+ -------
45
+ str
46
+ HTML string containing the static configuration with the script URL from global settings.
47
+ """
48
+ scriptUrl = get_js_cdn_url()
49
+ return lets_plot_kotlin_bridge.get_static_configure_html(scriptUrl)
50
+
51
+
52
+ def _generate_display_html_for_raw_spec(
53
+ plot_spec: Dict,
54
+ sizing_options: Dict,
55
+ *,
56
+ dynamic_script_loading: bool = False,
57
+ force_immediate_render: bool = False,
58
+ responsive: bool = False
59
+ ) -> str:
60
+ """
61
+ Generate HTML for displaying a plot from 'raw' specification (not processed by plot backend)
62
+ with customizable options.
63
+
64
+ Parameters
65
+ ----------
66
+ plot_spec : Dict
67
+ Dict containing the plot specification.
68
+ sizing_options : Dict
69
+ Dict containing sizing policy options (width_mode, height_mode, width, height).
70
+ dynamic_script_loading : bool, default=False
71
+ Controls how the generated JS code interacts with the lets-plot JS library.
72
+ If True, assumes the library will be loaded dynamically.
73
+ If False, assumes the library is already present in the page header (static loading).
74
+ force_immediate_render : bool, default=False
75
+ Controls the timing of plot rendering.
76
+ If True, forces immediate plot rendering.
77
+ If False, waits for ResizeObserver(JS) event and renders the plot after the plot
78
+ container is properly layouted in DOM.
79
+ responsive : bool, default=False
80
+ If True, makes the plot responsive to container size changes.
81
+
82
+ Returns
83
+ -------
84
+ str
85
+ HTML string containing the plot with specified options.
86
+
87
+ Notes
88
+ -----
89
+ The sizing_options dict supports the following structure:
90
+ {
91
+ 'width_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
92
+ 'height_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
93
+ 'width': number, # optional
94
+ 'height': number # optional
95
+ }
96
+
97
+ Sizing modes determine how the plot dimensions are calculated:
98
+
99
+ 1. FIXED mode:
100
+ - Uses the explicitly provided width/height values
101
+ - Falls back to the default figure size if no values provided
102
+ - Not responsive to container size
103
+
104
+ 2. MIN mode:
105
+ Applies the smallest dimension among:
106
+ - The default figure size
107
+ - The specified width/height (if provided)
108
+ - The container size (if available)
109
+
110
+ 3. FIT mode:
111
+ Uses either:
112
+ - The specified width/height if provided
113
+ - Otherwise uses container size if available
114
+ - Falls back to default figure size if neither is available
115
+
116
+ 4. SCALED mode:
117
+ - Always preserves the figure's aspect ratio
118
+ - Typical usage: one dimension (usually width) uses FIXED/MIN/FIT mode
119
+ and SCALED height adjusts to maintain aspect ratio
120
+ - Special case: when both width and height are SCALED:
121
+ * Requires container size to be available
122
+ * Fits figure within container while preserving aspect ratio
123
+ * Neither dimension is predetermined
124
+
125
+ """
126
+ plot_spec = _standardize_plot_spec(plot_spec)
127
+ sizing_options = standardize_dict(sizing_options)
128
+ return lets_plot_kotlin_bridge.get_display_html_for_raw_spec(
129
+ plot_spec,
130
+ sizing_options,
131
+ dynamic_script_loading,
132
+ force_immediate_render,
133
+ responsive
134
+ )