Browse Source

[ADD] web_graph_radar: added export to png

pull/328/head
Veronika 9 years ago
parent
commit
804cb1aa34
  1. 37
      web_graph_radar/static/src/js/web_graph_radar.js
  2. 5
      web_graph_radar/static/src/xml/web_graph_radar.xml

37
web_graph_radar/static/src/js/web_graph_radar.js

@ -80,6 +80,41 @@ 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,6 +9,11 @@
<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