From 7c1448222b9491889f1d861da132930889f66f75 Mon Sep 17 00:00:00 2001 From: Christian Mol Date: Wed, 15 Mar 2023 11:39:50 +0100 Subject: [PATCH 1/2] Add @christianmol as a contributor --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 50140e260..93bf70f58 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -383,6 +383,15 @@ "review", "userTesting" ] + }, + { + "login": "christianmol", + "name": "Christian Mol", + "avatar_url": "https://avatars.githubusercontent.com/u/36736693?v=4", + "profile": "https://github.com/christianmol", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7 diff --git a/README.md b/README.md index ba1724ed6..cd3b23db7 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [![Build Status][build-badge]][build] [![Coverage Status][coverage-badge]][coverage] -[![All Contributors](https://img.shields.io/badge/all_contributors-37-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-38-orange.svg?style=flat-square)](#contributors) [![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] @@ -165,7 +165,7 @@ Thanks goes to these people ([emoji key][emojis]): | [Juan Narvaez
Juan Narvaez](https://github.com/jdnarvaez)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=jdnarvaez "Code") | [Mike
Mike](https://github.com/mikehazell)
[📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=mikehazell "Documentation") [💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=mikehazell "Code") [⚠️](https://github.com/cornerstonejs/cornerstoneTools/commits?author=mikehazell "Tests") | [Sangkeun Kim
Sangkeun Kim](http://sisobus.com)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=sisobus "Code") [💬](#question-sisobus "Answering Questions") | [Victor Saase
Victor Saase](https://github.com/vsaase)
[🤔](#ideas-vsaase "Ideas, Planning, & Feedback") | [Michael Wasser
Michael Wasser](http://www.mikewasser.com)
[📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=untoldone "Documentation") | [Amandeep Singh
Amandeep Singh](https://github.com/singhArmani)
[🖋](#content-singhArmani "Content") | [Madison Dickson
Madison Dickson](http://mix3dstudios.com)
[📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=mix3d "Documentation") | | [Kevin Lee Drum
Kevin Lee Drum](https://github.com/kevinleedrum)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=kevinleedrum "Code") | [Makarand Bauskar
Makarand Bauskar](https://github.com/mmbauskar)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=mbauskar "Code") | [Biharck Araujo
Biharck Araujo](http://www.biharck.com.br)
[💡](#example-biharck "Examples") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=biharck "Documentation") | [Devon Bernard
Devon Bernard](https://www.linkedin.com/in/devonbernard)
[📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=DevonBernard "Documentation") | [Karl-Heinrich
Karl-Heinrich](https://github.com/Karl-Heinrich)
[🐛](https://github.com/cornerstonejs/cornerstoneTools/issues?q=author%3AKarl-Heinrich "Bug reports") [💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=Karl-Heinrich "Code") [⚠️](https://github.com/cornerstonejs/cornerstoneTools/commits?author=Karl-Heinrich "Tests") | [counterxing
counterxing](https://blog.xingbofeng.com/)
[🐛](https://github.com/cornerstonejs/cornerstoneTools/issues?q=author%3Axingbofeng "Bug reports") [💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=xingbofeng "Code") | [Jorge Lopes
Jorge Lopes](https://github.com/jlopes90)
[💬](#question-jlopes90 "Answering Questions") | | [Gabriel Garrido
Gabriel Garrido](http://garrido.io)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=Ggpsv "Code") | [ASVBPREAUBV
ASVBPREAUBV](https://github.com/ASVBPREAUBV)
[📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=ASVBPREAUBV "Documentation") | [frolic06
frolic06](https://github.com/frolic06)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=frolic06 "Code") | [codepage949
codepage949](https://github.com/codepage949)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=codepage949 "Code") | [Asherah Connor
Asherah Connor](https://kivikakk.ee)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=kivikakk "Code") | [Ikko Ashimine
Ikko Ashimine](https://bandism.net/)
[🐛](https://github.com/cornerstonejs/cornerstoneTools/issues?q=author%3Aeltociear "Bug reports") | [Bill Wallace
Bill Wallace](https://github.com/wayfarer3130)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=wayfarer3130 "Code") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=wayfarer3130 "Documentation") | -| [Bruno Alves de Faria
Bruno Alves de Faria](http://radicalimaging.com/)
[🐛](https://github.com/cornerstonejs/cornerstoneTools/issues?q=author%3Abrunoalvesdefaria "Bug reports") [💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Code") [🖋](#content-brunoalvesdefaria "Content") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Documentation") [🔌](#plugin-brunoalvesdefaria "Plugin/utility libraries") [👀](#review-brunoalvesdefaria "Reviewed Pull Requests") [⚠️](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Tests") [🔧](#tool-brunoalvesdefaria "Tools") [📓](#userTesting-brunoalvesdefaria "User Testing") | [Igor Octaviano
Igor Octaviano](http://igoroctaviano.com)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=igoroctaviano "Code") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=igoroctaviano "Documentation") [🚧](#maintenance-igoroctaviano "Maintenance") [👀](#review-igoroctaviano "Reviewed Pull Requests") [📓](#userTesting-igoroctaviano "User Testing") | +| [Bruno Alves de Faria
Bruno Alves de Faria](http://radicalimaging.com/)
[🐛](https://github.com/cornerstonejs/cornerstoneTools/issues?q=author%3Abrunoalvesdefaria "Bug reports") [💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Code") [🖋](#content-brunoalvesdefaria "Content") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Documentation") [🔌](#plugin-brunoalvesdefaria "Plugin/utility libraries") [👀](#review-brunoalvesdefaria "Reviewed Pull Requests") [⚠️](https://github.com/cornerstonejs/cornerstoneTools/commits?author=brunoalvesdefaria "Tests") [🔧](#tool-brunoalvesdefaria "Tools") [📓](#userTesting-brunoalvesdefaria "User Testing") | [Igor Octaviano
Igor Octaviano](http://igoroctaviano.com)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=igoroctaviano "Code") [📖](https://github.com/cornerstonejs/cornerstoneTools/commits?author=igoroctaviano "Documentation") [🚧](#maintenance-igoroctaviano "Maintenance") [👀](#review-igoroctaviano "Reviewed Pull Requests") [📓](#userTesting-igoroctaviano "User Testing") | [Christian Mol
Christian Mol](https://github.com/christianmol)
[💻](https://github.com/cornerstonejs/cornerstoneTools/commits?author=christianmol "Code") | This project follows the [all-contributors][all-contributors] specification. From 37affa2aac5c997a1540c3a234fb6e7ea888ef41 Mon Sep 17 00:00:00 2001 From: Christian Mol Date: Wed, 15 Mar 2023 12:12:02 +0100 Subject: [PATCH 2/2] feat(StackScrollTool): Added invert option that allows scrolling in the opposite direction. Allows the StackScrollTool to be inverted in scroll direction. If used in combination with the scroll wheel tool that already has an invert option, this tool would not follow the same direction, resulting in incoherent behaviour. --- src/tools/StackScrollTool.js | 10 ++++-- src/tools/StackScrollTool.test.js | 54 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/tools/StackScrollTool.js b/src/tools/StackScrollTool.js index 3b43faf16..9835b7c33 100644 --- a/src/tools/StackScrollTool.js +++ b/src/tools/StackScrollTool.js @@ -20,6 +20,7 @@ export default class StackScrollTool extends BaseTool { configuration: { loop: false, allowSkipping: true, + invert: false, }, svgCursor: stackScrollCursor, }; @@ -33,7 +34,7 @@ export default class StackScrollTool extends BaseTool { _dragCallback(evt) { const eventData = evt.detail; const { element, deltaPoints } = eventData; - const { loop, allowSkipping } = this.configuration; + const { loop, allowSkipping, invert } = this.configuration; const options = getToolOptions(this.name, element); const pixelsPerImage = this._getPixelPerImage(element); @@ -46,7 +47,12 @@ export default class StackScrollTool extends BaseTool { if (Math.abs(deltaY) >= pixelsPerImage) { const imageIdIndexOffset = Math.round(deltaY / pixelsPerImage); - scroll(element, imageIdIndexOffset, loop, allowSkipping); + scroll( + element, + invert ? -imageIdIndexOffset : imageIdIndexOffset, + loop, + allowSkipping + ); options.deltaY = deltaY % pixelsPerImage; } else { diff --git a/src/tools/StackScrollTool.test.js b/src/tools/StackScrollTool.test.js index 1b3070b72..8480789a4 100644 --- a/src/tools/StackScrollTool.test.js +++ b/src/tools/StackScrollTool.test.js @@ -43,6 +43,12 @@ describe('StachScroll.js', () => { expect(instantiatedTool.configuration.allowSkipping).toEqual(true); }); + + it('should have default configuration invert as false', () => { + const instantiatedTool = new StackScrollTool(); + + expect(instantiatedTool.configuration.invert).toEqual(false); + }); }); describe('_dragCallback', () => { @@ -74,5 +80,53 @@ describe('StachScroll.js', () => { expect(scroll).not.toHaveBeenCalled(); }); + + it('should call scroll with positive index when DeltaY is positive and invert is set to false', () => { + instantiatedTool._getDeltaY.mockReturnValue(600); + instantiatedTool._getPixelPerImage.mockReturnValue(100); + + instantiatedTool._dragCallback(mockEvent); + + expect(scroll).toHaveBeenCalledWith({}, 6, false, true); + }); + + it('should call scroll with negative index when DeltaY is negative and invert is set to false', () => { + instantiatedTool._getDeltaY.mockReturnValue(-600); + instantiatedTool._getPixelPerImage.mockReturnValue(100); + + instantiatedTool._dragCallback(mockEvent); + + expect(scroll).toHaveBeenCalledWith({}, -6, false, true); + }); + + it('should call scroll with negative index when DeltaY is positive and invert is set to true', () => { + instantiatedTool = new StackScrollTool({ + configuration: { invert: true }, + }); + instantiatedTool._getDeltaY = jest.fn(); + instantiatedTool._getPixelPerImage = jest.fn(); + scroll.mockClear(); + + instantiatedTool._getDeltaY.mockReturnValue(600); + instantiatedTool._getPixelPerImage.mockReturnValue(100); + instantiatedTool._dragCallback(mockEvent); + + expect(scroll).toHaveBeenCalledWith({}, -6, false, true); + }); + + it('should call scroll with positive index when DeltaY is negative and invert is set to true', () => { + instantiatedTool = new StackScrollTool({ + configuration: { invert: true }, + }); + instantiatedTool._getDeltaY = jest.fn(); + instantiatedTool._getPixelPerImage = jest.fn(); + scroll.mockClear(); + + instantiatedTool._getDeltaY.mockReturnValue(-600); + instantiatedTool._getPixelPerImage.mockReturnValue(100); + instantiatedTool._dragCallback(mockEvent); + + expect(scroll).toHaveBeenCalledWith({}, 6, false, true); + }); }); });