lets-plot 4.7.0rc1__cp312-cp312-manylinux2014_x86_64.manylinux_2_17_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 (95) hide show
  1. lets_plot/__init__.py +283 -0
  2. lets_plot/_global_settings.py +196 -0
  3. lets_plot/_kbridge.py +141 -0
  4. lets_plot/_type_utils.py +133 -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 +333 -0
  14. lets_plot/export/__init__.py +6 -0
  15. lets_plot/export/ggsave_.py +141 -0
  16. lets_plot/frontend_context/__init__.py +8 -0
  17. lets_plot/frontend_context/_configuration.py +151 -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 +19 -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 +3 -0
  48. lets_plot/plot/__init__.py +64 -0
  49. lets_plot/plot/_global_theme.py +14 -0
  50. lets_plot/plot/annotation.py +290 -0
  51. lets_plot/plot/coord.py +242 -0
  52. lets_plot/plot/core.py +1060 -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 +8839 -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 +392 -0
  60. lets_plot/plot/geom_livemap_.py +310 -0
  61. lets_plot/plot/ggbunch_.py +96 -0
  62. lets_plot/plot/gggrid_.py +126 -0
  63. lets_plot/plot/ggtb_.py +55 -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 +320 -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 +1342 -0
  76. lets_plot/plot/series_meta.py +203 -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 +772 -0
  81. lets_plot/plot/theme_set.py +393 -0
  82. lets_plot/plot/tooltip.py +486 -0
  83. lets_plot/plot/util.py +237 -0
  84. lets_plot/settings_utils.py +244 -0
  85. lets_plot/tilesets.py +429 -0
  86. lets_plot-4.7.0rc1.dist-info/METADATA +196 -0
  87. lets_plot-4.7.0rc1.dist-info/RECORD +95 -0
  88. lets_plot-4.7.0rc1.dist-info/WHEEL +6 -0
  89. lets_plot-4.7.0rc1.dist-info/licenses/LICENSE +21 -0
  90. lets_plot-4.7.0rc1.dist-info/licenses/licenses/LICENSE.FreeType +166 -0
  91. lets_plot-4.7.0rc1.dist-info/licenses/licenses/LICENSE.ImageMagick +106 -0
  92. lets_plot-4.7.0rc1.dist-info/licenses/licenses/LICENSE.expat +21 -0
  93. lets_plot-4.7.0rc1.dist-info/licenses/licenses/LICENSE.fontconfig +200 -0
  94. lets_plot-4.7.0rc1.dist-info/top_level.txt +2 -0
  95. lets_plot_kotlin_bridge.cpython-312-x86_64-linux-gnu.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,196 @@
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_MAGICK_EXPORT = 'LETS_PLOT_MAGICK_EXPORT' # bool
22
+ ENV_MAPTILES_KIND = 'LETS_PLOT_MAPTILES_KIND'
23
+ ENV_MAPTILES_URL = 'LETS_PLOT_MAPTILES_URL'
24
+ ENV_MAPTILES_THEME = 'LETS_PLOT_MAPTILES_THEME'
25
+ ENV_GEOCODING_URL = 'LETS_PLOT_GEOCODING_URL'
26
+
27
+ # Dev mode env variables have 'LETS_PLOT_DEV_' prefix instead of 'LETS_PLOT_'.
28
+ ENV_DEV_HTML_ISOLATED_FRAME = 'LETS_PLOT_DEV_HTML_ISOLATED_FRAME' # bool
29
+ ENV_DEV_OFFLINE = 'LETS_PLOT_DEV_OFFLINE' # bool
30
+ ENV_DEV_NO_JS = 'LETS_PLOT_DEV_NO_JS' # bool
31
+ ENV_DEV_MAX_WIDTH = 'LETS_PLOT_DEV_MAX_WIDTH'
32
+ ENV_DEV_MAX_HEIGHT = 'LETS_PLOT_DEV_MAX_HEIGHT'
33
+ ENV_DEV_MAGICK_EXPORT = 'LETS_PLOT_DEV_MAGICK_EXPORT' # bool
34
+ ENV_DEV_MAPTILES_KIND = 'LETS_PLOT_DEV_MAPTILES_KIND'
35
+ ENV_DEV_MAPTILES_URL = 'LETS_PLOT_DEV_MAPTILES_URL'
36
+ ENV_DEV_MAPTILES_THEME = 'LETS_PLOT_DEV_MAPTILES_THEME'
37
+ ENV_DEV_GEOCODING_URL = 'LETS_PLOT_DEV_GEOCODING_URL'
38
+
39
+ # Options
40
+
41
+ HTML_ISOLATED_FRAME = 'html_isolated_frame'
42
+ OFFLINE = 'offline'
43
+ NO_JS = 'no_js'
44
+ JS_BASE_URL = 'js_base_url'
45
+ JS_PATH_TO_FILE = 'js_path_to_file'
46
+ JS_NAME = 'js_name'
47
+ JS_URL_MANUAL = 'js_url_manual'
48
+ MAX_WIDTH = 'max_width'
49
+ MAX_HEIGHT = 'max_height'
50
+ MAGICK_EXPORT = 'magick_export'
51
+
52
+ MAPTILES_KIND = 'maptiles_kind'
53
+ MAPTILES_URL = 'maptiles_url'
54
+ MAPTILES_THEME = 'maptiles_theme'
55
+ MAPTILES_ATTRIBUTION = 'maptiles_attribution'
56
+ MAPTILES_MIN_ZOOM = 'maptiles_min_zoom'
57
+ MAPTILES_MAX_ZOOM = 'maptiles_max_zoom'
58
+ MAPTILES_SOLID_FILL_COLOR = 'maptiles_fill_color'
59
+ TILES_VECTOR_LETS_PLOT = 'vector_lets_plot'
60
+ TILES_RASTER_ZXY = 'raster_zxy'
61
+ TILES_SOLID = 'solid'
62
+ TILES_CHESSBOARD = 'chessboard'
63
+ GEOCODING_PROVIDER_URL = 'geocoding_url'
64
+ GEOCODING_ROUTE = '/map_data/geocoding'
65
+ FRAGMENTS_ENABLED = 'fragments_enabled'
66
+
67
+ _DATALORE_TILES_SERVICE = 'wss://tiles.datalore.jetbrains.com'
68
+ _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>.'
69
+ _DATALORE_TILES_THEME = 'color'
70
+ _DATALORE_TILES_MIN_ZOOM = 1
71
+ _DATALORE_TILES_MAX_ZOOM = 15
72
+ _DATALORE_GEOCODING_SERVICE = 'https://geo2.datalore.jetbrains.com'
73
+
74
+
75
+ def _init_value(actual_name: str, def_val: Any) -> Any:
76
+ env_val = _get_env_val(actual_name)
77
+ return env_val if env_val else def_val
78
+
79
+
80
+ def _get_env_val(actual_name: str) -> Any:
81
+ env_name = "LETS_PLOT_{}".format(actual_name.upper())
82
+ return os.environ.get(env_name)
83
+
84
+
85
+ _settings = {
86
+ OFFLINE: _init_value(OFFLINE, False), # default: download from CDN
87
+ NO_JS: _init_value(NO_JS, False),
88
+ MAGICK_EXPORT: _init_value(MAGICK_EXPORT, True), # default: use cairo for export
89
+ # JS_BASE_URL: 'https://dl.bintray.com/jetbrains/lets-plot',
90
+ # JS_BASE_URL: "https://cdnjs.cloudflare.com/ajax/libs/lets-plot",
91
+ JS_BASE_URL: "https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v{version}".format(version=__version__),
92
+ JS_PATH_TO_FILE: "js-package/distr",
93
+ JS_NAME: '', # default: lets-plot.min.js
94
+ GEOCODING_PROVIDER_URL: _init_value(GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
95
+ MAPTILES_KIND: _init_value(MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
96
+ MAPTILES_URL: _init_value(MAPTILES_URL, _DATALORE_TILES_SERVICE),
97
+ MAPTILES_ATTRIBUTION: _init_value(MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
98
+ MAPTILES_THEME: _init_value(MAPTILES_THEME, _DATALORE_TILES_THEME),
99
+ MAPTILES_MIN_ZOOM: _init_value(MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
100
+ MAPTILES_MAX_ZOOM: _init_value(MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
101
+
102
+ 'dev_' + OFFLINE: _init_value('dev_' + OFFLINE, True), # default: embed js into the notebook
103
+ 'dev_' + NO_JS: _init_value('dev_' + NO_JS, False),
104
+ 'dev_' + MAGICK_EXPORT: _init_value('dev_' + MAGICK_EXPORT, True), # default: use cairo for export
105
+ # We don't publish "dev" version, it must be served on localhost:
106
+ # $ cd lets-plot
107
+ # ./gradlew js-package:jsBrowserDevelopmentWebpack
108
+ # $ python -m http.server 8080
109
+ 'dev_' + JS_BASE_URL: "http://127.0.0.1:8080",
110
+ 'dev_' + JS_PATH_TO_FILE: "js-package/build/dist/js/developmentExecutable",
111
+ 'dev_' + JS_NAME: '', # default: lets-plot.js
112
+ 'dev_' + GEOCODING_PROVIDER_URL: _init_value('dev_' + GEOCODING_PROVIDER_URL, _DATALORE_GEOCODING_SERVICE),
113
+ 'dev_' + MAPTILES_KIND: _init_value('dev_' + MAPTILES_KIND, TILES_VECTOR_LETS_PLOT),
114
+ 'dev_' + MAPTILES_URL: _init_value('dev_' + MAPTILES_URL, _DATALORE_TILES_SERVICE),
115
+ 'dev_' + MAPTILES_ATTRIBUTION: _init_value('dev_' + MAPTILES_ATTRIBUTION, _DATALORE_TILES_ATTRIBUTION),
116
+ 'dev_' + MAPTILES_THEME: _init_value('dev_' + MAPTILES_THEME, _DATALORE_TILES_THEME),
117
+ 'dev_' + MAPTILES_MIN_ZOOM: _init_value('dev_' + MAPTILES_MIN_ZOOM, _DATALORE_TILES_MIN_ZOOM),
118
+ 'dev_' + MAPTILES_MAX_ZOOM: _init_value('dev_' + MAPTILES_MAX_ZOOM, _DATALORE_TILES_MAX_ZOOM),
119
+ }
120
+
121
+
122
+ def _to_actual_name(name: str) -> str:
123
+ if name.startswith("dev_"):
124
+ return name
125
+
126
+ return name if is_production() else 'dev_' + name
127
+
128
+
129
+ def _get_global_val_intern(actual_name: str) -> Any:
130
+ # `settings` dict has precedence over environment variables.
131
+ env_val = _get_env_val(actual_name)
132
+ return _settings.get(actual_name, env_val)
133
+
134
+
135
+ def is_production() -> bool:
136
+ return 'dev' not in __version__
137
+
138
+
139
+ def get_js_cdn_url() -> str:
140
+ if has_global_value(JS_URL_MANUAL):
141
+ return get_global_str(JS_URL_MANUAL)
142
+
143
+ base_url = get_global_str(JS_BASE_URL)
144
+
145
+ js_path_to_file = get_global_str(JS_PATH_TO_FILE)
146
+
147
+ if has_global_value(JS_NAME):
148
+ name = get_global_str(JS_NAME)
149
+ else:
150
+ name = "lets-plot.min.js" if is_production() else "lets-plot.js".format(version=__version__)
151
+ # name = "lets-plot-{version}.{suffix}".format(version=__version__, suffix=suffix)
152
+ # name = "lets-plot.{suffix}".format(suffix=suffix)
153
+
154
+ # url = "{base_url}/{name}".format(base_url=base_url, name=name)
155
+ url = "{base_url}/{js_path_to_file}/{name}".format(base_url=base_url, js_path_to_file=js_path_to_file, name=name)
156
+ return url
157
+
158
+
159
+ def has_global_value(name: str) -> bool:
160
+ val = _get_global_val_intern(_to_actual_name(name))
161
+
162
+ if isinstance(val, bool):
163
+ return True
164
+ if isinstance(val, str) and not val.strip():
165
+ return False
166
+ return bool(val)
167
+
168
+
169
+ def get_global_val(name: str) -> Any:
170
+ if not has_global_value(name):
171
+ raise ValueError("Not defined '{}'".format(_to_actual_name(name)))
172
+
173
+ return _get_global_val_intern(_to_actual_name(name))
174
+
175
+
176
+ def get_global_str(name: str) -> str:
177
+ val = get_global_val(name)
178
+ if not isinstance(val, str):
179
+ raise ValueError("Not string value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
180
+ return val
181
+
182
+
183
+ def get_global_bool(name: str) -> bool:
184
+ val = get_global_val(name)
185
+ if isinstance(val, bool):
186
+ return val
187
+
188
+ if isinstance(val, str):
189
+ if val.lower() in ['true', '1', 't', 'y', 'yes']:
190
+ return True
191
+ elif val.lower() in ['false', '0', 'f', 'n', 'no']:
192
+ return False
193
+ else:
194
+ raise ValueError("Can't convert str to boolean : ['{}'] : {}".format(_to_actual_name(name), val))
195
+
196
+ raise ValueError("Not boolean value: ['{}'] : {}".format(_to_actual_name(name), type(val)))
lets_plot/_kbridge.py ADDED
@@ -0,0 +1,141 @@
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
+ def _export_png(bytestring: Dict, output_width: float, output_height: float, unit: str, dpi: int, scale: float) -> str:
23
+ """
24
+ Export a plot to PNG format. Returns base64 encoded string of the PNG image.
25
+ """
26
+ plot_spec = _standardize_plot_spec(bytestring)
27
+ return lets_plot_kotlin_bridge.export_png(plot_spec, output_width, output_height, unit, dpi, scale)
28
+
29
+
30
+ def _generate_static_html_page(plot_spec: Dict, iframe: bool) -> str:
31
+ plot_spec = _standardize_plot_spec(plot_spec)
32
+ scriptUrl = get_js_cdn_url()
33
+ return lets_plot_kotlin_bridge.export_html(plot_spec, scriptUrl, iframe)
34
+
35
+
36
+ def _standardize_plot_spec(plot_spec: Dict) -> Dict:
37
+ """
38
+ :param plot_spec: dict
39
+ """
40
+ if not isinstance(plot_spec, dict):
41
+ raise ValueError("dict expected but was {}".format(type(plot_spec)))
42
+
43
+ return standardize_dict(plot_spec)
44
+
45
+
46
+ def _generate_static_configure_html() -> str:
47
+ """
48
+ Generate static HTML configuration.
49
+
50
+ Returns
51
+ -------
52
+ str
53
+ HTML string containing the static configuration with the script URL from global settings.
54
+ """
55
+ scriptUrl = get_js_cdn_url()
56
+ return lets_plot_kotlin_bridge.get_static_configure_html(scriptUrl)
57
+
58
+
59
+ def _generate_display_html_for_raw_spec(
60
+ plot_spec: Dict,
61
+ sizing_options: Dict,
62
+ *,
63
+ dynamic_script_loading: bool = False,
64
+ force_immediate_render: bool = False,
65
+ responsive: bool = False
66
+ ) -> str:
67
+ """
68
+ Generate HTML for displaying a plot from 'raw' specification (not processed by plot backend)
69
+ with customizable options.
70
+
71
+ Parameters
72
+ ----------
73
+ plot_spec : Dict
74
+ Dict containing the plot specification.
75
+ sizing_options : Dict
76
+ Dict containing sizing policy options (width_mode, height_mode, width, height).
77
+ dynamic_script_loading : bool, default=False
78
+ Controls how the generated JS code interacts with the lets-plot JS library.
79
+ If True, assumes the library will be loaded dynamically.
80
+ If False, assumes the library is already present in the page header (static loading).
81
+ force_immediate_render : bool, default=False
82
+ Controls the timing of plot rendering.
83
+ If True, forces immediate plot rendering.
84
+ If False, waits for ResizeObserver(JS) event and renders the plot after the plot
85
+ container is properly layouted in DOM.
86
+ responsive : bool, default=False
87
+ If True, makes the plot responsive to container size changes.
88
+
89
+ Returns
90
+ -------
91
+ str
92
+ HTML string containing the plot with specified options.
93
+
94
+ Notes
95
+ -----
96
+ The sizing_options dict supports the following structure:
97
+ {
98
+ 'width_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
99
+ 'height_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
100
+ 'width': number, # optional
101
+ 'height': number # optional
102
+ }
103
+
104
+ Sizing modes determine how the plot dimensions are calculated:
105
+
106
+ 1. FIXED mode:
107
+ - Uses the explicitly provided width/height values
108
+ - Falls back to the default figure size if no values provided
109
+ - Not responsive to container size
110
+
111
+ 2. MIN mode:
112
+ Applies the smallest dimension among:
113
+ - The default figure size
114
+ - The specified width/height (if provided)
115
+ - The container size (if available)
116
+
117
+ 3. FIT mode:
118
+ Uses either:
119
+ - The specified width/height if provided
120
+ - Otherwise uses container size if available
121
+ - Falls back to default figure size if neither is available
122
+
123
+ 4. SCALED mode:
124
+ - Always preserves the figure's aspect ratio
125
+ - Typical usage: one dimension (usually width) uses FIXED/MIN/FIT mode
126
+ and SCALED height adjusts to maintain aspect ratio
127
+ - Special case: when both width and height are SCALED:
128
+ * Requires container size to be available
129
+ * Fits figure within container while preserving aspect ratio
130
+ * Neither dimension is predetermined
131
+
132
+ """
133
+ plot_spec = _standardize_plot_spec(plot_spec)
134
+ sizing_options = standardize_dict(sizing_options)
135
+ return lets_plot_kotlin_bridge.get_display_html_for_raw_spec(
136
+ plot_spec,
137
+ sizing_options,
138
+ dynamic_script_loading,
139
+ force_immediate_render,
140
+ responsive
141
+ )