| import { isVisible } from '../util/TickUtils'; |
| import { CartesianTickItem } from '../util/types'; |
| import { getEveryNthWithCondition } from '../util/getEveryNthWithCondition'; |
| import { Sign } from './getTicks'; |
|
|
| export function getEquidistantTicks( |
| sign: Sign, |
| boundaries: { start: number; end: number }, |
| getTickSize: (tick: CartesianTickItem, index: number) => number, |
| ticks: ReadonlyArray<CartesianTickItem>, |
| minTickGap: number, |
| ): ReadonlyArray<CartesianTickItem> { |
| |
| const result = (ticks || []).slice(); |
|
|
| const { start: initialStart, end } = boundaries; |
| let index = 0; |
| |
| |
| let stepsize = 1; |
| let start = initialStart; |
|
|
| while (stepsize <= result.length) { |
| |
| |
|
|
| const entry = ticks?.[index]; |
|
|
| |
| if (entry === undefined) { |
| return getEveryNthWithCondition(ticks, stepsize); |
| } |
|
|
| |
| const i = index; |
| let size: number | undefined; |
| const getSize = () => { |
| if (size === undefined) { |
| size = getTickSize(entry, i); |
| } |
|
|
| return size; |
| }; |
|
|
| const tickCoord = entry.coordinate; |
| |
| const isShow = index === 0 || isVisible(sign, tickCoord, getSize, start, end); |
|
|
| if (!isShow) { |
| |
| index = 0; |
| start = initialStart; |
| stepsize += 1; |
| } |
|
|
| if (isShow) { |
| |
| start = tickCoord + sign * (getSize() / 2 + minTickGap); |
| index += stepsize; |
| } |
| } |
|
|
| return []; |
| } |
|
|