eea.plotly 1.2__tar.gz → 1.4__tar.gz
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.
- {eea_plotly-1.2/eea.plotly.egg-info → eea_plotly-1.4}/PKG-INFO +11 -1
- {eea_plotly-1.2 → eea_plotly-1.4}/docs/HISTORY.txt +10 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/browser/preview.py +20 -9
- eea_plotly-1.4/eea/plotly/browser/preview_adapter/adapter.py +23 -0
- eea_plotly-1.4/eea/plotly/browser/preview_adapter/soer_miniature.py +79 -0
- eea_plotly-1.4/eea/plotly/profiles/default/controlpanel.json +10097 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/controlpanel/configure.zcml +8 -0
- eea_plotly-1.4/eea/plotly/restapi/controlpanel/reset.py +42 -0
- eea_plotly-1.4/eea/plotly/setuphandlers.py +48 -0
- eea_plotly-1.4/eea/plotly/version.txt +1 -0
- {eea_plotly-1.2 → eea_plotly-1.4/eea.plotly.egg-info}/PKG-INFO +11 -1
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/SOURCES.txt +4 -0
- eea_plotly-1.2/eea/plotly/setuphandlers.py +0 -29
- eea_plotly-1.2/eea/plotly/version.txt +0 -1
- {eea_plotly-1.2 → eea_plotly-1.4}/CONTRIBUTING.md +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/MANIFEST.in +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/README.rst +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/docs/LICENSE.GPL +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/docs/LICENSE.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/README.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/behaviors.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/browser/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/browser/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/browser/controlpanel.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/browser/pt/visualization_view.pt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/controlpanel.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/deserializer/blocks.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/deserializer/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/deserializer/dxcontent.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/deserializer/dxfields.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/interfaces.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/io_csv.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/bg/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/bg/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/cs/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/cs/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/da/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/da/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/de/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/de/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/eea.pot +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/el/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/el/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/en/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/en/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/es/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/es/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/et/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/et/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/eu/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/eu/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/fi/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/fi/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/fr/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/fr/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/hr/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/hr/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/hu/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/hu/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/is/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/is/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/it/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/it/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/kl/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/kl/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/lt/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/lt/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/lv/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/lv/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/mt/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/mt/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/nl/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/nl/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/no/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/no/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pl/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pl/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/plone-manual.pot +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pt/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pt/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pt_BR/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/pt_BR/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/ro/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/ro/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/ru/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/ru/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sk/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sk/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sl/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sl/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sv/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/sv/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/tr/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/tr/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/update.sh +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/zh_TW/LC_MESSAGES/eea.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/locales/zh_TW/LC_MESSAGES/plone.po +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/permissions.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/browserlayer.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/controlpanel.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/metadata.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/registry.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/rolemap.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/types/visualization.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/default/types.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/uninstall/browserlayer.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/uninstall/controlpanel.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles/uninstall/registry.xml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/profiles.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/controlpanel/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/controlpanel/get.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/visualization/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/restapi/visualization/get.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/serializer/blocks.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/serializer/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/serializer/dxfields.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/serializer/utils.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/tests/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/tests/base.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/tests/test_doctests.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/upgrades/__init__.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/upgrades/configure.zcml +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea/plotly/utils.py +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/dependency_links.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/entry_points.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/namespace_packages.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/not-zip-safe +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/requires.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/eea.plotly.egg-info/top_level.txt +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/setup.cfg +0 -0
- {eea_plotly-1.2 → eea_plotly-1.4}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: eea.plotly
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4
|
|
4
4
|
Summary: volto-plotlycharts backend support
|
|
5
5
|
Home-page: https://github.com/eea/eea.plotly
|
|
6
6
|
Author: European Environment Agency: IDM2 A-Team
|
|
@@ -145,6 +145,16 @@ EEA_ - European Environment Agency (EU)
|
|
|
145
145
|
Changelog
|
|
146
146
|
=========
|
|
147
147
|
|
|
148
|
+
1.4 - (2025-05-30)
|
|
149
|
+
---------------------------
|
|
150
|
+
* Change: update soer_miniature preview adapter
|
|
151
|
+
[razvanMiu]
|
|
152
|
+
|
|
153
|
+
1.3 - (2025-05-29)
|
|
154
|
+
---------------------------
|
|
155
|
+
* Change: Add preview adapter
|
|
156
|
+
[razvanMiu]
|
|
157
|
+
|
|
148
158
|
1.2 - (2025-03-13)
|
|
149
159
|
---------------------------
|
|
150
160
|
* Change: Add theme property
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
1.4 - (2025-05-30)
|
|
5
|
+
---------------------------
|
|
6
|
+
* Change: update soer_miniature preview adapter
|
|
7
|
+
[razvanMiu]
|
|
8
|
+
|
|
9
|
+
1.3 - (2025-05-29)
|
|
10
|
+
---------------------------
|
|
11
|
+
* Change: Add preview adapter
|
|
12
|
+
[razvanMiu]
|
|
13
|
+
|
|
4
14
|
1.2 - (2025-03-13)
|
|
5
15
|
---------------------------
|
|
6
16
|
* Change: Add theme property
|
|
@@ -10,6 +10,8 @@ from Products.Five.browser import BrowserView
|
|
|
10
10
|
from eea.plotly.controlpanel import IPlotlySettings
|
|
11
11
|
from eea.plotly.utils import sanitizeVisualization
|
|
12
12
|
|
|
13
|
+
from .preview_adapter.adapter import get_preview_adapter
|
|
14
|
+
|
|
13
15
|
|
|
14
16
|
def deepUpdate(original, update):
|
|
15
17
|
""" Recursively update a dictionary with another dictionary."""
|
|
@@ -27,16 +29,19 @@ def deepUpdate(original, update):
|
|
|
27
29
|
class PlotlyPreview(BrowserView):
|
|
28
30
|
"""Plotly Preview"""
|
|
29
31
|
|
|
32
|
+
visualization = None
|
|
30
33
|
name = None
|
|
34
|
+
width = 1200
|
|
35
|
+
height = 900
|
|
31
36
|
|
|
32
37
|
def render(self):
|
|
33
38
|
"""Render"""
|
|
34
39
|
|
|
35
|
-
visualization = copy.deepcopy(
|
|
40
|
+
self.visualization = copy.deepcopy(
|
|
36
41
|
sanitizeVisualization(self.context.visualization)
|
|
37
42
|
)
|
|
38
43
|
|
|
39
|
-
if not visualization:
|
|
44
|
+
if not self.visualization:
|
|
40
45
|
self.request.response.setStatus(404)
|
|
41
46
|
return {
|
|
42
47
|
"message": "Visualization is not defined",
|
|
@@ -54,24 +59,28 @@ class PlotlyPreview(BrowserView):
|
|
|
54
59
|
if t.get("id") == self.name:
|
|
55
60
|
theme = copy.deepcopy(t)
|
|
56
61
|
break
|
|
57
|
-
if theme and "layout" in visualization:
|
|
62
|
+
if theme and "layout" in self.visualization:
|
|
58
63
|
data = theme.get("data", {})
|
|
59
64
|
layout = theme.get("layout", {})
|
|
60
|
-
for trIndex, tr in enumerate(
|
|
65
|
+
for trIndex, tr in enumerate(
|
|
66
|
+
self.visualization.get("data", [])):
|
|
61
67
|
trType = tr.get("type", "")
|
|
62
68
|
if trType in data:
|
|
63
69
|
newTrIndex = min(trIndex, len(data[trType])-1)
|
|
64
70
|
newTr = data[trType][newTrIndex]
|
|
65
71
|
deepUpdate(tr, newTr)
|
|
66
|
-
deepUpdate(visualization["layout"], layout)
|
|
67
|
-
visualization["layout"]["template"] = theme
|
|
72
|
+
deepUpdate(self.visualization["layout"], layout)
|
|
73
|
+
self.visualization["layout"]["template"] = theme
|
|
74
|
+
|
|
75
|
+
get_preview_adapter(self, self.name)
|
|
68
76
|
|
|
69
|
-
fig = pio.from_json(json.dumps(visualization), skip_invalid=True)
|
|
77
|
+
fig = pio.from_json(json.dumps(self.visualization), skip_invalid=True)
|
|
70
78
|
|
|
71
|
-
if "template" not in visualization["layout"]:
|
|
79
|
+
if "template" not in self.visualization["layout"]:
|
|
72
80
|
fig.update_layout(template=None)
|
|
73
81
|
|
|
74
|
-
image = fig.to_image(
|
|
82
|
+
image = fig.to_image(
|
|
83
|
+
format="svg", width=self.width, height=self.height)
|
|
75
84
|
|
|
76
85
|
sh = self.request.response.setHeader
|
|
77
86
|
|
|
@@ -86,6 +95,8 @@ class PlotlyPreview(BrowserView):
|
|
|
86
95
|
def publishTraverse(self, request, name):
|
|
87
96
|
"""used for traversal via publisher, i.e. when using as a url"""
|
|
88
97
|
self.name = name
|
|
98
|
+
self.width = int(request.form.get("width", self.width))
|
|
99
|
+
self.height = int(request.form.get("height", self.height))
|
|
89
100
|
return self
|
|
90
101
|
|
|
91
102
|
def __call__(self):
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
""" Preview adapter for Plotly browser. """
|
|
2
|
+
|
|
3
|
+
adapters = {
|
|
4
|
+
"soer_miniature": (
|
|
5
|
+
"eea.plotly.browser.preview_adapter.soer_miniature.serialize"
|
|
6
|
+
),
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_preview_adapter(context, name):
|
|
11
|
+
""" Get the preview adapter for a given name.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
name (str): The name of the preview adapter.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
class: The preview adapter class if found, otherwise None.
|
|
18
|
+
"""
|
|
19
|
+
if name in adapters:
|
|
20
|
+
module_name, func = adapters[name].rsplit(".", 1)
|
|
21
|
+
module = __import__(module_name, fromlist=[func])
|
|
22
|
+
return getattr(module, func)(context)
|
|
23
|
+
return None
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
""" SOER miniature theme for Plotly visualizations. """
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def nice_step(vmin, vmax, target_ticks=5):
|
|
6
|
+
""" Calculate a 'nice' step size for the axis ticks. """
|
|
7
|
+
span = abs(vmax - vmin)
|
|
8
|
+
if span == 0:
|
|
9
|
+
return 1 # arbitrary fallback
|
|
10
|
+
|
|
11
|
+
# Initial guess for raw step size
|
|
12
|
+
raw_step = span / target_ticks
|
|
13
|
+
|
|
14
|
+
# Determine the power of 10
|
|
15
|
+
magnitude = 10 ** math.floor(math.log10(raw_step))
|
|
16
|
+
residual = raw_step / magnitude
|
|
17
|
+
|
|
18
|
+
# Choose a nice multiplier
|
|
19
|
+
if residual < 1.5:
|
|
20
|
+
nice_multiplier = 1
|
|
21
|
+
elif residual < 3:
|
|
22
|
+
nice_multiplier = 2
|
|
23
|
+
elif residual < 7:
|
|
24
|
+
nice_multiplier = 5
|
|
25
|
+
else:
|
|
26
|
+
nice_multiplier = 10
|
|
27
|
+
|
|
28
|
+
return nice_multiplier * magnitude
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def getMin(arr):
|
|
32
|
+
""" Get minimum value from array """
|
|
33
|
+
return min(float(v) for v in arr if v is not None)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def getMax(arr):
|
|
37
|
+
""" Get maximum value from array """
|
|
38
|
+
return max(float(v) for v in arr if v is not None)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def serialize(context):
|
|
42
|
+
""" Serialize the context for SOER miniature theme"""
|
|
43
|
+
|
|
44
|
+
# Solve x axis range
|
|
45
|
+
if context.visualization is None or len(context.visualization["data"]) < 2:
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
years = context.visualization["data"][0].get("x", [])
|
|
49
|
+
tickvals = context.visualization["layout"]["xaxis"].get("tickvals", [])
|
|
50
|
+
|
|
51
|
+
if tickvals and years:
|
|
52
|
+
min_year = getMin(tickvals)
|
|
53
|
+
max_year = getMax(years)
|
|
54
|
+
|
|
55
|
+
context.visualization["layout"]["xaxis"]["range"] = [
|
|
56
|
+
min_year - 2, max_year + 2]
|
|
57
|
+
context.visualization["layout"]["xaxis"]["autorange"] = False
|
|
58
|
+
|
|
59
|
+
# Solve y axis range
|
|
60
|
+
|
|
61
|
+
y_values = context.visualization["data"][0].get(
|
|
62
|
+
"y", []) + context.visualization["data"][1].get("y", [])
|
|
63
|
+
|
|
64
|
+
if y_values:
|
|
65
|
+
min_y = getMin(y_values)
|
|
66
|
+
max_y = getMax(y_values)
|
|
67
|
+
|
|
68
|
+
step = nice_step(min_y, max_y, 10)
|
|
69
|
+
|
|
70
|
+
context.visualization["layout"]["yaxis"]["range"] = [
|
|
71
|
+
min_y - step, max_y + step]
|
|
72
|
+
context.visualization["layout"]["yaxis"]["autorange"] = False
|
|
73
|
+
|
|
74
|
+
if "text" in context.visualization["data"][0]:
|
|
75
|
+
context.visualization["data"][0]["text"] = [
|
|
76
|
+
(t if t is None else " " + str(t))
|
|
77
|
+
for t in context.visualization["data"][0]["text"]]
|
|
78
|
+
|
|
79
|
+
return True
|