Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reorganize event handlers to let scrollbar move properly when sc… #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
// Plugins
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const vtkRules = require('vtk.js/Utilities/config/dependency.js').webpack.core
.rules;
Expand Down Expand Up @@ -58,6 +58,7 @@ module.exports = (env, argv) => {
},
resolve: {
modules: [path.resolve(__dirname, './../node_modules'), SRC_PATH],
fallback: { fs: false, path: false, zlib: false },
},
externals: [
// Used to build/load metadata
Expand Down
4 changes: 2 additions & 2 deletions .webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
library: 'cornerstoneViewport',
libraryTarget: 'umd',
globalObject: 'this',
clean: true
clean: true,
},
module: {
rules: [
Expand All @@ -41,7 +41,7 @@ module.exports = {
alias: {
'@cornerstone-viewport': ENTRY_VIEWPORT,
},
fallback: { fs: false, path: false },
fallback: { fs: false, path: false, zlib: false },
},
plugins: [
// Show build progress
Expand Down
23 changes: 23 additions & 0 deletions examples/ExamplePageBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ExamplePageBasic extends Component {
{ name: 'StackScrollMultiTouch', mode: 'active' },
],
imageIds: [
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.9.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.10.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.11.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.12.dcm',
],
Expand Down Expand Up @@ -82,8 +84,29 @@ class ExamplePageBasic extends Component {
{ name: 'StackScrollMultiTouch', mode: 'active' },
],
imageIds: [
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.1.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.2.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.3.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.4.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.5.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.6.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.7.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.8.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.9.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.10.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.11.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.12.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.13.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.14.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.15.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.16.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.17.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.18.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.19.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.20.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.21.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.22.dcm',
'dicomweb://s3.amazonaws.com/lury/PTCTStudy/1.3.6.1.4.1.25403.52237031786.3872.20100510032220.23.dcm',
],
};

Expand Down
47 changes: 29 additions & 18 deletions src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,23 @@ class CornerstoneViewport extends Component {

// Updates state's imageId, and imageIndex
this.element[addOrRemoveEventListener](
cornerstone.EVENTS.NEW_IMAGE,
this.onNewImage
cornerstoneTools.EVENTS.STACK_SCROLL,
this.onStackScroll
);

// Updates state's imageId, and imageIndex
this.element[addOrRemoveEventListener](
cornerstone.EVENTS.NEW_IMAGE,
this.onNewImageDebounced
);
if (this.props.onNewImage) {
this.element[addOrRemoveEventListener](
cornerstone.EVENTS.NEW_IMAGE,
this.onNewImage
);
}

if (this.props.onNewImageDebounced) {
this.element[addOrRemoveEventListener](
cornerstone.EVENTS.NEW_IMAGE,
this.onNewImageDebounced
);
}

// Updates state's viewport
this.element[addOrRemoveEventListener](
Expand Down Expand Up @@ -711,25 +719,28 @@ class CornerstoneViewport extends Component {
});
};

onNewImageHandler = (event, callback) => {
onStackScroll = (event) => {
const { newImageIdIndex } = event.detail;

this.setState({ imageIdIndex: newImageIdIndex });
};

onNewImage = (event) => {
const { imageId } = event.detail.image;
const { sopInstanceUid } =
cornerstone.metaData.get('generalImageModule', imageId) || {};
const currentImageIdIndex = this.props.imageIds.indexOf(imageId);

// TODO: Should we grab and set some imageId specific metadata here?
// Could prevent cornerstone dependencies in child components.
this.setState({ imageIdIndex: currentImageIdIndex });

if (callback) {
callback({ currentImageIdIndex, sopInstanceUid });
}
this.props.onNewImage({ currentImageIdIndex, sopInstanceUid });
};

onNewImage = (event) => this.onNewImageHandler(event, this.props.onNewImage);

onNewImageDebounced = debounce((event) => {
this.onNewImageHandler(event, this.props.onNewImageDebounced);
const { imageId } = event.detail.image;
const { sopInstanceUid } =
cornerstone.metaData.get('generalImageModule', imageId) || {};
const currentImageIdIndex = this.props.imageIds.indexOf(imageId);

this.props.onNewImageDebounced({ currentImageIdIndex, sopInstanceUid });
}, this.props.onNewImageDebounceTime);

onImageLoaded = () => {
Expand Down