Skip to content

Commit

Permalink
chore(react-chart): fix default tick format for small viewport (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBogomolov authored Apr 2, 2019
1 parent 12cf72b commit 7fdf293
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
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

0 comments on commit 7fdf293

Please sign in to comment.