From 9fd261b7d42abf5204d680e753566220d6bbace2 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <blakcap@users.noreply.github.com> Date: Tue, 16 May 2017 10:29:24 +0200 Subject: [PATCH] plots update when aliases change, fixed table alias update, #20 --- .../reports/app/directives/edit/plotItem.js | 35 ++++++++++++++----- .../reports/app/directives/tableItem.js | 14 ++++++-- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/beat/web/reports/static/reports/app/directives/edit/plotItem.js b/beat/web/reports/static/reports/app/directives/edit/plotItem.js index 8c85a6044..79c6df93d 100644 --- a/beat/web/reports/static/reports/app/directives/edit/plotItem.js +++ b/beat/web/reports/static/reports/app/directives/edit/plotItem.js @@ -47,6 +47,25 @@ angular.module('reportApp') PlotService.addPlot(scope.group, scope.id, scope.renderDivId); }); + let plotTimer; + + const updatePlot = () => { + clearTimeout(plotTimer); + + const queueUpdate = () => { + let el = document.querySelector(`#${scope.renderDivId}`); + // if the container is rendered and it already has had a render, + // redo the render + if(el && el.childNodes.length > 0){ + el.innerHTML = ''; + PlotService.addPlot(scope.group, scope.id, scope.renderDivId); + } + }; + + plotTimer = setTimeout(queueUpdate, 1000); + }; + + // if the group has exps added/removed, rerender the plot scope.$watch( // angular doesnt watch arrays properly (i.e. watching scope.group._experimentNames), @@ -55,15 +74,13 @@ angular.module('reportApp') // because it compares shallowly and getters commonly return a new obj each time. // so, watch the getters length instead () => scope.group.experiments.length, - (newExps, oldExps) => { - let el = document.querySelector(`#${scope.renderDivId}`); - // if the container is rendered and it already has had a render, - // redo the render - if(el && el.childNodes.length > 0){ - el.innerHTML = ''; - PlotService.addPlot(scope.group, scope.id, scope.renderDivId); - } - } + updatePlot + ); + + // if the group has aliases changed, rerender the plot + scope.$watch( + () => JSON.stringify(scope.group._aliases), + updatePlot ); scope.exportSrcFunc = () => () => { diff --git a/beat/web/reports/static/reports/app/directives/tableItem.js b/beat/web/reports/static/reports/app/directives/tableItem.js index 9162d1b98..b1db73311 100644 --- a/beat/web/reports/static/reports/app/directives/tableItem.js +++ b/beat/web/reports/static/reports/app/directives/tableItem.js @@ -72,12 +72,20 @@ angular.module('reportApp') }; // gets the field val for the given exp scope.getFieldVal = (expName, field) => { - const alias = scope.group.aliases[expName].length > 0 ? scope.group.aliases[expName] : expName; + const alias = scope.group.aliases[expName].length > 0 ? + scope.group.aliases[expName] : expName; - let fVal = scope.tableables[alias] ? - scope.tableables[alias][field] : undefined; + const name = scope.tableables[alias] ? + alias : expName; + + let fVal = scope.tableables[name] ? scope.tableables[name][field] : undefined; let val; + console.log(expName); + console.log(alias); + console.log(scope.tableables); + console.log(fVal); + if(field === scope.fields[0]){ val = alias; } else if(!fVal){ -- GitLab