Skip to content

Commit 2bb40d5

Browse files
committed
move getShowAttrDflt function to a separate file
1 parent 2a3b38e commit 2bb40d5

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/plots/cartesian/show_dflt.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
/*
4+
* Attributes 'showexponent', 'showtickprefix' and 'showticksuffix'
5+
* share values.
6+
*
7+
* If only 1 attribute is set,
8+
* the remaining attributes inherit that value.
9+
*
10+
* If 2 attributes are set to the same value,
11+
* the remaining attribute inherits that value.
12+
*
13+
* If 2 attributes are set to different values,
14+
* the remaining is set to its dflt value.
15+
*
16+
*/
17+
module.exports = function getShowAttrDflt(containerIn) {
18+
var showAttrsAll = ['showexponent', 'showtickprefix', 'showticksuffix'];
19+
var showAttrs = showAttrsAll.filter(function(a) {
20+
return containerIn[a] !== undefined;
21+
});
22+
var sameVal = function(a) {
23+
return containerIn[a] === containerIn[showAttrs[0]];
24+
};
25+
26+
if(showAttrs.every(sameVal) || showAttrs.length === 1) {
27+
return containerIn[showAttrs[0]];
28+
}
29+
};

src/plots/cartesian/tick_label_defaults.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Lib = require('../../lib');
44
var contrast = require('../../components/color').contrast;
55
var layoutAttributes = require('./layout_attributes');
6+
var getShowAttrDflt = require('./show_dflt');
67
var handleArrayContainerDefaults = require('../array_container_defaults');
78

89
module.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options, config) {
@@ -69,34 +70,6 @@ function handleOtherDefaults(containerIn, containerOut, coerce, axType, options)
6970
}
7071
}
7172

72-
/*
73-
* Attributes 'showexponent', 'showtickprefix' and 'showticksuffix'
74-
* share values.
75-
*
76-
* If only 1 attribute is set,
77-
* the remaining attributes inherit that value.
78-
*
79-
* If 2 attributes are set to the same value,
80-
* the remaining attribute inherits that value.
81-
*
82-
* If 2 attributes are set to different values,
83-
* the remaining is set to its dflt value.
84-
*
85-
*/
86-
function getShowAttrDflt(containerIn) {
87-
var showAttrsAll = ['showexponent', 'showtickprefix', 'showticksuffix'];
88-
var showAttrs = showAttrsAll.filter(function(a) {
89-
return containerIn[a] !== undefined;
90-
});
91-
var sameVal = function(a) {
92-
return containerIn[a] === containerIn[showAttrs[0]];
93-
};
94-
95-
if(showAttrs.every(sameVal) || showAttrs.length === 1) {
96-
return containerIn[showAttrs[0]];
97-
}
98-
}
99-
10073
function tickformatstopDefaults(valueIn, valueOut) {
10174
function coerce(attr, dflt) {
10275
return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);

0 commit comments

Comments
 (0)