Skip to content
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

Bug fix - do not display empty bars when line.width is zero #4056

Merged
merged 4 commits into from Jul 18, 2019

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jul 17, 2019

Fixes #4047.
Empty bar and funnel rectangles should not be displayed when marker.line.width is set to zero.

Codepen after

Also addressing #4057 for bars in this PR.
Codepen after

@plotly/plotly_js

src/traces/bar/plot.js Outdated Show resolved Hide resolved
"type": "bar",
"marker": {
"line": {
"width": [10, 0, 10, 0, 10]
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this mock only has array marker.line.width value. Could you add one trace that test scaler marker.line.width?

Maybe you can leave this mock alone and simply add another mock using https://codepen.io/MojtabaSamimi/pen/bXbmba , so that we also test the relative-stacked case.

@etpinard
Copy link
Contributor

Thanks for taking this one @archmoj - I made two minor comments.

move getLineWidth function to helpers and reuse it in hover
also fixing 4057
@archmoj
Copy link
Contributor Author

archmoj commented Jul 17, 2019

@etpinard Thanks for the review!
This is now ready for the second round.
As I updated the PR description please note that the #4057 is also addressed for bars.

src/traces/bar/helpers.js Outdated Show resolved Hide resolved
@@ -64,3 +64,12 @@ exports.getValue = function(arrayOrScalar, index) {
else if(index < arrayOrScalar.length) value = arrayOrScalar[index];
return value;
};

exports.getLineWidth = function(trace, di) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Bars don't have line.width, but still calling this getMarkerLineWidth would be better.

src/lib/index.js Outdated Show resolved Hide resolved
for(var i = 0; i < imax; i++) cd[i][cdAttr] = isNumber ? +traceAttr[i] : traceAttr[i];
for(var i = 0; i < imax; i++) {
var v = traceAttr[i];
cd[i][cdAttr] = hasFn ? fn(v) : v;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what's faster

var hasFn = typeof fn === 'function';
for(var i = 0; i < N; i++) {
  arrayOut[i] = hasFn ? fn(arrayIn[i]) : arrayIn[i];
}

or

fn = typeof fn === 'function' ? fn : Lib.noop;
for(var i = 0; i < N; i++) {
  arrayOut[i] = fn(arrayIn[i]);
}

No need to change anything, I'm just thinking out-loud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting question. And I like the minimalist version with Lib.noop!
That may depend on the browser.
Having two loops may also be fast.

var i = 0;
if (typeof fn === 'function') {
  for(; i < N; ++i) arrayOut[i] = fn(arrayIn[i]);
} else {
  for(; i < N; ++i) arrayOut[i] = arrayIn[i];
}

@etpinard
Copy link
Contributor

Nicely done 💃

Thanks for the fixes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extra bar traces show up in stacked bar chart in relative barmode in >=1.48.0
2 participants