diff --git a/setup/web_widget_json_graph/odoo/addons/web_widget_json_graph b/setup/web_widget_json_graph/odoo/addons/web_widget_json_graph new file mode 120000 index 000000000..83f4c9df3 --- /dev/null +++ b/setup/web_widget_json_graph/odoo/addons/web_widget_json_graph @@ -0,0 +1 @@ +../../../../web_widget_json_graph \ No newline at end of file diff --git a/setup/web_widget_json_graph/setup.py b/setup/web_widget_json_graph/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_widget_json_graph/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_json_graph/README.rst b/web_widget_json_graph/README.rst new file mode 100644 index 000000000..88a76936a --- /dev/null +++ b/web_widget_json_graph/README.rst @@ -0,0 +1,172 @@ +===================== +Web Widget JSON Graph +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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/12.0/web_widget_json_graph + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_widget_json_graph + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to load a line graph per ordered pair from an One2many or +Many2many field. + +.. image:: https://raw.githubusercontent.com/OCA/web/12.0/web_widget_json_graph/static/description/widget_in_action.png + :width: 400px + :alt: Widget in action + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Use this widget by including:: + + + +For example:: + + + +The JSON needs to be like:: + + fields = ['field1', 'field2', 'field3', ...] + field_x = 'field_x' + dictionary = self.value_ids.sorted(field_x).read(fields) + color = { + 'field1': HEXCOLOR1, + 'field2': '#FFBB78', + 'field3': '#1F77B4', + ... + } + dictionary = self.value_ids.sorted(field_x).read(fields) + content = {} + data = [] + for field in fields: + if field != field_x: + content[field] = [] + for rec in dictionary: + content[field].append({'x': rec[field_x], 'y': rec[field]}) + if field in color: + data.append({'values': content[field], 'key': field, + 'color': color[field]}) + continue + data.append({'values': content[field], 'key': field}) + info = { + 'label_x': 'X Label', + 'label_y': 'Y label', + 'data': data + } + self.field_text_json = json.dumps(info) + +For example:: + + fields = ['sequence', 'value', 'sma', 'cma'] + field_x = 'sequence' + dictionary = self.value_ids.sorted(field_x).read(fields) + color = { + 'value': '#2CA02C', + 'sma': '#FFBB78' + } + dictionary = self.value_ids.sorted(field_x).read(fields) + content = {} + data = [] + for field in fields: + if field != field_x: + content[field] = [] + for rec in dictionary: + content[field].append({'x': rec[field_x], 'y': rec[field]}) + if field in color: + data.append({'values': content[field], 'key': field, + 'color': color[field]}) + continue + data.append({'values': content[field], 'key': field}) + info = { + 'label_x': 'Sequence', + 'label_y': '', + 'data': data + } + self.values_data = json.dumps(info) + +Known issues / Roadmap +====================== + +* ``nolabel`` is ignored, this image will never bring a label, by default simply use an extra separator. +* A graph will always use 100% of the width, pending the css dynamic attribute. +* Height is harcoded. + +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 +~~~~~~~ + +* Vauxoo + +Contributors +~~~~~~~~~~~~ + +* Francisco Luna +* José Robles +* Luis González +* Nhomar Hernández + +Other credits +~~~~~~~~~~~~~ + +Vauxoo + +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-luisg123v| image:: https://github.com/luisg123v.png?size=40px + :target: https://github.com/luisg123v + :alt: luisg123v + +Current `maintainer `__: + +|maintainer-luisg123v| + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_json_graph/__init__.py b/web_widget_json_graph/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_widget_json_graph/__manifest__.py b/web_widget_json_graph/__manifest__.py new file mode 100644 index 000000000..20ef64cce --- /dev/null +++ b/web_widget_json_graph/__manifest__.py @@ -0,0 +1,28 @@ +{ + "name": "Web Widget JSON Graph", + "version": "15.0.1.0.0", + "author": "Vauxoo, Odoo Community Association (OCA)", + "license": "LGPL-3", + "category": "Hidden/Dependency", + "website": "https://github.com/OCA/web", + "maintainers": [ + "luisg123v", + "frahikLV", + ], + "summary": "Draw json fields with graphs.", + "depends": [ + "web", + ], + "data": [], + "assets": { + "web.assets_backend": [ + "web_widget_json_graph/static/src/js/web_widget_json_graph.js", + ], + "web.assets_qweb": [ + "web_widget_json_graph/static/src/xml/web_widget_json_graph.xml", + ], + }, + "auto_install": False, + "installable": True, + "application": False, +} diff --git a/web_widget_json_graph/readme/CONTRIBUTORS.rst b/web_widget_json_graph/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..77a45d1e6 --- /dev/null +++ b/web_widget_json_graph/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Francisco Luna +* José Robles +* Luis González +* Nhomar Hernández diff --git a/web_widget_json_graph/readme/CREDITS.rst b/web_widget_json_graph/readme/CREDITS.rst new file mode 100644 index 000000000..d0ec12698 --- /dev/null +++ b/web_widget_json_graph/readme/CREDITS.rst @@ -0,0 +1 @@ +Vauxoo diff --git a/web_widget_json_graph/readme/DESCRIPTION.rst b/web_widget_json_graph/readme/DESCRIPTION.rst new file mode 100644 index 000000000..f4ccac423 --- /dev/null +++ b/web_widget_json_graph/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module allows to load a line graph per ordered pair from an One2many or +Many2many field. + +.. image:: ../static/description/widget_in_action.png + :width: 400px + :alt: Widget in action diff --git a/web_widget_json_graph/readme/ROADMAP.rst b/web_widget_json_graph/readme/ROADMAP.rst new file mode 100644 index 000000000..8da47ae01 --- /dev/null +++ b/web_widget_json_graph/readme/ROADMAP.rst @@ -0,0 +1 @@ +* None diff --git a/web_widget_json_graph/readme/USAGE.rst b/web_widget_json_graph/readme/USAGE.rst new file mode 100644 index 000000000..95a9f377a --- /dev/null +++ b/web_widget_json_graph/readme/USAGE.rst @@ -0,0 +1,63 @@ +Use this widget by including:: + + + +For example:: + + + +The JSON needs to be like:: + + info = { + "type": "line", + "data": {"datasets": [], "labels": []}, + "options": { + "scales": { + "yAxes": [ + { + "ticks": {"beginAtZero": True, "stacked": False}, + "scaleLabel": {"display": True, "labelString": "Quantity"}, + } + ], + "xAxes": [ + { + "scaleLabel": {"display": True, "labelString": "Date"}, + } + ], + }, + "elements": {"point": {"radius": 3}}, + "legend": {"labels": {"usePointStyle": True}}, + "tooltips": {"intersect": False, "axis": "xy", "mode": "index"}, + }, + } + self.field_text_json = json.dumps(info) + +For example:: + + plot_dataset = [1, 2, 3, 4, 3, 2] + labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] + info = { + "type": "line", + "data": {"datasets": plot_dataset, "labels": labels}, + "options": { + "scales": { + "yAxes": [ + { + "ticks": {"beginAtZero": True, "stacked": False}, + "scaleLabel": {"display": True, "labelString": "Quantity"}, + } + ], + "xAxes": [ + { + "scaleLabel": {"display": True, "labelString": "Date"}, + } + ], + }, + "elements": {"point": {"radius": 3}}, + "legend": {"labels": {"usePointStyle": True}}, + "tooltips": {"intersect": False, "axis": "xy", "mode": "index"}, + }, + } + self.values_data = json.dumps(info) + +For more information, please see `Chart Js Documentation `. diff --git a/web_widget_json_graph/static/description/icon.png b/web_widget_json_graph/static/description/icon.png new file mode 100644 index 000000000..2750f47fb Binary files /dev/null and b/web_widget_json_graph/static/description/icon.png differ diff --git a/web_widget_json_graph/static/description/index.html b/web_widget_json_graph/static/description/index.html new file mode 100644 index 000000000..25c77de5a --- /dev/null +++ b/web_widget_json_graph/static/description/index.html @@ -0,0 +1,512 @@ + + + + + + +Web Widget JSON Graph + + + +
+

