Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb8f1ec

Browse files
committed
adapt failing waterfall jasmine tests
1 parent b6fdaed commit cb8f1ec

File tree

1 file changed

+44
-125
lines changed

1 file changed

+44
-125
lines changed

test/jasmine/tests/waterfall_test.js

Lines changed: 44 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ var Drawing = require('@src/components/drawing');
77

88
var Axes = require('@src/plots/cartesian/axes');
99

10-
var click = require('../assets/click');
11-
var DBLCLICKDELAY = require('../../../src/constants/interactions').DBLCLICKDELAY;
1210
var createGraphDiv = require('../assets/create_graph_div');
1311
var destroyGraphDiv = require('../assets/destroy_graph_div');
1412
var failTest = require('../assets/fail_test');
@@ -213,17 +211,27 @@ describe('waterfall calc / crossTraceCalc', function() {
213211
var gd = mockWaterfallPlot([{
214212
y: [2, 1, 2]
215213
}, {
216-
y: [3, 1, 2]
214+
y: [3, 1, null, 2, null],
215+
measure: ['absolute', 'relative', 'total', 'relative', 'total']
217216
}], {
218217
waterfallmode: 'overlay'
219218
});
220219

221220
var cd = gd.calcdata;
222-
assertPointField(cd, 'x', [[0, 1, 2], [0, 1, 2]]);
223-
assertPointField(cd, 'y', [[2, 3, 5], [3, 4, 6]]);
224-
assertPointField(cd, 'b', [[0, 0, 0], [0, 0, 0]]);
225-
assertPointField(cd, 's', [[2, 3, 5], [3, 4, 6]]);
226-
assertPointField(cd, 'p', [[0, 1, 2], [0, 1, 2]]);
221+
assertPointField(cd, 'w', [[0.8, 0.8, 0.8], [0.8, 0.8, 0.8, 0.8, 0.8]]);
222+
assertPointField(cd, 'x', [[0, 1, 2], [0, 1, 2, 3, 4]]);
223+
assertPointField(cd, 'y', [[2, 3, 5], [3, 4, 4, 6, 6]]);
224+
assertPointField(cd, 'b', [[0, 0, 0], [0, 0, 0, 0, 0]]);
225+
assertPointField(cd, 's', [[2, 3, 5], [3, 4, 4, 6, 6]]);
226+
assertPointField(cd, 'p', [[0, 1, 2], [0, 1, 2, 3, 4]]);
227+
assertPointField(cd, 'p0', [[-0.4, 0.6, 1.6], [-0.4, 0.6, 1.6, 2.6, 3.6]]);
228+
assertPointField(cd, 'p1', [[0.4, 1.4, 2.4], [0.4, 1.4, 2.4, 3.4, 4.4]]);
229+
assertPointField(cd, 's0', [[0, 2, 3], [0, 3, 0, 4, 0]]);
230+
assertPointField(cd, 's1', [[2, 3, 5], [3, 4, 4, 6, 6]]);
231+
assertPointField(cd, 'isSum', [[false, false, false], [true, false, true, false, true]]);
232+
assertPointField(cd, 'rawS', [[2, 1, 2], [3, 1, 0, 2, 0]]);
233+
assertPointField(cd, 'dir', [['increasing', 'increasing', 'increasing'], ['totals', 'increasing', 'totals', 'increasing', 'totals']]);
234+
assertPointField(cd, 'hasTotals', [[false, undefined, undefined], [true, undefined, undefined, undefined, undefined]]);
227235
assertTraceField(cd, 't.barwidth', [0.8, 0.8]);
228236
assertTraceField(cd, 't.poffset', [-0.4, -0.4]);
229237
assertTraceField(cd, 't.bargroupwidth', [0.8, 0.8]);
@@ -233,19 +241,29 @@ describe('waterfall calc / crossTraceCalc', function() {
233241
var gd = mockWaterfallPlot([{
234242
y: [2, 1, 2]
235243
}, {
236-
y: [3, 1, 2]
244+
y: [3, 1, null, 2, null],
245+
measure: ['absolute', null, 'total', null, 'total']
237246
}], {
238247
waterfallmode: 'group',
239248
// asumming default waterfallgap is 0.2
240249
waterfallgroupgap: 0.1
241250
});
242251

243252
var cd = gd.calcdata;
244-
assertPointField(cd, 'x', [[-0.2, 0.8, 1.8], [0.2, 1.2, 2.2]]);
245-
assertPointField(cd, 'y', [[2, 3, 5], [3, 4, 6]]);
246-
assertPointField(cd, 'b', [[0, 0, 0], [0, 0, 0]]);
247-
assertPointField(cd, 's', [[2, 3, 5], [3, 4, 6]]);
248-
assertPointField(cd, 'p', [[0, 1, 2], [0, 1, 2]]);
253+
assertPointField(cd, 'w', [[0.36, 0.36, 0.36], [0.36, 0.36, 0.36, 0.36, 0.36]]);
254+
assertPointField(cd, 'x', [[-0.2, 0.8, 1.8], [0.2, 1.2, 2.2, 3.2, 4.2]]);
255+
assertPointField(cd, 'y', [[2, 3, 5], [3, 4, 4, 6, 6]]);
256+
assertPointField(cd, 'b', [[0, 0, 0], [0, 0, 0, 0, 0]]);
257+
assertPointField(cd, 's', [[2, 3, 5], [3, 4, 4, 6, 6]]);
258+
assertPointField(cd, 'p', [[0, 1, 2], [0, 1, 2, 3, 4]]);
259+
assertPointField(cd, 'p0', [[-0.38, 0.62, 1.62], [0.02, 1.02, 2.02, 3.02, 4.02]]);
260+
assertPointField(cd, 'p1', [[-0.02, 0.98, 1.98], [0.38, 1.38, 2.38, 3.38, 4.38]]);
261+
assertPointField(cd, 's0', [[0, 2, 3], [0, 3, 0, 4, 0]]);
262+
assertPointField(cd, 's1', [[2, 3, 5], [3, 4, 4, 6, 6]]);
263+
assertPointField(cd, 'isSum', [[false, false, false], [true, false, true, false, true]]);
264+
assertPointField(cd, 'rawS', [[2, 1, 2], [3, 1, 0, 2, 0]]);
265+
assertPointField(cd, 'dir', [['increasing', 'increasing', 'increasing'], ['totals', 'increasing', 'totals', 'increasing', 'totals']]);
266+
assertPointField(cd, 'hasTotals', [[false, undefined, undefined], [true, undefined, undefined, undefined, undefined]]);
249267
assertTraceField(cd, 't.barwidth', [0.36, 0.36]);
250268
assertTraceField(cd, 't.poffset', [-0.38, 0.02]);
251269
assertTraceField(cd, 't.bargroupwidth', [0.8, 0.8]);
@@ -617,31 +635,11 @@ describe('A waterfall plot', function() {
617635
};
618636
}
619637

620-
function assertTextFontFamilies(expFontFamilies) {
621-
return function() {
622-
var selection = d3.selectAll(WATERFALL_TEXT_SELECTOR);
623-
expect(selection.size()).toBe(expFontFamilies.length);
624-
selection.each(function(d, i) {
625-
expect(this.style.fontFamily).toBe(expFontFamilies[i]);
626-
});
627-
};
628-
}
629-
630-
function assertTextFontSizes(expFontSizes) {
631-
return function() {
632-
var selection = d3.selectAll(WATERFALL_TEXT_SELECTOR);
633-
expect(selection.size()).toBe(expFontSizes.length);
634-
selection.each(function(d, i) {
635-
expect(this.style.fontSize).toBe(expFontSizes[i] + 'px');
636-
});
637-
};
638-
}
639-
640-
it('should show waterfall texts (inside case)', function(done) {
638+
it('should show texts (inside case)', function(done) {
641639
var data = [{
642640
y: [10, 20, 30],
643641
type: 'waterfall',
644-
text: ['1', 'Very very very very very long waterfall text'],
642+
text: ['1', 'Very very very very very long text'],
645643
textposition: 'inside',
646644
}];
647645
var layout = {};
@@ -667,11 +665,11 @@ describe('A waterfall plot', function() {
667665
.then(done);
668666
});
669667

670-
it('should show waterfall texts (horizontal case)', function(done) {
668+
it('should show texts (horizontal case)', function(done) {
671669
var data = [{
672670
x: [10, -20, 30],
673671
type: 'waterfall',
674-
text: ['Very very very very very long waterfall text', -20],
672+
text: ['Very very very very very long text', -20],
675673
textposition: 'outside',
676674
}];
677675
var layout = {};
@@ -709,16 +707,15 @@ describe('A waterfall plot', function() {
709707
}
710708
};
711709

712-
it('should take waterfall fill opacities into account when calculating contrasting inside text colors', function(done) {
710+
it('should take fill opacities into account when calculating contrasting inside text colors', function(done) {
713711
var trace = {
714712
x: [5, 10],
715-
y: [5, 15],
713+
y: [5, -15],
716714
text: ['Giraffes', 'Zebras'],
717715
type: 'waterfall',
718716
textposition: 'inside',
719-
marker: {
720-
color: ['rgba(0, 0, 0, 0.2)', 'rgba(0, 0, 0, 0.8)']
721-
}
717+
increasing: { marker: { color: 'rgba(0, 0, 0, 0.2)' } },
718+
decreasing: { marker: { color: 'rgba(0, 0, 0, 0.8)' } }
722719
};
723720

724721
Plotly.plot(gd, [trace])
@@ -736,84 +733,6 @@ describe('A waterfall plot', function() {
736733
.then(done);
737734
});
738735

739-
it('should retain text styles throughout selecting and deselecting data points', function(done) {
740-
var trace1 = {
741-
x: ['giraffes', 'orangutans', 'monkeys'],
742-
y: [12, 18, 29],
743-
text: [12, 18, 29],
744-
type: 'waterfall',
745-
textposition: 'inside',
746-
textfont: {
747-
color: ['red', 'orange'],
748-
family: ['Arial', 'serif'],
749-
size: [8, 24]
750-
},
751-
insidetextfont: {
752-
color: ['blue'],
753-
family: ['Arial'],
754-
size: [16]
755-
}
756-
};
757-
var trace2 = Lib.extendDeep({}, trace1, {textposition: 'outside'});
758-
var layout = {
759-
waterfallmode: 'group',
760-
font: {
761-
family: 'Roboto',
762-
size: 12
763-
},
764-
clickmode: 'event+select'
765-
};
766-
767-
Plotly.plot(gd, [trace1, trace2], layout)
768-
.then(function() {
769-
assertNonSelectionModeStyle('before selection');
770-
})
771-
.then(function() {
772-
return select1stWaterfall2ndTrace();
773-
})
774-
.then(function() {
775-
assertSelectionModeStyle('in selection mode');
776-
})
777-
.then(function() {
778-
return deselect1stWaterfall2ndTrace();
779-
})
780-
.then(function() {
781-
assertNonSelectionModeStyle('after selection');
782-
})
783-
.catch(failTest)
784-
.then(done);
785-
786-
function assertSelectionModeStyle(label) {
787-
var unselColor = ['black', '0.2'];
788-
assertTextFontColors([unselColor, unselColor, unselColor, 'red', unselColor, unselColor], label)();
789-
assertTextFontFamilies(['Arial', 'serif', 'Roboto', 'Arial', 'serif', 'Roboto'])();
790-
assertTextFontSizes([16, 24, 12, 8, 24, 12])();
791-
}
792-
793-
function assertNonSelectionModeStyle(label) {
794-
assertTextFontColors(['blue', 'orange', LIGHT, 'red', 'orange', DARK], label)();
795-
assertTextFontFamilies(['Arial', 'serif', 'Roboto', 'Arial', 'serif', 'Roboto'])();
796-
assertTextFontSizes([16, 24, 12, 8, 24, 12])();
797-
}
798-
799-
function select1stWaterfall2ndTrace() {
800-
return new Promise(function(resolve) {
801-
click(176, 354);
802-
resolve();
803-
});
804-
}
805-
806-
function deselect1stWaterfall2ndTrace() {
807-
return new Promise(function(resolve) {
808-
var delayAvoidingDblClick = DBLCLICKDELAY * 1.01;
809-
setTimeout(function() {
810-
click(176, 354);
811-
resolve();
812-
}, delayAvoidingDblClick);
813-
});
814-
}
815-
});
816-
817736
it('should be able to restyle', function(done) {
818737
var mock = {
819738
data: [
@@ -1294,14 +1213,14 @@ describe('waterfall hover', function() {
12941213
it('should return the correct hover point data (case x)', function() {
12951214
var out = _hover(gd, 0, 0, 'x');
12961215

1297-
expect(out.style).toEqual([0, 'rgb(255, 102, 97)', 0, 13.23]);
1216+
expect(out.style).toEqual([0, '#3D9970', 0, 13.23]);
12981217
assertPos(out.pos, [11.87, 106.8, 52.71, 52.71]);
12991218
});
13001219

13011220
it('should return the correct hover point data (case closest)', function() {
13021221
var out = _hover(gd, -0.2, 12, 'closest');
13031222

1304-
expect(out.style).toEqual([0, 'rgb(255, 102, 97)', 0, 13.23]);
1223+
expect(out.style).toEqual([0, '#3D9970', 0, 13.23]);
13051224
assertPos(out.pos, [11.87, 59.33, 52.71, 52.71]);
13061225
});
13071226
});
@@ -1469,11 +1388,11 @@ describe('waterfall hover', function() {
14691388
})
14701389
.then(function() {
14711390
// you can still hover over the gap (14) but the label will
1472-
// get pushed in to the waterfall
1391+
// get pushed in to the bar
14731392
var out = _hover(gd, 14, 2, 'x');
14741393
assertPos(out.pos, [145, 155, 110, 110]);
14751394

1476-
// in closest mode you must be over the waterfall though
1395+
// in closest mode you must be over the bar though
14771396
out = _hover(gd, 14, 2, 'closest');
14781397
expect(out).toBe(false);
14791398

0 commit comments

Comments
 (0)