|
| 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 | +}; |
0 commit comments