Veronika
9 years ago
9 changed files with 139 additions and 41 deletions
-
45web_graph_export_png/README.rst
-
3web_graph_export_png/__init__.py
-
17web_graph_export_png/__openerp__.py
-
BINweb_graph_export_png/static/description/icon.png
-
42web_graph_export_png/static/src/js/web_graph_export_png.js
-
14web_graph_export_png/static/src/xml/web_graph_export_png.xml
-
17web_graph_export_png/view/web_graph_export_png.xml
-
35web_graph_radar/static/src/js/web_graph_radar.js
-
5web_graph_radar/static/src/xml/web_graph_radar.xml
@ -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. |
@ -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). |
@ -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, |
|||
} |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -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(); |
|||
}; |
|||
} |
|||
}, |
|||
}); |
|||
} |
@ -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> |
@ -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> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue