-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e88ab3
commit 92cad96
Showing
5 changed files
with
90 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
|
||
import { CanvasRect, type CanvasRectProps } from './CanvasRect'; | ||
|
||
export type DottedBorderRectProps = CanvasRectProps & { | ||
lineWidth: number; | ||
spacing: number; | ||
}; | ||
|
||
/** | ||
* radius 1 black dot with radius 3 white region around it | ||
*/ | ||
function squareDot(ctx: CanvasRenderingContext2D, cx: number, cy: number) { | ||
ctx.fillStyle = 'white'; | ||
ctx.fillRect(cx - 1, cy - 1, 3, 3); | ||
ctx.fill(); | ||
|
||
ctx.fillStyle = 'black'; | ||
ctx.fillRect(cx, cy, 1, 1); | ||
ctx.fill(); | ||
} | ||
|
||
export const DottedBorderRect = ({ | ||
timeStart, | ||
timeEnd, | ||
spaceStart, | ||
spaceEnd, | ||
fillStyle, | ||
lineWidth, | ||
spacing, | ||
}: DottedBorderRectProps) => { | ||
const drawBorder = ( | ||
ctx: CanvasRenderingContext2D, | ||
timeAxis: string, | ||
timePixelSize: number, | ||
spacePixelSize: number | ||
) => { | ||
const width = timeAxis === 'x' ? timePixelSize : spacePixelSize; | ||
const height = timeAxis === 'x' ? spacePixelSize : timePixelSize; | ||
|
||
ctx.lineWidth = lineWidth; | ||
|
||
for (let i = 0; Math.abs(i) < Math.abs(width); i += spacing * Math.sign(width)) { | ||
squareDot(ctx, i, 0); | ||
squareDot(ctx, i, 0 + height); | ||
} | ||
for (let i = 0; Math.abs(i) < Math.abs(height); i += spacing * Math.sign(height)) { | ||
squareDot(ctx, 0, i); | ||
squareDot(ctx, 0 + width, i); | ||
} | ||
}; | ||
return ( | ||
<CanvasRect | ||
timeStart={timeStart} | ||
timeEnd={timeEnd} | ||
spaceStart={spaceStart} | ||
spaceEnd={spaceEnd} | ||
fillStyle={fillStyle} | ||
drawBorder={drawBorder} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters