-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathindex.js
106 lines (82 loc) · 2.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var Scene2D = require('./scene2d');
var Plots = require('../plots');
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
exports.name = 'gl2d';
exports.attr = ['xaxis', 'yaxis'];
exports.idRoot = ['x', 'y'];
exports.idRegex = {
x: /^x([2-9]|[1-9][0-9]+)?$/,
y: /^y([2-9]|[1-9][0-9]+)?$/
};
exports.attrRegex = {
x: /^xaxis([2-9]|[1-9][0-9]+)?$/,
y: /^yaxis([2-9]|[1-9][0-9]+)?$/
};
exports.attributes = require('../cartesian/attributes');
exports.plot = function plotGl2d(gd) {
var fullLayout = gd._fullLayout,
fullData = gd._fullData,
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d');
for(var i = 0; i < subplotIds.length; i++) {
var subplotId = subplotIds[i],
subplotObj = fullLayout._plots[subplotId],
fullSubplotData = Plots.getSubplotData(fullData, 'gl2d', subplotId);
// ref. to corresp. Scene instance
var scene = subplotObj._scene2d;
// If Scene is not instantiated, create one!
if(scene === undefined) {
scene = new Scene2D({
id: subplotId,
graphDiv: gd,
container: gd.querySelector('.gl-container'),
staticPlot: gd._context.staticPlot,
plotGlPixelRatio: gd._context.plotGlPixelRatio
},
fullLayout
);
// set ref to Scene instance
subplotObj._scene2d = scene;
}
scene.plot(fullSubplotData, gd.calcdata, fullLayout, gd.layout);
}
};
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var oldSceneKeys = Plots.getSubplotIds(oldFullLayout, 'gl2d');
for(var i = 0; i < oldSceneKeys.length; i++) {
var oldSubplot = oldFullLayout._plots[oldSceneKeys[i]],
xaName = oldSubplot.xaxis._name,
yaName = oldSubplot.yaxis._name;
if(!!oldSubplot._scene2d && (!newFullLayout[xaName] || !newFullLayout[yaName])) {
oldSubplot._scene2d.destroy();
}
}
};
exports.toSVG = function(gd) {
var fullLayout = gd._fullLayout,
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d'),
size = fullLayout._size;
for(var i = 0; i < subplotIds.length; i++) {
var subplot = fullLayout._plots[subplotIds[i]],
scene = subplot._scene2d;
var imageData = scene.toImage('png');
var image = fullLayout._glimages.append('svg:image');
image.attr({
xmlns: xmlnsNamespaces.svg,
'xlink:href': imageData,
x: size.l,
y: size.t,
width: size.w,
height: size.h,
preserveAspectRatio: 'none'
});
scene.destroy();
}
};