Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
76c0cb4
add web_widget_mpld3_chart
JordiBForgeFlow Feb 11, 2020
8745358
[IMP] web_widget_mpld3_chart: black, isort
AdriaGForgeFlow Mar 17, 2020
f48186e
[UPD] Update web_widget_mpld3_chart.pot
oca-travis Mar 17, 2020
e788022
[ADD] icon.png
OCA-git-bot Mar 17, 2020
48858d0
[UPD] README.rst
OCA-git-bot Mar 17, 2020
e94fecb
Added translation using Weblate (Spanish)
claudiagn Feb 17, 2021
b702986
[IMP] web_widget_mpld3_chart: black, isort, prettier
GenisPForgeFlow May 31, 2021
f808051
[MIG] web_widget_mpld3_chart: Migration to 14.0
GenisPForgeFlow May 31, 2021
bd86e53
[UPD] Update web_widget_mpld3_chart.pot
oca-travis Sep 10, 2021
ac0669a
[UPD] README.rst
OCA-git-bot Sep 10, 2021
ef8c21a
[15.0][MIG] web_widget_mpld3_chart
ChrisOForgeFlow Jan 7, 2022
02f205f
[IMP] web_widget_mpld3_chart: Force version of mpld3
JordiBForgeFlow Jan 17, 2023
779802a
[UPD] Update web_widget_mpld3_chart.pot
Jan 17, 2023
a719307
[UPD] README.rst
OCA-git-bot Jan 17, 2023
752e9fd
Update translation files
weblate Jan 17, 2023
f6f41ef
[16.0][MIG] web_widget_mpld3_chart
ChrisOForgeFlow Jun 22, 2023
c3caf43
[IMP] web_widget_mpld3_chart: Move js to owl
BernatPForgeFlow Nov 13, 2023
b965b16
[IMP] web_widget_mpld3_chart: Move widget from CharField to Component…
BernatPForgeFlow Nov 30, 2023
1439474
[UPD] Update web_widget_mpld3_chart.pot
Dec 4, 2023
122c624
[BOT] post-merge updates
OCA-git-bot Dec 4, 2023
1ffd713
Added translation using Weblate (Italian)
mymage Dec 4, 2023
c574de1
Translated using Weblate (Italian)
mymage Dec 4, 2023
80c5fe2
Translated using Weblate (Spanish)
Ivorra78 Dec 7, 2023
e75cfb6
[IMP] web_widget_mpld3_chart: pre-commit execution
lef-adhoc Nov 23, 2024
c4a5ac7
[MIG] web_widget_mpld3_chart: Migration to 17.0
lef-adhoc Nov 23, 2024
3eebeaf
[UPD] Update web_widget_mpld3_chart.pot
Jan 30, 2025
6563f0b
[BOT] post-merge updates
OCA-git-bot Jan 30, 2025
ec068a2
[IMP] web_widget_mpld3_chart: pre-commit auto fixes
ThiagoMForgeFlow Mar 28, 2025
3f4074c
[MIG] web_widget_mpld3_chart: Migration to 18.0
ThiagoMForgeFlow Mar 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# generated from manifests external_dependencies
beautifulsoup4
bokeh==3.6.3
mpld3==0.5.10
161 changes: 161 additions & 0 deletions web_widget_mpld3_chart/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
======================
Web Widget mpld3 Chart
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:671a850d1911018fe9105e0d3c6f95fd235257bade3adba7267cc1cad2641cbe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/18.0/web_widget_mpld3_chart
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_mpld3_chart
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the possibility to insert mpld3 charts into Odoo
standard views. This is an interactive D3js-based viewer which brings
matplotlib graphics to the browser.

If you want to see some samples of mpld3's capabilities follow this
`link <http://mpld3.github.io/>`__.

**Table of contents**

.. contents::
:local:

Installation
============

You need to install the python mpld3 library:

::

pip install mpld3

Usage
=====

To insert a mpld3 chart in a view proceed as follows:

1. You should inherit from abstract class abstract.mpld3.parser:

::

_name = 'res.partner'
_inherit = ['res.partner', 'abstract.mpld3.parser']

2. Import the required libraries:

::

import matplotlib.pyplot as plt

3. Declare a json computed field like this:

::

mpld3_chart = fields.Json(
string='Mpld3 Chart',
compute='_compute_mpld3_chart',
)

4. In its computed method do:

::

def _compute_mpld3_chart(self):
for rec in self:
# Design your mpld3 figure:
plt.scatter([1, 10], [5, 9])
figure = plt.figure()
rec.mpld3_chart = self.convert_figure_to_json(figure)

5. In the view, add something like this wherever you want to display
your mpld3 chart:

::

<div>
<field name="mpld3_chart" widget="mpld3_chart" nolabel="1"/>
</div>

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_mpld3_chart%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ForgeFlow

Contributors
------------

- Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
- Christopher Ormaza <chris.ormaza@forgeflow.com>

Other credits
-------------

