Skip to content

Commit 7d38cf0

Browse files
committed
Update schema and set defaults
1 parent a4ce2b7 commit 7d38cf0

File tree

3 files changed

+873
-84
lines changed

3 files changed

+873
-84
lines changed

src/components/colorbar/attributes.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,23 @@ module.exports = overrideAll({
6060
min: -2,
6161
max: 3,
6262
description: [
63-
'Sets the x position of the color bar (in plot fraction).',
64-
'Defaults to 1.02 when `orientation` is *v* and',
65-
'0.5 when `orientation` is *h*.'
63+
'Sets the x position with respect to `xref` of the color bar (in plot fraction).',
64+
'When `xref` is *paper*, defaults to 1.02 when `orientation` is *v* and',
65+
'0.5 when `orientation` is *h*.',
66+
'When `xref` is *container*, defaults to *1* when `orientation` is *v* and',
67+
'0.5 when `orientation` is *h*.',
68+
'Must be between *0* and *1* if `xref` is *container*.'
69+
].join(' ')
70+
},
71+
xref: {
72+
valType: 'enumerated',
73+
dflt: 'paper',
74+
values: ['container', 'paper'],
75+
editType: 'layoutstyle',
76+
description: [
77+
'Sets the container `x` refers to.',
78+
'*container* spans the entire `width` of the plot.',
79+
'*paper* refers to the width of the plotting area only.'
6680
].join(' ')
6781
},
6882
xanchor: {
@@ -87,11 +101,25 @@ module.exports = overrideAll({
87101
min: -2,
88102
max: 3,
89103
description: [
90-
'Sets the y position of the color bar (in plot fraction).',
91-
'Defaults to 0.5 when `orientation` is *v* and',
92-
'1.02 when `orientation` is *h*.'
104+
'Sets the y position with respect to `yref` of the color bar (in plot fraction).',
105+
'When `yref` is *paper*, defaults to 0.5 when `orientation` is *v* and',
106+
'1.02 when `orientation` is *h*.',
107+
'When `yref` is *container*, defaults to 0.5 when `orientation` is *v* and',
108+
'1 when `orientation` is *h*.',
109+
'Must be between *0* and *1* if `yref` is *container*.'
93110
].join(' ')
94111
},
112+
yref: {
113+
valType: 'enumerated',
114+
dflt: 'paper',
115+
values: ['container', 'paper'],
116+
editType: 'layoutstyle',
117+
description: [
118+
'Sets the container `y` refers to.',
119+
'*container* spans the entire `height` of the plot.',
120+
'*paper* refers to the height of the plotting area only.'
121+
].join(' '),
122+
},
95123
yanchor: {
96124
valType: 'enumerated',
97125
values: ['top', 'middle', 'bottom'],

src/components/colorbar/defaults.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,32 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
3737
isVertical ? h : w
3838
);
3939

40-
coerce('x', isVertical ? 1.02 : 0.5);
41-
coerce('xanchor', isVertical ? 'left' : 'center');
40+
var yref = coerce('yref');
41+
var xref = coerce('xref');
42+
43+
var isPaperY = yref === 'paper';
44+
var isPaperX = xref === 'paper';
45+
46+
var defaultX, defaultY, defaultYAnchor;
47+
var defaultXAnchor = 'left';
48+
49+
if(isVertical) {
50+
defaultYAnchor = 'middle';
51+
defaultXAnchor = 'left';
52+
defaultX = isPaperX ? 1.02 : 1;
53+
defaultY = 0.5;
54+
} else {
55+
defaultYAnchor = 'bottom';
56+
defaultXAnchor = 'center';
57+
defaultX = 0.5;
58+
defaultY = isPaperY ? 1.02 : 1;
59+
}
60+
61+
coerce('x', defaultX);
62+
coerce('xanchor', defaultXAnchor);
4263
coerce('xpad');
43-
coerce('y', isVertical ? 0.5 : 1.02);
44-
coerce('yanchor', isVertical ? 'middle' : 'bottom');
64+
coerce('y', defaultY);
65+
coerce('yanchor', defaultYAnchor);
4566
coerce('ypad');
4667
Lib.noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);
4768

0 commit comments

Comments
 (0)