Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts: Add options support for X and Y axis #41109

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Added passing through options for X, Y axis
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const LineChart: FC< LineChartProps > = ( {
withTooltips = true,
showLegend = false,
legendOrientation = 'horizontal',
options = {},
} ) => {
const providerTheme = useChartTheme();

Expand Down Expand Up @@ -124,8 +125,13 @@ const LineChart: FC< LineChartProps > = ( {
yScale={ { type: 'linear', nice: true } }
>
<AnimatedGrid columns={ false } numTicks={ 4 } />
<AnimatedAxis orientation="bottom" numTicks={ 5 } tickFormat={ formatDateTick } />
<AnimatedAxis orientation="left" numTicks={ 4 } />
<AnimatedAxis
orientation="bottom"
numTicks={ 5 }
tickFormat={ formatDateTick }
{ ...options?.axis?.x }
/>
<AnimatedAxis orientation="left" numTicks={ 4 } { ...options?.axis?.y } />

{ data.map( ( seriesData, index ) => (
<AnimatedLineSeries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ Default.args = {
data: sampleData,
showLegend: false,
legendOrientation: 'horizontal',
options: {
axis: {
x: {
orientation: 'bottom',
},
y: {
orientation: 'left',
},
},
},
};

// Story with single data series
Expand Down
24 changes: 24 additions & 0 deletions projects/js-packages/charts/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Orientation } from '@visx/axis';
import type { CSSProperties } from 'react';

type ValueOf< T > = T[ keyof T ];

declare type OrientationType = ValueOf< typeof Orientation >;

export type DataPoint = {
label: string;
value: number;
Expand Down Expand Up @@ -65,6 +70,15 @@ export type ChartTheme = {
gridColorDark: string;
};

declare type AxisOptions = {
orientation?: OrientationType;
numTicks?: number;
axisClassName?: string;
axisLineClassName?: string;
labelClassName?: string;
tickClassName?: string;
};

/**
* Base properties shared across all chart components
*/
Expand Down Expand Up @@ -110,6 +124,16 @@ export type BaseChartProps< T = DataPoint | DataPointDate > = {
* Grid visibility. x is default.
*/
gridVisibility?: 'x' | 'y' | 'xy' | 'none';

/**
* More options for the chart.
*/
options?: {
axis?: {
x?: AxisOptions;
y?: AxisOptions;
};
};
};

/**
Expand Down
Loading