Skip to content

Commit

Permalink
Merge pull request #1165 from parklab/flekschas/satori-fixes
Browse files Browse the repository at this point in the history
Flekschas/satori fixes
  • Loading branch information
jkmarx committed May 24, 2016
2 parents 0e5a8b4 + e7faab6 commit c107ba1
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 98 deletions.
1 change: 0 additions & 1 deletion refinery/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
<script src="{% static "vendor/angular-bootstrap/ui-bootstrap-tpls.min.js" %}"></script>
<script src="{% static "vendor/angular-drag-and-drop-lists/angular-drag-and-drop-lists.min.js" %}"></script>
<script src="{% static "vendor/ng-webworker/src/ng-webworker.min.js" %}"></script>
<script src="{% static "vendor/ng-webworker/src/worker_wrapper.min.js" %}"></script>
<script src="{% static "vendor/filesize/lib/filesize.min.js" %}"></script>
<script src="{% static "vendor/lodash/lodash.min.js" %}"></script>
<script src="{% static "vendor/lodash-migrate/dist/lodash-migrate.min.js" %}"></script>
Expand Down
2 changes: 1 addition & 1 deletion refinery/ui/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"lodash": "3.10.1",
"lodash-migrate": "0.2.6",
"ng-file-upload": "1.6.6",
"ng-webworker": "0.2.2",
"ng-webworker": "0.2.3",
"spark-md5": "2.0.2",
"spectrum": "1.7.0",
"tipsy": "0.1.7",
Expand Down
158 changes: 93 additions & 65 deletions refinery/ui/source/js/dashboard/controllers/vis-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

