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(StackViewport): weird interaction between scroll() and setImageIdIndex() #1208

Open
wants to merge 2 commits into
base: main
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ interface IStackViewport extends IViewport {
// (undocumented)
setDefaultProperties(ViewportProperties: StackViewportProperties, imageId?: string): void;
// (undocumented)
setImageIdIndex(imageIdIndex: number): Promise<string>;
setImageIdIndex(imageIdIndex: number, overwriteScrollIndex?: boolean): Promise<string>;
// (undocumented)
setProperties({ voiRange, invert, interpolationType, rotation, colormap, }: StackViewportProperties, suppressEvents?: boolean): void;
// (undocumented)
Expand Down Expand Up @@ -3138,7 +3138,7 @@ export class StackViewport extends Viewport implements IStackViewport, IImagesLo
// (undocumented)
setDefaultProperties(ViewportProperties: StackViewportProperties, imageId?: string): void;
// (undocumented)
setImageIdIndex(imageIdIndex: number): Promise<string>;
setImageIdIndex(imageIdIndex: number, overwriteScrollIndex?: any): Promise<string>;
// (undocumented)
protected setInterpolationType: (interpolationType: InterpolationType) => void;
// (undocumented)
Expand Down
20 changes: 17 additions & 3 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2445,8 +2445,12 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
/**
* Loads the image based on the provided imageIdIndex
* @param imageIdIndex - number represents imageId index
* @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index
*/
private async _setImageIdIndex(imageIdIndex: number): Promise<string> {
private async _setImageIdIndex(
imageIdIndex: number,
overwriteScrollIndex?: boolean
): Promise<string> {
if (imageIdIndex >= this.imageIds.length) {
throw new Error(
`ImageIdIndex provided ${imageIdIndex} is invalid, the stack only has ${this.imageIds.length} elements`
Expand All @@ -2455,6 +2459,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {

// Update the state of the viewport to the new imageIdIndex;
this.currentImageIdIndex = imageIdIndex;
if (overwriteScrollIndex) {
this.targetImageIdIndex = this.currentImageIdIndex;
}
this.hasPixelSpacing = true;
this.viewportStatus = ViewportStatus.PRE_RENDER;

Expand Down Expand Up @@ -2583,8 +2590,12 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
*
* @param imageIdIndex - number represents imageId index in the list of
* provided imageIds in setStack
* @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index
*/
public setImageIdIndex(imageIdIndex: number): Promise<string> {
public setImageIdIndex(
imageIdIndex: number,
overwriteScrollIndex?
): Promise<string> {
this._throwIfDestroyed();

// If we are already on this imageId index, stop here
Expand All @@ -2593,7 +2604,10 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
}

// Otherwise, get the imageId and attempt to display it
const imageIdPromise = this._setImageIdIndex(imageIdIndex);
const imageIdPromise = this._setImageIdIndex(
imageIdIndex,
overwriteScrollIndex
);

return imageIdPromise;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/types/IStackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ export default interface IStackViewport extends IViewport {
* Loads the image based on the provided imageIdIndex. It is an Async function which
* returns a promise that resolves to the imageId.
*/
setImageIdIndex(imageIdIndex: number): Promise<string>;
setImageIdIndex(
imageIdIndex: number,
overwriteScrollIndex?: boolean
): Promise<string>;
/**
* Calibrates the image with new metadata that has been added for imageId. To calibrate
* a viewport, you should add your calibration data manually to
Expand Down