-
Notifications
You must be signed in to change notification settings - Fork 1
continue stride #57
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
Merged
Merged
continue stride #57
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
68540b6
stride and slice
lazarusA 73da02e
Merge branch 'la/show_data' into la/continue_stride
lazarusA 923f366
adapt to ui
lazarusA d4d8025
maybe
lazarusA d950aa3
cleaner Array Display
lazarusA 778b0dd
meta
lazarusA 72fd4ae
log slices
lazarusA da788ce
mv up
lazarusA 9e1e81b
groups
lazarusA 46d6050
wide
lazarusA dc50599
colors
lazarusA f1a26a1
no
lazarusA 9b858a8
all fix
lazarusA 137c436
scalar
lazarusA cb908d0
resolved
lazarusA e5b1ba8
steps
lazarusA df5f491
scalar
lazarusA d093abc
more
lazarusA 48fab65
comments
lazarusA 26b6a20
scroll
lazarusA dd94677
matrix
lazarusA 8d9df0e
monospace
lazarusA 09026d9
fix if
lazarusA f59aaf2
load
lazarusA 65e12fb
cleanup headers
lazarusA 0b0b4b4
do nc_get_vars
lazarusA 15d6d68
fix overflow
lazarusA 621715d
resolveDim cleanup
lazarusA 7377e04
no cast
lazarusA 2af5d48
dataset
lazarusA f29fe77
vars text
lazarusA 476100f
slices and all
lazarusA 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,260 @@ | ||
| 'use client'; | ||
| import React from 'react'; | ||
| import { Input } from '@/components/ui/input'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { Spinner } from '@/components/ui/spinner'; | ||
| import { Alert, AlertDescription } from '@/components/ui/alert'; | ||
| import { Terminal, ChevronRight, ChevronDown } from 'lucide-react'; | ||
| import { slice as ncSlice } from '@earthyscience/netcdf4-wasm'; | ||
| import { VariableInfo, VariableArrayData } from './types'; | ||
|
|
||
| // Types | ||
| export type SelectionMode = 'all' | 'scalar' | 'slice'; | ||
|
|
||
| export interface SliceSelectionState { | ||
| mode: SelectionMode; | ||
| scalar: string; | ||
| start: string; | ||
| stop: string; | ||
| step: string; | ||
| } | ||
|
|
||
| export function defaultSelection(): SliceSelectionState { | ||
| return { mode: 'all', scalar: '0', start: '0', stop: '', step: '1' }; | ||
| } | ||
|
|
||
| // buildSelection — converts UI state → DimSelection[] for dataset.get() | ||
| export function buildSelection( | ||
| sels: SliceSelectionState[], | ||
| shape: Array<number | bigint> | ||
| ): Array<null | number | ReturnType<typeof ncSlice>> { | ||
| return sels.map((s, i) => { | ||
| const dimSize = Number(shape[i]); | ||
|
|
||
| if (s.mode === 'all') return ncSlice(0, dimSize, 1); | ||
|
|
||
| if (s.mode === 'scalar') { | ||
| let idx = parseInt(s.scalar); | ||
| if (Number.isNaN(idx)) idx = 0; | ||
| if (idx < 0) idx = dimSize + idx; | ||
| if (idx < 0 || idx >= dimSize) { | ||
| throw new Error(`index ${idx} out of bounds for dim ${i} size ${dimSize}`); | ||
| } | ||
| return idx; | ||
| } | ||
|
|
||
| let start = s.start !== '' ? parseInt(s.start) : 0; | ||
| let stop = s.stop !== '' ? parseInt(s.stop) : dimSize; | ||
| let step = s.step !== '' ? parseInt(s.step) : 1; | ||
|
|
||
| if (Number.isNaN(start)) start = 0; | ||
| if (Number.isNaN(stop)) stop = dimSize; | ||
| if (Number.isNaN(step)) step = 1; | ||
|
|
||
| if (start < 0) start = dimSize + start; | ||
| if (stop < 0) stop = dimSize + stop; | ||
|
|
||
| return ncSlice(start, stop, step); | ||
| }); | ||
| } | ||
|
|
||
| interface SliceTesterSectionProps { | ||
| info: VariableInfo; | ||
| sliceSelections: SliceSelectionState[]; | ||
| setSliceSelections: React.Dispatch<React.SetStateAction<SliceSelectionState[]>>; | ||
| expandedSliceTester: boolean; | ||
| setExpandedSliceTester: (v: boolean) => void; | ||
| sliceResult: VariableArrayData | null; | ||
| sliceError: string | null; | ||
| loadingSlice: boolean; | ||
| onRun: () => void; | ||
| } | ||
|
|
||
| const SliceTester: React.FC<SliceTesterSectionProps> = ({ | ||
| info, | ||
| sliceSelections, | ||
| setSliceSelections, | ||
| expandedSliceTester, | ||
| setExpandedSliceTester, | ||
| sliceResult, | ||
| sliceError, | ||
| loadingSlice, | ||
| onRun, | ||
| }) => { | ||
| if (!info?.shape || info.shape.length === 0) return null; | ||
|
|
||
| const shape: number[] = info.shape.map(Number); | ||
|
|
||
| const updateSel = (i: number, patch: Partial<SliceSelectionState>) => | ||
| setSliceSelections(prev => prev.map((s, idx) => idx === i ? { ...s, ...patch } : s)); | ||
|
|
||
| const resultPreview = sliceResult | ||
| ? (() => { | ||
| const len = sliceResult.length ?? 0; | ||
| const count = Math.min(30, len); | ||
| const items: string[] = []; | ||
| for (let i = 0; i < count; i++) { | ||
| const v = sliceResult[i] as number | bigint | string; | ||
| items.push(typeof v === 'number' ? v.toFixed(4) : String(v)); | ||
| } | ||
| const suffix = len > 30 ? `, … (${len} total)` : ''; | ||
| return `[${items.join(', ')}${suffix}]`; | ||
| })() | ||
| : null; | ||
|
|
||
| const elementCount = sliceResult ? sliceResult.length ?? 0 : 0; | ||
|
|
||
| const selectionPreview = sliceSelections.map((s, i) => { | ||
| if (s.mode === 'all') return 'null'; | ||
| if (s.mode === 'scalar') return s.scalar || '0'; | ||
| const parts: string[] = [s.start || '0', s.stop || String(shape[i])]; | ||
| if (s.step && s.step !== '1') parts.push(s.step); | ||
| return `slice(${parts.join(', ')})`; | ||
| }).join(', '); | ||
|
|
||
| return ( | ||
| <div className="border-[0.1px] rounded-lg overflow-hidden mt-2"> | ||
| {/* Header */} | ||
| <button | ||
| onClick={() => setExpandedSliceTester(!expandedSliceTester)} | ||
| className="w-full flex items-center justify-between p-3 hover:bg-accent/50 transition-colors cursor-pointer" | ||
| > | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-sm font-semibold">Slice & Index Tester</span> | ||
| <span className="text-xs text-muted-foreground font-mono"> | ||
| shape: [{shape.join(', ')}] | ||
| </span> | ||
| </div> | ||
| {expandedSliceTester | ||
| ? <ChevronDown className="h-4 w-4 flex-shrink-0" /> | ||
| : <ChevronRight className="h-4 w-4 flex-shrink-0" /> | ||
| } | ||
| </button> | ||
|
|
||
| {expandedSliceTester && ( | ||
| <div className="px-3 pb-3 space-y-3"> | ||
|
|
||
| {/* Dimension rows */} | ||
| <div className="space-y-2"> | ||
| {shape.map((dimSize, i) => { | ||
| const dimName = info.dimensions?.[i] ?? `dim_${i}`; | ||
| const sel = sliceSelections[i] ?? defaultSelection(); | ||
|
|
||
| return ( | ||
| <div key={i} className="border rounded-md p-2 space-y-2 bg-muted/30"> | ||
| {/* Label + mode tabs */} | ||
| <div className="flex items-center gap-2 flex-wrap"> | ||
| <span className="font-mono text-xs text-muted-foreground w-24 shrink-0 truncate"> | ||
| {dimName} | ||
| <span className="text-muted-foreground/60"> [{dimSize}]</span> | ||
| </span> | ||
| <div className="flex rounded-md border overflow-hidden text-xs"> | ||
| {(['all', 'scalar', 'slice'] as SelectionMode[]).map(m => ( | ||
| <button | ||
| key={m} | ||
| onClick={() => updateSel(i, { mode: m })} | ||
| className={`px-2 py-1 transition-colors ${ | ||
| sel.mode === m | ||
| ? 'bg-primary text-primary-foreground font-semibold' | ||
| : 'hover:bg-accent/50' | ||
| }`} | ||
| > | ||
| {m === 'all' ? 'null' : m} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Scalar input */} | ||
| {sel.mode === 'scalar' && ( | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-xs text-muted-foreground w-10">index</span> | ||
| <Input | ||
| type="number" | ||
| min={-dimSize} | ||
| max={dimSize - 1} | ||
| value={sel.scalar} | ||
| onChange={e => updateSel(i, { scalar: e.target.value })} | ||
| className="h-7 text-xs w-28 font-mono" | ||
| placeholder="0" | ||
| /> | ||
| <span className="text-xs text-muted-foreground"> | ||
| (0 … {dimSize - 1}, or negative) | ||
| </span> | ||
| </div> | ||
| )} | ||
|
|
||
| {/* Slice inputs */} | ||
| {sel.mode === 'slice' && ( | ||
| <div className="flex items-center gap-2 flex-wrap"> | ||
| {[ | ||
| { label: 'start', key: 'start' as const, placeholder: '0' }, | ||
| { label: 'stop', key: 'stop' as const, placeholder: String(dimSize) }, | ||
| { label: 'step', key: 'step' as const, placeholder: '1' }, | ||
| ].map(({ label, key, placeholder }) => ( | ||
| <div key={key} className="flex items-center gap-1"> | ||
| <span className="text-xs text-muted-foreground w-8">{label}</span> | ||
| <Input | ||
| type="number" | ||
| value={sel[key]} | ||
| onChange={e => updateSel(i, { [key]: e.target.value })} | ||
| className="h-7 text-xs w-20 font-mono" | ||
| placeholder={placeholder} | ||
| /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
|
|
||
| {/* Selection preview */} | ||
| <div className="text-xs font-mono text-muted-foreground bg-muted/50 rounded px-2 py-1.5 break-all"> | ||
| {`dataset.get("${info.name}", [${selectionPreview}])`} | ||
| </div> | ||
|
|
||
| {/* Run + result count */} | ||
| <div className="flex items-center gap-2"> | ||
| <Button | ||
| size="sm" | ||
| onClick={onRun} | ||
| disabled={loadingSlice} | ||
| style={{ backgroundColor: '#644FF0', color: 'white' }} | ||
lazarusA marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| className="flex-shrink-0" | ||
| > | ||
| {loadingSlice | ||
| ? <><Spinner className="h-3 w-3 mr-2" />Running…</> | ||
| : 'Run' | ||
| } | ||
| </Button> | ||
| {sliceResult && ( | ||
| <span className="text-xs text-muted-foreground"> | ||
| {elementCount} elements | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Error */} | ||
| {sliceError && ( | ||
| <Alert variant="destructive" className="py-2"> | ||
| <Terminal className="h-4 w-4 flex-shrink-0" /> | ||
| <AlertDescription className="text-xs break-words">{sliceError}</AlertDescription> | ||
| </Alert> | ||
| )} | ||
|
|
||
| {/* Result preview */} | ||
| {resultPreview && ( | ||
| <pre className="bg-muted p-2 rounded font-mono text-xs overflow-x-auto whitespace-pre-wrap break-all"> | ||
| {resultPreview} | ||
| </pre> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export { SliceTester }; | ||
| export default SliceTester; | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.