Skip to content

Rotate hover labels in a few more scenarios #3043

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 4 commits into from
Sep 25, 2018
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
Prev Previous commit
Next Next commit
assert hover label rotation
  • Loading branch information
etpinard committed Sep 24, 2018
commit a64943beed66538d239e6f1915c1f2efd16f32e9
49 changes: 29 additions & 20 deletions test/jasmine/assets/custom_assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function count(selector) {
* - axis {string}
* - vOrder {array of number}
* - hOrder {array of number}
* - isRotated {boolean}
* @param {string} msg
*/
exports.assertHoverLabelContent = function(expectation, msg) {
Expand All @@ -105,17 +106,22 @@ exports.assertHoverLabelContent = function(expectation, msg) {
var axMsg = 'common axis hover label';
var axCnt = count(axSelector);

var reRotate = /(\brotate\(.*?\);?)/;

if(ptCnt === 1) {
assertLabelContent(
d3.select(ptSelector + '> text.nums'),
expectation.nums,
ptMsg + ' (nums)'
);
assertLabelContent(
d3.select(ptSelector + '> text.name'),
expectation.name,
ptMsg + ' (name)'
);
var g = d3.select(ptSelector);
var numsSel = g.select('text.nums');
var nameSel = g.select('text.name');

assertLabelContent(numsSel, expectation.nums, ptMsg + ' (nums)');
assertLabelContent(nameSel, expectation.name, ptMsg + ' (name)');

if('isRotated' in expectation) {
expect(g.attr('transform').match(reRotate))
.negateIf(expectation.isRotated)
.toBe(null, ptMsg + ' should be rotated');

}
} else if(ptCnt > 1) {
if(!Array.isArray(expectation.nums) || !Array.isArray(expectation.name)) {
fail(ptMsg + ': expecting more than 1 labels.');
Expand All @@ -126,16 +132,19 @@ exports.assertHoverLabelContent = function(expectation, msg) {

var bboxes = [];
d3.selectAll(ptSelector).each(function(_, i) {
assertLabelContent(
d3.select(this).select('text.nums'),
expectation.nums[i],
ptMsg + ' (nums ' + i + ')'
);
assertLabelContent(
d3.select(this).select('text.name'),
expectation.name[i],
ptMsg + ' (name ' + i + ')'
);
var g = d3.select(this);
var numsSel = g.select('text.nums');
var nameSel = g.select('text.name');

assertLabelContent(numsSel, expectation.nums[i], ptMsg + ' (nums ' + i + ')');
assertLabelContent(nameSel, expectation.name[i], ptMsg + ' (name ' + i + ')');

if('isRotated' in expectation) {
expect(g.attr('transform').match(reRotate))
.negateIf(expectation.isRotated)
.toBe(null, ptMsg + ' ' + i + ' should be rotated');
}

bboxes.push({bbox: this.getBoundingClientRect(), index: i});
});
if(expectation.vOrder) {
Expand Down
3 changes: 3 additions & 0 deletions test/jasmine/tests/violin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ describe('Test violin hover:', function() {
name: ['categories', '', '', '', '', '', ''],
axis: 'categories',
hOrder: [4, 5, 3, 6, 0, 2, 1],
isRotated: true
}, {
desc: 'multiple horizontal violins',
mock: require('@mocks/box_grouped_horz.json'),
Expand All @@ -454,6 +455,7 @@ describe('Test violin hover:', function() {
name: ['kale', '', '', '', ''],
axis: 'day 2',
hOrder: [4, 3, 0, 2, 1],
isRotated: true
}, {
desc: 'multiple horizontal violins (under hovermode:closest)',
mock: require('@mocks/box_grouped_horz.json'),
Expand All @@ -473,6 +475,7 @@ describe('Test violin hover:', function() {
],
name: ['radishes', '', '', '', ''],
hOrder: [4, 3, 0, 2, 1],
isRotated: true
}]
.forEach(function(specs) {
it('should generate correct hover labels ' + specs.desc, function(done) {
Expand Down