-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathindex.js
82 lines (68 loc) · 2.16 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
/**
* 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 Plots = require('../../plots/plots');
var counterRegex = require('../../lib').counterRegex;
var createPolar = require('./polar');
var constants = require('./constants');
var attr = constants.attr;
var name = constants.name;
var counter = counterRegex(name);
var attributes = {};
attributes[attr] = {
valType: 'subplotid',
role: 'info',
dflt: name,
editType: 'calc',
description: [
'Sets a reference between this trace\'s data coordinates and',
'a polar subplot.',
'If *polar* (the default value), the data refer to `layout.polar`.',
'If *polar2*, the data refer to `layout.polar2`, and so on.'
].join(' ')
};
function plot(gd) {
var fullLayout = gd._fullLayout;
var calcData = gd.calcdata;
var subplotIds = Plots.getSubplotIds(fullLayout, name);
for(var i = 0; i < subplotIds.length; i++) {
var id = subplotIds[i];
var subplotCalcData = Plots.getSubplotCalcData(calcData, name, id);
var subplot = fullLayout[id]._subplot;
if(!subplot) {
subplot = createPolar(gd, id);
fullLayout[id]._subplot = subplot;
}
subplot.plot(subplotCalcData, fullLayout, gd._promises);
}
}
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var oldIds = Plots.getSubplotIds(oldFullLayout, name);
for(var i = 0; i < oldIds.length; i++) {
var id = oldIds[i];
var oldSubplot = oldFullLayout[id]._subplot;
if(!newFullLayout[id] && !!oldSubplot) {
oldSubplot.framework.remove();
for(var k in oldSubplot.clipPaths) {
oldSubplot.clipPaths[k].remove();
}
}
}
}
module.exports = {
attr: attr,
name: name,
idRoot: name,
idRegex: counter,
attrRegex: counter,
attributes: attributes,
layoutAttributes: require('./layout_attributes'),
supplyLayoutDefaults: require('./layout_defaults'),
plot: plot,
clean: clean
};