Skip to content

The Open Standard for Generative UI

Refactor chart components to replace CondensedXAxisTick with SVGXAxisTick (#226)

Ankit Dasc80bf5c1e914
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.json
index fefbb637f..53b986a46 100644
--- a/js/packages/react-ui/package.json
+++ b/js/packages/react-ui/package.json
@@ -2,7 +2,7 @@
"type": "module",
"name": "@crayonai/react-ui",
"license": "MIT",
- "version": "0.9.1",
+ "version": "0.9.2",
"description": "Component library for Generative UI SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
index b99d6b405..34e1ccc93 100644
--- a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
@@ -15,10 +15,10 @@ import {
import {
ActiveDot,
cartesianGrid,
- CondensedXAxisTick,
- CondensedXAxisTickVariant,
CustomTooltipContent,
DefaultLegend,
+ SVGXAxisTick,
+ SVGXAxisTickVariant,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
@@ -32,7 +32,7 @@ export interface AreaChartCondensedProps<T extends AreaChartData> {
theme?: PaletteName;
customPalette?: string[];
variant?: AreaChartVariant;
- tickVariant?: CondensedXAxisTickVariant;
+ tickVariant?: SVGXAxisTickVariant;
grid?: boolean;
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
isAnimationActive?: boolean;
@@ -257,7 +257,7 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
interval="preserveStartEnd"
minTickGap={5}
height={xAxisHeight}
- tick={<CondensedXAxisTick />}
+ tick={<SVGXAxisTick />}
angle={calculatedAngle}
orientation="bottom"
padding={{
diff --git a/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
index 425c74cf9..03617644b 100644
--- a/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
@@ -15,11 +15,11 @@ import {
} from "../hooks";
import {
cartesianGrid,
- CondensedXAxisTick,
- CondensedXAxisTickVariant,
CustomTooltipContent,
DefaultLegend,
LineInBarShape,
+ SVGXAxisTick,
+ SVGXAxisTickVariant,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
@@ -34,7 +34,7 @@ export interface BarChartCondensedProps<T extends BarChartData> {
theme?: PaletteName;
customPalette?: string[];
variant?: BarChartVariant;
- tickVariant?: CondensedXAxisTickVariant;
+ tickVariant?: SVGXAxisTickVariant;
grid?: boolean;
radius?: number;
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
@@ -365,7 +365,7 @@ const BarChartCondensedComponent = <T extends BarChartData>({
interval="preserveStartEnd"
minTickGap={5}
height={xAxisHeight}
- tick={<CondensedXAxisTick />}
+ tick={<SVGXAxisTick />}
angle={calculatedAngle}
orientation="bottom"
padding={{
diff --git a/js/packages/react-ui/src/components/Charts/HorizontalBarChart/HorizontalBarChart.tsx b/js/packages/react-ui/src/components/Charts/HorizontalBarChart/HorizontalBarChart.tsx
index e4366eb4d..54e3fbc8f 100644
--- a/js/packages/react-ui/src/components/Charts/HorizontalBarChart/HorizontalBarChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/HorizontalBarChart/HorizontalBarChart.tsx
@@ -11,7 +11,7 @@ import {
CustomTooltipContent,
DefaultLegend,
SideBarTooltip,
- SimpleXAxisTick,
+ SVGXAxisTick,
verticalCartesianGrid,
YAxisTick,
} from "../shared";
@@ -275,7 +275,7 @@ const HorizontalBarChartComponent = <T extends HorizontalBarChartData>({
tickLine={false}
axisLine={false}
tickFormatter={numberTickFormatter}
- tick={<SimpleXAxisTick />}
+ tick={<SVGXAxisTick />}
/>
{/* Invisible bars to maintain scale synchronization */}
{dataKeys.map((key) => {
diff --git a/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
index 029123828..c645a1367 100644
--- a/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
@@ -15,10 +15,10 @@ import { LineChartData, LineChartVariant } from "../LineChart/types";
import {
ActiveDot,
cartesianGrid,
- CondensedXAxisTick,
- CondensedXAxisTickVariant,
CustomTooltipContent,
DefaultLegend,
+ SVGXAxisTick,
+ SVGXAxisTickVariant,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
@@ -32,7 +32,7 @@ export interface LineChartCondensedProps<T extends LineChartData> {
theme?: PaletteName;
customPalette?: string[];
variant?: LineChartVariant;
- tickVariant?: CondensedXAxisTickVariant;
+ tickVariant?: SVGXAxisTickVariant;
grid?: boolean;
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
isAnimationActive?: boolean;
@@ -258,7 +258,7 @@ const LineChartCondensedComponent = <T extends LineChartData>({
interval="preserveStartEnd"
minTickGap={5}
height={xAxisHeight}
- tick={<CondensedXAxisTick />}
+ tick={<SVGXAxisTick />}
angle={calculatedAngle}
orientation="bottom"
padding={{
diff --git a/js/packages/react-ui/src/components/Charts/ScatterChart/ScatterChart.tsx b/js/packages/react-ui/src/components/Charts/ScatterChart/ScatterChart.tsx
index f4a80d252..811f9e594 100644
--- a/js/packages/react-ui/src/components/Charts/ScatterChart/ScatterChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/ScatterChart/ScatterChart.tsx
@@ -10,7 +10,7 @@ import {
DefaultLegend,
gridCartesianGrid,
SideBarTooltip,
- SimpleXAxisTick,
+ SVGXAxisTick,
YAxisTick,
} from "../shared";
import { LegendItem } from "../types";
@@ -214,7 +214,7 @@ export const ScatterChart = ({
tickLine={false}
axisLine={false}
tickFormatter={numberTickFormatter}
- tick={<SimpleXAxisTick />}
+ tick={<SVGXAxisTick dy={10} />}
domain={xDomain}
dataKey={xAxisDataKey}
/>
@@ -248,7 +248,7 @@ export const ScatterChart = ({
height={chartHeight + 10}
data={transformedData}
margin={{
- top: 15,
+ top: 10,
bottom: 12,
left: 0,
right: 0,
diff --git a/js/packages/react-ui/src/components/Charts/charts.scss b/js/packages/react-ui/src/components/Charts/charts.scss
index 38404c71a..b2ea6e3a4 100644
--- a/js/packages/react-ui/src/components/Charts/charts.scss
+++ b/js/packages/react-ui/src/components/Charts/charts.scss
@@ -30,14 +30,13 @@
// shared components css
@forward "./shared/XAxisTick/xAxisTick.scss";
-@forward "./shared/CondensedXAxisTick/condensedXAxisTick.scss";
+@forward "./shared/SVGXAxisTick/svgXAxisTick.scss";
@forward "./shared/DefaultLegend/defaultLegend.scss";
@forward "./shared/StackedLegend/stackedLegend.scss";
@forward "./shared/YAxisTick/yAxisTick.scss";
@forward "./shared/ScrollButtonsHorizontal/scrollButtonsHorizontal.scss";
@forward "./shared/ScrollButtonsVertical/scrollButtonsVertical.scss";
@forward "./shared/LabelTooltip/labelTooltip.scss";
-@forward "./shared/SimpleXAxisTick/simpleXAxisTick.scss";
// portal tooltip css
@forward "./shared/PortalTooltip/portalTooltip.scss";
diff --git a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx
deleted file mode 100644
index 4dc93f704..000000000
--- a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-import clsx from "clsx";
-import React from "react";
-
-export type CondensedXAxisTickVariant = "singleLine" | "angled";
-
-interface CondensedXAxisTickProps {
- x?: number;
- y?: number;
- payload?: {
- value: any;
- };
- className?: string;
- angle?: number;
- textAnchor?: string;
-}
-
-const CondensedXAxisTick = React.forwardRef<SVGTextElement, CondensedXAxisTickProps>(
- (props, ref) => {
- const { x, y, payload, className, angle = 0, textAnchor = "middle" } = props;
-
- const value = String(payload?.value || "");
-
- if (x === undefined || y === undefined) {
- return null;
- }
-
- // Apply rotation transform if angle is provided
- const transform = angle !== 0 ? `rotate(${angle}, ${x}, ${y})` : undefined;
-
- return (
- <text
- ref={ref}
- className={clsx("crayon-chart-condensed-x-axis-tick", className)}
- x={x}
- y={y}
- dy={16}
- textAnchor={textAnchor}
- transform={transform}
- >
- {value}
- </text>
- );
- },
-);
-
-CondensedXAxisTick.displayName = "CondensedXAxisTick";
-
-export { CondensedXAxisTick };
-export type { CondensedXAxisTickProps };
diff --git a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/index.ts b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/index.ts
deleted file mode 100644
index 25b824215..000000000
--- a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { CondensedXAxisTick } from "./CondensedXAxisTick";
-export type { CondensedXAxisTickProps, CondensedXAxisTickVariant } from "./CondensedXAxisTick";
diff --git a/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/SVGXAxisTick.tsx b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/SVGXAxisTick.tsx
new file mode 100644
index 000000000..88de3a244
--- /dev/null
+++ b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/SVGXAxisTick.tsx
@@ -0,0 +1,68 @@
+import clsx from "clsx";
+import React from "react";
+import { numberTickFormatter } from "../../utils";
+
+export type SVGXAxisTickVariant = "singleLine" | "angled";
+
+interface SVGXAxisTickProps {
+ x?: number;
+ y?: number;
+ payload?: {
+ value: any;
+ };
+ className?: string;
+ angle?: number;
+ textAnchor?: "start" | "middle" | "end";
+ tickFormatter?: (value: any) => string;
+ dy?: number;
+}
+
+const SVGXAxisTick = React.forwardRef<SVGTextElement, SVGXAxisTickProps>((props, ref) => {
+ const {
+ x,
+ y,
+ payload,
+ className,
+ angle = 0,
+ textAnchor = "middle",
+ tickFormatter,
+ dy = 16,
+ } = props;
+
+ if (x === undefined || y === undefined) {
+ return null;
+ }
+
+ const raw = payload?.value;
+ // Auto-detect: Use custom formatter, or format numbers automatically, or stringify
+ const displayValue = tickFormatter
+ ? tickFormatter(raw)
+ : typeof raw === "number"
+ ? numberTickFormatter(raw)
+ : String(raw ?? "");
+
+ const transform = angle !== 0 ? `rotate(${angle}, ${x}, ${y})` : undefined;
+
+ return (
+ <text
+ ref={ref}
+ className={clsx(
+ "crayon-chart-svg-x-axis-tick",
+ angle !== 0 && "crayon-chart-svg-x-axis-tick-angled",
+ className,
+ )}
+ x={x}
+ y={y}
+ dy={dy}
+ textAnchor={textAnchor}
+ transform={transform}
+ >
+ {displayValue}
+ </text>
+ );
+});
+
+SVGXAxisTick.displayName = "SVGXAxisTick";
+
+export { SVGXAxisTick };
+export type { SVGXAxisTickProps };
diff --git a/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/index.ts b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/index.ts
new file mode 100644
index 000000000..29e83fdd5
--- /dev/null
+++ b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/index.ts
@@ -0,0 +1,2 @@
+export { SVGXAxisTick } from "./SVGXAxisTick";
+export type { SVGXAxisTickProps, SVGXAxisTickVariant } from "./SVGXAxisTick";
diff --git a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/svgXAxisTick.scss
similarity index 72%
rename from js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss
rename to js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/svgXAxisTick.scss
index be14d455d..42af18c9b 100644
--- a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss
+++ b/js/packages/react-ui/src/components/Charts/shared/SVGXAxisTick/svgXAxisTick.scss
@@ -1,11 +1,11 @@
@use "../../../../cssUtils" as cssUtils;
-.crayon-chart-condensed-x-axis-tick {
+.crayon-chart-svg-x-axis-tick {
@include cssUtils.typography(label, extra-small);
fill: cssUtils.$secondary-text;
}
-.crayon-chart-condensed-x-axis-tick-angled {
+.crayon-chart-svg-x-axis-tick-angled {
@include cssUtils.typography(label, extra-small);
fill: cssUtils.$secondary-text;
}
diff --git a/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/SimpleXAxisTick.tsx b/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/SimpleXAxisTick.tsx
deleted file mode 100644
index 8b96ff136..000000000
--- a/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/SimpleXAxisTick.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { numberTickFormatter } from "../../utils";
-interface SimpleXAxisTickProps {
- x?: number;
- y?: number;
- payload?: {
- value: string | number;
- };
-}
-
-export const SimpleXAxisTick = ({ x, y, payload }: SimpleXAxisTickProps) => {
- if (x === undefined || y === undefined || !payload) {
- return null;
- }
-
- const displayValue =
- typeof payload?.value === "number"
- ? numberTickFormatter(payload?.value)
- : String(payload?.value);
-
- return (
- <g transform={`translate(${x},${y})`}>
- <text x={0} y={0} dy={16} textAnchor="middle" className="crayon-chart-numeric-x-axis-tick">
- {displayValue}
- </text>
- </g>
- );
-};
diff --git a/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/simpleXAxisTick.scss b/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/simpleXAxisTick.scss
deleted file mode 100644
index 18ef3e997..000000000
--- a/js/packages/react-ui/src/components/Charts/shared/SimpleXAxisTick/simpleXAxisTick.scss
+++ /dev/null
@@ -1,5 +0,0 @@
-@use "../../../../cssUtils" as cssUtils;
-.crayon-chart-numeric-x-axis-tick {
- @include cssUtils.typography(label, extra-small);
- fill: cssUtils.$secondary-text;
-}
diff --git a/js/packages/react-ui/src/components/Charts/shared/index.ts b/js/packages/react-ui/src/components/Charts/shared/index.ts
index c3bcda086..f0bd23b31 100644
--- a/js/packages/react-ui/src/components/Charts/shared/index.ts
+++ b/js/packages/react-ui/src/components/Charts/shared/index.ts
@@ -1,13 +1,12 @@
export * from "./ActiveDot/ActiveDot";
export * from "./CartesianGrid/cartesianGrid";
-export * from "./CondensedXAxisTick";
export * from "./DefaultLegend/DefaultLegend";
export * from "./LineInBarShape";
export * from "./PortalTooltip";
export * from "./ScrollButtonsHorizontal";
export * from "./ScrollButtonsVertical";
export * from "./SideBarTooltip";
-export * from "./SimpleXAxisTick/SimpleXAxisTick";
export * from "./StackedLegend/StackedLegend";
+export * from "./SVGXAxisTick";
export * from "./XAxisTick/XAxisTick";
export * from "./YAxisTick/YAxisTick";
diff --git a/js/packages/react-ui/src/components/IconButton/iconButton.scss b/js/packages/react-ui/src/components/IconButton/iconButton.scss
index 275adfc82..356626f6e 100644
--- a/js/packages/react-ui/src/components/IconButton/iconButton.scss
+++ b/js/packages/react-ui/src/components/IconButton/iconButton.scss
@@ -9,6 +9,7 @@
cursor: pointer;
transition: all 0.2s ease;
padding: 0;
+ flex-shrink: 0;
//icon
&-icon {