mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { ChartConfig } from '@/components/interfaces/SQLEditor/UtilityPanel/ChartConfig'
|
|
|
|
export const checkHasNonPositiveValues = (data: Record<string, unknown>[], key: string): boolean =>
|
|
data.some((row) => (row[key] as number) <= 0)
|
|
|
|
export const formatLogTick = (value: number): string => {
|
|
if (value >= 1_000_000)
|
|
return `${(value / 1_000_000).toLocaleString(undefined, { maximumFractionDigits: 1 })}M`
|
|
if (value >= 1_000)
|
|
return `${(value / 1_000).toLocaleString(undefined, { maximumFractionDigits: 1 })}k`
|
|
return value.toLocaleString()
|
|
}
|
|
|
|
// Add helper function for cumulative results
|
|
export const getCumulativeResults = (results: { rows: any[] }, config: ChartConfig) => {
|
|
if (!results?.rows?.length) {
|
|
return []
|
|
}
|
|
|
|
const cumulativeResults = results.rows.reduce((acc, row) => {
|
|
const prev = acc[acc.length - 1] || {}
|
|
const next = {
|
|
...row,
|
|
[config.yKey]: (prev[config.yKey] || 0) + row[config.yKey],
|
|
}
|
|
return [...acc, next]
|
|
}, [])
|
|
|
|
return cumulativeResults
|
|
}
|