diff --git a/frontend/js/ci.js b/frontend/js/ci.js index 53142f93f..69590eeec 100644 --- a/frontend/js/ci.js +++ b/frontend/js/ci.js @@ -164,7 +164,7 @@ const getEChartsOptions = () => { } -const getChartOptions = (measurements, chart_element) => { +const getChartOptions = (measurements) => { const options = getEChartsOptions(); options.title.text = `Workflow energy cost per run [mJ]`; @@ -231,18 +231,14 @@ const getChartOptions = (measurements, chart_element) => { } -const displayGraph = (measurements) => { - const element = createChartContainer("#chart-container", "run-energy"); +const displayGraph = (chart_instance, measurements) => { - const options = getChartOptions(measurements, element); // iterates - const chart_instance = echarts.init(element); + const options = getChartOptions(measurements); // iterates chart_instance.setOption(options); window.onresize = function () { // set callback when ever the user changes the viewport chart_instance.resize(); } - - return chart_instance; } const displayStatsTable = (measurements) => { @@ -379,15 +375,44 @@ const getLastRunBadge = async (repo, branch, workflow_id) => { } const getMeasurements = async (repo, branch, workflow_id, start_date = null, end_date = null) => { - try { - if(end_date == null) end_date = dateToYMD(new Date(), short=true); - if(start_date == null) start_date = dateToYMD(new Date((new Date()).setDate((new Date).getDate() -30)), short=true); - const api_string=`/v1/ci/measurements?repo=${repo}&branch=${branch}&workflow=${workflow_id}&start_date=${start_date}&end_date=${end_date}`; - return await makeAPICall(api_string); - } catch (err) { - showNotification('Could not get data from API', err); - throw err - } + if(end_date == null) end_date = dateToYMD(new Date(), short=true); + if(start_date == null) start_date = dateToYMD(new Date((new Date()).setDate((new Date).getDate() -30)), short=true); + const api_string=`/v1/ci/measurements?repo=${repo}&branch=${branch}&workflow=${workflow_id}&start_date=${start_date}&end_date=${end_date}`; + return await makeAPICall(api_string); +} + +const bindRefreshButton = (repo, branch, workflow_id, chart_instance) => { + // When the user selects a subset of the measurement data via the date-picker + $('#submit').on('click', async function () { + const startDate = dateToYMD(new Date($('#rangestart input').val()), short=true); + const endDate = dateToYMD(new Date($('#rangeend input').val()), short=true); + + let measurements = null; + try { + measurements = await getMeasurements(repo, branch, workflow_id, startDate, endDate); // iterates I + } catch (err) { + showNotification('Could not get data from API', err); + return; // abort + } + + displayStatsTable(measurements.data); //iterates II + displayCITable(measurements.data, repo); // Iterates I (total: 1) + + // set new chart instance options + const options = getChartOptions(measurements.data); //iterates I + chart_instance.clear(); + chart_instance.setOption(options); + + chart_instance.off('legendselectchanged') // remove + // we need to re-bind the handler here and can also not really refactor that + // without using a global variable. echarts .on does not allow to pass data to the handler + chart_instance.on('legendselectchanged', function (params) { + // get list of all legends that are on + const selectedLegends = params.selected; + const filteredMeasurements = measurements.data.filter(measurement => selectedLegends[measurement[5]]); + displayStatsTable(filteredMeasurements); + }); + }); } $(document).ready((e) => { @@ -398,6 +423,7 @@ $(document).ready((e) => { let branch = escapeString(url_params.get('branch')); let repo = escapeString(url_params.get('repo')); let workflow_id = escapeString(url_params.get('workflow')); + const ci_data_node = document.querySelector('#ci-data') if (repo == null || repo == '' || repo == 'null') { showNotification('No Repo', 'Repo parameter in URL is empty or not present. Did you follow a correct URL?'); @@ -412,21 +438,37 @@ $(document).ready((e) => { return; } + const element = createChartContainer("#chart-container", "run-energy"); + const chart_instance = echarts.init(element); + + bindRefreshButton(repo, branch, workflow_id, chart_instance) + + ci_data_node.insertAdjacentHTML('afterbegin', `