diff --git a/web_graph_export_png/README.rst b/web_graph_export_png/README.rst new file mode 100644 index 00000000..bbf62667 --- /dev/null +++ b/web_graph_export_png/README.rst @@ -0,0 +1,45 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================== +Graph Export To PNG +=================== + +This module extends the functionality of web_graph module allow export to png + +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 +`_. + +Credits +======= + +Contributors +------------ + +* Veronika Kotovich +* Florent THOMAS (financial support) + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_graph_export_png/__init__.py b/web_graph_export_png/__init__.py new file mode 100644 index 00000000..e095c40c --- /dev/null +++ b/web_graph_export_png/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2016 IT-Projects +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). \ No newline at end of file diff --git a/web_graph_export_png/__openerp__.py b/web_graph_export_png/__openerp__.py new file mode 100644 index 00000000..b36be41c --- /dev/null +++ b/web_graph_export_png/__openerp__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2016 IT-Projects +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Graph Export to PNG', + 'version': '8.0.1.0.0', + 'category': 'Web', + 'summary': 'Add graph export to png option.', + 'author': "IT-Projects LLC,Odoo Community Association (OCA)", + 'license': 'AGPL-3', + 'website': 'https://twitter.com/vkotovi4', + 'depends': ['web_graph'], + 'qweb': ['static/src/xml/web_graph_export_png.xml'], + 'data': ['view/web_graph_export_png.xml'], + 'installable': True, + 'auto_install': False, +} \ No newline at end of file diff --git a/web_graph_export_png/static/description/icon.png b/web_graph_export_png/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_graph_export_png/static/description/icon.png differ diff --git a/web_graph_export_png/static/src/js/web_graph_export_png.js b/web_graph_export_png/static/src/js/web_graph_export_png.js new file mode 100644 index 00000000..c90354ee --- /dev/null +++ b/web_graph_export_png/static/src/js/web_graph_export_png.js @@ -0,0 +1,42 @@ +openerp.web_graph_export_png = function(instance) { + + var _t = instance.web._t; + + instance.web_graph.Graph.include({ + option_selection: function (event) { + this._super(event); + if (event.currentTarget.getAttribute('data-choice') == 'export_png') { + var svg = document.querySelector("svg"); + + if (typeof window.XMLSerializer != "undefined") { + var svgData = (new XMLSerializer()).serializeToString(svg); + } else if (typeof svg.xml != "undefined") { + var svgData = svg.xml; + } + + var canvas = document.createElement("canvas"); + var svgSize = svg.getBoundingClientRect(); + canvas.width = svgSize.width; + canvas.height = svgSize.height; + var ctx = canvas.getContext("2d"); + //set background color + ctx.fillStyle = 'white'; + //draw background / rect on entire canvas + ctx.fillRect(0,0,canvas.width,canvas.height); + + var img = document.createElement("img"); + img.setAttribute("src", "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgData))) ); + img.onload = function() { + ctx.drawImage(img, 0, 0); + var imgsrc = canvas.toDataURL("image/png", 1.0); + var a = document.createElement("a"); + a.download = "graph"+".png"; + a.href = imgsrc; + document.body.appendChild(a); + a.click(); + a.remove(); + }; + } + }, + }); +} diff --git a/web_graph_export_png/static/src/xml/web_graph_export_png.xml b/web_graph_export_png/static/src/xml/web_graph_export_png.xml new file mode 100644 index 00000000..85b999c8 --- /dev/null +++ b/web_graph_export_png/static/src/xml/web_graph_export_png.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/web_graph_export_png/view/web_graph_export_png.xml b/web_graph_export_png/view/web_graph_export_png.xml new file mode 100644 index 00000000..a01af259 --- /dev/null +++ b/web_graph_export_png/view/web_graph_export_png.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/web_graph_radar/static/src/js/web_graph_radar.js b/web_graph_radar/static/src/js/web_graph_radar.js index a9430942..3d461ad0 100644 --- a/web_graph_radar/static/src/js/web_graph_radar.js +++ b/web_graph_radar/static/src/js/web_graph_radar.js @@ -77,41 +77,6 @@ openerp.web_graph_radar = function(instance) { return chart; }); - }, - option_selection: function (event) { - this._super(event); - if (event.currentTarget.getAttribute('data-choice') == 'export_png') { - var svg = document.querySelector("svg"); - - if (typeof window.XMLSerializer != "undefined") { - var svgData = (new XMLSerializer()).serializeToString(svg); - } else if (typeof svg.xml != "undefined") { - var svgData = svg.xml; - } - - var canvas = document.createElement("canvas"); - var svgSize = svg.getBoundingClientRect(); - canvas.width = svgSize.width; - canvas.height = svgSize.height; - var ctx = canvas.getContext("2d"); - //set background color - ctx.fillStyle = 'white'; - //draw background / rect on entire canvas - ctx.fillRect(0,0,canvas.width,canvas.height); - - var img = document.createElement("img"); - img.setAttribute("src", "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgData))) ); - img.onload = function() { - ctx.drawImage(img, 0, 0); - var imgsrc = canvas.toDataURL("image/png", 1.0); - var a = document.createElement("a"); - a.download = "graph"+".png"; - a.href = imgsrc; - document.body.appendChild(a); - a.click(); - a.remove(); - }; - } - }, + } }); } diff --git a/web_graph_radar/static/src/xml/web_graph_radar.xml b/web_graph_radar/static/src/xml/web_graph_radar.xml index 761f15cc..9e5bf4ac 100644 --- a/web_graph_radar/static/src/xml/web_graph_radar.xml +++ b/web_graph_radar/static/src/xml/web_graph_radar.xml @@ -9,11 +9,6 @@ - - - \ No newline at end of file