Switch Random.id() to Math.random() for triggering reactive updates. Random.id() is taking 40ms on Chrome for some reason

This commit is contained in:
Erik Ziegler 2017-10-25 13:11:44 +02:00
parent 05d9a41f45
commit 37fff25b50
7 changed files with 16 additions and 17 deletions

View File

@ -4,7 +4,6 @@
// Pull request: https://github.com/chafey/cornerstoneTools/pull/230 // Pull request: https://github.com/chafey/cornerstoneTools/pull/230
import { cornerstone, cornerstoneTools, cornerstoneMath } from 'meteor/ohif:cornerstone'; import { cornerstone, cornerstoneTools, cornerstoneMath } from 'meteor/ohif:cornerstone';
cornerstoneTools.copyPoints
const { copyPoints, pauseEvent } = cornerstoneTools; const { copyPoints, pauseEvent } = cornerstoneTools;
let isClickEvent = true; let isClickEvent = true;

View File

@ -212,7 +212,7 @@ Template.stageSortable.events({
} }
// Update the Session variable to the UI re-renders // Update the Session variable to the UI re-renders
Session.set('LayoutManagerUpdated', Random.id()); Session.set('LayoutManagerUpdated', Math.random());
}, options); }, options);
}, },
@ -234,7 +234,7 @@ Template.stageSortable.events({
ProtocolEngine.stage = newIndex; ProtocolEngine.stage = newIndex;
// Update the Session variable to the UI re-renders // Update the Session variable to the UI re-renders
Session.set('LayoutManagerUpdated', Random.id()); Session.set('LayoutManagerUpdated', Math.random());
}, },
'click .moveStageDown': function() { 'click .moveStageDown': function() {
// Get the old and new indices following a 'sort' event // Get the old and new indices following a 'sort' event
@ -254,6 +254,6 @@ Template.stageSortable.events({
ProtocolEngine.stage = newIndex; ProtocolEngine.stage = newIndex;
// Update the Session variable to the UI re-renders // Update the Session variable to the UI re-renders
Session.set('LayoutManagerUpdated', Random.id()); Session.set('LayoutManagerUpdated', Math.random());
} }
}); });

View File

@ -60,7 +60,7 @@ Template.cineDialog.onCreated(() => {
playClipData.framesPerSecond = OHIF.viewer.cine.framesPerSecond; playClipData.framesPerSecond = OHIF.viewer.cine.framesPerSecond;
} }
Session.set('UpdateCINE', Random.id()); Session.set('UpdateCINE', Math.random());
}; };
// Define the actions API // Define the actions API
@ -123,7 +123,7 @@ Template.cineDialog.onCreated(() => {
} }
// Update the session to refresh the framerate text // Update the session to refresh the framerate text
Session.set('UpdateCINE', Random.id()); Session.set('UpdateCINE', Math.random());
}); });
}); });

View File

