-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcalc.js
61 lines (43 loc) · 1.62 KB
/
calc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var isNumeric = require('fast-isnumeric');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var makeComputeError = require('./compute_error');
module.exports = function calc(gd) {
var calcdata = gd.calcdata;
for(var i = 0; i < calcdata.length; i++) {
var calcTrace = calcdata[i],
trace = calcTrace[0].trace;
if(!Registry.traceIs(trace, 'errorBarsOK')) continue;
var xa = Axes.getFromId(gd, trace.xaxis),
ya = Axes.getFromId(gd, trace.yaxis);
calcOneAxis(calcTrace, trace, xa, 'x');
calcOneAxis(calcTrace, trace, ya, 'y');
}
};
function calcOneAxis(calcTrace, trace, axis, coord) {
var opts = trace['error_' + coord] || {},
isVisible = (opts.visible && ['linear', 'log'].indexOf(axis.type) !== -1),
vals = [];
if(!isVisible) return;
var computeError = makeComputeError(opts);
for(var i = 0; i < calcTrace.length; i++) {
var calcPt = calcTrace[i],
calcCoord = calcPt[coord];
if(!isNumeric(axis.c2l(calcCoord))) continue;
var errors = computeError(calcCoord, i);
if(isNumeric(errors[0]) && isNumeric(errors[1])) {
var shoe = calcPt[coord + 's'] = calcCoord - errors[0],
hat = calcPt[coord + 'h'] = calcCoord + errors[1];
vals.push(shoe, hat);
}
}
Axes.expand(axis, vals, {padded: true});
}