Web Widget JSON Graph

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

This module allows to load a line graph per ordered pair from an One2many or +Many2many field.

+Widget in action +

Table of contents

+ +
+

Usage

+

Use this widget by including:

+
+<field name="field_text_json" widget="json_graph" />
+
+

For example:

+
+<field name="values_data" widget="json_graph"/>
+
+

The JSON needs to be like:

+
+fields = ['field1', 'field2', 'field3', ...]
+field_x = 'field_x'
+dictionary = self.value_ids.sorted(field_x).read(fields)
+color = {
+    'field1': HEXCOLOR1,
+    'field2': '#FFBB78',
+    'field3': '#1F77B4',
+    ...
+}
+dictionary = self.value_ids.sorted(field_x).read(fields)
+content = {}
+data = []
+for field in fields:
+    if field != field_x:
+        content[field] = []
+        for rec in dictionary:
+            content[field].append({'x': rec[field_x], 'y': rec[field]})
+        if field in color:
+            data.append({'values': content[field], 'key': field,
+                'color': color[field]})
+            continue
+        data.append({'values': content[field], 'key': field})
+info = {
+    'label_x': 'X Label',
+    'label_y': 'Y label',
+    'data': data
+}
+self.field_text_json = json.dumps(info)
+
+

For example:

+
+fields = ['sequence', 'value', 'sma', 'cma']
+field_x = 'sequence'
+dictionary = self.value_ids.sorted(field_x).read(fields)
+color = {
+    'value': '#2CA02C',
+    'sma': '#FFBB78'
+}
+dictionary = self.value_ids.sorted(field_x).read(fields)
+content = {}
+data = []
+for field in fields:
+    if field != field_x:
+        content[field] = []
+        for rec in dictionary:
+            content[field].append({'x': rec[field_x], 'y': rec[field]})
+        if field in color:
+            data.append({'values': content[field], 'key': field,
+                'color': color[field]})
+            continue
+        data.append({'values': content[field], 'key': field})
+info = {
+    'label_x': 'Sequence',
+    'label_y': '',
+    'data': data
+}
+self.values_data = json.dumps(info)
+
+
+
+