@ -63,7 +63,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
// Sets the global variable // Sets the global variable
OHIF.viewer.cine.framesPerSecond = parseFloat(stack.frameRate); OHIF.viewer.cine.framesPerSecond = parseFloat(stack.frameRate);
// Update the cine dialog FPS // Update the cine dialog FPS
Session.set('UpdateCINE', Random.id()); Session.set('UpdateCINE', Math.random());
} }
// Shortcut for array with image IDs // Shortcut for array with image IDs
@ -284,7 +284,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
// Use Session to trigger reactive updates in the viewportOverlay helper functions // Use Session to trigger reactive updates in the viewportOverlay helper functions
// This lets the viewport overlay always display correct window / zoom values // This lets the viewport overlay always display correct window / zoom values
Session.set('CornerstoneImageRendered' + viewportIndex, Random.id()); Session.set('CornerstoneImageRendered' + viewportIndex, Math.random());
// Save the current viewport into the OHIF.viewer.data global variable // Save the current viewport into the OHIF.viewer.data global variable
const viewport = cornerstone.getViewport(element); const viewport = cornerstone.getViewport(element);
@ -302,7 +302,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
$element.on('CornerstoneImageRendered', onImageRendered); $element.on('CornerstoneImageRendered', onImageRendered);
// Set a random value for the Session variable in order to trigger an overlay update // Set a random value for the Session variable in order to trigger an overlay update
Session.set('CornerstoneImageRendered' + viewportIndex, Random.id()); Session.set('CornerstoneImageRendered' + viewportIndex, Math.random());
// Define a function to run whenever the Cornerstone viewport changes images // Define a function to run whenever the Cornerstone viewport changes images
// (e.g. during scrolling) // (e.g. during scrolling)
@ -319,7 +319,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
// Update the templateData with the new imageId // Update the templateData with the new imageId
// This allows the template helpers to update reactively // This allows the template helpers to update reactively
templateData.imageId = eventData.enabledElement.image.imageId; templateData.imageId = eventData.enabledElement.image.imageId;
Session.set('CornerstoneNewImage' + viewportIndex, Random.id()); Session.set('CornerstoneNewImage' + viewportIndex, Math.random());
layoutManager.viewportData[viewportIndex].imageId = eventData.enabledElement.image.imageId; layoutManager.viewportData[viewportIndex].imageId = eventData.enabledElement.image.imageId;
// Get the element and stack data // Get the element and stack data
@ -353,7 +353,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
$element.on('CornerstoneNewImage', onNewImage); $element.on('CornerstoneNewImage', onNewImage);
// Set a random value for the Session variable in order to trigger an overlay update // Set a random value for the Session variable in order to trigger an overlay update
Session.set('CornerstoneNewImage' + viewportIndex, Random.id()); Session.set('CornerstoneNewImage' + viewportIndex, Math.random());
const onStackScroll = (e, eventData) => { const onStackScroll = (e, eventData) => {
// Attention: Adding OHIF.log.info in this function may decrease the performance // Attention: Adding OHIF.log.info in this function may decrease the performance
@ -361,7 +361,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
// enabled/disabled -> cornerstone[toolName].tool.enable) // enabled/disabled -> cornerstone[toolName].tool.enable)
// Update the imageSlider value // Update the imageSlider value
Session.set('CornerstoneNewImage' + viewportIndex, Random.id()); Session.set('CornerstoneNewImage' + viewportIndex, Math.random());
}; };
$element.off('CornerstoneStackScroll', onStackScroll); $element.off('CornerstoneStackScroll', onStackScroll);

View File

@ -46,7 +46,7 @@ Template.viewerMain.onRendered(() => {
OHIF.viewerbase.layoutManager = new LayoutManager(parentElement, studies); OHIF.viewerbase.layoutManager = new LayoutManager(parentElement, studies);
studyPrefetcher.setStudies(studies); studyPrefetcher.setStudies(studies);
Session.set('OHIFViewerMainRendered', Random.id()); Session.set('OHIFViewerMainRendered', Math.random());
}); });
Template.viewerMain.onDestroyed(() => { Template.viewerMain.onDestroyed(() => {

View File

@ -30,7 +30,7 @@ export class LayoutManager {
this.isZoomed = false; this.isZoomed = false;
const updateSessionFn = () => Tracker.afterFlush(() => Session.set('LayoutManagerUpdated', Random.id())); const updateSessionFn = () => Tracker.afterFlush(() => Session.set('LayoutManagerUpdated', Math.random()));
this.updateSession = _.throttle(updateSessionFn, 300); this.updateSession = _.throttle(updateSessionFn, 300);
} }

View File

@ -188,7 +188,7 @@ const toggleDialog = element => {
$element.toggleClass('dialog-open', !isClosed); $element.toggleClass('dialog-open', !isClosed);
} }
Session.set('UpdateCINE', Random.id()); Session.set('UpdateCINE', Math.random());
}; };
// Toggle the play/stop state for the cornerstone clip tool // Toggle the play/stop state for the cornerstone clip tool
@ -204,7 +204,7 @@ const toggleCinePlay = () => {
} }
// Update the UpdateCINE session property // Update the UpdateCINE session property
Session.set('UpdateCINE', Random.id()); Session.set('UpdateCINE', Math.random());
}; };
// Show/hide the CINE dialog // Show/hide the CINE dialog
@ -305,7 +305,7 @@ const isStackScrollLinkingDisabled = () => {
}; };
// Create an event listener to update playing state when a clip stops playing // Create an event listener to update playing state when a clip stops playing
$(window).on('CornerstoneToolsClipStopped', () => Session.set('UpdateCINE', Random.id())); $(window).on('CornerstoneToolsClipStopped', () => Session.set('UpdateCINE', Math.random()));
/** /**
* Export functions inside viewportUtils namespace. * Export functions inside viewportUtils namespace.