-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cachedStatistics throttling and textBox rendering (#329)
* fix: throttling of the cachedStats * rebased modifications
- Loading branch information
Showing
8 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/cornerstone-tools/src/eventDispatchers/measurementModifiedEventDispatcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
eventTarget, | ||
getRenderingEngine, | ||
} from '@precisionmetrics/cornerstone-render' | ||
import EVENTS from '../enums/CornerstoneTools3DEvents' | ||
import triggerAnnotationRenderForViewportUIDs from '../util/triggerAnnotationRenderForViewportUIDs' | ||
|
||
/** | ||
* This is a callback function that is called when a measurement is modified. | ||
* Since we are throttling the cachedStats calculation for annotation tools, | ||
* we need to trigger a final render for the toolData so that the measurement | ||
* textBox is updated. | ||
* Todo: This will trigger all the annotation tools to re-render, although DOM | ||
* will update those that have changed, but more efficient would be to only | ||
* update the changed toolData. | ||
* Todo: A better way is to extract the textBox render logic from the renderToolData | ||
* of all tools and just trigger a render for that (instead of the entire toolData, even if | ||
* no svg update happens since the attributes for handles are the same) | ||
*/ | ||
const onMeasurementModified = function (evt) { | ||
const { viewportUID, renderingEngineUID } = evt.detail | ||
const renderingEngine = getRenderingEngine(renderingEngineUID) | ||
triggerAnnotationRenderForViewportUIDs(renderingEngine, [viewportUID]) | ||
} | ||
|
||
const enable = function () { | ||
eventTarget.addEventListener( | ||
EVENTS.MEASUREMENT_MODIFIED, | ||
onMeasurementModified | ||
) | ||
} | ||
|
||
const disable = function () { | ||
eventTarget.removeEventListener( | ||
EVENTS.MEASUREMENT_MODIFIED, | ||
onMeasurementModified | ||
) | ||
} | ||
|
||
export default { | ||
enable, | ||
disable, | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cornerstone-tools/src/eventListeners/annotations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import measurementSelectionListener from './measurementSelectionListener' | ||
import measurementModifiedListener from './measurementModifiedListener' | ||
|
||
export { measurementSelectionListener, measurementModifiedListener } |
22 changes: 22 additions & 0 deletions
22
packages/cornerstone-tools/src/eventListeners/annotations/measurementModifiedListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getRenderingEngine } from '@precisionmetrics/cornerstone-render' | ||
import triggerAnnotationRenderForViewportUIDs from '../../util/triggerAnnotationRenderForViewportUIDs' | ||
|
||
/** | ||
* This is a callback function that is called when a measurement is modified. | ||
* Since we are throttling the cachedStats calculation for annotation tools, | ||
* we need to trigger a final render for the toolData so that the measurement | ||
* textBox is updated. | ||
* Todo: This will trigger all the annotation tools to re-render, although DOM | ||
* will update those that have changed, but more efficient would be to only | ||
* update the changed toolData. | ||
* Todo: A better way is to extract the textBox render logic from the renderToolData | ||
* of all tools and just trigger a render for that (instead of the entire toolData, even if | ||
* no svg update happens since the attributes for handles are the same) | ||
*/ | ||
function measurementModifiedListener(evt): void { | ||
const { viewportUID, renderingEngineUID } = evt.detail | ||
const renderingEngine = getRenderingEngine(renderingEngineUID) | ||
triggerAnnotationRenderForViewportUIDs(renderingEngine, [viewportUID]) | ||
} | ||
|
||
export default measurementModifiedListener |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/cornerstone-tools/src/eventListeners/toolStyles/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters