Skip to content

Commit

Permalink
improve no data conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Dec 9, 2024
1 parent e9164bc commit 4871103
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/web-console/src/scenes/Editor/Metrics/graph.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from "react"
import styled from "styled-components"
import { MetricDuration, Widget, xAxisFormat } from "./utils"
import { MetricDuration, Widget, xAxisFormat, hasData } from "./utils"
import { useGraphOptions } from "./useGraphOptions"
import uPlot from "uplot"
import UplotReact from "uplot-react"
Expand Down Expand Up @@ -179,7 +179,7 @@ export const Graph = ({
data={data}
onCreate={(uplot) => {
uPlotRef.current = uplot
if (data[0].length === 0 && !loading) {
if (!hasData(data) && !loading) {
const noData = document.createElement("div")
noData.className = "graph-no-data"
uplot.over.appendChild(noData)
Expand Down
5 changes: 3 additions & 2 deletions packages/web-console/src/scenes/Editor/Metrics/metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MetricType,
LastNotNull,
ResultType,
hasData,
} from "./utils"
import { widgets } from "./widgets"
import { QuestContext } from "../../../providers"
Expand Down Expand Up @@ -54,7 +55,7 @@ export const Metric = ({
}) => {
const { quest } = useContext(QuestContext)
const [loading, setLoading] = useState(false)
const [data, setData] = useState<uPlot.AlignedData>()
const [data, setData] = useState<uPlot.AlignedData>([[], []])
const [lastNotNull, setLastNotNull] = useState<number>()
const [colorPickerOpen, setColorPickerOpen] = useState(false)

Expand Down Expand Up @@ -143,7 +144,7 @@ export const Metric = ({
return (
<Graph
lastRefresh={lastRefresh}
data={metric.tableId && data ? data : [[], []]}
data={metric.tableId && hasData(data) ? data : [[], []]}
canZoomToData={canZoomToData}
onZoomToData={handleZoomToData}
colors={[metric.color]}
Expand Down
7 changes: 7 additions & 0 deletions packages/web-console/src/scenes/Editor/Metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,10 @@ export const getRollingAppendRowLimit = (
refreshRateInSeconds: number,
sampleBy: SampleBy,
) => Math.ceil(refreshRateInSeconds / sampleByInSeconds[sampleBy])

export const hasData = (data?: uPlot.AlignedData) => {
if (!data || data[1].length === 0) return false
return (
data[1].length > 0 && data[1].some((value) => value !== null && value !== 0)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const commitRate: Widget = {
-- it is important this is 1s, should this value change
-- the "commit_rate" value will have to be adjusted to rate/s
sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]}
-- fill(0)
fill(0)
)
-- there is a bug in QuestDB, which does not sort the window dataset
-- once the bug is fixed the order can be removed
Expand Down

0 comments on commit 4871103

Please sign in to comment.