Skip to content

Commit 8c1e7a1

Browse files
committed
fix funnel bars and connectors as well
1 parent 49a9605 commit 8c1e7a1

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/traces/funnel/plot.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var d3 = require('d3');
1212
var Lib = require('../../lib');
1313
var Drawing = require('../../components/drawing');
14+
var BADNUM = require('../../constants/numerical').BADNUM;
1415
var barPlot = require('../bar/plot');
1516
var clearMinTextSize = require('../bar/uniform_text').clearMinTextSize;
1617

@@ -66,14 +67,21 @@ function plotConnectorRegions(gd, plotinfo, cdModule, traceLayer) {
6667

6768
var shape = '';
6869

69-
if(x[3] !== undefined && y[3] !== undefined) {
70+
if(
71+
x[0] !== BADNUM && y[0] !== BADNUM &&
72+
x[1] !== BADNUM && y[1] !== BADNUM &&
73+
x[2] !== BADNUM && y[2] !== BADNUM &&
74+
x[3] !== BADNUM && y[3] !== BADNUM
75+
) {
7076
if(isHorizontal) {
7177
shape += 'M' + x[0] + ',' + y[1] + 'L' + x[2] + ',' + y[2] + 'H' + x[3] + 'L' + x[1] + ',' + y[1] + 'Z';
7278
} else {
7379
shape += 'M' + x[1] + ',' + y[1] + 'L' + x[2] + ',' + y[3] + 'V' + y[2] + 'L' + x[1] + ',' + y[0] + 'Z';
7480
}
7581
}
7682

83+
if(shape === '') shape = 'M0,0Z';
84+
7785
Lib.ensureSingle(d3.select(this), 'path')
7886
.attr('d', shape)
7987
.call(Drawing.setClipUrl, plotinfo.layerClipId, gd);

test/jasmine/tests/funnel_test.js

+49
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var rgb = color.rgb;
1717
var customAssertions = require('../assets/custom_assertions');
1818
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
1919
var checkTextTemplate = require('../assets/check_texttemplate');
20+
var checkTransition = require('../assets/check_transitions');
2021
var Fx = require('@src/components/fx');
2122

2223
var d3 = require('d3');
@@ -1033,6 +1034,54 @@ describe('A funnel plot', function() {
10331034
.then(done);
10341035
});
10351036

1037+
it('handle BADNUM positions', function(done) {
1038+
var y1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
1039+
var y2 = y1; // no transition now
1040+
var mockCopy = {
1041+
data: [
1042+
{
1043+
type: 'funnel',
1044+
x: [
1045+
0,
1046+
1,
1047+
'',
1048+
'NaN',
1049+
NaN,
1050+
Infinity,
1051+
-Infinity,
1052+
undefined,
1053+
null,
1054+
9,
1055+
10
1056+
],
1057+
y: y1
1058+
}
1059+
],
1060+
layout: {
1061+
width: 400,
1062+
height: 300
1063+
}
1064+
};
1065+
1066+
var barTests = [
1067+
[0, '.point path', 'attr', 'd', ['M12,12V108H12V12Z', 'M12,12V108H23V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M120,12V108H120V12Z', 'M23,12V108H120V12Z', 'M120,12V108H228V12Z']]
1068+
];
1069+
1070+
var connectorTests = [
1071+
[0, '.regions path', 'attr', 'd', ['M12,108L12,12H23L12,108Z', 'M23,108L120,12H228L120,108Z', 'M0,0Z']]
1072+
];
1073+
1074+
var animateOpts = {data: [{y: y2}]};
1075+
var transitionOpts = false; // use default
1076+
1077+
checkTransition(gd, mockCopy, animateOpts, transitionOpts, barTests)
1078+
.then(function() {
1079+
return checkTransition(gd, mockCopy, animateOpts, transitionOpts, connectorTests);
1080+
})
1081+
.catch(failTest)
1082+
.then(done);
1083+
});
1084+
10361085
it('should be able to deal with transform that empty out the data coordinate arrays', function(done) {
10371086
Plotly.plot(gd, {
10381087
data: [{

0 commit comments

Comments
 (0)