Skip to content

Commit 3b85f7f

Browse files
authored
Merge pull request #1297 from plotly/ie9-fix
fallbacks for IE9
2 parents 7ef3235 + 675103c commit 3b85f7f

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

src/lib/is_array.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
/**
1212
* Return true for arrays, whether they're untyped or not.
1313
*/
14+
15+
// IE9 fallback
16+
var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
17+
{isView: function() { return false; }} :
18+
ArrayBuffer;
19+
1420
module.exports = function isArray(a) {
15-
return Array.isArray(a) || ArrayBuffer.isView(a);
21+
return Array.isArray(a) || ab.isView(a);
1622
};

src/traces/heatmap/plot.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ function plotOne(gd, plotinfo, cd) {
337337

338338
if(zsmooth) { // best or fast, works fastest with imageData
339339
var pxIndex = 0,
340+
pixels;
341+
342+
try {
340343
pixels = new Uint8Array(imageWidth * imageHeight * 4);
344+
}
345+
catch(e) {
346+
pixels = new Array(imageWidth * imageHeight * 4);
347+
}
341348

342349
if(zsmooth === 'best') {
343350
var xPixArray = new Array(x.length),
@@ -379,7 +386,17 @@ function plotOne(gd, plotinfo, cd) {
379386
}
380387

381388
var imageData = context.createImageData(imageWidth, imageHeight);
382-
imageData.data.set(pixels);
389+
try {
390+
imageData.data.set(pixels);
391+
}
392+
catch(e) {
393+
var pxArray = imageData.data,
394+
dlen = pxArray.length;
395+
for(j = 0; j < dlen; j ++) {
396+
pxArray[j] = pixels[j];
397+
}
398+
}
399+
383400
context.putImageData(imageData, 0, 0);
384401
} else { // zsmooth = false -> filling potentially large bricks works fastest with fillRect
385402
for(j = 0; j < m; j++) {

test/jasmine/assets/ie9_mock.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
delete window.Promise;
2+
3+
delete window.ArrayBuffer;
4+
delete window.Uint8Array;
5+
delete window.Float32Array;
6+
delete window.Float64Array;
7+
delete window.Int16Array;
8+
delete window.Int32Array;

test/jasmine/bundle_tests/ie9_test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var Plotly = require('@lib/core');
2+
3+
Plotly.register([
4+
require('@lib/bar'),
5+
require('@lib/box'),
6+
require('@lib/heatmap'),
7+
require('@lib/histogram'),
8+
require('@lib/histogram2d'),
9+
require('@lib/histogram2dcontour'),
10+
require('@lib/pie'),
11+
require('@lib/contour'),
12+
require('@lib/scatterternary'),
13+
require('@lib/ohlc'),
14+
require('@lib/candlestick')
15+
]);
16+
17+
var createGraphDiv = require('../assets/create_graph_div');
18+
var destroyGraphDiv = require('../assets/destroy_graph_div');
19+
20+
describe('Bundle with IE9 supported trace types:', function() {
21+
22+
afterEach(destroyGraphDiv);
23+
24+
it(' check that ie9_mock.js did its job', function() {
25+
expect(function() { return ArrayBuffer; })
26+
.toThrow(new ReferenceError('ArrayBuffer is not defined'));
27+
expect(function() { return Uint8Array; })
28+
.toThrow(new ReferenceError('Uint8Array is not defined'));
29+
});
30+
31+
it('heatmaps with smoothing should work', function(done) {
32+
var gd = createGraphDiv();
33+
var data = [{
34+
type: 'heatmap',
35+
z: [[1, 2, 3], [2, 1, 2]],
36+
zsmooth: 'best'
37+
}];
38+
39+
Plotly.plot(gd, data).then(done);
40+
});
41+
42+
});

test/jasmine/karma.conf.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var arg = process.argv[4];
2020
var testFileGlob = arg ? arg : 'tests/*_test.js';
2121
var isSingleSuiteRun = (arg && arg.indexOf('bundle_tests/') === -1);
2222
var isRequireJSTest = (arg && arg.indexOf('bundle_tests/requirejs') !== -1);
23+
var isIE9Test = (arg && arg.indexOf('bundle_tests/ie9') !== -1);
2324

2425
var pathToMain = '../../lib/index.js';
2526
var pathToJQuery = 'assets/jquery-1.8.3.min.js';
@@ -127,6 +128,18 @@ else if(isRequireJSTest) {
127128
testFileGlob
128129
];
129130
}
131+
else if(isIE9Test) {
132+
// load ie9_mock.js before plotly.js+test bundle
133+
// to catch reference errors that could occur
134+
// when plotly.js is first loaded.
135+
136+
func.defaultConfig.files = [
137+
'./assets/ie9_mock.js',
138+
testFileGlob
139+
];
140+
141+
func.defaultConfig.preprocessors[testFileGlob] = ['browserify'];
142+
}
130143
else {
131144
func.defaultConfig.files = [
132145
pathToJQuery,

0 commit comments

Comments
 (0)