-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdefaults.js
More file actions
94 lines (76 loc) · 2.45 KB
/
defaults.js
File metadata and controls
94 lines (76 loc) · 2.45 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
var Lib = require('../../lib');
var Template = require('../../plot_api/plot_template');
var attributes = require('./attributes');
module.exports = function colorlegendDefaults(layoutIn, layoutOut, fullData) {
var colorlegendIds = findColorlegendIds(fullData);
layoutOut._colorlegends = [];
for(var i = 0; i < colorlegendIds.length; i++) {
var id = colorlegendIds[i];
var containerIn = layoutIn[id] || {};
var containerOut = Template.newContainer(layoutOut, id);
handleColorlegendDefaults(containerIn, containerOut, layoutOut, id);
if(containerOut.visible) {
containerOut._id = id;
layoutOut._colorlegends.push(id);
}
}
};
function findColorlegendIds(fullData) {
var ids = [];
for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];
if(!trace.visible) continue;
var marker = trace.marker;
if(marker && marker.colorlegend) {
var id = marker.colorlegend;
if(ids.indexOf(id) === -1) {
ids.push(id);
}
}
}
return ids;
}
function handleColorlegendDefaults(containerIn, containerOut, layoutOut, id) {
function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
}
var visible = coerce('visible');
if(!visible) return;
// Title
coerce('title.text');
Lib.coerceFont(coerce, 'title.font', layoutOut.font);
coerce('title.side');
// Orientation first - affects positioning defaults
var orientation = coerce('orientation');
// Positioning - defaults depend on orientation
var isHorizontal = orientation === 'h';
if(isHorizontal) {
// Horizontal: top-right, outside the chart
coerce('x', 1.02);
coerce('xanchor', 'left');
coerce('y', 1);
coerce('yanchor', 'top');
} else {
// Vertical: right side of chart (default from attributes)
coerce('x');
coerce('xanchor');
coerce('y');
coerce('yanchor');
}
coerce('xref');
coerce('yref');
// Styling
coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
coerce('borderwidth');
Lib.coerceFont(coerce, 'font', layoutOut.font);
coerce('itemsizing');
coerce('itemwidth');
// Behavior
coerce('itemclick');
coerce('itemdoubleclick');
// Binning
coerce('binning');
coerce('nbins');
}