mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[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:
committed by
Francisco Javier Luna Vazquez
parent
d4704c67c4
commit
802570e791
4
web_widget_json_graph/readme/CONTRIBUTORS.rst
Normal file
4
web_widget_json_graph/readme/CONTRIBUTORS.rst
Normal 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>
|
||||
1
web_widget_json_graph/readme/CREDITS.rst
Normal file
1
web_widget_json_graph/readme/CREDITS.rst
Normal file
@@ -0,0 +1 @@
|
||||
Vauxoo
|
||||
6
web_widget_json_graph/readme/DESCRIPTION.rst
Normal file
6
web_widget_json_graph/readme/DESCRIPTION.rst
Normal 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
|
||||
3
web_widget_json_graph/readme/ROADMAP.rst
Normal file
3
web_widget_json_graph/readme/ROADMAP.rst
Normal 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.
|
||||
67
web_widget_json_graph/readme/USAGE.rst
Normal file
67
web_widget_json_graph/readme/USAGE.rst
Normal 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)
|
||||
Reference in New Issue
Block a user