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

chore(react-chart): fix default tick format for small viewport #1945

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
2 changes: 2 additions & 0 deletions packages/dx-chart-core/src/plugins/axis/computeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ describe('axisCoordinates', () => {
textAnchor: 'middle',
y1: 0, y2: -5, x1: 25, x2: 25,
}]);
expect(scale.tickFormat).toBeCalledWith(10);
} finally {
delete scale.tickFormat;
}
Expand Down Expand Up @@ -175,6 +176,7 @@ describe('axisCoordinates', () => {
textAnchor: 'middle',
y1: 0, y2: -5, x1: 25, x2: 25,
}]);
expect(userFormat).toBeCalledWith(scale, 10);
} finally {
delete scale.tickFormat;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/dx-chart-core/src/plugins/axis/computeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const createTicks = <T>(
.map((tick, index) => callback(fixedScale(tick), String(index), tick));
};

const getFormat = (scale: ScaleObject, tickFormat?: TickFormatFn): GetFormatFn => {
const getFormat = (scale: ScaleObject, count: number, tickFormat?: TickFormatFn): GetFormatFn => {
if (scale.tickFormat) {
return tickFormat ? tickFormat(scale) : scale.tickFormat();
return tickFormat ? tickFormat(scale, count) : scale.tickFormat(count);
}
return tick => tick;
};
Expand Down Expand Up @@ -73,7 +73,7 @@ export const axisCoordinates: AxisCoordinatesFn = ({
position, tickSize, indentFromAxis,
);
const tickCount = getTickCount(scale.range(), paneSize[1 - Number(isHor)]);
const formatTick = getFormat(scale, tickFormat);
const formatTick = getFormat(scale, tickCount, tickFormat);
const ticks = createTicks(scale, tickCount, (coordinates, key, tick) => ({
key,
x1: coordinates,
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-chart-core/src/types/plugins.axis.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from './chart-core.types';
/** @internal */
export type ProcessTickFn<T> = (coord: number, key: string, tick: any) => T;
export type TickFormatFn = (scale: ScaleObject) => GetFormatFn;
export type TickFormatFn = (scale: ScaleObject, count?: number) => GetFormatFn;
/** @internal */
export type AxisCoordinatesArg = {
scaleName: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-chart/api/dx-react-chart.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ interface TargetData {
declare type TargetList = ReadonlyArray<SeriesRef>;

// @public (undocumented)
declare type TickFormatFn = (scale: ScaleObject) => GetFormatFn;
declare type TickFormatFn = (scale: ScaleObject, count?: number) => GetFormatFn;

// @public (undocumented)
declare const Title: React.ComponentType<TitleProps>;
Expand Down