Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: remove old AreaChart from ChartRenderer, remove yAxisLimit api.

TzeYiing184073974ee4
diff --git a/studio/components/to-be-cleaned/Charts/ChartHandler.tsx b/studio/components/to-be-cleaned/Charts/ChartHandler.tsx
index 9ae694c1fdd..8863794adf7 100644
--- a/studio/components/to-be-cleaned/Charts/ChartHandler.tsx
+++ b/studio/components/to-be-cleaned/Charts/ChartHandler.tsx
@@ -6,7 +6,8 @@ import { Dictionary } from 'components/grid'
import { API_URL } from 'lib/constants'
import { get } from 'lib/common/fetch'
-import { BarChart, AreaChart } from './ChartRenderer'
+import { BarChart } from './ChartRenderer'
+import AreaChart from 'components/ui/Charts/AreaChart'
import { ChartData } from './ChartHandler.types'
import { AreaProps } from 'recharts'
@@ -172,10 +173,10 @@ const ChartHandler: FC<Props> = ({
<AreaChart
data={chartData?.data ?? []}
format={format || chartData?.format}
- attribute={attribute}
- yAxisLimit={chartData?.yAxisLimit}
+ xAxisKey="timestamp"
+ yAxisKey={attribute}
highlightedValue={highlightedValue}
- label={label}
+ title={label}
customDateFormat={customDateFormat}
/>
)}
diff --git a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
index 1f030158c24..8329a32669a 100644
--- a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
+++ b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
@@ -3,7 +3,6 @@ import { Loading } from 'ui'
import { useState } from 'react'
import {
BarChart as RechartBarChart,
- AreaChart as RechartAreaChart,
Area,
Bar,
XAxis,
@@ -268,125 +267,4 @@ export function BarChart({
</div>
</Loading>
)
-}
-
-export function AreaChart({
- data,
- attribute,
- yAxisLimit,
- format,
- highlightedValue,
- customDateFormat,
- label,
-}: any) {
- const hasData = dataCheck(data, attribute)
-
- const [focusBar, setFocusBar] = useState<any>(null)
- const [mouseLeave, setMouseLeave] = useState<any>(true)
-
- const onMouseMove = (state: any) => {
- if (state?.activeTooltipIndex) {
- setFocusBar(state.activeTooltipIndex)
- setMouseLeave(false)
- } else {
- setFocusBar(null)
- setMouseLeave(true)
- }
- }
-
- const onMouseLeave = () => {
- setFocusBar(false)
- setMouseLeave(true)
- }
-
- // For future reference: https://github.com/supabase/supabase/pull/5311#discussion_r800852828
- const chartHeight = 160
-
- return (
- <Loading active={!data}>
- <Header
- label={label}
- attribute={attribute}
- focus={focusBar}
- highlightedValue={highlightedValue}
- data={data}
- format={format}
- customDateFormat={customDateFormat}
- />
- <div
- style={{
- width: '100%',
- height: `${chartHeight}px`,
- }}
- >
- {hasData ? (
- <>
- <ResponsiveContainer width="100%" height={chartHeight}>
- <RechartAreaChart
- data={data}
- margin={{
- top: 0,
- right: 0,
- left: 0,
- bottom: 0,
- }}
- className="overflow-visible"
- onMouseMove={onMouseMove}
- onMouseLeave={onMouseLeave}
- >
- <defs>
- <linearGradient id="colorUv" x1="0" y1="0" x2="0" y2="1">
- <stop offset="5%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0.8} />
- <stop offset="95%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0} />
- </linearGradient>
- </defs>
- <XAxis
- dataKey="period_start"
- //interval={size === 'small' ? 5 : 1}
- interval={data ? data.length - 2 : 0}
- angle={0}
- // stroke="#4B5563"
- tick={{
- fontSize: '0px',
- color: CHART_COLORS.TICK,
- }}
- axisLine={{
- stroke: CHART_COLORS.AXIS,
- }}
- tickLine={{
- stroke: CHART_COLORS.AXIS,
- }}
- />
- {yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}
- <Tooltip content={<CustomTooltip />} />
- <Area
- type="monotone"
- dataKey={attribute}
- stroke={CHART_COLORS.GREEN_1}
- fillOpacity={1}
- fill="url(#colorUv)"
- />
- </RechartAreaChart>
- </ResponsiveContainer>
- {data && (
- <div className="-mt-5 flex items-center justify-between text-xs text-scale-900">
- <span>
- {dayjs(data[0].period_start).format(
- customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME
- )}
- </span>
- <span>
- {dayjs(data[data?.length - 1]?.period_start).format(
- customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME
- )}
- </span>
- </div>
- )}
- </>
- ) : (
- <EmptyState />
- )}
- </div>
- </Loading>
- )
-}
+}
\ No newline at end of file
diff --git a/studio/components/ui/Charts/AreaChart.stories.tsx b/studio/components/ui/Charts/AreaChart.stories.tsx
index 59f8982f76d..bb7787919d2 100644
--- a/studio/components/ui/Charts/AreaChart.stories.tsx
+++ b/studio/components/ui/Charts/AreaChart.stories.tsx
@@ -29,9 +29,9 @@ export const AreaChart = () => (
{ title: 'Highlighted Value', props: { highlightedValue: 123 } },
{ title: 'UTC Dates', props: { displayDateInUtc: true } },
{ title: 'Custom date format', props: { customDateFormat: 'HH:mm' } },
- { title: 'No data', props: { data: [] } },
{ title: 'Value format', props: { format: 'c' } },
{ title: 'Minimal Value format', props: { minimalHeader: true, format: 'c' } },
+ { title: 'No data', props: { data: [] } },
].map(({ title, props }) => (
<div className="w-72 h-72">
<ExampleName>{title}</ExampleName>
diff --git a/studio/components/ui/Charts/AreaChart.tsx b/studio/components/ui/Charts/AreaChart.tsx
index ab511a956ff..caaf298c9c5 100644
--- a/studio/components/ui/Charts/AreaChart.tsx
+++ b/studio/components/ui/Charts/AreaChart.tsx
@@ -15,9 +15,7 @@ import utc from 'dayjs/plugin/utc'
import ChartNoData from './NoDataPlaceholder'
dayjs.extend(utc)
-export interface AreaChartProps<D = Datum> extends CommonChartProps {
- data: D[]
- yAxisLimit?: any
+export interface AreaChartProps<D = Datum> extends CommonChartProps<D> {
yAxisKey: string
xAxisKey: string
format?: string
@@ -27,7 +25,6 @@ export interface AreaChartProps<D = Datum> extends CommonChartProps {
const AreaChart: React.FC<AreaChartProps> = ({
data,
- yAxisLimit,
yAxisKey,
xAxisKey,
format,
@@ -99,7 +96,6 @@ const AreaChart: React.FC<AreaChartProps> = ({
axisLine={{ stroke: CHART_COLORS.AXIS }}
tickLine={{ stroke: CHART_COLORS.AXIS }}
/>
- {yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}
<Tooltip content={() => null} />
<Area
type="monotone"
diff --git a/studio/components/ui/Charts/Charts.types.tsx b/studio/components/ui/Charts/Charts.types.tsx
index 1d9024515e6..352c2f60f99 100644
--- a/studio/components/ui/Charts/Charts.types.tsx
+++ b/studio/components/ui/Charts/Charts.types.tsx
@@ -1,15 +1,22 @@
-export interface CommonChartProps {
+export interface CommonChartProps<D>
+ extends Pick<
+ HeaderType<D>,
+ | 'highlightedValue'
+ | 'customDateFormat'
+ | 'data'
+ | 'format'
+ | 'minimalHeader'
+ | 'displayDateInUtc'
+ > {
title?: string
- minimalHeader?: boolean
- highlightedValue?: number
}
export type HeaderType<D> = {
attribute: string
focus: number | null
format?: string
- highlightedValue?: number
- data?: D[]
+ highlightedValue?: number | string
+ data: D[]
customDateFormat?: string
label: string
minimalHeader?: boolean