From 46755b29a5019cb5d6e6c907a00d413d8d4dfb5f Mon Sep 17 00:00:00 2001 From: Adam Abeshouse Date: Fri, 26 Jan 2018 13:56:49 -0500 Subject: [PATCH] Merge pull request #53 from cBioPortal/webgl-fail-gracefully Fail gracefully if WebGL context is not obtainable --- packages/oncoprintjs/dist/oncoprint.bundle.js | 172 ++++++++++++++++++ packages/oncoprintjs/index.d.ts | 1 + packages/oncoprintjs/src/js/oncoprint.js | 172 ++++++++++++++++++ 3 files changed, 345 insertions(+) diff --git a/packages/oncoprintjs/dist/oncoprint.bundle.js b/packages/oncoprintjs/dist/oncoprint.bundle.js index a3237c59d7a..f0a3fe947f0 100644 --- a/packages/oncoprintjs/dist/oncoprint.bundle.js +++ b/packages/oncoprintjs/dist/oncoprint.bundle.js @@ -13782,6 +13782,13 @@ var Oncoprint = (function () { })(); function Oncoprint(ctr_selector, width) { var self = this; + + this.webgl_unavailable = (document.createElement('canvas').getContext('experimental-webgl') === null); + if (this.webgl_unavailable) { + $(ctr_selector).append("

WebGL context cannot be retrieved, so oncoprint cannot be used. Please visit WebGL Report to explore your browsers WebGL capabilities.

"); + return; + } + this.ctr_selector = ctr_selector; var $ctr = $('').css({'position':'relative', 'display':'inline-block'}).appendTo(ctr_selector); @@ -14128,6 +14135,9 @@ var Oncoprint = (function () { }; Oncoprint.prototype.setMinimapVisible = function (visible) { + if(this.webgl_unavailable) { + return; + } if (visible) { this.$minimap_div.css({'display': 'block', 'top': this.model.getCellViewHeight() + 30, 'left': $(this.ctr_selector).width() - this.$minimap_div.outerWidth() - 10}); } else { @@ -14138,15 +14148,27 @@ var Oncoprint = (function () { } Oncoprint.prototype.scrollTo = function(left) { + if(this.webgl_unavailable) { + return; + } this.$dummy_scroll_div.scrollLeft(left); } Oncoprint.prototype.onHorzZoom = function(callback) { + if(this.webgl_unavailable) { + return; + } this.horz_zoom_callbacks.push(callback); } Oncoprint.prototype.onMinimapClose = function(callback) { + if(this.webgl_unavailable) { + return; + } this.minimap_close_callbacks.push(callback); } Oncoprint.prototype.moveTrack = function(target_track, new_previous_track) { + if(this.webgl_unavailable) { + return; + } this.model.moveTrack(target_track, new_previous_track); this.cell_view.moveTrack(this.model); this.label_view.moveTrack(this.model); @@ -14161,6 +14183,9 @@ var Oncoprint = (function () { resizeAndOrganizeAfterTimeout(this); } Oncoprint.prototype.setTrackGroupOrder = function(index, track_order, dont_sort) { + if(this.webgl_unavailable) { + return; + } this.model.setTrackGroupOrder(index, track_order); this.cell_view.setTrackGroupOrder(this.model); this.label_view.setTrackGroupOrder(this.model); @@ -14174,6 +14199,9 @@ var Oncoprint = (function () { resizeAndOrganizeAfterTimeout(this); } Oncoprint.prototype.setTrackGroupLegendOrder = function(group_order) { + if(this.webgl_unavailable) { + return; + } this.model.setTrackGroupLegendOrder(group_order); this.legend_view.setTrackGroupLegendOrder(this.model); @@ -14181,6 +14209,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.keepSorted = function(keep_sorted) { + if(this.webgl_unavailable) { + return; + } this.keep_sorted = (typeof keep_sorted === 'undefined' ? true : keep_sorted); if (this.keep_sorted) { this.sort(); @@ -14188,6 +14219,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.addTracks = function (params_list) { + if(this.webgl_unavailable) { + return; + } // Update model var track_ids = []; params_list = params_list.map(function (o) { @@ -14214,6 +14248,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.removeTrack = function (track_id) { + if(this.webgl_unavailable) { + return; + } // Update model this.model.removeTrack(track_id); // Update views @@ -14231,6 +14268,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.removeTracks = function(track_ids) { + if(this.webgl_unavailable) { + return; + } this.keepSorted(false); this.suppressRendering(); for (var i=0; i= 11 var MAX_CANVAS_SIDE = 8192; @@ -14670,29 +14824,47 @@ var Oncoprint = (function () { } Oncoprint.prototype.toDataUrl = function(callback) { + if(this.webgl_unavailable) { + return; + } this.toCanvas(function(canvas) { callback(canvas.toDataURL()); }); } Oncoprint.prototype.highlightTrack = function(track_id) { + if(this.webgl_unavailable) { + return; + } this.label_view.highlightTrack(track_id, this.model); } Oncoprint.prototype.getIdOrder = function(all) { + if(this.webgl_unavailable) { + return; + } return this.model.getIdOrder(all); } Oncoprint.prototype.setIdClipboardContents = function(array) { + if(this.webgl_unavailable) { + return; + } this.id_clipboard = array.slice(); for (var i=0; i { + webgl_unavailable: boolean; setMinimapVisible:(visible:boolean)=>void; scrollTo:(left:number)=>void; onHorzZoom:(callback:(newHorzZoom:number)=>void)=>void; diff --git a/packages/oncoprintjs/src/js/oncoprint.js b/packages/oncoprintjs/src/js/oncoprint.js index a9dba709341..be8b0101ef8 100644 --- a/packages/oncoprintjs/src/js/oncoprint.js +++ b/packages/oncoprintjs/src/js/oncoprint.js @@ -29,6 +29,13 @@ var Oncoprint = (function () { })(); function Oncoprint(ctr_selector, width) { var self = this; + + this.webgl_unavailable = (document.createElement('canvas').getContext('experimental-webgl') === null); + if (this.webgl_unavailable) { + $(ctr_selector).append("

