Files
ohif-viewer/platform/viewer/src/connectedComponents/ConnectedLayoutButton.js
T

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-13 15:36:46 -04:00
import { LayoutButton } from '@ohif/ui';
import OHIF from '@ohif/core';
import { connect } from 'react-redux';
2019-01-06 21:59:25 +01:00
const { setLayout } = OHIF.redux.actions;
const mapStateToProps = state => {
2019-05-29 08:39:54 -04:00
return {
currentLayout: state.viewports.layout,
};
2019-01-06 21:59:25 +01:00
};
const mapDispatchToProps = dispatch => {
2019-05-29 08:39:54 -04:00
return {
// TODO: Change if layout switched becomes more complex
onChange: (selectedCell, currentLayout) => {
2019-05-29 08:39:54 -04:00
let viewports = [];
const rows = selectedCell.row + 1;
const columns = selectedCell.col + 1;
const numViewports = rows * columns;
for (let i = 0; i < numViewports; i++) {
// Hacky way to allow users to exit MPR "mode"
const viewport = currentLayout.viewports[i];
let plugin = viewport && viewport.plugin;
if (viewport && viewport.vtk) {
plugin = 'cornerstone';
}
2019-05-29 08:39:54 -04:00
viewports.push({
height: `${100 / rows}%`,
width: `${100 / columns}%`,
plugin,
2019-05-29 08:39:54 -04:00
});
}
const layout = {
viewports,
};
2019-01-06 21:59:25 +01:00
2019-05-29 08:39:54 -04:00
dispatch(setLayout(layout));
},
};
2019-01-06 21:59:25 +01:00
};
const mergeProps = (propsFromState, propsFromDispatch) => {
const onChangeFromDispatch = propsFromDispatch.onChange;
const { currentLayout } = propsFromState;
return {
onChange: (selectedCell) => onChangeFromDispatch(selectedCell, currentLayout)
};
}
2019-01-06 21:59:25 +01:00
const ConnectedLayoutButton = connect(
2019-05-29 08:39:54 -04:00
mapStateToProps,
mapDispatchToProps,
mergeProps
2019-01-06 21:59:25 +01:00
)(LayoutButton);
export default ConnectedLayoutButton;