Skip to content

Commit

Permalink
Added a global UUID to cornerstone enabled elements to allow for easy…
Browse files Browse the repository at this point in the history
… tracking of elements from other libraries (e.g. cornerstoneTools).
  • Loading branch information
James Petts committed Sep 18, 2018
1 parent 06770b5 commit 790a31c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import drawImageSync from './internal/drawImageSync.js';
import requestAnimationFrame from './internal/requestAnimationFrame.js';
import tryEnableWebgl from './internal/tryEnableWebgl.js';
import triggerEvent from './triggerEvent.js';
import generateUUID from './generateUUID.js';
import EVENTS from './events.js';
import getCanvas from './internal/getCanvas.js';

Expand Down Expand Up @@ -60,7 +61,8 @@ export default function (element, options) {
options,
layers: [],
data: {},
renderingTools: {}
renderingTools: {},
uuid: generateUUID()
};

addEnabledElement(enabledElement);
Expand Down
21 changes: 21 additions & 0 deletions src/generateUUID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Generates a UUID for the enabledElement.
*
* @return {String} the UUID.
*/
export default function () { // https://stackoverflow.com/a/8809472/9208320 Public Domain/MIT
/* eslint no-bitwise: ["error", { "allow": ["&","|"] }] */
let d = new Date().getTime();

if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
d += performance.now(); // Use high-precision timer if available
}

return 'x.x.x.x.x.x.xxxx.xxx.x.x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (d + Math.random() * 16) % 16 | 0;

d = Math.floor(d / 16);

return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}

0 comments on commit 790a31c

Please sign in to comment.