MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getScaledPoints

Function getScaledPoints

src/ui-react-dom-charts/common/data.ts:81–134  ·  view source on GitHub ↗
(
  kind: Kind,
  points: DataPoint[],
  [xMin, xMax, yMin, yMax]: Bounds,
  [width, height]: Size,
  xValues?: XValue[],
  xScale: XScale = CATEGORY,
  timestampUnit: TimestampUnit = MILLISECOND,
  xTitle?: string,
  yTitle?: string,
)

Source from the content-addressed store, hash-verified

79};
80
81export const getScaledPoints = (
82 kind: Kind,
83 points: DataPoint[],
84 [xMin, xMax, yMin, yMax]: Bounds,
85 [width, height]: Size,
86 xValues?: XValue[],
87 xScale: XScale = CATEGORY,
88 timestampUnit: TimestampUnit = MILLISECOND,
89 xTitle?: string,
90 yTitle?: string,
91): ScaledPoint[] => {
92 const continuousX = xScale != CATEGORY;
93 const xDomain: Domain = continuousX
94 ? [xMin as number, xMax as number]
95 : [0, 0];
96 const yDomain: Domain = [yMin ?? 0, yMax ?? 0];
97 const xCategories = mapNew<XValue, number>();
98
99 arrayForEach(
100 isNullish(xValues) || arrayIsEmpty(xValues)
101 ? arrayMap(points, ([, xValue]) => xValue)
102 : xValues,
103 (xValue) =>
104 collHas(xCategories, xValue)
105 ? 0
106 : mapSet(xCategories, xValue, collSize(xCategories)),
107 );
108
109 return arrayFilter(
110 arrayMap(points, ([rowId, xValue, yValue]): ScaledPoint | undefined => {
111 const x = getX(
112 xValue,
113 xScale,
114 timestampUnit,
115 xDomain,
116 xCategories,
117 width,
118 kind,
119 );
120 return isUndefined(x)
121 ? undefined
122 : [
123 rowId,
124 xValue,
125 yValue,
126 x,
127 height - getScale(yValue, yDomain[0], yDomain[1], height),
128 xTitle,
129 yTitle,
130 ];
131 }),
132 (point): point is ScaledPoint => !isUndefined(point),
133 );
134};
135
136const getX = (
137 xValue: XValue,

Callers 3

LineSeries.tsxFile · 0.90
BarSeries.tsxFile · 0.90
CartesianChartFunction · 0.90

Calls 12

mapNewFunction · 0.90
arrayForEachFunction · 0.90
isNullishFunction · 0.90
arrayIsEmptyFunction · 0.90
arrayMapFunction · 0.90
collHasFunction · 0.90
mapSetFunction · 0.90
collSizeFunction · 0.90
arrayFilterFunction · 0.90
isUndefinedFunction · 0.90
getXFunction · 0.70
getScaleFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…