From c974f4a82ee3cd4b5b73b95d66d99854a0e5d3bc Mon Sep 17 00:00:00 2001 From: Adriel Santiago Date: Wed, 23 Jan 2019 18:06:40 -0500 Subject: Handle window and container resize events Resizes metrics graph on window and sidebard width changes --- app/assets/javascripts/lib/utils/common_utils.js | 16 +++++++++ .../monitoring/components/charts/area.vue | 31 ++++++++++++++++ .../monitoring/components/dashboard.vue | 42 ++++++++++------------ 3 files changed, 65 insertions(+), 24 deletions(-) (limited to 'app/assets/javascripts') diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index ae8b4b4d635..0ceff10a02a 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -220,6 +220,22 @@ export const scrollToElement = element => { ); }; +/** + * Returns a function that can only be invoked once between + * each browser screen repaint. + * @param {Function} fn + */ +export const debounceByAnimationFrame = fn => { + let requestId; + + return function debounced(...args) { + if (requestId) { + window.cancelAnimationFrame(requestId); + } + requestId = window.requestAnimationFrame(() => fn.apply(this, args)); + }; +}; + /** this will take in the `name` of the param you want to parse in the url if the name does not exist this function will return `null` diff --git a/app/assets/javascripts/monitoring/components/charts/area.vue b/app/assets/javascripts/monitoring/components/charts/area.vue index 5ca561259b6..91004ca54a9 100644 --- a/app/assets/javascripts/monitoring/components/charts/area.vue +++ b/app/assets/javascripts/monitoring/components/charts/area.vue @@ -1,6 +1,9 @@ @@ -92,11 +120,14 @@ export default {
diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index 0b4bb9cc686..76059cb602d 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -1,5 +1,4 @@