Skip to content

Commit 0a8d444

Browse files
committed
break up default step for errorbar in separate file
1 parent ae66e10 commit 0a8d444

File tree

2 files changed

+76
-49
lines changed

2 files changed

+76
-49
lines changed

src/components/errorbars/defaults.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright 2012-2015, 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 isNumeric = require('fast-isnumeric');
12+
13+
var Plots = require('../../plots/plots');
14+
var Lib = require('../../lib');
15+
16+
var attributes = require('./attributes');
17+
18+
19+
module.exports = function(traceIn, traceOut, defaultColor, opts) {
20+
var objName = 'error_' + opts.axis,
21+
containerOut = traceOut[objName] = {},
22+
containerIn = traceIn[objName] || {};
23+
24+
function coerce (attr, dflt) {
25+
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
26+
}
27+
28+
var hasErrorBars = (
29+
containerIn.array !== undefined ||
30+
containerIn.value !== undefined ||
31+
containerIn.type === 'sqrt'
32+
);
33+
34+
var visible = coerce('visible', hasErrorBars);
35+
36+
if(visible === false) return;
37+
38+
var type = coerce('type', 'array' in containerIn ? 'data' : 'percent'),
39+
symmetric = true;
40+
41+
if(type !== 'sqrt') {
42+
symmetric = coerce('symmetric',
43+
!((type === 'data' ? 'arrayminus' : 'valueminus') in containerIn));
44+
}
45+
46+
if(type === 'data') {
47+
var array = coerce('array');
48+
if(!array) containerOut.array = [];
49+
coerce('traceref');
50+
if(!symmetric) {
51+
var arrayminus = coerce('arrayminus');
52+
if(!arrayminus) containerOut.arrayminus = [];
53+
coerce('tracerefminus');
54+
}
55+
}
56+
else if(type==='percent' || type==='constant') {
57+
coerce('value');
58+
if(!symmetric) coerce('valueminus');
59+
}
60+
61+
var copyAttr = 'copy_'+opts.inherit+'style';
62+
if(opts.inherit) {
63+
var inheritObj = traceOut['error_' + opts.inherit];
64+
if((inheritObj||{}).visible) {
65+
coerce(copyAttr, !(containerIn.color ||
66+
isNumeric(containerIn.thickness) ||
67+
isNumeric(containerIn.width)));
68+
}
69+
}
70+
if(!opts.inherit || !containerOut[copyAttr]) {
71+
coerce('color', defaultColor);
72+
coerce('thickness');
73+
coerce('width', Plots.traceIs(traceOut, 'gl3d') ? 0 : 4);
74+
}
75+
};

src/components/errorbars/index.js

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,7 @@ var errorBars = module.exports = {};
1717

1818
errorBars.attributes = require('./attributes');
1919

20-
errorBars.supplyDefaults = function(traceIn, traceOut, defaultColor, opts) {
21-
var objName = 'error_' + opts.axis,
22-
containerOut = traceOut[objName] = {},
23-
containerIn = traceIn[objName] || {};
24-
25-
function coerce (attr, dflt) {
26-
return Plotly.Lib.coerce(containerIn, containerOut, errorBars.attributes, attr, dflt);
27-
}
28-
29-
var visible = coerce('visible', 'array' in containerIn || 'value' in containerIn);
30-
if(visible) {
31-
var type = coerce('type', 'array' in containerIn ? 'data' : 'percent'),
32-
symmetric = true;
33-
if(type!=='sqrt') {
34-
symmetric = coerce('symmetric',
35-
!((type==='data' ? 'arrayminus' : 'valueminus') in containerIn));
36-
}
37-
38-
if(type==='data') {
39-
var array = coerce('array');
40-
if(!array) containerOut.array = [];
41-
coerce('traceref');
42-
if(!symmetric) {
43-
var arrayminus = coerce('arrayminus');
44-
if(!arrayminus) containerOut.arrayminus = [];
45-
coerce('tracerefminus');
46-
}
47-
}
48-
else if(type==='percent' || type==='constant') {
49-
coerce('value');
50-
if(!symmetric) coerce('valueminus');
51-
}
52-
53-
var copyAttr = 'copy_'+opts.inherit+'style';
54-
if(opts.inherit) {
55-
var inheritObj = traceOut['error_' + opts.inherit];
56-
if((inheritObj||{}).visible) {
57-
coerce(copyAttr, !(containerIn.color ||
58-
isNumeric(containerIn.thickness) ||
59-
isNumeric(containerIn.width)));
60-
}
61-
}
62-
if(!opts.inherit || !containerOut[copyAttr]) {
63-
coerce('color', defaultColor);
64-
coerce('thickness');
65-
coerce('width', Plotly.Plots.traceIs(traceOut, 'gl3d') ? 0 : 4);
66-
}
67-
}
68-
};
20+
errorBars.supplyDefaults = require('./defaults');
6921

7022
// size the error bar itself (for all types except data)
7123
function errorval(type, dataval, errval) {

0 commit comments

Comments
 (0)