-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSpaceGraduations.tsx
61 lines (51 loc) · 1.54 KB
/
SpaceGraduations.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useCallback } from 'react';
import { useDraw } from '../hooks/useCanvas';
import { type DrawingFunction } from '../lib/types';
import { getCrispLineCoordinate } from '../utils/canvas';
const SpaceGraduations = () => {
const drawingFunction = useCallback<DrawingFunction>(
(
ctx,
{
timePixelOffset,
getSpacePixel,
operationalPoints,
swapAxis,
width,
height,
theme: { spaceGraduationsStyles },
}
) => {
const axisSize = !swapAxis ? width : height;
// Draw operational point lines:
operationalPoints.forEach((point) => {
const styles = spaceGraduationsStyles[point.importanceLevel || 0];
if (!styles) return;
ctx.strokeStyle = styles.color;
ctx.lineWidth = styles.width;
ctx.globalAlpha = styles.opacity || 1;
if (styles.dashArray) {
ctx.setLineDash(styles.dashArray || []);
ctx.lineDashOffset = -timePixelOffset;
}
const spacePixel = getCrispLineCoordinate(getSpacePixel(point.position), ctx.lineWidth);
ctx.beginPath();
if (!swapAxis) {
ctx.moveTo(0, spacePixel);
ctx.lineTo(axisSize, spacePixel);
} else {
ctx.moveTo(spacePixel, 0);
ctx.lineTo(spacePixel, axisSize);
}
ctx.stroke();
});
ctx.setLineDash([]);
ctx.lineDashOffset = 0;
ctx.globalAlpha = 1;
},
[]
);
useDraw('graduations', drawingFunction);
return null;
};
export default SpaceGraduations;