diff --git a/ui/web/static/js/dashboards.js b/ui/web/static/js/dashboards.js index f6632ba5..298b25a6 100644 --- a/ui/web/static/js/dashboards.js +++ b/ui/web/static/js/dashboards.js @@ -98,13 +98,15 @@ function editGrid(grid) { gridState.items.forEach((itemData) => { const newItem = document.createElement("div"); newItem.className = "item"; + newItem.classList.add("item-editable"); newItem.innerHTML = itemData.innerHTML.trim(); var scriptTag = document.createElement("script"); scriptTag.type = "text/javascript"; scriptTag.defer = true; scriptTag.innerHTML = itemData.widgetScript; newItem.appendChild(scriptTag); - const item = grid.add(newItem); + grid.add(newItem); + resizeObserver.observe(newItem); }); grid.layout(gridState.layout); } @@ -119,11 +121,6 @@ function editGrid(grid) { item.disabled = false; }); - document.querySelectorAll(".item").forEach((item) => { - item.classList.add("item-editable"); - resizeObserver.observe(item); - }); - return grid; } @@ -140,10 +137,12 @@ const resizeObserver = new ResizeObserver((entries) => { var el = item.getElement(); grid = item.getGrid(); + const contentEl = el.querySelector(".item-content"); + var chart = echarts.getInstanceByDom(contentEl); + // Calculate the change in width and height var widthChange = target.clientWidth - previousSize.width; var heightChange = target.clientHeight - previousSize.height; - const contentEl = el.querySelector(".item-content"); var itemContentWidth = parseInt(window.getComputedStyle(contentEl).getPropertyValue("width")) + widthChange; var itemContentHeight = @@ -159,6 +158,10 @@ const resizeObserver = new ResizeObserver((entries) => { el.style.height = target.clientHeight + "px"; el.querySelector(".item-content").style.width = itemContentWidth + "px"; el.querySelector(".item-content").style.height = itemContentHeight + "px"; + chart.resize({ + width: itemContentWidth, + height: itemContentHeight, + }); grid.refreshItems(); grid.layout(true); } diff --git a/ui/web/templates/charts/arealinechartmodal.html b/ui/web/templates/charts/arealinechartmodal.html index 18dc5650..9b844e49 100644 --- a/ui/web/templates/charts/arealinechartmodal.html +++ b/ui/web/templates/charts/arealinechartmodal.html @@ -98,86 +98,83 @@