Skip to content

Commit 8b0497c

Browse files
committed
Merge PR #3000 into 17.0
Signed-off-by pedrobaeza
2 parents 860d9fb + 0bf8825 commit 8b0497c

21 files changed

+21531
-0
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# generated from manifests external_dependencies
2+
beautifulsoup4
23
bokeh==3.4.1
4+
mpld3==0.5.10
35
plotly==5.22.0

web_widget_mpld3_chart/README.rst

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
======================
2+
Web Widget mpld3 Chart
3+
======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:a74d15907ff4678410ffd1913b2f75b5c7d818852dc75f13bba0311a6ffeda6e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
20+
:target: https://github.com/OCA/web/tree/17.0/web_widget_mpld3_chart
21+
:alt: OCA/web
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_widget_mpld3_chart
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module adds the possibility to insert mpld3 charts into Odoo
32+
standard views. This is an interactive D3js-based viewer which brings
33+
matplotlib graphics to the browser.
34+
35+
If you want to see some samples of mpld3's capabilities follow this
36+
`link <http://mpld3.github.io/>`__.
37+
38+
**Table of contents**
39+
40+
.. contents::
41+
:local:
42+
43+
Installation
44+
============
45+
46+
You need to install the python mpld3 library:
47+
48+
::
49+
50+
pip install mpld3
51+
52+
Usage
53+
=====
54+
55+
To insert a mpld3 chart in a view proceed as follows:
56+
57+
1. You should inherit from abstract class abstract.mpld3.parser:
58+
59+
::
60+
61+
_name = 'res.partner'
62+
_inherit = ['res.partner', 'abstract.mpld3.parser']
63+
64+
2. Import the required libraries:
65+
66+
::
67+
68+
import matplotlib.pyplot as plt
69+
70+
3. Declare a json computed field like this:
71+
72+
::
73+
74+
mpld3_chart = fields.Json(
75+
string='Mpld3 Chart',
76+
compute='_compute_mpld3_chart',
77+
)
78+
79+
4. In its computed method do:
80+
81+
::
82+
83+
def _compute_mpld3_chart(self):
84+
for rec in self:
85+
# Design your mpld3 figure:
86+
plt.scatter([1, 10], [5, 9])
87+
figure = plt.figure()
88+
rec.mpld3_chart = self.convert_figure_to_json(figure)
89+
90+
5. In the view, add something like this wherever you want to display
91+
your mpld3 chart:
92+
93+
::
94+
95+
<div>
96+
<field name="mpld3_chart" widget="mpld3_chart" nolabel="1"/>
97+
</div>
98+
99+
Bug Tracker
100+
===========
101+
102+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
103+
In case of trouble, please check there if your issue has already been reported.
104+
If you spotted it first, help us to smash it by providing a detailed and welcomed
105+
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_mpld3_chart%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
106+
107+
Do not contact contributors directly about support or help with technical issues.
108+
109+
Credits
110+
=======
111+
112+
Authors
113+
-------
114+
115+
* ForgeFlow
116+
117+
Contributors
118+
------------
119+
120+
- Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
121+
- Christopher Ormaza <chris.ormaza@forgeflow.com>
122+
123+
Other credits
124+
-------------
125+
126+
- This module uses the library
127+
`mpld3 <https://github.com/mpld3/mpld3>`__ which is under the
128+
open-source BSD 3-clause "New" or "Revised" License. Copyright (c)
129+
2013, Jake Vanderplas
130+
- This module uses the library `BeautifulSoup
131+
4 <https://pypi.org/project/beautifulsoup4/>`__ which is under the
132+
open-source MIT License. Copyright (c) 2014, Leonard Richardson
133+
- Odoo Community Association (OCA)
134+
135+
Maintainers
136+
-----------
137+
138+
This module is maintained by the OCA.
139+
140+
.. image:: https://odoo-community.org/logo.png
141+
:alt: Odoo Community Association
142+
:target: https://odoo-community.org
143+
144+
OCA, or the Odoo Community Association, is a nonprofit organization whose
145+
mission is to support the collaborative development of Odoo features and
146+
promote its widespread use.
147+
148+
.. |maintainer-JordiBForgeFlow| image:: https://github.com/JordiBForgeFlow.png?size=40px
149+
:target: https://github.com/JordiBForgeFlow
150+
:alt: JordiBForgeFlow
151+
.. |maintainer-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px
152+
:target: https://github.com/ChrisOForgeFlow
153+
:alt: ChrisOForgeFlow
154+
155+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
156+
157+
|maintainer-JordiBForgeFlow| |maintainer-ChrisOForgeFlow|
158+
159+
This module is part of the `OCA/web <https://github.com/OCA/web/tree/17.0/web_widget_mpld3_chart>`_ project on GitHub.
160+
161+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

