Skip to content

Commit

Permalink
Allow querying plot from URL (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanep97 authored Oct 9, 2024
1 parent 46e5c17 commit 858052a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion iop4api/templates/iop4api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
selectedTabs: [C1selectedTab_0, C2selectedTab_0],
// log
logEntries: [],
// plot
// plot (also uses input_astrosource in query vars)
showPlot: false,
plot_config_fast: true,
enable_full_lc: false,
Expand All @@ -121,6 +121,8 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
use_hostcorrected: false,
plot_config_band: 'R',
plot_config_band_options: ['R', 'V', 'B', 'U', 'I'],
input_date_start: '',
input_date_end: '',
// plot (flagging)
selected_plot_idx: [],
show_selected_plot_pts: false,
Expand Down Expand Up @@ -331,6 +333,9 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
},
methods: {
updateURL() {
// Get the current query parameters
const currentParams = window.location.search;

// Start forming the new URL based on the selected tabs
let newURL = '/iop4/';

Expand All @@ -354,6 +359,9 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
}
}

// Append the original query parameters to the new URL
newURL += currentParams;

window.history.pushState({}, '', newURL);
},
updateSelectedTabFromPath() {
Expand Down Expand Up @@ -404,6 +412,21 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
}
return Number(value).toFixed(precision);
},
// auto load plot from url (e.g. /iop4/explore/plot/?srcname=2200%2B420&from=2024-01-01&to=2024-09-01)
autoSubmitPlotForm() {
load_source_plot(document.getElementById('plot_astrosource_form'));
},
getPlotQueryParams() {
const params = new URLSearchParams(window.location.search);
return {
srcname: params.get('srcname') || '',
date1: params.get('from') || '',
date2: params.get('to') || '',
band: params.get('band') || 'R',
fast: params.get('fast') || 'false',
errors: params.get('errors') || 'true',
};
},
},
beforeMount() {
this.updateSelectedTabFromPath();
Expand All @@ -412,6 +435,21 @@ <h2><a href="https://vhega.iaa.es/">VHEGA@IAA-CSIC</a></h2>
window.addEventListener('popstate', () => {
this.updateSelectedTabFromPath();
});
// auto load plot from url
const params = this.getPlotQueryParams();
this.input_astrosource = params.srcname;
this.input_date_start = params.date1;
this.input_date_end = params.date2;
this.plot_config_band = params.band;
this.plot_config_fast = params.fast === 'true';
this.enable_errorbars = params.errors === 'true';

if (this.input_astrosource) { // && this.input_date_start && this.input_date_end) {
console.log('auto plotting from url with params', params);
Vue.nextTick(() => {
this.autoSubmitPlotForm();
});
}
}
}).use(Quasar).mount('#app')

Expand Down

0 comments on commit 858052a

Please sign in to comment.