-
Notifications
You must be signed in to change notification settings - Fork 3
Jp/permute array #664
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
Draft
TheJeran
wants to merge
6
commits into
main
Choose a base branch
from
jp/permute_array
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Jp/permute array #664
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b811a2
Added component
TheJeran da924b5
Initial plotting with appropriate axis lines working. Only works on 3…
TheJeran 907e4ac
Disable Plot when duplicates
TheJeran 57cc7fd
Working well enough for commit
TheJeran 2e6dd6d
Reenable Borders
TheJeran 4efb7ed
Gemini suggestions
TheJeran 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
| import React, {useRef, useState, useEffect} from 'react' | ||
| import { useGlobalStore } from '@/GlobalStates/GlobalStore' | ||
| import { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@/components/ui/select"; | ||
|
|
||
| export const DimensionOrder = ({dimNames, setDuplicateDims}: {dimNames: string[], setDuplicateDims: React.Dispatch<React.SetStateAction<boolean>>}) => { | ||
| const {permute} = useGlobalStore.getState() // Just need the value on mount to set initial <select> values | ||
| const slotCount = Math.min(3, dimNames.length); | ||
| const permuteRef = useRef<number[]>( | ||
| Array.from({ length: slotCount }, (_, i) => i) | ||
| ) | ||
| const [warnDuplicates, setWarnDuplicates] = useState(false); | ||
| const handleChange = (slotIdx: number, dimIdx: number) => { | ||
| permuteRef.current[slotIdx] = dimIdx; | ||
| useGlobalStore.setState({ permute: [...permuteRef.current] }); | ||
| const permuteArray = permuteRef.current; | ||
| const hasDupes = permuteArray.length != new Set(permuteArray).size | ||
| setWarnDuplicates(hasDupes) | ||
| setDuplicateDims(hasDupes) | ||
| }; | ||
|
|
||
| useEffect(()=>{ //The first render didn't have dimNames and used default value. UseEffect updates after fetch. Also updates when switching to variable with diff Dims | ||
| // At the moment it resets each time because of the double click issue with menus that got introduced in 0.3.0. | ||
| permuteRef.current = Array.from({ length: slotCount }, (_, i) => i) | ||
| useGlobalStore.setState({ permute: [...permuteRef.current] }); | ||
| },[slotCount]) | ||
| return ( | ||
| <> | ||
| <div className="flex gap-2"> | ||
| {Array.from({ length: slotCount }).map((_, slotIdx) => ( | ||
| <Select | ||
| key={slotIdx} | ||
| value={String(permute?.[slotIdx])} | ||
| onValueChange={(v) => handleChange(slotIdx, Number(v))} | ||
| > | ||
| <SelectTrigger className='flex-1 min-w-0 truncate'> | ||
| <SelectValue /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| {dimNames.map((dim, dimIdx) => ( | ||
| <SelectItem key={dimIdx} value={String(dimIdx)}> | ||
| {dim} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </Select> | ||
| ))} | ||
| </div> | ||
| {warnDuplicates && <p className='text-red-500 font-bold'> | ||
| DUPLICATE DIMENSION USED | ||
| </p>} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
The
useEffecthook currently only triggers whenslotCountchanges. If you switch to a different variable that has the same number of dimensions (e.g., switching from one 3D variable to another 3D variable),slotCountremains3, meaning the effect won't run and the dimension permutation will not reset. AddingdimNamesto the dependency array ensures the permutation resets correctly when switching variables.