From 65ce8e04505536e61b412efd11aef04b2a2c4094 Mon Sep 17 00:00:00 2001 From: Demurest Date: Thu, 7 Nov 2024 16:03:49 -0300 Subject: [PATCH 1/3] chartjs time problem fix --- .../src/probability_api/static/probability.js | 44 ++++++++++++++----- .../probability_api/templates/prob.html.jinja | 22 ++++++++-- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/lightcurve/src/probability_api/static/probability.js b/lightcurve/src/probability_api/static/probability.js index fa5875fe9..90eff28f4 100644 --- a/lightcurve/src/probability_api/static/probability.js +++ b/lightcurve/src/probability_api/static/probability.js @@ -1,5 +1,4 @@ let probability_data_aux -let mychart let data = { labels: [], @@ -101,10 +100,11 @@ export function init(){ reverseData(raw_tax) + + let mychart = new Chart(ctx, config); probability_data_aux = [] - mychart = new Chart(ctx, config); - updateMyChart(initial_value, raw_tax, raw_group_prob_dict) + updateMyChart(mychart, initial_value, raw_tax, raw_group_prob_dict) custom_select.addEventListener('click', () => { custom_select.querySelector('.select').classList.toggle('open'); @@ -117,7 +117,7 @@ export function init(){ option.classList.add('selected'); option.closest('.select').querySelector('.select__trigger span').textContent = option.textContent; - updateMyChart(option.getAttribute("data-value"), raw_tax, raw_group_prob_dict) + updateMyChart(mychart, option.getAttribute("data-value"), raw_tax, raw_group_prob_dict) } }) } @@ -161,7 +161,7 @@ function getScale(max_value){ return (max_value/3) } -function updateMyChart(classifier_name, raw_tax, raw_group_prob_dict){ +function updateMyChart(mychart, classifier_name, raw_tax, raw_group_prob_dict){ let max_value let classes_arr = raw_tax[classifier_name].classes let classifier_data = Object.values(raw_group_prob_dict[classifier_name])[0] @@ -170,13 +170,13 @@ function updateMyChart(classifier_name, raw_tax, raw_group_prob_dict){ max_value = maxValue(classifier_data) - removeDataChart() - updateDataChart(classes_arr, max_value) + removeDataChart(mychart) + updateDataChart(mychart, classes_arr, max_value) - isDark(); + isDark(mychart); } -function removeDataChart(){ +function removeDataChart(mychart){ mychart.data.labels.length = 0; mychart.data.datasets.forEach((dataset) => { dataset.data.length = 0; @@ -186,7 +186,7 @@ function removeDataChart(){ mychart.update(); } -function updateDataChart(labels, max_value){ +function updateDataChart(mychart, labels, max_value){ mychart.data.labels.push(...labels); mychart.data.datasets.forEach((dataset) => { dataset.data.push(...probability_data_aux); @@ -198,7 +198,7 @@ function updateDataChart(labels, max_value){ mychart.update(); } -function isDark(){ +function isDark(mychart){ if(document.getElementById("probabilities-app").classList.contains("tw-dark")){ mychart.config.options.scales.r.backgroundColor = 'rgba(245, 245, 245, 0.2)' mychart.config.options.scales.r.angleLines.color = '#F5F5F5' @@ -207,4 +207,24 @@ function isDark(){ mychart.update(); } -} \ No newline at end of file +} + +export function elementReady(selector) { + return new Promise((resolve, reject) => { + const el = document.querySelector(selector); + if (el) { + resolve(el); + } + + new MutationObserver((mutationRecords, observer) => { + Array.from(document.querySelectorAll(selector)).forEach(element => { + resolve(element); + observer.disconnect(); + }); + }) + .observe(document.documentElement, { + childList: true, + subtree: true + }); + }); + } \ No newline at end of file diff --git a/lightcurve/src/probability_api/templates/prob.html.jinja b/lightcurve/src/probability_api/templates/prob.html.jinja index 222a66cd8..b6974658b 100644 --- a/lightcurve/src/probability_api/templates/prob.html.jinja +++ b/lightcurve/src/probability_api/templates/prob.html.jinja @@ -1,5 +1,4 @@ - @@ -46,9 +45,26 @@ +