Skip to content

Commit b418b5f

Browse files
committed
rename getBubbleSizFn -> makeBubbleSizeFn + put it separate file
1 parent 6002788 commit b418b5f

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

src/components/drawing/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var Plotly = require('../../plotly');
1313
var d3 = require('d3');
1414
var isNumeric = require('fast-isnumeric');
1515

16+
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
17+
1618
var drawing = module.exports = {};
1719

1820
// -----------------------------------------------------
@@ -175,7 +177,7 @@ drawing.pointStyle = function(s, trace) {
175177
// only scatter & box plots get marker path and opacity
176178
// bars, histograms don't
177179
if(Plotly.Plots.traceIs(trace, 'symbols')) {
178-
var sizeFn = Plotly.Scatter.getBubbleSizeFn(trace);
180+
var sizeFn = makeBubbleSizeFn(trace);
179181

180182
s.attr('d', function(d) {
181183
var r;

src/traces/scatter/index.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,6 @@ scatter.cleanData = function(fullData) {
7979

8080
scatter.colorbar = require('./colorbar');
8181

82-
// used in the drawing step for 'scatter' and 'scattegeo' and
83-
// in the convert step for 'scatter3d'
84-
scatter.getBubbleSizeFn = function(trace) {
85-
var marker = trace.marker,
86-
sizeRef = marker.sizeref || 1,
87-
sizeMin = marker.sizemin || 0;
88-
89-
// for bubble charts, allow scaling the provided value linearly
90-
// and by area or diameter.
91-
// Note this only applies to the array-value sizes
92-
93-
var baseFn = marker.sizemode==='area' ?
94-
function(v) { return Math.sqrt(v / sizeRef); } :
95-
function(v) { return v / sizeRef; };
96-
97-
// TODO add support for position/negative bubbles?
98-
// TODO add 'sizeoffset' attribute?
99-
return function(v) {
100-
var baseSize = baseFn(v / 2);
101-
102-
// don't show non-numeric and negative sizes
103-
return (isNumeric(baseSize) && baseSize>0) ?
104-
Math.max(baseSize, sizeMin) : 0;
105-
};
106-
};
107-
10882
scatter.calc = function(gd, trace) {
10983
var xa = Axes.getFromId(gd,trace.xaxis||'x'),
11084
ya = Axes.getFromId(gd,trace.yaxis||'y');
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2012-2016, 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+
10+
'use strict';
11+
12+
var isNumeric = require('fast-isnumeric');
13+
14+
15+
// used in the drawing step for 'scatter' and 'scattegeo' and
16+
// in the convert step for 'scatter3d'
17+
module.exports = function makeBubbleSizeFn(trace) {
18+
var marker = trace.marker,
19+
sizeRef = marker.sizeref || 1,
20+
sizeMin = marker.sizemin || 0;
21+
22+
// for bubble charts, allow scaling the provided value linearly
23+
// and by area or diameter.
24+
// Note this only applies to the array-value sizes
25+
26+
var baseFn = marker.sizemode==='area' ?
27+
function(v) { return Math.sqrt(v / sizeRef); } :
28+
function(v) { return v / sizeRef; };
29+
30+
// TODO add support for position/negative bubbles?
31+
// TODO add 'sizeoffset' attribute?
32+
return function(v) {
33+
var baseSize = baseFn(v / 2);
34+
35+
// don't show non-numeric and negative sizes
36+
return (isNumeric(baseSize) && baseSize>0) ?
37+
Math.max(baseSize, sizeMin) : 0;
38+
};
39+
};

src/traces/scatter3d/convert.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ var triangulate = require('delaunay-triangulate');
1818
var Lib = require('../../lib');
1919
var str2RgbaArray = require('../../lib/str2rgbarray');
2020
var formatColor = require('../../lib/gl_format_color');
21-
22-
var Scatter = require('../scatter');
21+
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2322

2423
var DASH_PATTERNS = require('../../constants/gl3d_dashes.json');
2524
var MARKER_SYMBOLS = require('../../constants/gl_markers.json');
@@ -210,7 +209,7 @@ function convertPlotlyOptions(scene, data) {
210209
}
211210

212211
if ('marker' in data) {
213-
var sizeFn = Scatter.getBubbleSizeFn(data);
212+
var sizeFn = makeBubbleSizeFn(data);
214213

215214
params.scatterColor = formatColor(marker, 1, len);
216215
params.scatterSize = formatParam(marker.size, len, calculateSize, 20, sizeFn);

src/traces/scattergl/convert.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var formatColor = require('../../lib/gl_format_color');
2424
var Scatter = require('../scatter');
2525

2626
var ErrorBars = require('../../components/errorbars');
27+
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2728

2829
var MARKER_SYMBOLS = require('../../constants/gl_markers.json');
2930
var DASHES = require('../../constants/gl2d_dashes.json');
@@ -418,7 +419,7 @@ proto.updateFancy = function(options) {
418419
this.scatterOptions.colors = new Array(pId * 4);
419420
this.scatterOptions.borderColors = new Array(pId * 4);
420421

421-
var markerSizeFunc = Scatter.getBubbleSizeFn(options),
422+
var markerSizeFunc = makeBubbleSizeFn(options),
422423
markerOpts = options.marker,
423424
markerOpacity = markerOpts.opacity,
424425
traceOpacity = options.opacity,

0 commit comments

Comments
 (0)