-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prepare NMRium structure for printing fix: trigger printing after the NMRium viewer is rendered and rescaled to an A4 page
- Loading branch information
1 parent
d43911d
commit 33d5535
Showing
5 changed files
with
157 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { CSSProperties, RefObject, useDeferredValue, useEffect } from 'react'; | ||
|
||
import Viewer1D from '../1d/Viewer1D'; | ||
import FloatMoleculeStructures from '../1d-2d/components/FloatMoleculeStructures'; | ||
import Viewer2D from '../2d/Viewer2D'; | ||
import { useChartData } from '../context/ChartContext'; | ||
|
||
import { NMRiumProps } from './NMRium'; | ||
|
||
interface NMRiumViewerProps { | ||
emptyText: NMRiumProps['emptyText']; | ||
viewerRef: RefObject<HTMLDivElement>; | ||
style?: CSSProperties; | ||
onRender?: () => void; | ||
} | ||
|
||
export function NMRiumViewer(props: NMRiumViewerProps) { | ||
const { emptyText, viewerRef, onRender, style = {} } = props; | ||
const { displayerMode, width, height } = useChartData(); | ||
const renderDimension = useDeferredValue({ width, height }); | ||
useEffect(() => { | ||
if (typeof onRender !== 'function') { | ||
return; | ||
} | ||
|
||
requestAnimationFrame(() => { | ||
setTimeout(() => { | ||
if ( | ||
renderDimension.width !== width || | ||
renderDimension.height !== height | ||
) { | ||
onRender(); | ||
} | ||
}, 0); | ||
}); | ||
}, [onRender, width, height, renderDimension.width, renderDimension.height]); | ||
|
||
return ( | ||
<div | ||
id="nmrium-viewer" | ||
data-testid="viewer" | ||
ref={viewerRef} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
position: 'relative', | ||
backgroundColor: 'white', | ||
...style, | ||
}} | ||
> | ||
<FloatMoleculeStructures /> | ||
{displayerMode === '1D' ? ( | ||
<Viewer1D emptyText={emptyText} /> | ||
) : ( | ||
<Viewer2D emptyText={emptyText} /> | ||
)} | ||
</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
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