Skip to content

Commit 0983b21

Browse files
dyetpinard
authored andcommitted
Make toSVG
1 parent a6f86db commit 0983b21

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/plots/cartesian/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var getModuleCalcData = require('../get_data').getModuleCalcData;
1616

1717
var axisIds = require('./axis_ids');
1818
var constants = require('./constants');
19+
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1920

2021
exports.name = 'cartesian';
2122

@@ -523,3 +524,28 @@ function joinLayer(parent, nodeType, className, dataVal) {
523524

524525
return layer;
525526
}
527+
528+
exports.toSVG = function(gd) {
529+
var imageRoot = gd._fullLayout._glimages;
530+
var root = d3.select(gd).selectAll('.svg-container');
531+
var canvases = root.filter(function(d, i) {return i === root.size() - 1;})
532+
.selectAll('.gl-canvas-context, .gl-canvas-focus');
533+
534+
function canvasToImage() {
535+
var canvas = this;
536+
var imageData = canvas.toDataURL('image/png');
537+
var image = imageRoot.append('svg:image');
538+
539+
image.attr({
540+
xmlns: xmlnsNamespaces.svg,
541+
'xlink:href': imageData,
542+
preserveAspectRatio: 'none',
543+
x: 0,
544+
y: 0,
545+
width: canvas.width,
546+
height: canvas.height
547+
});
548+
}
549+
550+
canvases.each(canvasToImage);
551+
};

src/plots/polar/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ module.exports = {
7979
layoutAttributes: require('./layout_attributes'),
8080
supplyLayoutDefaults: require('./layout_defaults'),
8181
plot: plot,
82-
clean: clean
82+
clean: clean,
83+
toSVG: require('../cartesian').toSVG
8384
};

src/traces/scattergl/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ ScatterGl.sceneOptions = function sceneOptions(container, subplot, trace, positi
521521
};
522522

523523

524-
// make sure scene exists on subplot
524+
// make sure scene exists on subplot, return it
525525
ScatterGl.scene = function getScene(container, subplot) {
526526
var scene = subplot._scene;
527527
var layout = container._fullLayout;

0 commit comments

Comments
 (0)