Skip to content

Commit

Permalink
optimized loading layers processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanli-emory committed Nov 2, 2020
1 parent c7cfd6c commit db1adbf
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 89 deletions.
110 changes: 57 additions & 53 deletions apps/viewer/dataloaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,48 @@ function FormTempaltesLoader() {
}
}, 500);
}

let _l = false;
function OverlayersLoader() {
function HumanlayersLoader() {
function loadingOverlayers() {
$CAMIC.store.findMarkTypes($D.params.slideId)
//
.then(function(layers) {
typeIds = {};
if (!$D.overlayers) $D.overlayers = [];
// convert part not nesscary
for (let i = 0; i < layers.length; i++) {
$D.overlayers.push(covertToLayViewer(layers[i]));
}
_l = true;
})
//
.catch(function(error) {
// overlayers schema
$CAMIC.store.findMarkTypes($D.params.slideId, 'human').then(function(layers) {
typeIds = {};
if (!$D.overlayers) $D.overlayers = [];
// convert part not nesscary
$D.overlayers.push(...layers.map(covertToHumanLayer));
_l = true;
}).catch(function(error) {
// overlayers schema
_l = true;
$UI.message.addError('Loading Human Layers is Error');
console.error(error);
})
}

console.error(error);
})
//
.finally(function() {
if ($D.overlayers) {
var checkCoreIsReady = setInterval(function() {
if ($CAMIC && $D.params.data) {
clearInterval(checkCoreIsReady);
// load data
loadingOverlayers();
}
}, 500);
}

} else {
// set message
$UI.message.addError('Loading Overlayers is Error');
}
});
let _c = false;
function ComputerlayersLoader() {
function loadingOverlayers() {
$CAMIC.store.findMarkTypes($D.params.slideId, 'computer').then(function(layers) {
typeIds = {};
if (!$D.overlayers) $D.overlayers = [];
// convert part not nesscary
$D.overlayers.push(...layers.map(covertToCumputerLayer));
_c = true;
}).catch(function(error) {
// overlayers schema
_c = true;
$UI.message.addError('Loading Computer Layers is Error');
console.error(error);
});
}

var checkCoreIsReady = setInterval(function() {
Expand All @@ -86,37 +99,28 @@ function OverlayersLoader() {
}
}, 500);
}

let _h = false; // loading heatmap
function HeatmaplayersLoader() {
function loadingHeatmapOverlayers() {
$CAMIC.store.findHeatmapType($D.params.slideId)
//
.then(function(layers) {
if (!$D.overlayers)$D.overlayers = [];
// convert and load heatmap layer
const TypeId = randomId();
for (let i = 0; i < layers.length; i++) {
const item = layers[i].provenance.analysis;
$D.overlayers.push({id: item.execution_id,
name: item.execution_id,
typeId: TypeId,
typeName: item.computation});
}
_h = true;
})
.catch(function(error) {
// overlayers schema

console.error(error);
})
//
.finally(function() {
if ($D.overlayers) {
} else {
// set message
$UI.message.addError('Loading heatmap Overlayers is Error');
}
});
$CAMIC.store.findHeatmapType($D.params.slideId).then(function(layers) {
if (!$D.overlayers)$D.overlayers = [];
// convert and load heatmap layer
const TypeId = randomId();
for (let i = 0; i < layers.length; i++) {
const item = layers[i].provenance.analysis;
$D.overlayers.push({id: item.execution_id,
name: item.execution_id,
typeId: TypeId,
typeName: item.computation});
}
_h = true;
}).catch(function(error) {
// overlayers schema
_h = true;
$UI.message.addError('Loading heatmap Overlayers is Error');
console.error(error);
});
}

var checkCoreIsReady = setInterval(function() {
Expand Down
6 changes: 5 additions & 1 deletion apps/viewer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ function initialize() {
FormTempaltesLoader();

// loading the overlayers data
OverlayersLoader();
HumanlayersLoader();

// loading the overlayers data
ComputerlayersLoader();

// loading the heatmap overlayers data
HeatmaplayersLoader();
Expand Down Expand Up @@ -640,6 +643,7 @@ async function initUIcomponents() {
if (
$D.params.data &&
_l &&
_c &&
_h &&
$D.overlayers &&
$CAMIC &&
Expand Down
51 changes: 22 additions & 29 deletions common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,43 +480,36 @@ function isFunction(obj) {
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

function covertToLayViewer(item) {
const typeName = item.source;
const id = item.execution_id;
// support 2.0 style annotation data in refactor
const name = item.name || item.execution_id;
function covertToHumanLayer(data) {
const item = data._id;
const typeName = item.analysis.source;
const id = item.analysis.execution_id;
const name = item.analysis.name || item.analysis.execution_id;

// const isShow = l&&l.includes(id)?true:false;
if (!typeIds[typeName]) typeIds[typeName] = randomId();
// for segmentation
if (item.source == 'computer' && item.computation == 'segmentation') {
return {
id: id,
name: item.execution_id,
typeId: typeIds[typeName],
typeName: item.computation,
creator: item.creator,
data: null,
};
}
if (item.source == 'human') {
return {
id: id,
name: name,
typeId: typeIds[typeName],
typeName: typeName,
creator: item.creator,
shape: item.shape,
isGrid: item.isGrid? true: false,
data: null,
};
}
return {
id: id,
name: name,
typeId: typeIds[typeName],
typeName: typeName,
creator: item.creator,
shape: item.shape[0],
isGrid: item.analysis.isGrid? true: false,
data: null,
};
}

function covertToCumputerLayer(data) {
const typeName = data.source;
const id = data.execution_id;

if (!typeIds[typeName]) typeIds[typeName] = randomId();
return {
id: id,
name: id,
typeId: typeIds[typeName],
typeName: data.computation,
creator: data.creator,
data: null,
};
}
Expand Down
13 changes: 7 additions & 6 deletions core/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,20 @@ class Store {
// }).then(this.errorHandler);
// }

findMarkTypes(slide, name) {


findMarkTypes(slide, type) { // type = 'human' or 'computer'
const suffix = 'Mark/findMarkTypes';

const query = {};
//
if (!slide) {
console.error('Store.findMarkTypes needs slide ... ');
if (!slide || !type ) {
console.error('Store.findMarkTypes needs slide and type ... ');
return null;
}
query['slide'] = slide;
if (name) {
query['name'] = name;
}
query['type'] = type;

const url = this.base + suffix;
return fetch(url + '?' + objToParamStr(query), {
credentials: 'include',
Expand Down

0 comments on commit db1adbf

Please sign in to comment.