Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathsubplot_defaults.js
More file actions
Latest commit
70 lines (57 loc) · 2.66 KB
/
Copy pathsubplot_defaults.js
File metadata and controls
70 lines (57 loc) · 2.66 KB
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
'use strict';
varLib=require('../lib');
varTemplate=require('../plot_api/plot_template');
varhandleDomainDefaults=require('./domain').defaults;
/**
* Find and supply defaults to all subplots of a given type
* This handles subplots that are contained within one container - so
* gl3d, geo, ternary... but not 2d axes which have separate x and y axes
* finds subplots, coerces their `domain` attributes, then calls the
* given handleDefaults function to fill in everything else.
*
* layoutIn: the complete user-supplied input layout
* layoutOut: the complete finished layout
* fullData: the finished data array, used only to find subplots
* opts: {
* type: subplot type string
* attributes: subplot attributes object
* partition: 'x' or 'y', which direction to divide domain space by default
* (default 'x', ie side-by-side subplots)
* TODO: this option is only here because 3D and geo made opposite
* choices in this regard previously and I didn't want to change it.
* Instead we should do:
* - something consistent
* - something more square (4 cuts 2x2, 5/6 cuts 2x3, etc.)
* - something that includes all subplot types in one arrangement,
* now that we can have them together!
* handleDefaults: function of (subplotLayoutIn, subplotLayoutOut, coerce, opts)
* this opts object is passed through to handleDefaults, so attach any
* additional items needed by this function here as well
* }
*/
module.exports=functionhandleSubplotDefaults(layoutIn,layoutOut,fullData,opts){
varsubplotType=opts.type;
varsubplotAttributes=opts.attributes;
varhandleDefaults=opts.handleDefaults;
varpartition=opts.partition||'x';
varids=layoutOut._subplots[subplotType];
varidsLength=ids.length;
varbaseId=idsLength&&ids[0].replace(/\d+$/,'');
varsubplotLayoutIn,subplotLayoutOut;
functioncoerce(attr,dflt){
returnLib.coerce(subplotLayoutIn,subplotLayoutOut,subplotAttributes,attr,dflt);
}
for(vari=0;i<idsLength;i++){
varid=ids[i];
// ternary traces get a layout ternary for free!
if(layoutIn[id])subplotLayoutIn=layoutIn[id];
elsesubplotLayoutIn=layoutIn[id]={};
subplotLayoutOut=Template.newContainer(layoutOut,id,baseId);
if(!opts.noUirevision)coerce('uirevision',layoutOut.uirevision);
vardfltDomains={};
dfltDomains[partition]=[i/idsLength,(i+1)/idsLength];
handleDomainDefaults(subplotLayoutOut,layoutOut,coerce,dfltDomains);
opts.id=id;
handleDefaults(subplotLayoutIn,subplotLayoutOut,coerce,opts);
}
};