forked from codesquad-members-2022/airbnb
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 차트 레이아웃 시도 (svg, canvas) #12
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,38 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
const container = { | ||
width: '300px', | ||
height: '300px', | ||
}; | ||
|
||
const data = [ | ||
{ label: 'asd', x: 0, y: 0 }, | ||
{ label: 'z', x: 1, y: 400 }, | ||
{ label: 'dfa', x: 2, y: 200 }, | ||
{ label: 'wsa', x: 3, y: 100 }, | ||
{ label: 'hh', x: 4, y: 300 }, | ||
{ label: 'ert', x: 5, y: 500 }, | ||
{ label: 'Snbx', x: 6, y: 100 }, | ||
]; | ||
|
||
export default function CanvasLineChart() { | ||
const canvasRef = useRef<HTMLCanvasElement>(null); | ||
|
||
const drawLine = () => { | ||
// canvas 자체 | ||
const canvas = canvasRef.current; | ||
if (!canvas) return; | ||
canvas.width = 300; | ||
canvas.height = 300; | ||
// 선그리는 로직 | ||
}; | ||
|
||
useEffect(() => { | ||
drawLine(); | ||
}, []); | ||
return ( | ||
<div style={container}> | ||
<canvas style={{ ...container, border: '3px solid #ccc' }} ref={canvasRef}></canvas> | ||
</div> | ||
); | ||
} |
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,33 @@ | ||
const container = { | ||
width: '300px', | ||
height: '300px', | ||
}; | ||
|
||
const data = [ | ||
{ label: 'asd', x: 0, y: 0 }, | ||
{ label: 'z', x: 1, y: 400 }, | ||
{ label: 'dfa', x: 2, y: 200 }, | ||
{ label: 'wsa', x: 3, y: 100 }, | ||
{ label: 'hh', x: 4, y: 300 }, | ||
{ label: 'ert', x: 5, y: 500 }, | ||
{ label: 'Snbx', x: 6, y: 100 }, | ||
]; | ||
|
||
export default function SVGLineChart() { | ||
const points = data | ||
.map(element => { | ||
// svg에 표시할 때 px단위가 아니어서 비율로 계산 | ||
const x = (element.x / 6) * 100; | ||
const y = 100 - (element.y / 500) * 100; | ||
|
||
return `${x},${y}`; | ||
}) | ||
.join(' '); | ||
return ( | ||
<div style={container}> | ||
<svg viewBox={`0 0 100 100`} style={{ border: '3px solid #ccc' }}> | ||
<polyline fill="none" stroke="tomato" strokeWidth={1} points={points} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strokeWidth는 단위를 안써도 될까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 저도 이해가 부족한 것 같아서 추가적으로 학습해보겠습니다! |
||
</svg> | ||
</div> | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 지워주셔도 될것 같습니다!