- This module uses the library
`mpld3 <https://github.com/mpld3/mpld3>`__ which is under the
open-source BSD 3-clause "New" or "Revised" License. Copyright (c)
2013, Jake Vanderplas
- This module uses the library `BeautifulSoup
4 <https://pypi.org/project/beautifulsoup4/>`__ which is under the
open-source MIT License. Copyright (c) 2014, Leonard Richardson
- Odoo Community Association (OCA)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-JordiBForgeFlow| image:: https://github.com/JordiBForgeFlow.png?size=40px
:target: https://github.com/JordiBForgeFlow
:alt: JordiBForgeFlow
.. |maintainer-ThiagoMForgeFlow| image:: https://github.com/ThiagoMForgeFlow.png?size=40px
:target: https://github.com/ThiagoMForgeFlow
:alt: ThiagoMForgeFlow

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-JordiBForgeFlow| |maintainer-ThiagoMForgeFlow|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_widget_mpld3_chart>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions web_widget_mpld3_chart/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import models
24 changes: 24 additions & 0 deletions web_widget_mpld3_chart/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Web Widget mpld3 Chart",
"category": "Hidden",
"summary": "This widget allows to display charts using MPLD3 library.",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"version": "18.0.1.0.0",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"data": [],
"external_dependencies": {"python": ["mpld3==0.5.10", "beautifulsoup4"]},
"auto_install": False,
"development_status": "Beta",
"maintainers": ["JordiBForgeFlow", "ThiagoMForgeFlow"],
"license": "LGPL-3",
"assets": {
"web.assets_backend": [
"web_widget_mpld3_chart/static/src/js/*.js",
"web_widget_mpld3_chart/static/src/xml/*.xml",
],
},
}
22 changes: 22 additions & 0 deletions web_widget_mpld3_chart/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-07 22:34+0000\n"
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: web_widget_mpld3_chart
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
msgid "Utility to parse ploot figure to json data for widget Mpld3"
msgstr ""
"Utilidad para convertir figuras ploot en datos json para el widget Mpld3"
23 changes: 23 additions & 0 deletions web_widget_mpld3_chart/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_widget_mpld3_chart
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-04 15:34+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: web_widget_mpld3_chart
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
msgid "Utility to parse ploot figure to json data for widget Mpld3"
msgstr ""
"Utility per analizzare immagine disegnata in dati JSON per il widget MPLD3"
19 changes: 19 additions & 0 deletions web_widget_mpld3_chart/i18n/web_widget_mpld3_chart.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_widget_mpld3_chart
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: web_widget_mpld3_chart
#: model:ir.model,name:web_widget_mpld3_chart.model_abstract_mpld3_parser
msgid "Utility to parse ploot figure to json data for widget Mpld3"
msgstr ""
1 change: 1 addition & 0 deletions web_widget_mpld3_chart/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import abstract_mpld3_parser
30 changes: 30 additions & 0 deletions web_widget_mpld3_chart/models/abstract_mpld3_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2022 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


import logging

from odoo import api, models

_logger = logging.getLogger(__name__)

try:
import mpld3
from bs4 import BeautifulSoup
except (OSError, ImportError) as err:
_logger.debug(err)


class AbstractMpld3Parser(models.AbstractModel):
_name = "abstract.mpld3.parser"
_description = "Utility to parse ploot figure to json data for widget Mpld3"

@api.model
def convert_figure_to_json(self, figure):
html_string = mpld3.fig_to_html(figure, no_extras=True, include_libraries=False)
soup = BeautifulSoup(html_string, "lxml")
json_data = {
"div": str(soup.div),
"script": soup.script.decode_contents(),
}
return json_data
3 changes: 3 additions & 0 deletions web_widget_mpld3_chart/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions web_widget_mpld3_chart/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Jordi Ballester Alomar \<<jordi.ballester@forgeflow.com>\>
- Christopher Ormaza \<<chris.ormaza@forgeflow.com>\>
7 changes: 7 additions & 0 deletions web_widget_mpld3_chart/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- This module uses the library [mpld3](https://github.com/mpld3/mpld3)
which is under the open-source BSD 3-clause "New" or "Revised"
License. Copyright (c) 2013, Jake Vanderplas
- This module uses the library [BeautifulSoup
4](https://pypi.org/project/beautifulsoup4/) which is under the
open-source MIT License. Copyright (c) 2014, Leonard Richardson
- Odoo Community Association (OCA)
6 changes: 6 additions & 0 deletions web_widget_mpld3_chart/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module adds the possibility to insert mpld3 charts into Odoo
standard views. This is an interactive D3js-based viewer which brings
matplotlib graphics to the browser.

If you want to see some samples of mpld3's capabilities follow this
[link](http://mpld3.github.io/).
3 changes: 3 additions & 0 deletions web_widget_mpld3_chart/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
You need to install the python mpld3 library:

pip install mpld3
33 changes: 33 additions & 0 deletions web_widget_mpld3_chart/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
To insert a mpld3 chart in a view proceed as follows:

1. You should inherit from abstract class abstract.mpld3.parser:

_name = 'res.partner'
_inherit = ['res.partner', 'abstract.mpld3.parser']

2. Import the required libraries:

import matplotlib.pyplot as plt

3. Declare a json computed field like this:

mpld3_chart = fields.Json(
string='Mpld3 Chart',
compute='_compute_mpld3_chart',
)

4. In its computed method do:

def _compute_mpld3_chart(self):
for rec in self:
# Design your mpld3 figure:
plt.scatter([1, 10], [5, 9])
figure = plt.figure()
rec.mpld3_chart = self.convert_figure_to_json(figure)

5. In the view, add something like this wherever you want to display
your mpld3 chart:

<div>
<field name="mpld3_chart" widget="mpld3_chart" nolabel="1"/>
</div>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading