-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathmake_bubble_size_func.js
34 lines (27 loc) · 1023 Bytes
/
make_bubble_size_func.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
'use strict';
var isNumeric = require('fast-isnumeric');
// used in the drawing step for 'scatter' and 'scattegeo' and
// in the convert step for 'scatter3d'
module.exports = function makeBubbleSizeFn(trace, factor) {
if(!factor) {
factor = 2;
}
var marker = trace.marker;
var sizeRef = marker.sizeref || 1;
var sizeMin = marker.sizemin || 0;
// for bubble charts, allow scaling the provided value linearly
// and by area or diameter.
// Note this only applies to the array-value sizes
var baseFn = (marker.sizemode === 'area') ?
function(v) { return Math.sqrt(v / sizeRef); } :
function(v) { return v / sizeRef; };
// TODO add support for position/negative bubbles?
// TODO add 'sizeoffset' attribute?
return function(v) {
var baseSize = baseFn(v / factor);
// don't show non-numeric and negative sizes
return (isNumeric(baseSize) && (baseSize > 0)) ?
Math.max(baseSize, sizeMin) :
0;
};
};