From ee6537f5cb360f6ea1b6cad472dbaef0f15cebc9 Mon Sep 17 00:00:00 2001 From: Maciej Bodek Date: Fri, 29 Nov 2024 13:08:03 +0100 Subject: [PATCH] Implement zoom to data --- packages/browser-tests/questdb | 2 +- .../src/scenes/Editor/Metrics/graph.tsx | 65 ++++++++++++++--- .../src/scenes/Editor/Metrics/index.tsx | 35 ++------- .../src/scenes/Editor/Metrics/metric.tsx | 73 +++++++++++++++++-- .../src/scenes/Editor/Metrics/queries.ts | 21 ++++++ .../src/scenes/Editor/Metrics/utils.ts | 14 +--- 6 files changed, 155 insertions(+), 55 deletions(-) diff --git a/packages/browser-tests/questdb b/packages/browser-tests/questdb index 8b2df2ba3..550f13627 160000 --- a/packages/browser-tests/questdb +++ b/packages/browser-tests/questdb @@ -1 +1 @@ -Subproject commit 8b2df2ba31ff20d86c3e2b9d71fa874972028729 +Subproject commit 550f1362790c0502d54193573c8a0dc1a85c6670 diff --git a/packages/web-console/src/scenes/Editor/Metrics/graph.tsx b/packages/web-console/src/scenes/Editor/Metrics/graph.tsx index a468b671d..600c2b2a8 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/graph.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/graph.tsx @@ -44,6 +44,40 @@ const GraphWrapper = styled(Box).attrs({ align: "center", })` padding: 1rem 0; + + .graph-no-data { + position: absolute; + display: flex; + flex-direction: column; + gap: 1rem; + width: 100%; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + width: 100%; + text-align: center; + } + + .graph-no-data-text { + color: ${({ theme }) => theme.color.gray2}; + font-size: 1.4rem; + text-align: center; + } + + .graph-no-data-button { + align-self: center; + background-color: ${({ theme }) => theme.color.selection}; + border: none; + color: ${({ theme }) => theme.color.foreground}; + border-radius: 0.4rem; + height: 3rem; + padding: 0 1rem; + cursor: pointer; + + &:hover { + background-color: ${({ theme }) => theme.color.comment}; + } + } ` const Label = styled.div` @@ -63,21 +97,25 @@ type Props = { beforeLabel?: React.ReactNode loading?: boolean data: uPlot.AlignedData + canZoomToData?: boolean colors: string[] duration: MetricDuration yValue: (rawValue: number) => string actions?: React.ReactNode + onZoomToData?: () => void } export const Graph = ({ label, beforeLabel, data, + canZoomToData, colors, duration, yValue, loading, actions, + onZoomToData, }: Props) => { const timeRef = useRef(null) const valueRef = useRef(null) @@ -134,16 +172,25 @@ export const Graph = ({ uPlotRef.current = uplot if (data[0].length === 0) { const noData = document.createElement("div") - noData.innerText = "No data available for this period" - noData.style.position = "absolute" - noData.style.left = "50%" - noData.style.top = "50%" - noData.style.transform = "translate(-50%, -50%)" - noData.style.color = theme.color.gray2 - noData.style.fontSize = "1.2rem" - noData.style.width = "100%" - noData.style.textAlign = "center" + noData.className = "graph-no-data" uplot.over.appendChild(noData) + + const noDataText = document.createElement("span") + noDataText.innerText = "No data available for this period" + noDataText.className = "graph-no-data-text" + noData.appendChild(noDataText) + + if (canZoomToData) { + const zoomToDataButton = document.createElement("button") + zoomToDataButton.className = "graph-no-data-button" + zoomToDataButton.innerText = "Zoom to data" + zoomToDataButton.onclick = () => { + if (onZoomToData) { + onZoomToData() + } + } + noData.appendChild(zoomToDataButton) + } } }} /> diff --git a/packages/web-console/src/scenes/Editor/Metrics/index.tsx b/packages/web-console/src/scenes/Editor/Metrics/index.tsx index 64c78ca1a..d75a8f049 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/index.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/index.tsx @@ -197,36 +197,10 @@ export const Metrics = () => {