Known issues / Roadmap

+
    +
  • nolabel is ignored, this image will never bring a label, by default simply use an extra separator.
  • +
  • A graph will always use 100% of the width, pending the css dynamic attribute.
  • +
  • Height is harcoded.
  • +
+
+
+

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

+
    +
  • Vauxoo
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

Vauxoo

+
+
+

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.

+

Current maintainer:

+

luisg123v

+

This module is part of the OCA/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_widget_json_graph/static/description/widget_in_action.png b/web_widget_json_graph/static/description/widget_in_action.png new file mode 100644 index 000000000..c4d311ea0 Binary files /dev/null and b/web_widget_json_graph/static/description/widget_in_action.png differ diff --git a/web_widget_json_graph/static/src/js/web_widget_json_graph.js b/web_widget_json_graph/static/src/js/web_widget_json_graph.js new file mode 100644 index 000000000..3666f0835 --- /dev/null +++ b/web_widget_json_graph/static/src/js/web_widget_json_graph.js @@ -0,0 +1,29 @@ +odoo.define("web.web_widget_json_graph", function (require) { + "use strict"; + + var ajax = require("web.ajax"); + var AbstractField = require("web.AbstractField"); + var field_registry = require("web.field_registry"); + + var JSONGraphWidget = AbstractField.extend({ + jsLibs: ["/web/static/lib/Chart/Chart.js"], + willStart: function () { + this._super(); + return ajax.loadLibs(this); + }, + start: function () { + var config = JSON.parse(this.value); + this.$canvas = $(""); + this.$el.empty(); + this.$el.append(this.$canvas); + var context = this.$canvas[0].getContext("2d"); + // eslint-disable-next-line no-undef + this.chart = new Chart(context, config); + return this.chart; + }, + _destroy: function () { + return this._super(); + }, + }); + field_registry.add("json_graph", JSONGraphWidget); +}); diff --git a/web_widget_json_graph/static/src/xml/web_widget_json_graph.xml b/web_widget_json_graph/static/src/xml/web_widget_json_graph.xml new file mode 100644 index 000000000..19bf28419 --- /dev/null +++ b/web_widget_json_graph/static/src/xml/web_widget_json_graph.xml @@ -0,0 +1,6 @@ + + + + + +