The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(studio): modify area chart colours (#41496)
kemal.earth6c6d74fa210c
diff --git a/apps/design-system/registry/default/block/chart-composed-basic.tsx b/apps/design-system/registry/default/block/chart-composed-basic.tsxindex 99778d63f43..d9457c3d308 100644--- a/apps/design-system/registry/default/block/chart-composed-basic.tsx+++ b/apps/design-system/registry/default/block/chart-composed-basic.tsx@@ -28,16 +28,38 @@ export default function ComposedChartBasic() {},]- const data = Array.from({ length: 46 }, (_, i) => {+ const data = Array.from({ length: 40 }, (_, i) => {const date = new Date()- date.setMinutes(date.getMinutes() - i * 5) // Each point 5 minutes apart+ date.setMinutes(date.getMinutes() - i * 3) // Each point 3 minutes apart++ const progress = i / 40+ const standard_score = Math.floor(55 + progress * 55 + (Math.random() - 0.5) * 12)+ const performance = Math.floor(35 + progress * 35 + (Math.random() - 0.5) * 10)+ const efficiency = Math.floor(25 + progress * 25 + (Math.random() - 0.5) * 12)return {timestamp: date.toISOString(),- standard_score: Math.floor(Math.random() * 100),+ standard_score: Math.max(0, Math.min(100, standard_score)),+ performance: Math.max(0, Math.min(100, performance)),+ efficiency: Math.max(0, Math.min(100, efficiency)),}}).reverse()+ const chartConfig = {+ standard_score: {+ label: 'Standard Score',+ color: 'hsl(var(--brand-default))',+ },+ performance: {+ label: 'Performance',+ color: 'hsl(var(--chart-2))',+ },+ efficiency: {+ label: 'Efficiency',+ color: 'hsl(var(--chart-5))',+ },+ }+useEffect(() => {setTimeout(() => {setIsLoading(false)@@ -50,10 +72,8 @@ export default function ComposedChartBasic() {<ChartCard><ChartHeader><ChartTitle tooltip="This is a tooltip">Standard Bar Chart</ChartTitle>-<ChartActions actions={actions} /></ChartHeader>-<ChartContentisEmpty={data.length === 0}emptyState={@@ -86,10 +106,8 @@ export default function ComposedChartBasic() {<ChartCard><ChartHeader><ChartTitle tooltip="This is a tooltip">Standard Line Chart</ChartTitle>-<ChartActions actions={actions} /></ChartHeader>-<ChartContentisEmpty={data.length === 0}emptyState={@@ -105,6 +123,8 @@ export default function ComposedChartBasic() {<ChartLinedata={data}dataKey="standard_score"+ dataKeys={['standard_score', 'performance', 'efficiency']}+ config={chartConfig}showGrid={true}showYAxis={true}YAxisProps={{diff --git a/apps/studio/components/ui/Charts/Charts.constants.ts b/apps/studio/components/ui/Charts/Charts.constants.tsindex 3cd62f07549..425631bd170 100644--- a/apps/studio/components/ui/Charts/Charts.constants.ts+++ b/apps/studio/components/ui/Charts/Charts.constants.ts@@ -15,8 +15,8 @@ export const CHART_COLORS = {const LIGHT_STACKED_CHART_COLORS = ['#3ECF8E',- '#097c4f','#DA760B',+ '#097c4f','#EDC35E','#65BCD9','#0063E8',@@ -24,6 +24,17 @@ const LIGHT_STACKED_CHART_COLORS = ['#B616A6',]+const LIGHT_STACKED_CHART_FILLS = [+ '#9FE8C7',+ '#FFB885',+ '#4BA67A',+ '#F6D99F',+ '#B2DCEC',+ '#80B1F4',+ '#EDC9FC',+ '#DB8BD3',+]+const DARK_STACKED_CHART_COLORS = ['#3ECF8E','#A3FFC2',@@ -35,12 +46,24 @@ const DARK_STACKED_CHART_COLORS = ['#B616A6',]+const DARK_STACKED_CHART_FILLS = [+ '#2A5C3F',+ '#1F3D2A',+ '#5C3D0A',+ '#5C5230',+ '#2A3D45',+ '#001F3D',+ '#4A3D5C',+ '#3D1F3A',+]+// Default to light mode colors, will be updated based on themeexport let STACKED_CHART_COLORS = LIGHT_STACKED_CHART_COLORS-+export let STACKED_CHART_FILLS = LIGHT_STACKED_CHART_FILLS// Function to update colors based on themeexport const updateStackedChartColors = (isDarkMode: boolean) => {STACKED_CHART_COLORS = isDarkMode ? DARK_STACKED_CHART_COLORS : LIGHT_STACKED_CHART_COLORS+ STACKED_CHART_FILLS = isDarkMode ? DARK_STACKED_CHART_FILLS : LIGHT_STACKED_CHART_FILLS}// refer to packages/ui/radix-colors.js for full list of colorsdiff --git a/apps/studio/components/ui/Charts/ComposedChart.tsx b/apps/studio/components/ui/Charts/ComposedChart.tsxindex a247be4eed3..708c5397f37 100644--- a/apps/studio/components/ui/Charts/ComposedChart.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.tsx@@ -14,6 +14,7 @@ import {Tooltip,XAxis,YAxis,+ Customized,} from 'recharts'import { CategoricalChartState } from 'recharts/types/chart/types'@@ -24,6 +25,7 @@ import {CHART_COLORS,DateTimeFormats,STACKED_CHART_COLORS,+ STACKED_CHART_FILLS,updateStackedChartColors,} from './Charts.constants'import { CommonChartProps, Datum } from './Charts.types'@@ -71,6 +73,22 @@ export interface ComposedChartProps<D = Datum> extends CommonChartProps<D> {showNewBadge?: boolean}+interface CustomizedDotProps {+ formattedGraphicalItems?: Array<{+ props?: {+ points?: Array<{ x: number; y: number }>+ dataKey?: string+ }+ item?: {+ props?: {+ points?: Array<{ x: number; y: number }>+ dataKey?: string+ }+ }+ points?: Array<{ x: number; y: number }>+ }>+}+export function ComposedChart({chartId,data,@@ -120,7 +138,6 @@ export function ComposedChart({const [_activePayload, setActivePayload] = useState<any>(null)const [_showMaxValue, setShowMaxValue] = useState(showMaxValue)const [focusDataIndex, setFocusDataIndex] = useState<number | null>(null)- const [hoveredLabel, setHoveredLabel] = useState<string | null>(null)const [isActiveHoveredChart, setIsActiveHoveredChart] = useState(false)const [hiddenAttributes, setHiddenAttributes] = useState<Set<string>>(new Set())const isDarkMode = resolvedTheme?.includes('dark')@@ -240,7 +257,9 @@ export function ComposedChart({color: CHART_COLORS.REFERENCE_LINE,}- const referenceLines = attributes.filter((attribute) => attribute?.provider === 'reference-line')+ const referenceLines = attributes.filter((attribute) => {+ return attribute?.provider === 'reference-line'+ })const resolvedHighlightedLabel = getHeaderLabel()@@ -271,10 +290,15 @@ export function ComposedChart({return {...att,color: attribute?.color- ? resolvedTheme?.includes('dark')+ ? isDarkMode? attribute.color.dark: attribute.color.light: STACKED_CHART_COLORS[index % STACKED_CHART_COLORS.length],+ fill: attribute?.fill+ ? isDarkMode+ ? attribute.fill.dark+ : attribute.fill.light+ : STACKED_CHART_FILLS[index % STACKED_CHART_FILLS.length],}}): []@@ -417,24 +441,7 @@ export function ComposedChart({minTickGap={3}key={xAxisKey}/>- <Tooltip- content={(props) =>- showTooltip && !showHighlightActions ? (- <CustomTooltip- {...props}- format={format}- isPercentage={isPercentage}- label={resolvedHighlightedLabel}- attributes={attributes}- valuePrecision={valuePrecision}- showTotal={showTotal}- isActiveHoveredChart={- isActiveHoveredChart || (!!syncId && syncTooltip && hoveredIndex !== null)- }- />- ) : null- }- />+{chartStyle === 'bar'? visibleAttributes.map((attribute) => (<Bar@@ -456,29 +463,24 @@ export function ComposedChart({key={attribute.name}type="step"dataKey={attribute.name}- stackId={attributes?.find((a) => a.attribute === attribute.name)?.stackId ?? '1'}- fill={attribute.color}+ stackId="1"+ fill={attribute.fill}+ fillOpacity={1}stroke={attribute.color}radius={20}animationDuration={375}- fillOpacity={- hoveredLabel && hoveredLabel !== attribute.name- ? 0.075- : hoveredLabel === attribute.name- ? 0.3- : 0.25- }name={attributes?.find((a) => a.attribute === attribute.name)?.label || attribute.name}dot={false}+ activeDot={false}/>))}{/* Max value, if available */}{maxAttribute && _showMaxValue && (<Linekey={maxAttribute.attribute}- type="stepAfter"+ type="step"dataKey={maxAttribute.attribute}stroke={CHART_COLORS.REFERENCE_LINE}strokeWidth={2}@@ -488,14 +490,15 @@ export function ComposedChart({/>)}{referenceLines- .filter((line) => line.isReferenceLine)+ .filter((line) => {+ return line.isReferenceLine+ }).map((line) => (<ReferenceLinekey={line.attribute}y={line.value}strokeWidth={1}- {...line}- color={line.color?.dark}+ stroke={isDarkMode ? line.color?.dark : line.color?.light}strokeDasharray={line.strokeDasharray ?? '3 3'}label={undefined}>@@ -508,6 +511,7 @@ export function ComposedChart({/></ReferenceLine>))}+{/* Selection highlight */}{showHighlightActions && (<ReferenceArea@@ -519,6 +523,61 @@ export function ComposedChart({fillOpacity={0.2}/>)}+ <Tooltip+ content={(props) =>+ showTooltip && !showHighlightActions ? (+ <CustomTooltip+ {...props}+ format={format}+ isPercentage={isPercentage}+ label={resolvedHighlightedLabel}+ attributes={attributes}+ valuePrecision={valuePrecision}+ showTotal={showTotal}+ isActiveHoveredChart={+ isActiveHoveredChart || (!!syncId && syncTooltip && hoveredIndex !== null)+ }+ />+ ) : null+ }+ cursor={{+ stroke: isDarkMode ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.5)',+ strokeWidth: 1,+ }}+ />+ <Customized+ component={(props: CustomizedDotProps) => {+ const { formattedGraphicalItems } = props+ if (!formattedGraphicalItems || focusDataIndex === null) return null++ return (+ <g>+ {formattedGraphicalItems.map((item, index: number) => {+ const points = item.props?.points || item.item?.props?.points || item.points+ const dataKey = item.props?.dataKey || item.item?.props?.dataKey++ if (!points || !points[focusDataIndex]) return null++ const point = points[focusDataIndex]+ const attribute = visibleAttributes.find((a) => a.name === dataKey)+ if (!attribute) return null++ return (+ <circle+ key={`custom-dot-${dataKey}-${index}`}+ cx={point.x}+ cy={point.y}+ r={4}+ fill={attribute.fill}+ stroke={attribute.color}+ strokeWidth={1}+ />+ )+ })}+ </g>+ )+ }}+ /></RechartComposedChart><ChartHighlightActionschartHighlight={chartHighlight}@@ -546,7 +605,6 @@ export function ComposedChart({payload={[maxAttributeData, ...chartData]}attributes={attributes}showMaxValue={_showMaxValue}- onLabelHover={setHoveredLabel}onToggleAttribute={(attribute, options) => {setHiddenAttributes((prev) => {if (options?.exclusive) {diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsxindex dbfdc2ae9fc..746b61fef05 100644--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx@@ -43,6 +43,10 @@ export type MultiAttribute = {light: stringdark: string}+ fill?: {+ light?: string+ dark?: string+ }statusCode?: stringgrantType?: stringproviderType?: stringdiff --git a/packages/ui-patterns/src/Chart/charts/chart-line.tsx b/packages/ui-patterns/src/Chart/charts/chart-line.tsxindex 2acf85578c4..b514fb97323 100644--- a/packages/ui-patterns/src/Chart/charts/chart-line.tsx+++ b/packages/ui-patterns/src/Chart/charts/chart-line.tsx@@ -45,6 +45,7 @@ export type ChartHighlightAction = {export interface ChartLineProps {data: ChartLineTick[]dataKey: string+ dataKeys?: string[] // Add this lineconfig?: ChartConfigonLineClick?: (datum: ChartLineTick, tooltipData?: CategoricalChartState) => voidDateTimeFormat?: string@@ -72,6 +73,7 @@ export interface ChartLineProps {export const ChartLine = ({data,dataKey,+ dataKeys, // Add this lineconfig,onLineClick,DateTimeFormat = 'MMM D, YYYY, hh:mma',@@ -98,11 +100,14 @@ export const ChartLine = ({return null}- const chartConfig: ChartConfig = config || {- [dataKey]: {- label: dataKey,- },- }+ const keysToRender = dataKeys || [dataKey]++ const chartConfig: ChartConfig =+ config ||+ keysToRender.reduce((acc, key) => {+ acc[key] = { label: key }+ return acc+ }, {} as ChartConfig)const showHighlightActions =showHighlightArea &&@@ -209,14 +214,33 @@ export const ChartLine = ({fillOpacity={0.2}/>)}- <Area- type="step"- dataKey={dataKey}- fill={focusDataIndex !== null ? hoverColor : color}- fillOpacity={0.1}- stroke={focusDataIndex !== null ? hoverColor : color}- strokeWidth={strokeWidth}- />+ {keysToRender.map((key, index) => {+ const keyConfig = chartConfig[key]+ const lineColor =+ keyConfig?.color ||+ (keyConfig?.theme+ ? isDarkMode+ ? keyConfig.theme.dark+ : keyConfig.theme.light+ : color)+ const baseOpacity = 0.2+ const opacityIncrement = 0.1+ const maxOpacity = 0.6+ const fillOpacity = Math.min(baseOpacity + index * opacityIncrement, maxOpacity)++ return (+ <Area+ key={key}+ type="step"+ dataKey={key}+ fill={lineColor}+ fillOpacity={fillOpacity}+ stroke={lineColor}+ strokeWidth={strokeWidth}+ stackId={`stack-${key}`}+ />+ )+ })}</RechartAreaChart></ChartContainer>{data && data.length > 0 && (