Skip to content
Snippets Groups Projects
Commit f0155594 authored by jaden's avatar jaden
Browse files

store plot widget configs in report state tree, #33

parent 0d7c843a
No related branches found
No related tags found
1 merge request!223Reports overhaul
...@@ -40,11 +40,19 @@ angular.module('reportApp') ...@@ -40,11 +40,19 @@ angular.module('reportApp')
// container for the plots applet to insert into // container for the plots applet to insert into
scope.renderDivId = `${scope.domId}-render`; scope.renderDivId = `${scope.domId}-render`;
// the callback for when the plot renders
// (called every time the plot re-renders, e.g. user changes config/merged
const updatePlotConfig = (selectedPlotter, selectedConfig, isMerged) => {
scope.content.merged = isMerged;
scope.content.savedPlotter = selectedPlotter;
scope.content.savedConfig = selectedConfig;
};
// wait until the container html element is rendered. // wait until the container html element is rendered.
// angular will run these functions called with $timeout // angular will run these functions called with $timeout
// after everything has been rendered // after everything has been rendered
$timeout(function() { $timeout(function() {
PlotService.addPlot(scope.group, scope.itemId, scope.renderDivId); PlotService.addPlot(scope.group, scope.itemId, scope.renderDivId, updatePlotConfig);
}); });
let plotTimer; let plotTimer;
...@@ -58,7 +66,7 @@ angular.module('reportApp') ...@@ -58,7 +66,7 @@ angular.module('reportApp')
// redo the render // redo the render
if(el && el.childNodes.length > 0){ if(el && el.childNodes.length > 0){
el.innerHTML = ''; el.innerHTML = '';
PlotService.addPlot(scope.group, scope.itemId, scope.renderDivId); PlotService.addPlot(scope.group, scope.itemId, scope.renderDivId, updatePlotConfig);
} }
}; };
......
...@@ -58,10 +58,10 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe ...@@ -58,10 +58,10 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe
} }
// a plot obj can have different plotters, // a plot obj can have different plotters,
let plotter = content.savedPlotter || plotters.find(p => p.name === defaults.plotter); let plotter = plotters.find(p => p.name === content.savedPlotter) || plotters.find(p => p.name === defaults.plotter);
// which can each have different configurations (plotter parameter instances) // which can each have different configurations (plotter parameter instances)
let config = content.savedConfig || plotterParameters.find(pp => pp.name === defaults.parameter); let config = plotterParameters.find(pp => pp.name === content.savedConfig) || plotterParameters.find(pp => pp.name === defaults.parameter);
if(!content || !defaults || !plotter || !config){ if(!content || !defaults || !plotter || !config){
console.error(`plotter info not found: content: ${content} defaults: ${defaults} plotter: ${plotter} config: ${config}`); console.error(`plotter info not found: content: ${content} defaults: ${defaults} plotter: ${plotter} config: ${config}`);
...@@ -127,23 +127,17 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe ...@@ -127,23 +127,17 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe
return returnStruct; return returnStruct;
}; };
// makes the call to the server, via some helper funcs found in the global namespace const fetchDownload = (requestData, contentType) => {
const fetchRenderUsingStruct = (requestData, containerId) => { const urlPrefix = '';
// the 'url_prefix' field found throughout the BEAT code is confusing,
// but it seems to always be an empty string now
const urlPrefix = '';//UrlService.getApiSegment().split('/').filter(s => s.length > 0).join('/');
// promisify this utils func so we dont have to deal with callback hell
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
beat.experiments.utils.displayPlot( beat.experiments.utils.getPlotData(
// url_prefix // url_prefix
urlPrefix, urlPrefix,
// element to append render to
document.querySelector(`#${containerId}`),
// spread out the request data to fill the next 3 spots // spread out the request data to fill the next 3 spots
...requestData, ...requestData,
// dont replace inner content // content type: png, jpeg, pdf
false, contentType,
// callback // callback
(...args) => { (...args) => {
// resolve promise // resolve promise
...@@ -153,18 +147,43 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe ...@@ -153,18 +147,43 @@ angular.module('reportApp').factory('PlotService', ['UrlService', function(UrlSe
}); });
}; };
// makes the call to the server, via some helper funcs found in the global namespace
const fetchRender = (requestData, containerId, onRenderCallback) => {
// the 'url_prefix' field found throughout the BEAT code is confusing,
// but it seems to always be an empty string now
const urlPrefix = '';//UrlService.getApiSegment().split('/').filter(s => s.length > 0).join('/');
// promisify this utils func so we dont have to deal with callback hell
beat.experiments.utils.displayPlot(
// url_prefix
urlPrefix,
// element to append render to
document.querySelector(`#${containerId}`),
// spread out the request data to fill the next 3 spots
...requestData,
// dont replace inner content
false,
// callback
(plotter, config, merged) => {
onRenderCallback(plotter, config, merged);
}
);
};
// helper func to process a request to plot // helper func to process a request to plot
const processItem = (group, itemId, containerId) => { const processItem = (group, itemId, containerId, onRenderCallback) => {
const reqData = constructPlotInfo(group, itemId); const reqData = constructPlotInfo(group, itemId);
return fetchRenderUsingStruct(reqData, containerId);
fetchRender(reqData, containerId, onRenderCallback);
}; };
// used if we arent ready to directly service requests // used if we arent ready to directly service requests
const addItemToQueue = (group, itemId, containerId) => { const addItemToQueue = (group, itemId, containerId, onRenderCallback) => {
queue.push([ queue.push([
group, group,
itemId, itemId,
containerId containerId,
onRenderCallback
]); ]);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment