Skip to content

Commit fbea869

Browse files
committed
🌴 domain attributes
1 parent 7b0f718 commit fbea869

File tree

10 files changed

+100
-269
lines changed

10 files changed

+100
-269
lines changed

Diff for: src/plots/domain_attributes.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var extendFlat = require('../lib/extend').extendFlat;
12+
13+
/**
14+
* Make a xy domain attribute group
15+
*
16+
* @param {object} opts
17+
* @param {string}
18+
* opts.name: name to be inserted in the default description
19+
* @param {boolean}
20+
* opts.trace: set to true for trace containers
21+
* @param {string}
22+
* opts.editType: editType for all pieces
23+
*
24+
* @param {object} extra
25+
* @param {string}
26+
* extra.description: extra description. N.B we use
27+
* a separate extra container to make it compatible with
28+
* the compress_attributes transform.
29+
*
30+
* @return {object} attributes object containing {x,y} as specified
31+
*/
32+
module.exports = function(opts, extra) {
33+
opts = opts || {};
34+
extra = extra || {};
35+
36+
var base = {
37+
valType: 'info_array',
38+
role: 'info',
39+
editType: opts.editType,
40+
items: [
41+
{valType: 'number', min: 0, max: 1},
42+
{valType: 'number', min: 0, max: 1}
43+
],
44+
dflt: [0, 1]
45+
};
46+
47+
var namePart = opts.name || '';
48+
var contPart = opts.trace ? 'trace' : 'subplot';
49+
50+
return {
51+
x: extendFlat({}, base, {
52+
description: [
53+
'Sets the horizontal domain of this',
54+
namePart,
55+
contPart,
56+
'(in plot fraction).',
57+
extra.description
58+
].join(' ')
59+
}),
60+
y: extendFlat({}, base, {
61+
description: [
62+
'Sets the vertical domain of this',
63+
namePart,
64+
contPart,
65+
'(in plot fraction).',
66+
extra.description
67+
].join(' ')
68+
}),
69+
editType: opts.editType
70+
};
71+
};

Diff for: src/plots/geo/layout/layout_attributes.js

+9-34
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var colorAttrs = require('../../../components/color/attributes');
12+
var domainAttrs = require('../../domain_attributes');
1213
var constants = require('../constants');
1314
var overrideAll = require('../../../plot_api/edit_types').overrideAll;
1415

@@ -65,40 +66,14 @@ var geoAxesAttrs = {
6566
};
6667