web_widget_mpld3_chart/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
2+
from . import models
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 ForgeFlow, S.L.
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
{
5+
"name": "Web Widget mpld3 Chart",
6+
"category": "Hidden",
7+
"summary": "This widget allows to display charts using MPLD3 library.",
8+
"author": "ForgeFlow, Odoo Community Association (OCA)",
9+
"version": "17.0.1.0.0",
10+
"website": "https://github.com/OCA/web",
11+
"depends": ["web"],
12+
"data": [],
13+
"external_dependencies": {"python": ["mpld3==0.5.10", "beautifulsoup4"]},
14+
"auto_install": False,
15+
"development_status": "Beta",
16+
"maintainers": ["JordiBForgeFlow", "ChrisOForgeFlow"],
17+
"license": "LGPL-3",
18+
"assets": {
19+
"web.assets_backend": [
20+
"web_widget_mpld3_chart/static/src/js/*.js",
21+
"web_widget_mpld3_chart/static/src/xml/*.xml",
22+
],
23+
},
24+
}

web_widget_mpld3_chart/i18n/es.po

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 13.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"PO-Revision-Date: 2023-12-07 22:34+0000\n"
9+
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
10+
"Language-Team: none\n"
11+
"Language: es\n"
12+
"MIME-Version: 1.0\n"
13+
"Content-Type: text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding: \n"
15+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
16+
"X-Generator: Weblate 4.17\n"
17+
18+
#. module: web_widget_mpld3_chart
19+
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
20+
msgid "Utility to parse ploot figure to json data for widget Mpld3"
21+
msgstr ""
22+
"Utilidad para convertir figuras ploot en datos json para el widget Mpld3"

web_widget_mpld3_chart/i18n/it.po

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * web_widget_mpld3_chart
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2023-12-04 15:34+0000\n"
10+
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 4.17\n"
18+
19+
#. module: web_widget_mpld3_chart
20+
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
21+
msgid "Utility to parse ploot figure to json data for widget Mpld3"
22+
msgstr ""
23+
"Utility per analizzare immagine disegnata in dati JSON per il widget MPLD3"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * web_widget_mpld3_chart
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: web_widget_mpld3_chart
17+
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
18+
msgid "Utility to parse ploot figure to json data for widget Mpld3"
19+
msgstr ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import abstract_mpld3_parser
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2022 ForgeFlow S.L.
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
5+
import logging
6+
7+
from odoo import api, models
8+
9+
_logger = logging.getLogger(__name__)
10+
11+
try:
12+
import mpld3
13+
from bs4 import BeautifulSoup
14+
except (OSError, ImportError) as err:
15+
_logger.debug(err)
16+
17+
18+
class AbstractMpld3Parser(models.AbstractModel):
19+
_name = "abstract.mpld3.parser"
20+
_description = "Utility to parse ploot figure to json data for widget Mpld3"
21+
22+
@api.model
23+
def convert_figure_to_json(self, figure):
24+
html_string = mpld3.fig_to_html(figure, no_extras=True, include_libraries=False)
25+
soup = BeautifulSoup(html_string, "lxml")
26+
json_data = {
27+
"div": str(soup.div),
28+
"script": soup.script.decode_contents(),
29+
}
30+
return json_data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)