Skip to content

Filter numbers during calc step #4063

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 3 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ lib.mergeArray = function(traceAttr, cd, cdAttr, fn) {
lib.mergeArrayCastPositive = function(traceAttr, cd, cdAttr) {
return lib.mergeArray(traceAttr, cd, cdAttr, function(v) {
var w = +v;
return w > 0 ? w : 0;
return isNaN(w) ? NaN : w > 0 ? w : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want isNumeric here. Have tried something like

'marker.line.width': [NaN, null, undefined, [], {}, 0]`

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works OK with those cases. Using isNumeric might be slow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried running benchmarks here? I doubt that isNumeric is that much slower than isNaN

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, could we lock those cases down in a _module.calc test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are added in 39b9840.

});
};

Expand Down
14 changes: 7 additions & 7 deletions src/traces/funnel/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

'use strict';

var mergeArray = require('../../lib').mergeArray;
var Lib = require('../../lib');

// arrayOk attributes, merge them into calcdata array
module.exports = function arraysToCalcdata(cd, trace) {
for(var i = 0; i < cd.length; i++) cd[i].i = i;

mergeArray(trace.text, cd, 'tx');
mergeArray(trace.hovertext, cd, 'htx');
Lib.mergeArray(trace.text, cd, 'tx');
Lib.mergeArray(trace.hovertext, cd, 'htx');

var marker = trace.marker;
if(marker) {
mergeArray(marker.opacity, cd, 'mo');
mergeArray(marker.color, cd, 'mc');
Lib.mergeArray(marker.opacity, cd, 'mo');
Lib.mergeArray(marker.color, cd, 'mc');

var markerLine = marker.line;
if(markerLine) {
mergeArray(markerLine.color, cd, 'mlc');
mergeArray(markerLine.width, cd, 'mlw');
Lib.mergeArray(markerLine.color, cd, 'mlc');
Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');
}
}
};
8 changes: 4 additions & 4 deletions src/traces/scatter/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ module.exports = function arraysToCalcdata(cd, trace) {
Lib.mergeArray(trace.customdata, cd, 'data');
Lib.mergeArray(trace.textposition, cd, 'tp');
if(trace.textfont) {
Lib.mergeArray(trace.textfont.size, cd, 'ts');
Lib.mergeArrayCastPositive(trace.textfont.size, cd, 'ts');
Lib.mergeArray(trace.textfont.color, cd, 'tc');
Lib.mergeArray(trace.textfont.family, cd, 'tf');
}

var marker = trace.marker;
if(marker) {
Lib.mergeArray(marker.size, cd, 'ms');
Lib.mergeArray(marker.opacity, cd, 'mo');
Lib.mergeArrayCastPositive(marker.size, cd, 'ms');
Lib.mergeArrayCastPositive(marker.opacity, cd, 'mo');
Lib.mergeArray(marker.symbol, cd, 'mx');
Lib.mergeArray(marker.color, cd, 'mc');

var markerLine = marker.line;
if(marker.line) {
Lib.mergeArray(markerLine.color, cd, 'mlc');
Lib.mergeArray(markerLine.width, cd, 'mlw');
Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');
}

var markerGradient = marker.gradient;
Expand Down