src/helpers.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 1
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
// Some math magic of the function responsible for produce
2
// hill-like curve and, correctly position and drag
3
// points on the Y axis
4
export const hillFn = (point: number) =>
5
  50 * Math.sin((Math.PI / 50) * point - (1 / 2) * Math.PI) + 50;
6
7
// The inverse of the same magic to convert back values from
8
// chart back to the original before hillFn(). mainly used
9
// in dragging event and setting the setting new values.
10
export const hillFnInverse = (point: number) =>
11
  (25 * (2 * Math.asin((point - 50) / 50) + Math.PI)) / Math.PI;
12
13
// Calculate when the point is just near to the right side of the chart
14
export const textOutRange = (x: number) => x >= 80 && x <= 100;
15
16
export const calculateTextPositionForX = (size: number, x: number) => {
17
  const margin = size + 5;
18
  return textOutRange(x) ? -1 * margin : margin;
19
};
20
21
export const calculateTextMarginForY = () => 5;
22
23
export const uId = () => Math.random().toString(36).slice(-6);
24