-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
responsive charts with a normalized data source
- Loading branch information
Showing
5 changed files
with
165 additions
and
48 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,36 @@ | ||
import React from 'react'; | ||
import { Rect } from 'react-konva'; | ||
|
||
interface ColorRectProps { | ||
x?: number; | ||
y?: number; | ||
width?: number; | ||
height?: number; | ||
color?: string; | ||
shadowBlur?: number; | ||
key?: React.Key; | ||
} | ||
|
||
const ColorRect: React.FC<ColorRectProps> = ({ | ||
x = 0, | ||
y = 0, | ||
width = 50, | ||
height = 50, | ||
color = '#000000', | ||
shadowBlur = 5, | ||
key | ||
}) => { | ||
return ( | ||
<Rect | ||
x={x} | ||
y={y} | ||
width={width} | ||
height={height} | ||
fill={color} | ||
shadowBlur={shadowBlur} | ||
key={key} | ||
/> | ||
); | ||
}; | ||
|
||
export default ColorRect; |
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,40 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
interface StageSize { | ||
width: number; | ||
height: number; | ||
} | ||
|
||
interface RectSize { | ||
width: number; | ||
height: number; | ||
spacing: number; | ||
} | ||
|
||
export function useResponsiveStage(): { stageSize: StageSize; rectSize: RectSize } { | ||
const [stageSize, setStageSize] = useState<StageSize>({ width: 600, height: 400 }); | ||
const [rectSize, setRectSize] = useState<RectSize>({ width: 50, height: 50, spacing: 60 }); | ||
|
||
useEffect(() => { | ||
const updateSize = () => { | ||
if (window.innerWidth > 1024) { | ||
// For large screens (like 24-inch monitors) | ||
setStageSize({ width: 1200, height: 800 }); | ||
setRectSize({ width: 50, height: 50, spacing: 60 }); | ||
} else { | ||
// For small screens (like 6-inch phones) | ||
setStageSize({ width: window.innerWidth - 20, height: (window.innerHeight / 2) - 20 }); | ||
setRectSize({ width: 25, height: 25, spacing: 30 }); | ||
} | ||
}; | ||
|
||
window.addEventListener('resize', updateSize); | ||
updateSize(); // Set the initial size | ||
|
||
return () => { | ||
window.removeEventListener('resize', updateSize); | ||
}; | ||
}, []); | ||
|
||
return { stageSize, rectSize }; | ||
} |
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