function VisWrapperCtrl ($q, pubSub, dashboardVisData) {
this.$q = $q;
this.pubSub = pubSub;
var self = this;

self.$q = $q;
self.pubSub = pubSub;
self.dashboardVisData = dashboardVisData;

// Absolute root node: OWL:Thing
// The absolute root node is used for pruning the graph as it acts as a
// single entry point.
this.absRoot = 'http://www.w3.org/2002/07/owl#Thing';
self.absRoot = 'http://www.w3.org/2002/07/owl#Thing';

// Remix root nodes are a collection of nodes that act as meaningful entry
// points across different ontologies in regards to browsing.
this.remixRoots = [
self.remixRoots = [
'http://purl.obolibrary.org/obo/BTO_0002666',
'http://purl.obolibrary.org/obo/BTO_0000088',
'http://purl.obolibrary.org/obo/BTO_0000421',
Expand Down Expand Up @@ -61,7 +64,7 @@ function VisWrapperCtrl ($q, pubSub, dashboardVisData) {

// Currently OWL2NEO4J doesn't extract the preferred label and even then we
// might want to rename certain nodes in case their label is confusing.
this.rename = [{
self.rename = [{
uri: 'http://www.w3.org/2002/07/owl#Thing',
label: 'Root'
}, {
Expand All @@ -72,77 +75,102 @@ function VisWrapperCtrl ($q, pubSub, dashboardVisData) {
// Name of the property that is used to assess the size of a term.
// E.g. if `Liver` is used to annotate 5 data sets then the size of `Liver`
// is 5. The property of the term object is `dataSets` in this case.
this.propertyValue = 'dataSets';

// Trigger preloading / precomputing of D3 data for exploration.
dashboardVisData.load(
this.absRoot,
this.propertyValue,
this.remixRoots,
this.rename
);

var graph = this.$q.defer();
this.graph = graph.promise;

var treemap = this.$q.defer();
this.treemap = treemap.promise;

var annotations = this.$q.defer();
this.annotations = annotations.promise;

dashboardVisData.data
.then(function (results) {
graph.resolve({
graph: results.graph,
rootIds: [results.root]
});
treemap.resolve(results.treemap);
annotations.resolve(results.annotations);
})
.catch(function (error) {
this.loading = false;
if (error.number === 0) {
this.error = true;
} else {
this.noData = true;
}
}.bind(this));
self.propertyValue = 'dataSets';

self.graphDeferred = self.$q.defer();
self.graph = self.graphDeferred.promise;

self.treemapDeferred = self.$q.defer();
self.treemap = self.treemapDeferred.promise;

this.loading = true;
this.treemapLoading = $q.defer();
self.annotationsDeferred = self.$q.defer();
self.annotations = self.annotationsDeferred.promise;

this.pubSub.on('expandFinished', function () {
this.ready = true;
}.bind(this));
self.loading = true;
self.treemapLoading = $q.defer();

this.pubSub.on('vis.show', function () {
this.ready = true;
this.invisible = false;
}.bind(this));
self.pubSub.on('expandFinished', function () {
self.ready = true;
});

this.pubSub.on('collapsing', function () {
this.ready = false;
}.bind(this));
self.pubSub.on('vis.show', function () {
self.ready = true;
self.invisible = false;
});

this.pubSub.on('vis.hide', function () {
this.ready = false;
}.bind(this));
self.pubSub.on('collapsing', function () {
self.ready = false;
});

this.pubSub.on('vis.tempHide', function () {
this.invisible = true;
}.bind(this));
self.pubSub.on('vis.hide', function () {
self.ready = false;
});

this.pubSub.on('treemap.loaded', function () {
this.treemapLoading.resolve();
}.bind(this));
self.pubSub.on('vis.tempHide', function () {
self.invisible = true;
});

self.pubSub.on('treemap.loaded', function () {
self.treemapLoading.resolve();
});

// Will be useful in the future when multiple services need to load.
this.$q.all([this.treemapLoading.promise]).then(function () {
this.loading = false;
}.bind(this));
self.$q.all([self.treemapLoading.promise]).then(function () {
self.loading = false;
});
}

Object.defineProperty(
VisWrapperCtrl.prototype,
'active', {
enumerable: true,
get: function () {
return this._active;
},
set: function (value) {
this._active = value;

if (value) {
this.loadData();
}
}
}
);

VisWrapperCtrl.prototype.loadData = function () {
var self = this;

if (!self.loadingStarted) {
self.loadingStarted = true;

// Trigger preloading / precomputing of D3 data for exploration.
self.dashboardVisData.load(
self.absRoot,
self.propertyValue,
self.remixRoots,
self.rename
);

self.dashboardVisData.data
.then(function (results) {
self.graphDeferred.resolve({
graph: results.graph,
rootIds: [results.root]
});
self.treemapDeferred.resolve(results.treemap);
self.annotationsDeferred.resolve(results.annotations);
})
.catch(function (error) {
self.loading = false;
if (error.number === 0) {
self.error = true;
} else {
self.noData = true;
}
});
}
};

angular
.module('refineryDashboard')
.controller('VisWrapperCtrl', [
Expand Down
31 changes: 0 additions & 31 deletions refinery/ui/source/js/dashboard/directives/vis-wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ describe('Dashboard.directive.visWrapper: unit tests', function () {

var $compile;
var $rootScope;
var $httpBackend;
var settings;

inject(function (
$injector,
_$compile_,
_$httpBackend_,
_$rootScope_
) {
$compile = _$compile_;
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;

settings = $injector.get('settings');
});

$scope = $rootScope.$new();
Expand All @@ -34,32 +28,7 @@ describe('Dashboard.directive.visWrapper: unit tests', function () {
);
directiveEl = $compile(element)($scope);

$httpBackend
.expectGET(
settings.appRoot +
settings.refineryApi +
'/data_sets/ids/?format=json&order_by=-modification_date'
)
.respond(200);

$httpBackend
.expectGET(
settings.appRoot +
settings.neo4jApi +
'/annotations/'
)
.respond(200);

$httpBackend
.expectGET(
settings.appRoot +
settings.refineryApi +
'/data_sets/annotations/'
)
.respond(200);

$scope.$digest();
$httpBackend.flush();
});

describe('DOM', function () {
Expand Down
8 changes: 8 additions & 0 deletions refinery/ui/source/js/dashboard/services/vis-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function DashboardVisData ($q, neo4jToGraph, dataSet, graph, settings) {
var allDsIds = results[0];
var data = results[1];

if (!Object.keys(data).length) {
// User doesn't have access to data sets with annotations or the
// backend is broken and returns an empty object.
treemapData.reject({ number: 1 });
graphData.reject({ number: 1 });
return;
}

if (remixRoots) {
// Check existance of remix roots
var checkedRemixRoots = [];
Expand Down
7 changes: 7 additions & 0 deletions refinery/ui/source/js/ng-webworker-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ angular
WebworkerProvider.setHelperPath(
'/static/vendor/ng-webworker/src/worker_wrapper.min.js'
);

// Do not use the helper by default. This will anyway be overwritten by the
// plugin if the browser ID is MSIE.
WebworkerProvider.setUseHelper(false);

// Transfer ownership doesn't work with the worker_wrapper helper.
WebworkerProvider.setTransferOwnership(true);
}
);

0 comments on commit c107ba1

Please sign in to comment.