-
Notifications
You must be signed in to change notification settings - Fork 17
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
9 changed files
with
101 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { FiDownload } from 'react-icons/fi'; | ||
import { useMatrixConfig } from '../vis-packs/core/matrix/config'; | ||
import { sliceToCsv } from '../vis-packs/core/matrix/utils'; | ||
import DownloadBtn from './controls/DownloadBtn'; | ||
import Toolbar from './Toolbar'; | ||
|
||
function MatrixToolbar() { | ||
const currentSlice = useMatrixConfig((state) => state.currentSlice); | ||
if (currentSlice && currentSlice.shape.length > 2) { | ||
throw new Error('Expected current slice to have at most two dimensions'); | ||
} | ||
|
||
return ( | ||
<Toolbar> | ||
{currentSlice && ( | ||
<DownloadBtn | ||
icon={FiDownload} | ||
label="CSV" | ||
filename="export.csv" | ||
getDownloadUrl={() => { | ||
const data = sliceToCsv(currentSlice); | ||
return URL.createObjectURL( | ||
new Blob([data], { type: 'text/csv;charset=utf-8' }) | ||
); | ||
}} | ||
/> | ||
)} | ||
</Toolbar> | ||
); | ||
} | ||
|
||
export default MatrixToolbar; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { NdArray } from 'ndarray'; | ||
import create from 'zustand'; | ||
import createContext from 'zustand/context'; | ||
import type { Primitive } from '../../../providers/models'; | ||
import type { ConfigProviderProps } from '../../models'; | ||
import type { PrintableType } from '../models'; | ||
|
||
interface MatrixConfig { | ||
currentSlice: NdArray<Primitive<PrintableType>> | undefined; | ||
setCurrentSlice: (slice: NdArray<Primitive<PrintableType>>) => void; | ||
} | ||
|
||
function createStore() { | ||
return create<MatrixConfig>((set) => ({ | ||
currentSlice: undefined, | ||
setCurrentSlice: (slice) => set({ currentSlice: slice }), | ||
})); | ||
} | ||
|
||
const { Provider, useStore } = createContext<MatrixConfig>(); | ||
export const useMatrixConfig = useStore; | ||
|
||
export function MatrixConfigProvider(props: ConfigProviderProps) { | ||
const { children } = props; | ||
return <Provider createStore={createStore}>{children}</Provider>; | ||
} |
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