-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #889 from silx-kit/grid
Improve matrix vis performance through virtualisation of index/header cells
- Loading branch information
Showing
15 changed files
with
258 additions
and
188 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
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,33 @@ | ||
import create from 'zustand'; | ||
import createContext from 'zustand/context'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
import type { ConfigProviderProps } from '../../models'; | ||
|
||
interface MatrixVisConfig { | ||
sticky: boolean; | ||
toggleSticky: () => void; | ||
} | ||
|
||
function createStore() { | ||
return create<MatrixVisConfig>( | ||
persist( | ||
(set) => ({ | ||
sticky: false, | ||
toggleSticky: () => set((state) => ({ sticky: !state.sticky })), | ||
}), | ||
{ | ||
name: 'h5web:matrix', | ||
version: 1, | ||
} | ||
) | ||
); | ||
} | ||
|
||
const { Provider, useStore } = createContext<MatrixVisConfig>(); | ||
export const useMatrixVisConfig = 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useMeasure } from '@react-hookz/web'; | ||
import { useContext } from 'react'; | ||
import { FixedSizeGrid as IndexedGrid } from 'react-window'; | ||
|
||
import Cell from './Cell'; | ||
import styles from './MatrixVis.module.css'; | ||
import StickyGrid from './StickyGrid'; | ||
import { SettingsContext } from './context'; | ||
|
||
function Grid() { | ||
const { rowCount, columnCount, cellSize, setRenderedItems } = | ||
useContext(SettingsContext); | ||
|
||
const [wrapperSize, wrapperRef] = useMeasure<HTMLDivElement>(); | ||
|
||
return ( | ||
<div ref={wrapperRef} className={styles.wrapper}> | ||
{wrapperSize && ( | ||
<IndexedGrid | ||
className={styles.grid} | ||
innerElementType={StickyGrid} | ||
width={wrapperSize.width} | ||
height={wrapperSize.height} | ||
rowHeight={cellSize.height} | ||
rowCount={rowCount} | ||
columnWidth={cellSize.width} | ||
columnCount={columnCount} | ||
overscanCount={8} | ||
onItemsRendered={setRenderedItems} | ||
> | ||
{Cell} | ||
</IndexedGrid> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default Grid; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { range } from 'lodash'; | ||
import { useContext } from 'react'; | ||
|
||
import styles from './MatrixVis.module.css'; | ||
import { SettingsContext } from './context'; | ||
|
||
interface Props { | ||
indexMin: number; | ||
indexMax: number; | ||
transform: string /* to compensate for header cells not rendered in the range [0 indexMin] */; | ||
} | ||
|
||
function HeaderCells(props: Props) { | ||
const { indexMin, indexMax, transform } = props; | ||
const { cellSize } = useContext(SettingsContext); | ||
|
||
return ( | ||
<> | ||
{range(indexMin, indexMax).map((index) => ( | ||
<div | ||
key={index.toString()} | ||
className={styles.indexCell} | ||
style={{ ...cellSize, transform }} | ||
data-bg={index % 2 === 1 ? '' : undefined} | ||
> | ||
{index >= 0 && index} | ||
</div> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
export default HeaderCells; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.