8000 Split scatter module by etpinard · Pull Request #184 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Split scatter module #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 15, 2016
Prev Previous commit
Next Next commit
rename getBubbleSizFn -> makeBubbleSizeFn + put it separate file
  • Loading branch information
etpinard committed Jan 15, 2016
commit b418b5fe6767ad763fa0bd754a8d834d88606319
4 changes: 3 additions & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var Plotly = require('../../plotly');
var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');

var drawing = module.exports = {};

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

s.attr('d', function(d) {
var r;
Expand Down
26 changes: 0 additions & 26 deletions src/traces/scatter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,6 @@ scatter.cleanData = function(fullData) {

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

// used in the drawing step for 'scatter' and 'scattegeo' and
// in the convert step for 'scatter3d'
scatter.getBubbleSizeFn = function(trace) {
var marker = trace.marker,
sizeRef = marker.sizeref || 1,
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 / 2);

// don't show non-numeric and negative sizes
return (isNumeric(baseSize) && baseSize>0) ?
Math.max(baseSize, sizeMin) : 0;
};
};

scatter.calc = function(gd, trace) {
var xa = Axes.getFromId(gd,trace.xaxis||'x'),
ya = Axes.getFromId(gd,trace.yaxis||'y');
Expand Down
39 changes: 39 additions & 0 deletions src/traces/scatter/make_bubble_size_func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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');


// used in the drawing step for 'scatter' and 'scattegeo' and
// in the convert step for 'scatter3d'
module.exports = function makeBubbleSizeFn(trace) {
var marker = trace.marker,
sizeRef = marker.sizeref || 1,
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 / 2);

// don't show non-numeric and negative sizes
return (isNumeric(baseSize) && baseSize>0) ?
Math.max(baseSize, sizeMin) : 0;
};
};
5 changes: 2 additions & 3 deletions src/traces/scatter3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var triangulate = require('delaunay-triangulate');
var Lib = require('../../lib');
var str2RgbaArray = require('../../lib/str2rgbarray');
var formatColor = require('../../lib/gl_format_color');

var Scatter = require('../scatter');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');

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

if ('marker' in data) {
var sizeFn = Scatter.getBubbleSizeFn(data);
var sizeFn = makeBubbleSizeFn(data);

params.scatterColor = formatColor(marker, 1, len);
params.scatterSize = formatParam(marker.size, len, calculateSize, 20, sizeFn);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var formatColor = require('../../lib/gl_format_color');
var Scatter = require('../scatter');

var ErrorBars = require('../../components/errorbars');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');

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

var markerSizeFunc = Scatter.getBubbleSizeFn(options),
var markerSizeFunc = makeBubbleSizeFn(options),
markerOpts = options.marker,
markerOpacity = markerOpts.opacity,
traceOpacity = options.opacity,
Expand Down
0