From 3e81ecadfd5823b24fc28087596aa0246f2b6f60 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 12 Jan 2017 17:42:58 -0500 Subject: [PATCH 1/5] fallbacks for ie9 are better than typedarray polyfill but it works this way with the polyfill too. --- src/lib/is_array.js | 8 +++++++- src/traces/heatmap/plot.js | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib/is_array.js b/src/lib/is_array.js index 9b7d64e41aa..cda78eeb627 100644 --- a/src/lib/is_array.js +++ b/src/lib/is_array.js @@ -11,6 +11,12 @@ /** * Return true for arrays, whether they're untyped or not. */ + +// IE9 fallback +var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ? + {isView: function() { return false; }} : + ArrayBuffer; + module.exports = function isArray(a) { - return Array.isArray(a) || ArrayBuffer.isView(a); + return Array.isArray(a) || ab.isView(a); }; diff --git a/src/traces/heatmap/plot.js b/src/traces/heatmap/plot.js index 1fc5eda33de..02fbf077ee7 100644 --- a/src/traces/heatmap/plot.js +++ b/src/traces/heatmap/plot.js @@ -337,7 +337,14 @@ function plotOne(gd, plotinfo, cd) { if(zsmooth) { // best or fast, works fastest with imageData var pxIndex = 0, + pixels; + + try { pixels = new Uint8Array(imageWidth * imageHeight * 4); + } + catch(e) { + pixels = new Array(imageWidth * imageHeight * 4); + } if(zsmooth === 'best') { var xPixArray = new Array(x.length), @@ -379,7 +386,17 @@ function plotOne(gd, plotinfo, cd) { } var imageData = context.createImageData(imageWidth, imageHeight); - imageData.data.set(pixels); + try { + imageData.data.set(pixels); + } + catch(e) { + var pxArray = imageData.data, + dlen = pxArray.length; + for(j = 0; j < dlen; j ++) { + pxArray[j] = pixels[j]; + } + } + context.putImageData(imageData, 0, 0); } else { // zsmooth = false -> filling potentially large bricks works fastest with fillRect for(j = 0; j < m; j++) { From c0490d6b99fb3e5a848a43461bd4e8e47d50851d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 13 Jan 2017 11:58:30 -0500 Subject: [PATCH 2/5] try adding 'ie9' tests --- test/jasmine/tests/ie9_test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/jasmine/tests/ie9_test.js diff --git a/test/jasmine/tests/ie9_test.js b/test/jasmine/tests/ie9_test.js new file mode 100644 index 00000000000..a2338a49a6f --- /dev/null +++ b/test/jasmine/tests/ie9_test.js @@ -0,0 +1,32 @@ +var Plotly = require('@lib'); + +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); + +describe('IE9 environment', function() { + + var uint8Array = window.Uint8Array; + + beforeAll(function() { + window.Uint8Array = undefined; + }); + + afterAll(function() { + window.Uint8Array = uint8Array; + }); + + afterEach(function() { + destroyGraphDiv(); + }); + + it('heatmaps with smoothing should work', function(done) { + var gd = createGraphDiv(); + var data = [{ + type: 'heatmap', + z: [[1, 2, 3], [2, 1, 2]], + zsmooth: 'best' + }]; + + Plotly.plot(gd, data).then(done); + }); +}); From 4ce9df075a02f692ecc54d75bc7127c4b798c42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 13 Jan 2017 13:31:45 -0500 Subject: [PATCH 3/5] take 2 on ie9 test - in bundle_tests/ - mock IE9 env before loading plotly.js + test bundle --- test/jasmine/assets/ie9_mock.js | 8 ++++++ test/jasmine/bundle_tests/ie9_test.js | 40 +++++++++++++++++++++++++++ test/jasmine/karma.conf.js | 10 +++++++ 3 files changed, 58 insertions(+) create mode 100644 test/jasmine/assets/ie9_mock.js create mode 100644 test/jasmine/bundle_tests/ie9_test.js diff --git a/test/jasmine/assets/ie9_mock.js b/test/jasmine/assets/ie9_mock.js new file mode 100644 index 00000000000..0d032173c95 --- /dev/null +++ b/test/jasmine/assets/ie9_mock.js @@ -0,0 +1,8 @@ +delete window.Promise; + +delete window.ArrayBuffer; +delete window.Uint8Array; +delete window.Float32Array; +delete window.Float64Array; +delete window.Int16Array; +delete window.Int32Array; diff --git a/test/jasmine/bundle_tests/ie9_test.js b/test/jasmine/bundle_tests/ie9_test.js new file mode 100644 index 00000000000..d97105ef865 --- /dev/null +++ b/test/jasmine/bundle_tests/ie9_test.js @@ -0,0 +1,40 @@ +var Plotly = require('@lib/core'); + +Plotly.register([ + require('@lib/bar'), + require('@lib/box'), + require('@lib/heatmap'), + require('@lib/histogram'), + require('@lib/histogram2d'), + require('@lib/histogram2dcontour'), + require('@lib/pie'), + require('@lib/contour'), + require('@lib/scatterternary'), + require('@lib/ohlc'), + require('@lib/candlestick') +]); + +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); + +describe('Bundle with IE9 supported trace types:', function() { + + afterEach(destroyGraphDiv); + + it('[wip] check that ie9_mock.js did its job', function() { + expect(window.ArrayBuffer).toBeUndefined(); + expect(window.Uint8Array).toBeUndefined(); + }); + + it('heatmaps with smoothing should work', function(done) { + var gd = createGraphDiv(); + var data = [{ + type: 'heatmap', + z: [[1, 2, 3], [2, 1, 2]], + zsmooth: 'best' + }]; + + Plotly.plot(gd, data).then(done); + }); + +}); diff --git a/test/jasmine/karma.conf.js b/test/jasmine/karma.conf.js index 28f046bc961..6cd3e804b06 100644 --- a/test/jasmine/karma.conf.js +++ b/test/jasmine/karma.conf.js @@ -20,6 +20,7 @@ var arg = process.argv[4]; var testFileGlob = arg ? arg : 'tests/*_test.js'; var isSingleSuiteRun = (arg && arg.indexOf('bundle_tests/') === -1); var isRequireJSTest = (arg && arg.indexOf('bundle_tests/requirejs') !== -1); +var isIE9Test = (arg && arg.indexOf('bundle_tests/ie9') !== -1); var pathToMain = '../../lib/index.js'; var pathToJQuery = 'assets/jquery-1.8.3.min.js'; @@ -127,6 +128,15 @@ else if(isRequireJSTest) { testFileGlob ]; } +else if(isIE9Test) { + func.defaultConfig.files = [ + './assets/ie9_mock.js', +// '../../dist/extras/typedarray.min.js', + testFileGlob + ]; + + func.defaultConfig.preprocessors[testFileGlob] = ['browserify']; +} else { func.defaultConfig.files = [ pathToJQuery, From 7cb691eeda071100573e1a3f3397968a6f9ad300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 13 Jan 2017 14:02:24 -0500 Subject: [PATCH 4/5] AJ proof ie9 bundle test --- test/jasmine/bundle_tests/ie9_test.js | 8 +++++--- test/jasmine/karma.conf.js | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/jasmine/bundle_tests/ie9_test.js b/test/jasmine/bundle_tests/ie9_test.js index d97105ef865..d874657245b 100644 --- a/test/jasmine/bundle_tests/ie9_test.js +++ b/test/jasmine/bundle_tests/ie9_test.js @@ -21,9 +21,11 @@ describe('Bundle with IE9 supported trace types:', function() { afterEach(destroyGraphDiv); - it('[wip] check that ie9_mock.js did its job', function() { - expect(window.ArrayBuffer).toBeUndefined(); - expect(window.Uint8Array).toBeUndefined(); + it(' check that ie9_mock.js did its job', function() { + expect(function() { return ArrayBuffer; }) + .toThrow(new ReferenceError('ArrayBuffer is not defined')); + expect(function() { return Uint8Array; }) + .toThrow(new ReferenceError('Uint8Array is not defined')); }); it('heatmaps with smoothing should work', function(done) { diff --git a/test/jasmine/karma.conf.js b/test/jasmine/karma.conf.js index 6cd3e804b06..bd84e867925 100644 --- a/test/jasmine/karma.conf.js +++ b/test/jasmine/karma.conf.js @@ -129,9 +129,12 @@ else if(isRequireJSTest) { ]; } else if(isIE9Test) { + // load ie9_mock.js before plotly.js+test bundle + // to catch reference errors that could occur + // when plotly.js is first loaded. + func.defaultConfig.files = [ './assets/ie9_mock.js', -// '../../dist/extras/typedarray.min.js', testFileGlob ]; From 2b1c0febc7a95911ede8b14e966df4a0ed91c740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 13 Jan 2017 14:03:47 -0500 Subject: [PATCH 5/5] Revert "try adding 'ie9' tests" This reverts commit c0490d6b99fb3e5a848a43461bd4e8e47d50851d. --- test/jasmine/tests/ie9_test.js | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 test/jasmine/tests/ie9_test.js diff --git a/test/jasmine/tests/ie9_test.js b/test/jasmine/tests/ie9_test.js deleted file mode 100644 index a2338a49a6f..00000000000 --- a/test/jasmine/tests/ie9_test.js +++ /dev/null @@ -1,32 +0,0 @@ -var Plotly = require('@lib'); - -var createGraphDiv = require('../assets/create_graph_div'); -var destroyGraphDiv = require('../assets/destroy_graph_div'); - -describe('IE9 environment', function() { - - var uint8Array = window.Uint8Array; - - beforeAll(function() { - window.Uint8Array = undefined; - }); - - afterAll(function() { - window.Uint8Array = uint8Array; - }); - - afterEach(function() { - destroyGraphDiv(); - }); - - it('heatmaps with smoothing should work', function(done) { - var gd = createGraphDiv(); - var data = [{ - type: 'heatmap', - z: [[1, 2, 3], [2, 1, 2]], - zsmooth: 'best' - }]; - - Plotly.plot(gd, data).then(done); - }); -});