MCPcopy
hub / github.com/chart-kit/react-native-chart-kit / generateLinearTicks

Function generateLinearTicks

packages/core/src/scales/ticks.ts:4–28  ·  view source on GitHub ↗
({
  count = 5,
  domain = [0, 1]
}: LinearTickOptions = {})

Source from the content-addressed store, hash-verified

2import type { LinearTickOptions, TimeTickOptions, TimeTickUnit } from "./types";
3
4export const generateLinearTicks = ({
5 count = 5,
6 domain = [0, 1]
7}: LinearTickOptions = {}): number[] => {
8 const [start, stop] = domain;
9 const reverse = stop < start;
10 const min = reverse ? stop : start;
11 const max = reverse ? start : stop;
12 const step = tickStep(min, max, Math.max(1, count));
13
14 if (step === 0) {
15 return [start];
16 }
17
18 const first = Math.ceil(min / step) * step;
19 const ticks: number[] = [];
20
21 const epsilon = step * 1e-10;
22
23 for (let value = first; value <= max + epsilon; value += step) {
24 ticks.push(Number(value.toPrecision(12)));
25 }
26
27 return reverse ? ticks.reverse() : ticks;
28};
29
30const timeUnitMs: Record<TimeTickUnit, number> = {
31 millisecond: 1,

Callers 3

scales.test.tsFile · 0.90
buildBarChartModelFunction · 0.90

Calls 1

tickStepFunction · 0.90

Tested by

no test coverage detected