diff --git a/kpi_dashboard_bokeh/README.rst b/kpi_dashboard_bokeh/README.rst new file mode 100644 index 00000000..873f21e4 --- /dev/null +++ b/kpi_dashboard_bokeh/README.rst @@ -0,0 +1,101 @@ +=================== +Kpi Dashboard Bokeh +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github + :target: https://github.com/OCA/reporting-engine/tree/12.0/kpi_dashboard_bokeh + :alt: OCA/reporting-engine +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-kpi_dashboard_bokeh + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/143/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Define KPI dashboard graphs using bokeh. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +#. Access `Dashboards > Configuration > KPI Dashboards > Configure KPI` +#. Create a new KPI specifying with widget type `bokeh` + +In order to define the value, you can must define a function like:: + + from bokeh.plotting import figure + from bokeh.embed import components + + def test_demo_bokeh(self): + p = figure(width=1000, height=1000, sizing_mode="scale_both") + # import that as `from bokeh.plotting import figure` + p.line([0, 1, 2], [1, 10, random.random() * 10], line_width=5) + # (...) + # fill the record field with both markup and the script of a chart. + script, div = components(p) + return {"bokeh": "%s%s" % (div, script)} + + +You can also use `code`. The following items will be added automatically to the +code items: + +* `figure` +* `components` +* `simple_components`: Like components but adds a theme with no alpha background + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella + +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. + +This module is part of the `OCA/reporting-engine `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/kpi_dashboard_bokeh/__init__.py b/kpi_dashboard_bokeh/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/kpi_dashboard_bokeh/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/kpi_dashboard_bokeh/__manifest__.py b/kpi_dashboard_bokeh/__manifest__.py new file mode 100644 index 00000000..9bf5d2f4 --- /dev/null +++ b/kpi_dashboard_bokeh/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Kpi Dashboard Bokeh", + "summary": """ + Create dashboards using bokeh""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine ", + "depends": ["web_widget_bokeh_chart", "kpi_dashboard"], + "data": ["views/webclient_templates.xml"], + "qweb": ["static/src/xml/dashboard.xml"], + "demo": ["demo/demo_dashboard.xml"], +} diff --git a/kpi_dashboard_bokeh/demo/demo_dashboard.xml b/kpi_dashboard_bokeh/demo/demo_dashboard.xml new file mode 100644 index 00000000..2187080a --- /dev/null +++ b/kpi_dashboard_bokeh/demo/demo_dashboard.xml @@ -0,0 +1,30 @@ + + + + Bokeh + $ + code + bokeh + +p = figure(width=1000, height=1000, sizing_mode="scale_both", toolbar_location=None) +p.line([0, 1, 2], [1, 10, 5], line_width=5) +script, div = simple_components(p) +result = {"bokeh": "%s%s" % (div, script)} + + + + + + + Bokeh + + + 2 + 10 + 4 + #47bbb3 + #ffffff + + + diff --git a/kpi_dashboard_bokeh/models/__init__.py b/kpi_dashboard_bokeh/models/__init__.py new file mode 100644 index 00000000..5bb66de7 --- /dev/null +++ b/kpi_dashboard_bokeh/models/__init__.py @@ -0,0 +1 @@ +from . import kpi_kpi diff --git a/kpi_dashboard_bokeh/models/kpi_kpi.py b/kpi_dashboard_bokeh/models/kpi_kpi.py new file mode 100644 index 00000000..d397e332 --- /dev/null +++ b/kpi_dashboard_bokeh/models/kpi_kpi.py @@ -0,0 +1,50 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import fields, models +import logging + +_logger = logging.getLogger(__name__) + +try: + from bokeh.plotting import figure + from bokeh.themes import Theme + from bokeh.embed import components +except ImportError as e: + _logger.error(e) + + +class KpiKpi(models.Model): + + _inherit = "kpi.kpi" + + widget = fields.Selection(selection_add=[("bokeh", "Bokeh")]) + + def _get_bokeh_theme(self): + return Theme(json={ + "attrs": { + "Figure": { + "background_fill_alpha": 0, + "border_fill_alpha": 0, + "outline_line_alpha": 0, + }, + "Legend": { + "border_line_alpha": 0, + "background_fill_alpha": 0, + }, + "ColorBar": { + "bar_line_alpha": 0, + "background_fill_alpha": 0, + }, + } + }) + + def _get_code_input_dict(self): + res = super()._get_code_input_dict() + if self.widget == 'bokeh': + res.update({ + 'figure': figure, + 'components': components, + 'simple_components': lambda r: components( + r, theme=self._get_bokeh_theme()) + }) + return res diff --git a/kpi_dashboard_bokeh/readme/CONFIGURE.rst b/kpi_dashboard_bokeh/readme/CONFIGURE.rst new file mode 100644 index 00000000..6c887a52 --- /dev/null +++ b/kpi_dashboard_bokeh/readme/CONFIGURE.rst @@ -0,0 +1,24 @@ +#. Access `Dashboards > Configuration > KPI Dashboards > Configure KPI` +#. Create a new KPI specifying with widget type `bokeh` + +In order to define the value, you can must define a function like:: + + from bokeh.plotting import figure + from bokeh.embed import components + + def test_demo_bokeh(self): + p = figure(width=1000, height=1000, sizing_mode="scale_both") + # import that as `from bokeh.plotting import figure` + p.line([0, 1, 2], [1, 10, random.random() * 10], line_width=5) + # (...) + # fill the record field with both markup and the script of a chart. + script, div = components(p) + return {"bokeh": "%s%s" % (div, script)} + + +You can also use `code`. The following items will be added automatically to the +code items: + +* `figure` +* `components` +* `simple_components`: Like components but adds a theme with no alpha background diff --git a/kpi_dashboard_bokeh/readme/CONTRIBUTORS.rst b/kpi_dashboard_bokeh/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..93ec993e --- /dev/null +++ b/kpi_dashboard_bokeh/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Enric Tobella diff --git a/kpi_dashboard_bokeh/readme/DESCRIPTION.rst b/kpi_dashboard_bokeh/readme/DESCRIPTION.rst new file mode 100644 index 00000000..12f3b10c --- /dev/null +++ b/kpi_dashboard_bokeh/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Define KPI dashboard graphs using bokeh. diff --git a/kpi_dashboard_bokeh/static/description/icon.png b/kpi_dashboard_bokeh/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/kpi_dashboard_bokeh/static/description/icon.png differ diff --git a/kpi_dashboard_bokeh/static/description/index.html b/kpi_dashboard_bokeh/static/description/index.html new file mode 100644 index 00000000..91806011 --- /dev/null +++ b/kpi_dashboard_bokeh/static/description/index.html @@ -0,0 +1,448 @@ + + + + + + +Kpi Dashboard Bokeh + + + +
+