WebGL context cannot be retrieved, so oncoprint cannot be used. Please visit WebGL Report to explore your browsers WebGL capabilities.

"); + return; + } + this.ctr_selector = ctr_selector; var $ctr = $('').css({'position':'relative', 'display':'inline-block'}).appendTo(ctr_selector); @@ -375,6 +382,9 @@ var Oncoprint = (function () { }; Oncoprint.prototype.setMinimapVisible = function (visible) { + if(this.webgl_unavailable) { + return; + } if (visible) { this.$minimap_div.css({'display': 'block', 'top': this.model.getCellViewHeight() + 30, 'left': $(this.ctr_selector).width() - this.$minimap_div.outerWidth() - 10}); } else { @@ -385,15 +395,27 @@ var Oncoprint = (function () { } Oncoprint.prototype.scrollTo = function(left) { + if(this.webgl_unavailable) { + return; + } this.$dummy_scroll_div.scrollLeft(left); } Oncoprint.prototype.onHorzZoom = function(callback) { + if(this.webgl_unavailable) { + return; + } this.horz_zoom_callbacks.push(callback); } Oncoprint.prototype.onMinimapClose = function(callback) { + if(this.webgl_unavailable) { + return; + } this.minimap_close_callbacks.push(callback); } Oncoprint.prototype.moveTrack = function(target_track, new_previous_track) { + if(this.webgl_unavailable) { + return; + } this.model.moveTrack(target_track, new_previous_track); this.cell_view.moveTrack(this.model); this.label_view.moveTrack(this.model); @@ -408,6 +430,9 @@ var Oncoprint = (function () { resizeAndOrganizeAfterTimeout(this); } Oncoprint.prototype.setTrackGroupOrder = function(index, track_order, dont_sort) { + if(this.webgl_unavailable) { + return; + } this.model.setTrackGroupOrder(index, track_order); this.cell_view.setTrackGroupOrder(this.model); this.label_view.setTrackGroupOrder(this.model); @@ -421,6 +446,9 @@ var Oncoprint = (function () { resizeAndOrganizeAfterTimeout(this); } Oncoprint.prototype.setTrackGroupLegendOrder = function(group_order) { + if(this.webgl_unavailable) { + return; + } this.model.setTrackGroupLegendOrder(group_order); this.legend_view.setTrackGroupLegendOrder(this.model); @@ -428,6 +456,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.keepSorted = function(keep_sorted) { + if(this.webgl_unavailable) { + return; + } this.keep_sorted = (typeof keep_sorted === 'undefined' ? true : keep_sorted); if (this.keep_sorted) { this.sort(); @@ -435,6 +466,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.addTracks = function (params_list) { + if(this.webgl_unavailable) { + return; + } // Update model var track_ids = []; params_list = params_list.map(function (o) { @@ -461,6 +495,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.removeTrack = function (track_id) { + if(this.webgl_unavailable) { + return; + } // Update model this.model.removeTrack(track_id); // Update views @@ -478,6 +515,9 @@ var Oncoprint = (function () { } Oncoprint.prototype.removeTracks = function(track_ids) { + if(this.webgl_unavailable) { + return; + } this.keepSorted(false); this.suppressRendering(); for (var i=0; i= 11 var MAX_CANVAS_SIDE = 8192; @@ -917,29 +1071,47 @@ var Oncoprint = (function () { } Oncoprint.prototype.toDataUrl = function(callback) { + if(this.webgl_unavailable) { + return; + } this.toCanvas(function(canvas) { callback(canvas.toDataURL()); }); } Oncoprint.prototype.highlightTrack = function(track_id) { + if(this.webgl_unavailable) { + return; + } this.label_view.highlightTrack(track_id, this.model); } Oncoprint.prototype.getIdOrder = function(all) { + if(this.webgl_unavailable) { + return; + } return this.model.getIdOrder(all); } Oncoprint.prototype.setIdClipboardContents = function(array) { + if(this.webgl_unavailable) { + return; + } this.id_clipboard = array.slice(); for (var i=0; i