-
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.
- Loading branch information
Showing
12 changed files
with
193 additions
and
22 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,77 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Tree from 'react-d3-tree'; | ||
import TextSizeController from './TextSizeController.jsx'; | ||
import Controller from './Controller.jsx'; | ||
import CustomNode from './CustomNode.jsx'; | ||
|
||
const SEPERATION_INTERVAL = 0.5; | ||
const DEPTH_INTERVAL = 50; | ||
|
||
function App() { | ||
const [orientation, setOrientation] = useState('horizontal'); | ||
const [depthFactor, setDepthFactor] = useState(500); | ||
const [seperation, setSeperation] = useState(0.5); | ||
|
||
const changeOrientation = () => { | ||
if (orientation === 'vertical') setOrientation('horizontal'); | ||
else setOrientation('vertical'); | ||
}; | ||
|
||
const increaseDepthFactor = () => { | ||
setDepthFactor((prev) => prev + DEPTH_INTERVAL); | ||
}; | ||
|
||
const decreaseDepthFactor = () => { | ||
setDepthFactor((prev) => (prev - DEPTH_INTERVAL > 0 ? prev - DEPTH_INTERVAL : prev)); | ||
}; | ||
|
||
const increaseSeperation = () => { | ||
setSeperation((prev) => prev + SEPERATION_INTERVAL); | ||
}; | ||
|
||
const decreaseSeperation = () => { | ||
setSeperation((prev) => (prev - SEPERATION_INTERVAL > 0 ? prev - SEPERATION_INTERVAL : prev)); | ||
}; | ||
|
||
useEffect(() => { | ||
if (orientation === 'horizontal') { | ||
setDepthFactor(500); | ||
setSeperation(0.5); | ||
} else { | ||
setDepthFactor(100); | ||
setSeperation(2); | ||
} | ||
}, [orientation]); | ||
|
||
return ( | ||
<div style={{ width: '98vw', height: '98vh' }}> | ||
<Tree data={data} pathFunc='step' orientation='vertical' translate={{ x: 500, y: 250 }} separation={{ nonSiblings: 3, siblings: 3 }} /> | ||
<div style={{ width: '98vw', height: '95vh' }}> | ||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 }}> | ||
<div style={{ display: 'flex', gap: 5, alignItems: 'center', justifyContent: 'center' }}> | ||
<span>Orientation</span> | ||
<button type='button' onClick={changeOrientation}> | ||
{orientation} | ||
</button> | ||
</div> | ||
<TextSizeController /> | ||
<Controller title='Depth Factor' onClickIncrease={increaseDepthFactor} onClickDecrease={decreaseDepthFactor} /> | ||
<Controller title='Seperation' onClickIncrease={increaseSeperation} onClickDecrease={decreaseSeperation} /> | ||
</div> | ||
<Tree | ||
data={data} | ||
pathFunc='step' | ||
orientation={orientation} | ||
translate={{ x: 500, y: 250 }} | ||
separation={{ nonSiblings: seperation, siblings: seperation }} | ||
rootNodeClassName='node__root' | ||
branchNodeClassName='node__branch' | ||
leafNodeClassName='node__leaf' | ||
initialDepth={collapse ? 1 : undefined} | ||
depthFactor={depthFactor} | ||
renderCustomNodeElement={(rd3Props) => CustomNode({ ...rd3Props })} | ||
/> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render(<App />); | ||
ReactDOM.createRoot(document.getElementById('root')).render(<App />); |
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,15 @@ | ||
import React from 'react'; | ||
|
||
export default function Controller({ title, onClickIncrease, onClickDecrease }) { | ||
return ( | ||
<div style={{ display: 'flex', gap: 5, alignItems: 'center', justifyContent: 'center' }}> | ||
<span>{title}</span> | ||
<button type='button' onClick={onClickIncrease}> | ||
up | ||
</button> | ||
<button type='button' onClick={onClickDecrease}> | ||
down | ||
</button> | ||
</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,19 @@ | ||
import React from 'react'; | ||
|
||
export default function CustomNode({ nodeDatum, toggleNode }) { | ||
return ( | ||
<> | ||
<circle r='15' onClick={toggleNode}></circle> | ||
<g class='rd3t-label'> | ||
<text class='rd3t-label__title' text-anchor='center' x='20' y='20'> | ||
{nodeDatum.name} | ||
</text> | ||
<text class='rd3t-label__attributes'> | ||
<tspan x='20' y='20' dy='1.2em'> | ||
dir: {nodeDatum.attributes.dir} | ||
</tspan> | ||
</text> | ||
</g> | ||
</> | ||
); | ||
} |
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,64 @@ | ||
import React, { useState } from 'react'; | ||
import Controller from './Controller.jsx'; | ||
|
||
const TITLE_SIZE_INTERVAL = 1; | ||
const ATTRIBUTE_SIZE_INTERVAL = 1; | ||
|
||
export default function TextSizeController() { | ||
const [titleSize, setTitleSize] = useState(20); | ||
const [attributeSize, setAttributeSize] = useState(15); | ||
|
||
const increaseTitleSize = () => { | ||
setTitleSize((prev) => prev + TITLE_SIZE_INTERVAL); | ||
}; | ||
|
||
const decreaseTitleSize = () => { | ||
setTitleSize((prev) => (prev - TITLE_SIZE_INTERVAL > 0 ? prev - TITLE_SIZE_INTERVAL : prev)); | ||
}; | ||
|
||
const increaseAttributeSize = () => { | ||
setAttributeSize((prev) => prev + ATTRIBUTE_SIZE_INTERVAL); | ||
}; | ||
|
||
const decreaseAttributeSize = () => { | ||
setAttributeSize((prev) => (prev - ATTRIBUTE_SIZE_INTERVAL > 0 ? prev - ATTRIBUTE_SIZE_INTERVAL : prev)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Controller title='Title Size' onClickIncrease={increaseTitleSize} onClickDecrease={decreaseTitleSize} /> | ||
<Controller | ||
title='Attribute Size' | ||
onClickIncrease={increaseAttributeSize} | ||
onClickDecrease={decreaseAttributeSize} | ||
/> | ||
<style jsx> | ||
{` | ||
.node__root > g > .rd3t-label__title { | ||
font-size: ${titleSize}px; | ||
} | ||
.node__branch > g > .rd3t-label__title { | ||
font-size: ${titleSize}px; | ||
} | ||
.node__leaf > g > .rd3t-label__title { | ||
font-size: ${titleSize}px; | ||
} | ||
.node__root > g > .rd3t-label__attributes { | ||
font-size: ${attributeSize}px; | ||
} | ||
.node__branch > g > .rd3t-label__attributes { | ||
font-size: ${attributeSize}px; | ||
} | ||
.node__leaf > g > .rd3t-label__attributes { | ||
font-size: ${attributeSize}px; | ||
} | ||
`} | ||
</style> | ||
</> | ||
); | ||
} |