diff --git a/.webpack/webpack.config.js b/.webpack/webpack.config.js index fdf8dbb..1b424ff 100644 --- a/.webpack/webpack.config.js +++ b/.webpack/webpack.config.js @@ -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; @@ -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 diff --git a/.webpack/webpack.dev.js b/.webpack/webpack.dev.js index 848ba24..11d1b63 100644 --- a/.webpack/webpack.dev.js +++ b/.webpack/webpack.dev.js @@ -20,7 +20,7 @@ module.exports = { library: 'cornerstoneViewport', libraryTarget: 'umd', globalObject: 'this', - clean: true + clean: true, }, module: { rules: [ @@ -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 diff --git a/examples/ExamplePageBasic.js b/examples/ExamplePageBasic.js index 837e2cf..9431498 100644 --- a/examples/ExamplePageBasic.js +++ b/examples/ExamplePageBasic.js @@ -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', ], @@ -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', ], }; diff --git a/src/CornerstoneViewport/CornerstoneViewport.js b/src/CornerstoneViewport/CornerstoneViewport.js index 41af9d2..e0b066c 100644 --- a/src/CornerstoneViewport/CornerstoneViewport.js +++ b/src/CornerstoneViewport/CornerstoneViewport.js @@ -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]( @@ -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 = () => {