The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix reference line dynamic position
Joshen Lim02803aa60be3
diff --git a/studio/components/interfaces/BillingV2/Usage/Activity.tsx b/studio/components/interfaces/BillingV2/Usage/Activity.tsxindex 344cd5afcdd..401b72c5440 100644--- a/studio/components/interfaces/BillingV2/Usage/Activity.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Activity.tsx@@ -104,10 +104,10 @@ const Activity = () => {</div>) : (<BarChart+ hasQuotaattribute={MAU_KEY}data={mauData?.data ?? []}- unit={undefined}- yDomain={[0, monthly_active_users?.limit ?? 0]}+ yLimit={monthly_active_users?.limit ?? 0}yLeftMargin={18}yFormatter={(value) => value.toLocaleString()}/>@@ -172,10 +172,10 @@ const Activity = () => {</div>) : (<BarChart- attribute={MAU_KEY}+ hasQuota+ attribute={ASSET_TRANSFORMATIONS_KEY}data={assetTransformationsData?.data ?? []}- unit={undefined}- yDomain={[0, storage_image_render_count?.limit ?? 0]}+ yLimit={storage_image_render_count?.limit ?? 0}/>)}</>@@ -229,10 +229,11 @@ const Activity = () => {</div>) : (<BarChart+ hasQuotaattribute={FUNC_INVOCATIONS_KEY}data={funcInvocationsData?.data ?? []}unit={undefined}- yDomain={[0, func_invocations?.limit ?? 0]}+ yLimit={func_invocations?.limit ?? 0}yLeftMargin={26}yFormatter={(value) => value.toLocaleString()}/>@@ -277,21 +278,15 @@ const Activity = () => {</div><div className="space-y-1"><p>Sample usage over time</p>- <p className="text-sm text-scale-1000">Some description here</p>+ <p className="text-sm text-scale-1000">+ Some description here to explain what this metric is about+ </p></div><BarChart+ hasQuotaattribute="sample_data"data={generateUsageData('sample_data', 30)}- unit={undefined}- yDomain={[0, 100]}- reference={{- value: 65,- label: 'FREE QUOTA',- x: 60,- y: 49,- width: 200,- height: 24,- }}+ yLimit={70}/></div></div>diff --git a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsxindex 7e918caf964..7bb725e9347 100644--- a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx@@ -9,6 +9,7 @@ import { Button } from 'ui'import BarChart from './BarChart'import SectionContent from './SectionContent'import SectionHeader from './SectionHeader'+import { Y_DOMAIN_CEILING_MULTIPLIER } from './Usage.constants'const Bandwidth = () => {const { ref } = useParams()@@ -89,13 +90,12 @@ const Bandwidth = () => {<ShimmeringLoader className="w-1/2" /></div>) : (- // [Joshen] TODO- // - the max Y domain could be dynamic (slightly above limit, but take the usage + some threshold if above limit)<BarChart+ hasQuotaattribute={DB_EGRESS_KEY}data={dbEgressData?.data ?? []}unit={undefined}- yDomain={[0, db_egress?.limit ?? 0]}+ yLimit={db_egress?.limit ?? 0}yLeftMargin={14}yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}/>@@ -149,10 +149,11 @@ const Bandwidth = () => {</div>) : (<BarChart+ hasQuotaattribute={STORAGE_EGRESS_KEY}data={storageEgressData?.data ?? []}unit={undefined}- yDomain={[0, storage_egress?.limit ?? 0]}+ yLimit={storage_egress?.limit ?? 0}yLeftMargin={14}yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}/>diff --git a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx b/studio/components/interfaces/BillingV2/Usage/BarChart.tsxindex eea0934e8dc..9d8bfb4b526 100644--- a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx+++ b/studio/components/interfaces/BillingV2/Usage/BarChart.tsx@@ -8,26 +8,19 @@ import {Bar,ReferenceLine,Cell,+ Label,} from 'recharts'+import { Y_DOMAIN_CEILING_MULTIPLIER } from './Usage.constants'-// [Joshen] I don't think I should be replacing ChartHandler just yet as the styling of the usage charts-// are slightly different from that on the other pages, just in case.--interface Reference {- value: number- label: string- width: number- height: number- x: number- y: number-}+// [Joshen] This BarChart is specifically for usage, hence not a reusable component, and not+// replacing the existing BarChart in ui/Chartsexport interface BarChartProps {data: DataPoint[]attribute: string- reference?: Referenceunit?: string- yDomain?: number[]+ hasQuota?: boolean+ yLimit?: numberyLeftMargin?: numberyFormatter?: (value: number) => string}@@ -35,22 +28,23 @@ export interface BarChartProps {const BarChart = ({data,attribute,- reference,unit,- yDomain,+ hasQuota = false,+ yLimit,yLeftMargin = 10,yFormatter,}: BarChartProps) => {+ const yMin = 0 // We can consider passing this as a prop if there's a use case in the future+ const yMax = (yLimit ?? 0) * Y_DOMAIN_CEILING_MULTIPLIER++ const yDomain = [yMin, yLimit ?? 0]const ticks =- yDomain !== undefined- ? [- yDomain[0],- (yDomain[1] - yDomain[0]) * 0.25,- (yDomain[1] - yDomain[0]) * 0.5,- (yDomain[1] - yDomain[0]) * 0.75,- yDomain[1],- ]+ yLimit !== undefined && hasQuota+ ? [yMin, (yMax - yMin) * 0.25, (yMax - yMin) * 0.5, (yMax - yMin) * 0.75, yMax].map((x) =>+ Math.ceil(x)+ ): undefined+return (<div className="w-full h-[200px]"><ResponsiveContainer width="100%" height={200}>@@ -71,7 +65,7 @@ const BarChart = ({return (<CellclassName={- reference !== undefined && Number(entry[attribute]) >= reference.value+ yLimit !== undefined && Number(entry[attribute]) >= yLimit? 'fill-amber-900': 'fill-scale-1200'}@@ -79,21 +73,21 @@ const BarChart = ({)})}</Bar>- {reference && (+ {hasQuota && yLimit && (<ReferenceLine- y={reference.value}- label={+ y={yLimit}+ label={(props) => (<foreignObject- x={reference.x}- y={reference.y}- width={reference.width}- height={reference.height}+ x={props.viewBox.x + 30}+ y={props.viewBox.y - 10}+ width={200}+ height={24}><div className="text-[0.7rem] font-bold text-scale-1200 bg-scale-100 w-fit p-1.5 py-0.5 rounded-md">- {reference.label}+ PLAN QUOTA</div></foreignObject>- }+ )}/>)}</ComposedChart>diff --git a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsxindex c063ccde089..1cf17141e17 100644--- a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx@@ -60,7 +60,7 @@ const Infrastructure = () => {attribute={CPU_USAGE_KEY}data={cpuUsageData?.data ?? []}unit={cpuUsageData?.format}- yDomain={[0, 100]}+ yLimit={100}/>)}</SectionContent>@@ -81,7 +81,7 @@ const Infrastructure = () => {attribute={MEMORY_USAGE_KEY}data={memoryUsageData?.data ?? []}unit={memoryUsageData?.format}- yDomain={[0, 100]}+ yLimit={100}/>)}</SectionContent>@@ -102,7 +102,7 @@ const Infrastructure = () => {attribute={DISK_IO_BUDGET_KEY}data={ioBudgetData?.data ?? []}unit={ioBudgetData?.format}- yDomain={[0, 100]}+ yLimit={100}/>)}</SectionContent>diff --git a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsxindex 05d53409f69..48751ea6fcc 100644--- a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx+++ b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx@@ -89,10 +89,11 @@ const SizeAndCounts = () => {</div>) : (<BarChart+ hasQuotaattribute={TOTAL_DB_SIZE_KEY}data={dbSizeData?.data ?? []}unit={undefined}- yDomain={[0, db_size?.limit ?? 0]}+ yLimit={db_size?.limit ?? 0}yLeftMargin={14}yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}/>@@ -144,10 +145,11 @@ const SizeAndCounts = () => {</div>) : (<BarChart+ hasQuotaattribute={TOTAL_STORAGE_SIZE_KEY}data={storageSizeData?.data ?? []}unit={undefined}- yDomain={[0, storage_size?.limit ?? 0]}+ yLimit={storage_size?.limit ?? 0}yLeftMargin={14}yFormatter={(value) => formatBytes(value, 1, 'GB').replace(/\s/g, '')}/>diff --git a/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts b/studio/components/interfaces/BillingV2/Usage/Usage.constants.tsnew file mode 100644index 00000000000..d3b789be076--- /dev/null+++ b/studio/components/interfaces/BillingV2/Usage/Usage.constants.ts@@ -0,0 +1 @@+export const Y_DOMAIN_CEILING_MULTIPLIER = 4 / 3