Skip to content

Commit

Permalink
feat: print spectra (#2786)
Browse files Browse the repository at this point in the history
* feat: print spectra

feat: prepare NMRium structure for printing

fix: trigger printing after the NMRium viewer is rendered and rescaled to an A4 page

* feat: create print content component

* refactor: use new print component

* fix: print page config

* feat: improve print content page options modal

* fix: return the window size to origin after the print is finished

* chore: fix prettier and eslint

* chore: fix prettier and eslint

* fix: print padding

* feat: improve print

* feat: save print page settings in the workspace

* fix:  type and page padding

* fix: print in firefox

* refactor: change label from 'margin' to 'Margin'

* fix: display overlay div to prevent hover effects

close #3139
  • Loading branch information
hamed-musallam authored Jul 19, 2024
1 parent d1a48f1 commit 1287bc1
Show file tree
Hide file tree
Showing 15 changed files with 709 additions and 34 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"ml-tree-similarity": "^2.2.0",
"multiplet-analysis": "^2.1.2",
"nmr-correlation": "^2.3.3",
"nmr-load-save": "^0.34.2",
"nmr-load-save": "^0.35.0",
"nmr-processing": "^12.8.0",
"nmredata": "^0.9.11",
"numeral": "^2.0.6",
Expand Down Expand Up @@ -153,4 +153,4 @@
"vite": "^5.3.3",
"vitest": "^2.0.2"
}
}
}
8 changes: 6 additions & 2 deletions src/component/2d/Viewer2D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MouseTracker } from '../EventsTrackers/MouseTracker';
import { useChartData } from '../context/ChartContext';
import { useDispatch } from '../context/DispatchContext';
import { useMapKeyModifiers } from '../context/KeyModifierContext';
import { usePrintPage } from '../elements/print';
import Spinner from '../loader/Spinner';
import { options } from '../toolbar/ToolTypes';

Expand Down Expand Up @@ -284,10 +285,13 @@ interface ViewerResponsiveWrapperProps {
export function ViewerResponsiveWrapper(props: ViewerResponsiveWrapperProps) {
const dispatch = useDispatch();
const { width, height, children } = props;
const printOptions = usePrintPage();

useEffect(() => {
dispatch({ type: 'SET_DIMENSIONS', payload: { width, height } });
}, [width, height, dispatch]);
if (!printOptions) {
dispatch({ type: 'SET_DIMENSIONS', payload: { width, height } });
}
}, [width, height, dispatch, printOptions]);

return children;
}
Expand Down
17 changes: 16 additions & 1 deletion src/component/context/ChartContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { produce } from 'immer';
import { createContext, useContext } from 'react';

import { usePrintPage } from '../elements/print';
import { initialState, State } from '../reducer/Reducer';

export const ChartContext = createContext<State>(initialState);
export const ChartDataProvider = ChartContext.Provider;

export function useChartData() {
return useContext(ChartContext);
const data = useContext(ChartContext);

const printOptions = usePrintPage();

if (!printOptions) return data;

const { width, height } = printOptions;

const updatedData = produce(data, (draft) => {
draft.width = width;
draft.height = height;
});

return updatedData;
}
Loading

0 comments on commit 1287bc1

Please sign in to comment.