Skip to content
Open
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
12 changes: 9 additions & 3 deletions src/AbstractChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface AbstractChartConfig extends ChartConfig {
formatXLabel?: (xLabel: string) => string;
verticalLabelsHeightPercentage?: number;
formatTopBarValue?: (topBarValue: number) => string | number;
yAxisPosition?: 'left' | 'right';
}

export type AbstractChartState = {};
Expand Down Expand Up @@ -140,7 +141,7 @@ class AbstractChart<
height,
paddingTop,
paddingRight,
verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE
verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE,
} = config;
const basePosition = height * verticalLabelsHeightPercentage;

Expand Down Expand Up @@ -191,7 +192,9 @@ class AbstractChart<
horizontalLabelRotation = 0,
decimalPlaces = 2,
formatYLabel = (yLabel: string) => yLabel,
verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE
verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE,
yAxisPosition = 'left',
width
} = config;

const {
Expand All @@ -216,7 +219,10 @@ class AbstractChart<
}

const basePosition = height * verticalLabelsHeightPercentage;
const x = paddingRight - yLabelsOffset;
const x =
yAxisPosition === 'left'
? paddingRight - yLabelsOffset
: width - (yLabelsOffset - 10);
const y =
count === 1 && this.props.fromZero
? paddingTop + 4
Expand Down
10 changes: 8 additions & 2 deletions src/line-chart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export interface LineChartProps extends AbstractChartProps {
* The number of horizontal lines
*/
segments?: number;
/**
* The position of y axis
*/
yAxisPosition?: 'left' | 'right';
}

type LineChartState = {
Expand Down Expand Up @@ -815,7 +819,8 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
formatXLabel = xLabel => xLabel,
segments,
transparent = false,
chartConfig
chartConfig,
yAxisPosition,
} = this.props;

const { scrollableDotHorizontalOffset } = this.state;
Expand Down Expand Up @@ -893,7 +898,8 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
paddingTop: paddingTop as number,
paddingRight: paddingRight as number,
formatYLabel,
decimalPlaces: chartConfig.decimalPlaces
decimalPlaces: chartConfig.decimalPlaces,
yAxisPosition: yAxisPosition,
})}
</G>
<G>
Expand Down