-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathconvert.js
63 lines (51 loc) · 1.75 KB
/
convert.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
/**
* 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 Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
module.exports = function convert(scene) {
var fullSceneLayout = scene.fullSceneLayout;
var anns = fullSceneLayout.annotations;
for(var i = 0; i < anns.length; i++) {
mockAnnAxes(anns[i], scene);
}
scene.fullLayout._infolayer
.selectAll('.annotation-' + scene.id)
.remove();
};
function mockAnnAxes(ann, scene) {
var fullSceneLayout = scene.fullSceneLayout;
var domain = fullSceneLayout.domain;
var size = scene.fullLayout._size;
var base = {
// this gets fill in on render
pdata: null,
// to get setConvert to not execute cleanly
type: 'linear',
// don't try to update them on `editable: true`
autorange: false,
// set infinite range so that annotation draw routine
// does not try to remove 'outside-range' annotations,
// this case is handled in the render loop
range: [-Infinity, Infinity]
};
ann._xa = {};
Lib.extendFlat(ann._xa, base);
Axes.setConvert(ann._xa);
ann._xa._offset = size.l + domain.x[0] * size.w;
ann._xa.l2p = function() {
return 0.5 * (1 + ann.pdata[0] / ann.pdata[3]) * size.w * (domain.x[1] - domain.x[0]);
};
ann._ya = {};
Lib.extendFlat(ann._ya, base);
Axes.setConvert(ann._ya);
ann._ya._offset = size.t + (1 - domain.y[1]) * size.h;
ann._ya.l2p = function() {
return 0.5 * (1 - ann.pdata[1] / ann.pdata[3]) * size.h * (domain.y[1] - domain.y[0]);
};
}