-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathindex.js
114 lines (88 loc) · 3.21 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
107
108
109
110
111
112
113
114
/**
* Copyright 2012-2017, 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');
var constants = require('../cartesian/constants');
var Cartesian = require('../cartesian');
exports.name = 'gl2d';
exports.attr = ['xaxis', 'yaxis'];
exports.idRoot = ['x', 'y'];
exports.idRegex = constants.idRegex;
exports.attrRegex = constants.attrRegex;
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 id = oldSceneKeys[i],
oldSubplot = oldFullLayout._plots[id];
// old subplot wasn't gl2d; nothing to do
if(!oldSubplot._scene2d) continue;
// if no traces are present, delete gl2d subplot
var subplotData = Plots.getSubplotData(newFullData, 'gl2d', id);
if(subplotData.length === 0) {
oldSubplot._scene2d.destroy();
delete oldFullLayout._plots[id];
}
}
// since we use cartesian interactions, do cartesian clean
Cartesian.clean.apply(this, arguments);
};
exports.drawFramework = function(gd) {
if(!gd._context.staticPlot) {
Cartesian.drawFramework(gd);
}
};
exports.toSVG = function(gd) {
var fullLayout = gd._fullLayout,
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d');
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: 0,
y: 0,
width: '100%',
height: '100%',
preserveAspectRatio: 'none'
});
scene.destroy();
}
};