Browse Source

[ADD] added module web_graph_export_png

pull/328/head
Veronika 8 years ago
parent
commit
bddb601e95
  1. 45
      web_graph_export_png/README.rst
  2. 3
      web_graph_export_png/__init__.py
  3. 17
      web_graph_export_png/__openerp__.py
  4. BIN
      web_graph_export_png/static/description/icon.png
  5. 42
      web_graph_export_png/static/src/js/web_graph_export_png.js
  6. 14
      web_graph_export_png/static/src/xml/web_graph_export_png.xml
  7. 17
      web_graph_export_png/view/web_graph_export_png.xml
  8. 37
      web_graph_radar/static/src/js/web_graph_radar.js
  9. 5
      web_graph_radar/static/src/xml/web_graph_radar.xml

45
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
<https://github.com/OCA/web/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
<https://github.com/OCA/
web/issues/new?body=module:%20
web_graph_export_png%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Veronika Kotovich <veronika.kotovich@gmail.com>
* Florent THOMAS (financial support) <https://github.com/MindAndGo>
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.

3
web_graph_export_png/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 IT-Projects <https://www.it-projects.info>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

17
web_graph_export_png/__openerp__.py

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# © 2016 IT-Projects <https://www.it-projects.info>
# 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,
}

BIN
web_graph_export_png/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

42
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();
};
}
},
});
}

14
web_graph_export_png/static/src/xml/web_graph_export_png.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="GraphWidgetRadar" t-extend="GraphWidget">
<t t-jquery=".graph_options_selection" t-operation="append">
<label class="btn btn-default" data-choice="export_png" title="Export PNG">
<span class="fa fa-file-image-o"></span>
</label>
</t>
</t>
</templates>

17
web_graph_export_png/view/web_graph_export_png.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend"
name="web_graph_export_png assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_graph_export_png/static/src/js/web_graph_export_png.js">
</script>
</xpath>
</template>
</data>
</openerp>

37
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();
};
}
},
}
});
}

5
web_graph_radar/static/src/xml/web_graph_radar.xml

@ -9,11 +9,6 @@
<input type="radio" name="modes"/><span class="fa fa-certificate"></span>
</label>
</t>
<t t-jquery=".graph_options_selection" t-operation="append">
<label class="btn btn-default" data-choice="export_png" title="Export PNG">
<span class="fa fa-file-image-o"></span>
</label>
</t>
</t>
</templates>
Loading…
Cancel
Save