6768
module.exports = overrideAll({
68-
domain: {
69-
x: {
70-
valType: 'info_array',
71-
role: 'info',
72-
items: [
73-
{valType: 'number', min: 0, max: 1},
74-
{valType: 'number', min: 0, max: 1}
75-
],
76-
dflt: [0, 1],
77-
description: [
78-
'Sets the maximum horizontal domain of this map',
79-
'(in plot fraction).',
80-
'Note that geo subplots are constrained by domain.',
81-
'In general, when `projection.scale` is set to 1.',
82-
'a map will fit either its x or y domain, but not both. '
83-
].join(' ')
84-
},
85-
y: {
86-
valType: 'info_array',
87-
role: 'info',
88-
items: [
89-
{valType: 'number', min: 0, max: 1},
90-
{valType: 'number', min: 0, max: 1}
91-
],
92-
dflt: [0, 1],
93-
description: [
94-
'Sets the maximum vertical domain of this map',
95-
'(in plot fraction).',
96-
'Note that geo subplots are constrained by domain.',
97-
'In general, when `projection.scale` is set to 1.',
98-
'a map will fit either its x or y domain, but not both. '
99-
].join(' ')
100-
}
101-
},
69+
domain: domainAttrs({name: 'geo'}, {
70+
description: [
71+
'Note that geo subplots are constrained by domain.',
72+
'In general, when `projection.scale` is set to 1.',
73+
'a map will fit either its x or y domain, but not both. '
74+
].join(' ')
75+
}),
76+
10277
resolution: {
10378
valType: 'enumerated',
10479
values: [110, 50],

Diff for: src/plots/gl3d/layout/layout_attributes.js

+2-32
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
'use strict';
1111

1212
var gl3dAxisAttrs = require('./axis_attributes');
13+
var domainAttrs = require('../../domain_attributes');
1314
var extendFlat = require('../../../lib/extend').extendFlat;
1415
var counterRegex = require('../../../lib').counterRegex;
1516

16-
1717
function makeCameraVector(x, y, z) {
1818
return {
1919
x: {
@@ -74,37 +74,7 @@ module.exports = {
7474
}),
7575
editType: 'camera'
7676
},
77-
domain: {
78-
x: {
79-
valType: 'info_array',
80-
role: 'info',
81-
items: [
82-
{valType: 'number', min: 0, max: 1, editType: 'plot'},
83-
{valType: 'number', min: 0, max: 1, editType: 'plot'}
84-
],
85-
dflt: [0, 1],
86-
editType: 'plot',
87-
description: [
88-
'Sets the horizontal domain of this scene',
89-
'(in plot fraction).'
90-
].join(' ')
91-
},
92-
y: {
93-
valType: 'info_array',
94-
role: 'info',
95-
items: [
96-
{valType: 'number', min: 0, max: 1, editType: 'plot'},
97-
{valType: 'number', min: 0, max: 1, editType: 'plot'}
98-
],
99-
dflt: [0, 1],
100-
editType: 'plot',
101-
description: [
102-
'Sets the vertical domain of this scene',
103-
'(in plot fraction).'
104-
].join(' ')
105-
},
106-
editType: 'plot'
107-
},
77+
domain: domainAttrs({name: 'scene', editType: 'plot'}),
10878
aspectmode: {
10979
valType: 'enumerated',
11080
role: 'info',

Diff for: src/plots/mapbox/layout_attributes.js

+3-29
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
var Lib = require('../../lib');
1313
var defaultLine = require('../../components/color').defaultLine;
14+
var domainAttrs = require('../domain_attributes');
1415
var fontAttrs = require('../font_attributes');
1516
var textposition = require('../../traces/scatter/attributes').textposition;
1617
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1718

18-
1919
var fontAttr = fontAttrs({
2020
description: [
2121
'Sets the icon text font.',
@@ -26,34 +26,8 @@ fontAttr.family.dflt = 'Open Sans Regular, Arial Unicode MS Regular';
2626

2727
module.exports = overrideAll({
2828
_arrayAttrRegexps: [Lib.counterRegex('mapbox', '.layers', true)],
29-
domain: {
30-
x: {
31-
valType: 'info_array',
32-
role: 'info',
33-
items: [
34-
{valType: 'number', min: 0, max: 1},
35-
{valType: 'number', min: 0, max: 1}
36-
],
37-
dflt: [0, 1],
38-
description: [
39-
'Sets the horizontal domain of this subplot',
40-
'(in plot fraction).'
41-
].join(' ')
42-
},
43-
y: {
44-
valType: 'info_array',
45-
role: 'info',
46-
items: [
47-
{valType: 'number', min: 0, max: 1},
48-
{valType: 'number', min: 0, max: 1}
49-
],
50-
dflt: [0, 1],
51-
description: [
52-
'Sets the vertical domain of this subplot',
53-
'(in plot fraction).'
54-
].join(' ')
55-
}
56-
},
29+
30+
domain: domainAttrs({name: 'mapbox'}),
5731

5832
accesstoken: {
5933
valType: 'string',

Diff for: src/plots/polar/layout_attributes.js

+2-26
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@
1010

1111
var colorAttrs = require('../../components/color/attributes');
1212
var axesAttrs = require('../cartesian/layout_attributes');
13+
var domainAttrs = require('../domain_attributes');
1314
var extendFlat = require('../../lib').extendFlat;
1415
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1516

16-
var domainItem = {
17-
valType: 'info_array',
18-
role: 'info',
19-
editType: 'plot',
20-
items: [
21-
{valType: 'number', min: 0, max: 1},
22-
{valType: 'number', min: 0, max: 1}
23-
],
24-
dflt: [0, 1]
25-
};
26-
2717
var axisLineGridAttr = overrideAll({
2818
color: axesAttrs.color,
2919
showline: extendFlat({}, axesAttrs.showline, {dflt: true}),
@@ -266,21 +256,7 @@ module.exports = {
266256
// y: {},
267257
// zoom: {},
268258

269-
domain: {
270-
x: extendFlat({}, domainItem, {
271-
description: [
272-
'Sets the horizontal domain of this subplot',
273-
'(in plot fraction).'
274-
].join(' ')
275-
}),
276-
y: extendFlat({}, domainItem, {
277-
description: [
278-
'Sets the vertical domain of this subplot',
279-
'(in plot fraction).'
280-
].join(' ')
281-
}),
282-
editType: 'plot'
283-
},
259+
domain: domainAttrs({name: 'polar', editType: 'plot'}),
284260

285261
// Maybe this should angularaxis.range correspond to
286262
// angular span of the drawing area?

Diff for: src/plots/ternary/layout/layout_attributes.js

+3-29
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,13 @@
99
'use strict';
1010

1111
var colorAttrs = require('../../../components/color/attributes');
12+
var domainAttrs = require('../../domain_attributes');
1213
var ternaryAxesAttrs = require('./axis_attributes');
1314
var overrideAll = require('../../../plot_api/edit_types').overrideAll;
1415

15-
1616
module.exports = overrideAll({
17-
domain: {
18-
x: {
19-
valType: 'info_array',
20-
role: 'info',
21-
items: [
22-
{valType: 'number', min: 0, max: 1},
23-
{valType: 'number', min: 0, max: 1}
24-
],
25-
dflt: [0, 1],
26-
description: [
27-
'Sets the horizontal domain of this subplot',
28-
'(in plot fraction).'
29-
].join(' ')
30-
},
31-
y: {
32-
valType: 'info_array',
33-
role: 'info',
34-
items: [
35-
{valType: 'number', min: 0, max: 1},
36-
{valType: 'number', min: 0, max: 1}
37-
],
38-
dflt: [0, 1],
39-
description: [
40-
'Sets the vertical domain of this subplot',
41-
'(in plot fraction).'
42-
].join(' ')
43-
}
44-
},
17+
domain: domainAttrs({name: 'ternary'}),
18+
4519
bgcolor: {
4620
valType: 'color',
4721
role: 'style',

Diff for: src/traces/parcoords/attributes.js

+2-32
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,14 @@ var colorbarAttrs = require('../../components/colorbar/attributes');
1313
var colorscales = require('../../components/colorscale/scales');
1414
var axesAttrs = require('../../plots/cartesian/layout_attributes');
1515
var fontAttrs = require('../../plots/font_attributes');
16+
var domainAttrs = require('../../plots/domain_attributes');
1617

1718
var extend = require('../../lib/extend');
1819
var extendDeepAll = extend.extendDeepAll;
1920
var extendFlat = extend.extendFlat;
2021

2122
module.exports = {
22-
23-
domain: {
24-
x: {
25-
valType: 'info_array',
26-
role: 'info',
27-
items: [
28-
{valType: 'number', min: 0, max: 1, editType: 'calc'},
29-
{valType: 'number', min: 0, max: 1, editType: 'calc'}
30-
],
31-
dflt: [0, 1],
32-
editType: 'calc',
33-
description: [
34-
'Sets the horizontal domain of this `parcoords` trace',
35-
'(in plot fraction).'
36-
].join(' ')
37-
},
38-
y: {
39-
valType: 'info_array',
40-
role: 'info',
41-
items: [
42-
{valType: 'number', min: 0, max: 1, editType: 'calc'},
43-
{valType: 'number', min: 0, max: 1, editType: 'calc'}
44-
],
45-
dflt: [0, 1],
46-
editType: 'calc',
47-
description: [
48-
'Sets the vertical domain of this `parcoords` trace',
49-
'(in plot fraction).'
50-
].join(' ')
51-
},
52-
editType: 'calc'
53-
},
23+
domain: domainAttrs({name: 'parcoords', trace: true, editType: 'calc'}),
5424

5525
labelfont: fontAttrs({
5626
editType: 'calc',

0 commit comments

Comments
 (0)