Skip to content

Commit

Permalink
Feat/allow toggling axisline (#2)
Browse files Browse the repository at this point in the history
* allow toggling axisline for all chart types

* fix styling + add tests
  • Loading branch information
alexbalonperin authored Jun 8, 2024
1 parent d77d755 commit a641abb
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 10 deletions.
17 changes: 15 additions & 2 deletions src/components/chart-elements/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
showTooltip = true,
showLegend = true,
showGridLines = true,
showAxisLine = false,
showGradient = true,
autoMinValue = false,
curveType = "linear",
Expand Down Expand Up @@ -188,10 +189,16 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
interval={startEndOnly ? "preserveStartEnd" : intervalType}
tickLine={false}
axisLine={false}
axisLine={showAxisLine}
minTickGap={tickGap}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
Expand All @@ -210,7 +217,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
<YAxis
width={yAxisWidth}
hide={!showYAxis}
axisLine={false}
axisLine={showAxisLine}
tickLine={false}
type="number"
domain={yAxisDomain as AxisDomain}
Expand All @@ -224,6 +231,12 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickFormatter={valueFormatter}
allowDecimals={allowDecimals}
Expand Down
33 changes: 29 additions & 4 deletions src/components/chart-elements/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
showTooltip = true,
showLegend = true,
showGridLines = true,
showAxisLine = false,
autoMinValue = false,
minValue,
maxValue,
Expand Down Expand Up @@ -202,9 +203,15 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickLine={false}
axisLine={false}
axisLine={showAxisLine}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
Expand Down Expand Up @@ -235,9 +242,15 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickLine={false}
axisLine={false}
axisLine={showAxisLine}
tickFormatter={valueFormatter}
minTickGap={tickGap}
allowDecimals={allowDecimals}
Expand All @@ -260,7 +273,7 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
<YAxis
width={yAxisWidth}
hide={!showYAxis}
axisLine={false}
axisLine={showAxisLine}
tickLine={false}
type="number"
domain={yAxisDomain as AxisDomain}
Expand All @@ -274,6 +287,12 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickFormatter={
relative ? (value: number) => `${(value * 100).toString()} %` : valueFormatter
Expand All @@ -297,7 +316,7 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
width={yAxisWidth}
hide={!showYAxis}
dataKey={index}
axisLine={false}
axisLine={showAxisLine}
tickLine={false}
ticks={startEndOnly ? [data[0][index], data[data.length - 1][index]] : undefined}
type="category"
Expand All @@ -312,6 +331,12 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
>
{yAxisLabel && (
Expand Down
17 changes: 15 additions & 2 deletions src/components/chart-elements/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
showTooltip = true,
showLegend = true,
showGridLines = true,
showAxisLine = false,
autoMinValue = false,
curveType = "linear",
minValue,
Expand Down Expand Up @@ -185,9 +186,15 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickLine={false}
axisLine={false}
axisLine={showAxisLine}
minTickGap={tickGap}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
Expand All @@ -206,7 +213,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
<YAxis
width={yAxisWidth}
hide={!showYAxis}
axisLine={false}
axisLine={showAxisLine}
tickLine={false}
type="number"
domain={yAxisDomain as AxisDomain}
Expand All @@ -220,6 +227,12 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickFormatter={valueFormatter}
allowDecimals={allowDecimals}
Expand Down
18 changes: 16 additions & 2 deletions src/components/chart-elements/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface ScatterChartProps
showTooltip?: boolean;
showLegend?: boolean;
showGridLines?: boolean;
showAxisLine?: boolean;
autoMinXValue?: boolean;
minXValue?: number;
maxXValue?: number;
Expand Down Expand Up @@ -129,6 +130,7 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
showTooltip = true,
showLegend = true,
showGridLines = true,
showAxisLine = false,
autoMinXValue = false,
minXValue,
maxXValue,
Expand Down Expand Up @@ -246,10 +248,16 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
tickLine={false}
tickFormatter={valueFormatter.x}
axisLine={false}
axisLine={showAxisLine}
minTickGap={tickGap}
domain={xAxisDomain as AxisDomain}
allowDataOverflow={true}
Expand All @@ -272,7 +280,7 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
<YAxis
width={yAxisWidth}
hide={!showYAxis}
axisLine={false}
axisLine={showAxisLine}
tickLine={false}
dataKey={y}
type="number"
Expand All @@ -289,6 +297,12 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
"fill-tremor-content",
// dark
"dark:fill-dark-tremor-content",
// common
"stroke-1",
// light
"stroke-tremor-border",
// dark
"dark:stroke-dark-tremor-border",
)}
allowDecimals={allowDecimals}
allowDataOverflow={true}
Expand Down
1 change: 1 addition & 0 deletions src/components/chart-elements/common/BaseChartProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes<
showTooltip?: boolean;
showLegend?: boolean;
showGridLines?: boolean;
showAxisLine?: boolean;
autoMinValue?: boolean;
minValue?: number;
maxValue?: number;
Expand Down
6 changes: 6 additions & 0 deletions src/stories/chart-elements/AreaChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const ShowAxisLine: Story = {
args: {
showAxisLine: true,
},
};
6 changes: 6 additions & 0 deletions src/stories/chart-elements/BarChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const ShowAxisLine: Story = {
args: {
showAxisLine: true,
},
};
6 changes: 6 additions & 0 deletions src/stories/chart-elements/LineChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const ShowAxisLine: Story = {
args: {
showAxisLine: true,
},
};
6 changes: 6 additions & 0 deletions src/stories/chart-elements/ScatterChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const ShowAxisLine: Story = {
args: {
showAxisLine: true,
},
};

0 comments on commit a641abb

Please sign in to comment.