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

Function createPointScale

packages/core/src/scales/band.ts:42–64  ·  view source on GitHub ↗
({
  domain,
  range,
  padding = 0
}: CreatePointScaleOptions<TValue>)

Source from the content-addressed store, hash-verified

40};
41
42export const createPointScale = <TValue extends string | number>({
43 domain,
44 range,
45 padding = 0
46}: CreatePointScaleOptions<TValue>): PointScale<TValue> => {
47 const count = domain.length;
48 const rangeSpan = range[1] - range[0];
49 const step =
50 count <= 1 ? 0 : rangeSpan / Math.max(1, count - 1 + padding * 2);
51 const offset = count <= 1 ? rangeSpan / 2 : step * padding;
52 const positions = new Map<TValue, number>();
53
54 domain.forEach((value, index) => {
55 positions.set(value, range[0] + offset + step * index);
56 });
57
58 return {
59 domain,
60 range,
61 step,
62 scale: (value: TValue) => positions.get(value)
63 };
64};

Callers 3

scales.test.tsFile · 0.90
buildLineChartXScaleFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected