[ADD] web_widget_json_graph: Module to Draw json fields with graphs (#1733)

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

Co-Authored-By: Francisco Luna <fluna@vauxoo.com>
Co-Authored-By: José Robles <josemanuel@vauxoo.com>
Co-Authored-By: Luis González <lgonzalez@vauxoo.com>
Co-Authored-By: Nhomar Hernández <nhomar@vauxoo.com>

Co-authored-by: Francisco Luna <fluna@vauxoo.com>
Co-authored-by: José Robles <josemanuel@vauxoo.com>
Co-authored-by: Nhomar Hernández <nhomar@vauxoo.com>
This commit is contained in:
Luis González [Vauxoo]
2020-11-23 21:50:46 -06:00
committed by Francisco Javier Luna Vazquez
parent d4704c67c4
commit 802570e791
16 changed files with 2173 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
* Francisco Luna <fluna@vauxoo.com>
* José Robles <josemanuel@vauxoo.com>
* Luis González <lgonzalez@vauxoo.com>
* Nhomar Hernández <nhomar@vauxoo.com>

View File

@@ -0,0 +1 @@
Vauxoo

View File

@@ -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

View File

@@ -0,0 +1,3 @@
* ``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.

View File

@@ -0,0 +1,67 @@
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)