[MIG] web_widget_json_graph: Migration to 15.0

This commit is contained in:
Francisco Javier Luna Vazquez
2022-05-19 16:00:45 -05:00
parent b9c1cae096
commit 893247b517
9 changed files with 76 additions and 1430 deletions

View File

@@ -1,41 +1,25 @@
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({
template: "JSONGraph",
cssLibs: ["/web/static/lib/nvd3/nv.d3.css"],
jsLibs: [
"/web/static/lib/nvd3/d3.v3.js",
"/web/static/lib/nvd3/nv.d3.js",
"/web/static/src/js/libs/nvd3.js",
],
_render: function () {
var info = JSON.parse(this.value);
/* Jsl:ignore*/
/*
Ignoring lint erros caused by nv and d3 variables from NVD3.js
*/
if (info) {
nv.addGraph(function () {
var chart = nv.models.lineChart().useInteractiveGuideline(true);
chart.xAxis.axisLabel(info.label_x).tickFormat(d3.format(",r"));
chart.yAxis.axisLabel(info.label_y).tickFormat(d3.format(".02f"));
d3.select(".nv_content svg")
.datum(info.data)
.transition()
.duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
/* Jsl:end*/
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 = $("<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();