-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IE9 fixes - to make SVG maps compatible #1332
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
Changes from 3 commits
98adfae
ebc1a10
12aeb9d
4aa1a45
61ade94
2105930
0d555b4
66baf51
fe12729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ var bundleTestGlob = path.join(constants.pathToJasmineBundleTests, '**/*.js'); | |
|
||
// main | ||
assertJasmineSuites(); | ||
assertHeaders(); | ||
assertSrcContents(); | ||
assertFileNames(); | ||
assertCircularDeps(); | ||
|
||
|
@@ -44,8 +44,12 @@ function assertJasmineSuites() { | |
}); | ||
} | ||
|
||
// check for header in src and lib files | ||
function assertHeaders() { | ||
/* | ||
* tests about the contents of source (and lib) files: | ||
* - check for header comment | ||
* - check that we don't have .classList | ||
*/ | ||
function assertSrcContents() { | ||
var licenseSrc = constants.licenseSrc; | ||
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2); | ||
var logs = []; | ||
|
@@ -56,7 +60,15 @@ function assertHeaders() { | |
|
||
// parse through code string while keeping track of comments | ||
var comments = []; | ||
falafel(code, {onComment: comments, locations: true}, function() {}); | ||
falafel(code, {onComment: comments, locations: true}, function(node) { | ||
// look for .classList | ||
if(node.type === 'MemberExpression') { | ||
var parts = node.source().split('.'); | ||
if(parts[parts.length - 1] === 'classList') { | ||
logs.push(file + ' : contains .classList (IE failure)'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was hoping eslint would have an option for IE compatibility (actually not even IE11 supports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea! |
||
} | ||
} | ||
}); | ||
|
||
var header = comments[0]; | ||
|
||
|
@@ -70,7 +82,7 @@ function assertHeaders() { | |
} | ||
}); | ||
|
||
log('correct headers in lib/ and src/', logs); | ||
log('correct headers and contents in lib/ and src/', logs); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
var Lib = require('@src/lib'); | ||
var setCursor = require('@src/lib/setcursor'); | ||
var overrideCursor = require('@src/lib/override_cursor'); | ||
var config = require('@src/plot_api/plot_config'); | ||
|
||
var d3 = require('d3'); | ||
var Plotly = require('@lib'); | ||
|
@@ -1599,6 +1600,172 @@ describe('Test lib.js:', function() { | |
expect(Lib.isPlotDiv({})).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isD3Selection', function() { | ||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(function() { | ||
destroyGraphDiv(); | ||
Plotly.setPlotConfig({ queueLength: 0 }); | ||
}); | ||
|
||
it('recognizes real and duck typed selections', function() { | ||
var yesSelections = [ | ||
d3.select(gd), | ||
// this is what got us into trouble actually - d3 selections can | ||
// contain non-nodes - say for example d3 selections! then they | ||
// don't work correctly. But it makes a convenient test! | ||
d3.select(1), | ||
// just showing what we actually do in this function: duck type | ||
// using the `classed` method. | ||
{classed: function(v) { return !!v; }} | ||
]; | ||
|
||
yesSelections.forEach(function(v) { | ||
expect(Lib.isD3Selection(v)).toBe(true, v); | ||
}); | ||
}); | ||
|
||
it('rejects non-selections', function() { | ||
var notSelections = [ | ||
1, | ||
'path', | ||
[1, 2], | ||
[[1, 2]], | ||
{classed: 1}, | ||
gd | ||
]; | ||
|
||
notSelections.forEach(function(v) { | ||
expect(Lib.isD3Selection(v)).toBe(false, v); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('loggers', function() { | ||
var stashConsole, | ||
stashLogLevel; | ||
|
||
function consoleFn(name, hasApply, messages) { | ||
var out = function() { | ||
var args = []; | ||
for(var i = 0; i < arguments.length; i++) args.push(arguments[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because |
||
messages.push([name, args]); | ||
}; | ||
|
||
if(!hasApply) out.apply = undefined; | ||
|
||
return out; | ||
} | ||
|
||
function mockConsole(hasApply, hasTrace) { | ||
var out = { | ||
MESSAGES: [] | ||
}; | ||
out.log = consoleFn('log', hasApply, out.MESSAGES); | ||
out.error = consoleFn('error', hasApply, out.MESSAGES); | ||
|
||
if(hasTrace) out.trace = consoleFn('trace', hasApply, out.MESSAGES); | ||
|
||
return out; | ||
} | ||
|
||
beforeEach(function() { | ||
stashConsole = window.console; | ||
stashLogLevel = config.logging; | ||
}); | ||
|
||
afterEach(function() { | ||
window.console = stashConsole; | ||
config.logging = stashLogLevel; | ||
}); | ||
|
||
it('emits one console message if apply is available', function() { | ||
var c = window.console = mockConsole(true, true); | ||
config.logging = 2; | ||
|
||
Lib.log('tick', 'tock', 'tick', 'tock', 1); | ||
Lib.warn('I\'m', 'a', 'little', 'cuckoo', 'clock', [1, 2]); | ||
Lib.error('cuckoo!', 'cuckoo!!!', {a: 1, b: 2}); | ||
|
||
expect(c.MESSAGES).toEqual([ | ||
['trace', ['LOG:', 'tick', 'tock', 'tick', 'tock', 1]], | ||
['trace', ['WARN:', 'I\'m', 'a', 'little', 'cuckoo', 'clock', [1, 2]]], | ||
['error', ['ERROR:', 'cuckoo!', 'cuckoo!!!', {a: 1, b: 2}]] | ||
]); | ||
}); | ||
|
||
it('falls back on console.log if no trace', function() { | ||
var c = window.console = mockConsole(true, false); | ||
config.logging = 2; | ||
|
||
Lib.log('Hi'); | ||
Lib.warn(42); | ||
|
||
expect(c.MESSAGES).toEqual([ | ||
['log', ['LOG:', 'Hi']], | ||
['log', ['WARN:', 42]] | ||
]); | ||
}); | ||
|
||
it('falls back on separate calls if no apply', function() { | ||
var c = window.console = mockConsole(false, false); | ||
config.logging = 2; | ||
|
||
Lib.log('tick', 'tock', 'tick', 'tock', 1); | ||
Lib.warn('I\'m', 'a', 'little', 'cuckoo', 'clock', [1, 2]); | ||
Lib.error('cuckoo!', 'cuckoo!!!', {a: 1, b: 2}); | ||
|
||
expect(c.MESSAGES).toEqual([ | ||
['log', ['LOG:']], | ||
['log', ['tick']], | ||
['log', ['tock']], | ||
['log', ['tick']], | ||
['log', ['tock']], | ||
['log', [1]], | ||
['log', ['WARN:']], | ||
['log', ['I\'m']], | ||
['log', ['a']], | ||
['log', ['little']], | ||
['log', ['cuckoo']], | ||
['log', ['clock']], | ||
['log', [[1, 2]]], | ||
['error', ['ERROR:']], | ||
['error', ['cuckoo!']], | ||
['error', ['cuckoo!!!']], | ||
['error', [{a: 1, b: 2}]] | ||
]); | ||
}); | ||
|
||
it('omits .log at log level 1', function() { | ||
var c = window.console = mockConsole(true, true); | ||
config.logging = 1; | ||
|
||
Lib.log(1); | ||
Lib.warn(2); | ||
Lib.error(3); | ||
|
||
expect(c.MESSAGES).toEqual([ | ||
['trace', ['WARN:', 2]], | ||
['error', ['ERROR:', 3]] | ||
]); | ||
}); | ||
|
||
it('logs nothing at log level 0', function() { | ||
var c = window.console = mockConsole(true, true); | ||
config.logging = 0; | ||
|
||
Lib.log(1); | ||
Lib.warn(2); | ||
Lib.error(3); | ||
|
||
expect(c.MESSAGES).toEqual([]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Queue', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Maybe this also fixes #166 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe - I'll try that tonight and see if it implies any further fixes. Any other IE issues I should include in my testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does fix #166 - and 4aa1a45 should catch any of these
nanpx
orundefinedpx
errors, at least as long as they go through d3.Will investigate the other two tomorrow, they may be related.