-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcalc.js
42 lines (35 loc) · 1.12 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
/**
* Copyright 2012-2018, 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 colorscaleCalc = require('../../components/colorscale/calc');
module.exports = function calc(gd, trace) {
var u = trace.u;
var v = trace.v;
var w = trace.w;
var len = Math.min(u.length, v.length, w.length);
var normMax = -Infinity;
var normMin = Infinity;
var compMax = -Infinity;
for(var i = 0; i < len; i++) {
var uu = u[i];
var u2 = uu * uu;
var vv = v[i];
var v2 = vv * vv;
var ww = w[i];
var w2 = ww * ww;
var norm = Math.sqrt(u2 + v2 + w2);
normMax = Math.max(normMax, norm);
normMin = Math.min(normMin, norm);
compMax = Math.max(compMax, u2, v2, w2);
}
// stash max norm value to convert cmix/cmax -> vertexIntensityBounds
trace._normMax = normMax;
// stash max 'component' value for autorange pad
trace._compMax = Math.sqrt(compMax);
colorscaleCalc(trace, [normMin, normMax], '', 'c');
};