mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[15.0][MIG] web_widget_mpld3_chart
This commit is contained in:
committed by
Franco Leyes
parent
1ce441f118
commit
423c2dfd59
@@ -3,7 +3,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
|
||||
<title>Web Widget mpld3 Chart</title>
|
||||
<style type="text/css">
|
||||
|
||||
@@ -367,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_widget_mpld3_chart"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_widget_mpld3_chart"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_widget_mpld3_chart"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_mpld3_chart"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>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.</p>
|
||||
<p>If you want to see some samples of mpld3’s capabilities follow this <a class="reference external" href="http://mpld3.github.io/">link</a>.</p>
|
||||
@@ -397,9 +397,15 @@ pip install mpld3
|
||||
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
|
||||
<p>To insert a mpld3 chart in a view proceed as follows:</p>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">You should inherit from abstract class abstract.mpld3.parser:</p>
|
||||
<pre class="literal-block">
|
||||
_name = 'res.partner'
|
||||
_inherit = ['res.partner', 'abstract.mpld3.parser']
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Import the required libraries:</p>
|
||||
<pre class="literal-block">
|
||||
import matplotlib.pyplot as plt, mpld3
|
||||
import matplotlib.pyplot as plt
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Declare a text computed field like this:</p>
|
||||
@@ -417,7 +423,7 @@ def _compute_mpld3_chart(self):
|
||||
# Design your mpld3 figure:
|
||||
plt.scatter([1, 10], [5, 9])
|
||||
figure = plt.figure()
|
||||
rec.mpld3_chart = mpld3.fig_to_html(figure)
|
||||
rec.mpld3_chart = self.convert_figure_to_json(figure)
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">In the view, add something like this wherever you want to display your
|
||||
@@ -435,7 +441,7 @@ mpld3 chart:</p>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
|
||||
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
|
||||
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_mpld3_chart%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_mpld3_chart%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
@@ -450,6 +456,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Jordi Ballester Alomar <<a class="reference external" href="mailto:jordi.ballester@forgeflow.com">jordi.ballester@forgeflow.com</a>></li>
|
||||
<li>Christopher Ormaza <<a class="reference external" href="mailto:chris.ormaza@forgeflow.com">chris.ormaza@forgeflow.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="other-credits">
|
||||
@@ -468,7 +475,9 @@ Copyright (c) 2013, Jake Vanderplas</li>
|
||||
<p>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.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_widget_mpld3_chart">OCA/web</a> project on GitHub.</p>
|
||||
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
|
||||
<p><a class="reference external" href="https://github.com/JordiBForgeFlow"><img alt="JordiBForgeFlow" src="https://github.com/JordiBForgeFlow.png?size=40px" /></a> <a class="reference external" href="https://github.com/ChrisOForgeFlow"><img alt="ChrisOForgeFlow" src="https://github.com/ChrisOForgeFlow.png?size=40px" /></a></p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_widget_mpld3_chart">OCA/web</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import basicFields from "web.basic_fields";
|
||||
import fieldRegistry from "web.field_registry";
|
||||
|
||||
const Mpld3ChartWidget = basicFields.FieldChar.extend({
|
||||
jsLibs: [
|
||||
"/web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js",
|
||||
"/web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.7.js",
|
||||
],
|
||||
_renderReadonly: function () {
|
||||
try {
|
||||
const val = JSON.parse(this.value);
|
||||
const new_div = document.createElement("div");
|
||||
new_div.setAttribute("id", val.div);
|
||||
this.$el.html(new_div);
|
||||
this.$el.ready(function () {
|
||||
const script = document.createElement("script");
|
||||
script.setAttribute("type", "text/javascript");
|
||||
if ("textContent" in script) script.textContent = val.script;
|
||||
else script.text = val.script;
|
||||
$("head").append(script);
|
||||
});
|
||||
} catch (error) {
|
||||
return this._super(...arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
fieldRegistry.add("mpld3_chart", Mpld3ChartWidget);
|
||||
export default Mpld3ChartWidget;
|
||||
@@ -1,17 +0,0 @@
|
||||
odoo.define("web_widget_mpld3_chart", function (require) {
|
||||
"use strict";
|
||||
|
||||
var fieldRegistry = require("web.field_registry");
|
||||
var AbstractField = require("web.AbstractField");
|
||||
|
||||
var Mpld3ChartWidget = AbstractField.extend({
|
||||
start: function () {
|
||||
var val = this.value;
|
||||
this.$el.html(val);
|
||||
},
|
||||
});
|
||||
fieldRegistry.add("mpld3_chart", Mpld3ChartWidget);
|
||||
return {
|
||||
Mpld3ChartWidget: Mpld3ChartWidget,
|
||||
};
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
18568
web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js
vendored
Normal file
18568
web_widget_mpld3_chart/static/src/lib/d3/d3.v5.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2079
web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.7.js
Normal file
2079
web_widget_mpld3_chart/static/src/lib/mpld3/mpld3.v0.5.7.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user