Skip to content

Commit 706e7ae

Browse files
committed
fix sankey attributes and add better test
1 parent 9e4f1a0 commit 706e7ae

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

src/traces/sankey/attributes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ var attrs = module.exports = overrideAll({
122122
role: 'style',
123123
description: 'Sets the thickness (in px) of the `nodes`.'
124124
},
125-
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {flags: []}),
125+
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {valtype: 'enumerated', values: ['all', 'none', 'skip'], flags: [], arrayOk: false }),
126126
hoverlabel: fxAttrs.hoverlabel, // needs editType override,
127127
description: 'The nodes of the Sankey plot.'
128128
},
@@ -182,10 +182,10 @@ var attrs = module.exports = overrideAll({
182182
role: 'info',
183183
description: 'A numeric value representing the flow volume value.'
184184
},
185-
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {flags: []}),
185+
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {valtype: 'enumerated', values: ['all', 'none', 'skip'], flags: [], arrayOk: false }),
186186
hoverlabel: fxAttrs.hoverlabel, // needs editType override,
187187
description: 'The links of the Sankey plot.'
188-
},
188+
}
189189
}, 'calc', 'nested');
190190
// hide unsupported top-level properties from plot-schema
191191
attrs.hoverinfo = undefined;

src/traces/sankey/defaults.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var attributes = require('./attributes');
1313
var Color = require('../../components/color');
1414
var tinycolor = require('tinycolor2');
1515
var handleDomainDefaults = require('../../plots/domain').defaults;
16-
var Registry = require('../../registry');
16+
var handleFxDefaults = require('../../components/fx/defaults');
1717

1818
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
1919
function coerce(attr, dflt) {
@@ -26,10 +26,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2626
coerce('node.line.color');
2727
coerce('node.line.width');
2828
coerce('node.hoverinfo');
29-
Registry.getComponentMethod(
30-
'fx',
31-
'supplyDefaults'
32-
)(traceIn.node, traceOut.node, defaultColor, layout);
29+
handleFxDefaults(traceIn.node, traceOut.node, defaultColor, layout);
3330

3431
var colors = layout.colorway;
3532

@@ -46,10 +43,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4643
coerce('link.line.color');
4744
coerce('link.line.width');
4845
coerce('link.hoverinfo');
49-
Registry.getComponentMethod(
50-
'fx',
51-
'supplyDefaults'
52-
)(traceIn.link, traceOut.link, defaultColor, layout);
46+
handleFxDefaults(traceIn.link, traceOut.link, defaultColor, layout);
5347

5448
coerce('link.color', traceOut.link.value.map(function() {
5549
return tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?

test/jasmine/tests/sankey_test.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ describe('sankey tests', function() {
440440
'node.hoverlabel.bordercolor': 'blue',
441441
'node.hoverlabel.font.size': 20,
442442
'node.hoverlabel.font.color': 'black',
443-
'link.hoverlabel.bgcolor': 'red',
444-
'link.hoverlabel.bordercolor': 'blue',
445-
'link.hoverlabel.font.size': 20,
446-
'link.hoverlabel.font.color': 'black'
443+
'link.hoverlabel.bgcolor': 'yellow',
444+
'link.hoverlabel.bordercolor': 'magenta',
445+
'link.hoverlabel.font.size': 18,
446+
'link.hoverlabel.font.color': 'green'
447447
});
448448
})
449449
.then(function() {
@@ -459,7 +459,7 @@ describe('sankey tests', function() {
459459

460460
assertLabel(
461461
['source: Solid', 'target: Industry', '46TWh'],
462-
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 20, 'Roboto', 'rgb(0, 0, 0)']
462+
['rgb(255, 255, 0)', 'rgb(255, 0, 255)', 18, 'Roboto', 'rgb(0, 128, 0)']
463463
);
464464
})
465465
.catch(failTest)
@@ -547,6 +547,21 @@ describe('sankey tests', function() {
547547
.catch(failTest)
548548
.then(done);
549549
});
550+
551+
it('should not show link labels if link.hoverinfo is skip', function(done) {
552+
var gd = createGraphDiv();
553+
var mockCopy = Lib.extendDeep({}, mock);
554+
555+
Plotly.plot(gd, mockCopy).then(function() {
556+
return Plotly.restyle(gd, 'link.hoverinfo', 'skip');
557+
})
558+
.then(function() {
559+
_hover(link[0], link[1]);
560+
assertNoLabel();
561+
})
562+
.catch(failTest)
563+
.then(done);
564+
});
550565
});
551566

552567
describe('Test hover/click event data:', function() {
@@ -667,24 +682,26 @@ describe('sankey tests', function() {
667682
});
668683

669684
function assertNoHoverEvents(type) {
670-
return Promise.resolve()
671-
.then(function() { return _hover(type); })
672-
.then(failTest).catch(function(err) {
673-
expect(err).toBe('plotly_hover did not get called!');
674-
})
675-
.then(function() { return _unhover(type); })
676-
.then(failTest).catch(function(err) {
677-
expect(err).toBe('plotly_unhover did not get called!');
678-
});
685+
return function() {
686+
return Promise.resolve()
687+
.then(function() { return _hover(type); })
688+
.then(failTest).catch(function(err) {
689+
expect(err).toBe('plotly_hover did not get called!');
690+
})
691+
.then(function() { return _unhover(type); })
692+
.then(failTest).catch(function(err) {
693+
expect(err).toBe('plotly_unhover did not get called!');
694+
});
695+
};
679696
}
680697

681698
it('should not output hover/unhover event data when hovermoder is false', function(done) {
682699
var fig = Lib.extendDeep({}, mock);
683700

684701
Plotly.plot(gd, fig)
685702
.then(function() { return Plotly.relayout(gd, 'hovermode', false); })
686-
.then(function() { return assertNoHoverEvents('node');})
687-
.then(function() { return assertNoHoverEvents('link');})
703+
.then(assertNoHoverEvents('node'))
704+
.then(assertNoHoverEvents('link'))
688705
.catch(failTest)
689706
.then(done);
690707
});
@@ -694,7 +711,9 @@ describe('sankey tests', function() {
694711

695712
Plotly.plot(gd, fig)
696713
.then(function() { return Plotly.restyle(gd, 'link.hoverinfo', 'skip'); })
697-
.then(function() { return assertNoHoverEvents('link');})
714+
.then(assertNoHoverEvents('link'))
715+
.then(function() { return Plotly.restyle(gd, 'node.hoverinfo', 'skip'); })
716+
.then(assertNoHoverEvents('node'))
698717
.catch(failTest)
699718
.then(done);
700719
});

0 commit comments

Comments
 (0)