Kpi Dashboard Bokeh

+ + +

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runbot

+

Define KPI dashboard graphs using bokeh.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Access Dashboards > Configuration > KPI Dashboards > Configure KPI
  2. +
  3. Create a new KPI specifying with widget type bokeh
  4. +
+

In order to define the value, you can must define a function like:

+
+from bokeh.plotting import figure
+from bokeh.embed import components
+
+def test_demo_bokeh(self):
+    p = figure(width=1000, height=1000, sizing_mode="scale_both")
+    # import that as `from bokeh.plotting import figure`
+    p.line([0, 1, 2], [1, 10, random.random() * 10], line_width=5)
+    # (...)
+    # fill the record field with both markup and the script of a chart.
+    script, div = components(p)
+    return {"bokeh": "%s%s" % (div, script)}
+
+

You can also use code. The following items will be added automatically to the +code items:

+
    +
  • figure
  • +
  • components
  • +
  • simple_components: Like components but adds a theme with no alpha background
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/reporting-engine project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/kpi_dashboard_bokeh/static/src/js/bokeh_widget.js b/kpi_dashboard_bokeh/static/src/js/bokeh_widget.js new file mode 100644 index 00000000..4b68f7da --- /dev/null +++ b/kpi_dashboard_bokeh/static/src/js/bokeh_widget.js @@ -0,0 +1,20 @@ +odoo.define('kpi_dashboard.BokehWidget', function (require) { + "use strict"; + + var AbstractWidget = require('kpi_dashboard.AbstractWidget'); + var registry = require('kpi_dashboard.widget_registry'); + + + var BokehWidget = AbstractWidget.extend({ + template: 'kpi_dashboard.bokeh', + fillWidget: function (values) { + var val = values.value.bokeh; + var widget = this.$el.find('[data-bind="value"]'); + widget.css('height', this.widget_size_y - 90); + widget.html(val); + }, + }); + + registry.add('bokeh', BokehWidget); + return BokehWidget; +}); diff --git a/kpi_dashboard_bokeh/static/src/xml/dashboard.xml b/kpi_dashboard_bokeh/static/src/xml/dashboard.xml new file mode 100644 index 00000000..c862e1a7 --- /dev/null +++ b/kpi_dashboard_bokeh/static/src/xml/dashboard.xml @@ -0,0 +1,9 @@ + + diff --git a/kpi_dashboard_bokeh/views/webclient_templates.xml b/kpi_dashboard_bokeh/views/webclient_templates.xml new file mode 100644 index 00000000..3e63be4a --- /dev/null +++ b/kpi_dashboard_bokeh/views/webclient_templates.xml @@ -0,0 +1,11 @@ + + + +