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

Make legend toggle work in IE11 #2741

Merged
merged 3 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
15 changes: 14 additions & 1 deletion spec/util-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
notEmpty,
sanitise,
isNumber,
flattenArray
flattenArray,
getIEVersion,
isIE
} from '../src/util';

describe('util.js tests', function () {
Expand Down Expand Up @@ -215,4 +217,15 @@ describe('util.js tests', function () {

});

describe('getIEVersion and isIE', function () {

it('getIEVersion should return a number or false', function () {
expect(getIEVersion()).toMatch(/(\d+|false)/);
});
it('isIE should return true or false', function () {
expect(isIE()).toMatch(/(true|false)/);
});

});

});
3 changes: 2 additions & 1 deletion src/api.show.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Chart } from './core';
import { isIE } from './util';

Chart.prototype.show = function (targetIds, options) {
var $$ = this.internal, targets;
Expand All @@ -10,7 +11,7 @@ Chart.prototype.show = function (targetIds, options) {
targets = $$.svg.selectAll($$.selectorTargets(targetIds));

targets.transition()
.style('display', 'initial', 'important')
.style('display', isIE() ? 'block' : 'initial', 'important')
Copy link
Member

Choose a reason for hiding this comment

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

nice!

.style('opacity', 1, 'important')
.call($$.endall, function () {
targets.style('opacity', null).style('opacity', 1);
Expand Down
35 changes: 35 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,38 @@ export var isWithinBox = function(point, box, sensitivity = 0) {
return xStart < point[0] && point[0] < xEnd && yEnd < point[1] && point[1] < yStart;
};

/**
* Returns Internet Explorer version number (or false if no Internet Explorer used).
*/
export var getIEVersion = function() {
// https://stackoverflow.com/questions/19999388/check-if-user-is-using-ie
const agent = window.navigator.userAgent;
Copy link
Member

Choose a reason for hiding this comment

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

How about taking agent as function paramter? If we do so, we can write the tests like the below:

expect(getIEVersion('Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko ')).toBe(11)

Copy link
Contributor Author

@GDFaber GDFaber Jan 28, 2020

Choose a reason for hiding this comment

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

Sure, let's do this. I'm going to modify getIEVersion() to take an optional parameter so usage is kept simple and it can be tested as well.


let pos = agent.indexOf('MSIE '); // up to IE10
if (pos > 0) {
return parseInt(agent.substring(pos + 5, agent.indexOf('.', pos)), 10);
}

pos = agent.indexOf('Trident/'); // IE11
if (pos > 0) {
pos = agent.indexOf('rv:');
return parseInt(agent.substring(pos + 3, agent.indexOf('.', pos)), 10);
}

return false;
};

/**
* Returns whether the used browser is Internet Explorer.
*
* @param {Number} version Optional parameter to specify IE version
*/
export var isIE = function(version) {
const ver = getIEVersion();

if (typeof version === 'undefined') {
return !!ver;
}

return version === ver;
};