@@ -9,12 +9,31 @@ export type OccupancyBlock = {
9
9
spaceStart : number ;
10
10
spaceEnd : number ;
11
11
color : string ;
12
+ blinking ?: boolean ;
12
13
} ;
13
14
14
15
export type OccupancyBlockLayerProps = {
15
16
occupancyBlocks : OccupancyBlock [ ] ;
16
17
} ;
17
18
19
+ const getFillStyle = ( ctx : CanvasRenderingContext2D , color : string , isBlinking ?: boolean ) => {
20
+ if ( isBlinking ) {
21
+ const patternCanvas = document . createElement ( 'canvas' ) ;
22
+ patternCanvas . width = 8 ;
23
+ patternCanvas . height = 8 ;
24
+ const pctx = patternCanvas . getContext ( '2d' ) ! ;
25
+ pctx . clearRect ( 0 , 0 , 8 , 8 ) ;
26
+ pctx . strokeStyle = color ;
27
+ pctx . lineWidth = 2 ;
28
+ pctx . beginPath ( ) ;
29
+ pctx . moveTo ( 0 , 8 ) ;
30
+ pctx . lineTo ( 8 , 0 ) ;
31
+ pctx . stroke ( ) ;
32
+ return ctx . createPattern ( patternCanvas , 'repeat' ) ! ;
33
+ }
34
+ return color ;
35
+ } ;
36
+
18
37
export const OccupancyBlockLayer = ( { occupancyBlocks } : OccupancyBlockLayerProps ) => {
19
38
const drawOccupancyBlockLayer = useCallback < DrawingFunction > (
20
39
( ctx , { getTimePixel, getSpacePixel } ) => {
@@ -24,7 +43,7 @@ export const OccupancyBlockLayer = ({ occupancyBlocks }: OccupancyBlockLayerProp
24
43
const width = getTimePixel ( occupancyBlock . timeEnd ) - x ;
25
44
const height = getSpacePixel ( occupancyBlock . spaceEnd ) - y ;
26
45
27
- ctx . fillStyle = occupancyBlock . color ;
46
+ ctx . fillStyle = getFillStyle ( ctx , occupancyBlock . color , occupancyBlock . blinking ) ;
28
47
ctx . fillRect ( x , y , width , height ) ;
29
48
}
30
49
} ,
0 commit comments