dwv 0.30.3 → 0.30.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.30.7](https://github.com/ivmartel/dwv/releases/tag/v0.30.7) - 28/12/2021
4
+
5
+ ### Fixed
6
+
7
+ - Pinch zoom is not working [#1070](https://github.com/ivmartel/dwv/issues/1070)
8
+
9
+ ---
10
+
11
+ ## [v0.30.6](https://github.com/ivmartel/dwv/releases/tag/v0.30.6) - 20/12/2021
12
+
13
+ ### Fixed
14
+
15
+ - Zoom does not stay centred with overlay data [#1066](https://github.com/ivmartel/dwv/issues/1066)
16
+ - Image limit for offset overlap [#1065](https://github.com/ivmartel/dwv/issues/1065)
17
+
18
+ ---
19
+
20
+ ## [v0.30.5](https://github.com/ivmartel/dwv/releases/tag/v0.30.5) - 16/12/2021
21
+
22
+ ### Fixed
23
+
24
+ - Allow to play multi-frame data [#1064](https://github.com/ivmartel/dwv/issues/1064)
25
+ - Allow scroll for multi-frame data [#1063](https://github.com/ivmartel/dwv/issues/1063)
26
+ - Stop worker if no tasks left [#1062](https://github.com/ivmartel/dwv/issues/1062)
27
+
28
+ ---
29
+
30
+ ## [v0.30.4](https://github.com/ivmartel/dwv/releases/tag/v0.30.4) - 10/12/2021
31
+
32
+ ### Fixed
33
+
34
+ - Load i18next plugins as modules [#1057](https://github.com/ivmartel/dwv/issues/1057)
35
+ - Update overlays after event data change [#1056](https://github.com/ivmartel/dwv/issues/1056)
36
+
37
+ ### Dependencies
38
+
39
+ - Replace i18next-xhr-backend with i18next-http-backend [#1049](https://github.com/ivmartel/dwv/issues/1049)
40
+
41
+ ---
42
+
3
43
  ## [v0.30.3](https://github.com/ivmartel/dwv/releases/tag/v0.30.3) - 09/12/2021
4
44
 
5
45
  ### Fixed
package/dist/dwv.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! dwv 0.30.3 2021-12-09 16:13:34 */
1
+ /*! dwv 0.30.7 2021-12-30 11:37:54 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
@@ -6,7 +6,7 @@
6
6
  // AMD. Register as an anonymous module.
7
7
  define([
8
8
  'i18next',
9
- 'i18next-xhr-backend',
9
+ 'i18next-http-backend',
10
10
  'i18next-browser-languagedetector',
11
11
  'jszip',
12
12
  'konva',
@@ -17,11 +17,10 @@
17
17
  // only CommonJS-like environments that support module.exports,
18
18
  // like Node.
19
19
 
20
- // i18next-xhr-backend: requires XMlHttpRequest
21
20
  // Konva: requires 'canvas'
22
21
  module.exports = factory(
23
22
  require('i18next'),
24
- require('i18next-xhr-backend'),
23
+ require('i18next-http-backend'),
25
24
  require('i18next-browser-languagedetector'),
26
25
  require('jszip'),
27
26
  require('konva/cmj'),
@@ -31,7 +30,7 @@
31
30
  // Browser globals (root is window)
32
31
  root.dwv = factory(
33
32
  root.i18next,
34
- root.i18nextXHRBackend,
33
+ root.i18nextHttpBackend,
35
34
  root.i18nextBrowserLanguageDetector,
36
35
  root.JSZip,
37
36
  root.Konva,
@@ -40,7 +39,7 @@
40
39
  }
41
40
  }(this, function (
42
41
  i18next,
43
- i18nextXHRBackend,
42
+ i18nextHttpBackend,
44
43
  i18nextBrowserLanguageDetector,
45
44
  JSZip,
46
45
  Konva,
@@ -49,20 +48,27 @@
49
48
  // similar to what browserify does but reversed
50
49
  // https://www.contentful.com/blog/2017/01/17/the-global-object-in-javascript/
51
50
  var window = typeof window !== 'undefined' ?
52
- window : typeof self !== 'undefined' ?
53
- self : typeof global !== 'undefined' ?
54
- global : {};
55
-
56
- // latest i18next (>v17) does not export default
57
- // see #862 and https://github.com/i18next/i18next/commit/7c6c235
58
- if (typeof i18next !== 'undefined' &&
59
- typeof i18next.t === 'undefined') {
51
+ window : typeof self !== 'undefined' ?
52
+ self : typeof global !== 'undefined' ?
53
+ global : {};
54
+
55
+ // if it has a default, treat it as ESM
56
+ var isEsmModule = function (mod) {
57
+ return typeof mod !== 'undefined' &&
58
+ typeof mod.default !== 'undefined';
59
+ }
60
+ // i18next (>v17) comes as a module, see #862
61
+ if (isEsmModule(i18next)) {
60
62
  i18next = i18next.default;
61
63
  }
62
-
64
+ if (isEsmModule(i18nextHttpBackend)) {
65
+ i18nextHttpBackend = i18nextHttpBackend.default;
66
+ }
67
+ if (isEsmModule(i18nextBrowserLanguageDetector)) {
68
+ i18nextBrowserLanguageDetector = i18nextBrowserLanguageDetector.default;
69
+ }
63
70
  // Konva (>=v8) comes as a module, see #1044
64
- if (typeof Konva !== 'undefined' &&
65
- typeof Konva.Group === 'undefined') {
71
+ if (isEsmModule(Konva)) {
66
72
  Konva = Konva.default;
67
73
  }
68
74
 
@@ -525,7 +531,12 @@ dwv.App = function () {
525
531
  this.fitToContainer = function () {
526
532
  var layerGroup = stage.getActiveLayerGroup();
527
533
  if (layerGroup) {
528
- layerGroup.fitToContainer(self.getLastImage().getGeometry());
534
+ var geometry = self.getLastImage().getGeometry();
535
+ var size = geometry.getSize().get2D();
536
+ var spacing = geometry.getSpacing().get2D();
537
+ var width = size.x * spacing.x;
538
+ var height = size.y * spacing.y;
539
+ layerGroup.fitToContainer({x: width, y: height});
529
540
  layerGroup.draw();
530
541
  // update style
531
542
  //style.setBaseScale(layerGroup.getBaseScale());
@@ -1311,7 +1322,27 @@ dwv.App = function () {
1311
1322
  }
1312
1323
  }
1313
1324
 
1314
- layerGroup.fitToContainer();
1325
+ // fit to the maximum size
1326
+ var maxSize = {x: 0, y: 0};
1327
+ for (var i = 0; i < dataController.length(); ++i) {
1328
+ var dc = dataController.get(i);
1329
+ var geometry = dc.image.getGeometry();
1330
+ var viewOrient = dwv.gui.getViewOrientation(
1331
+ geometry,
1332
+ layerGroup.getTargetOrientation()
1333
+ );
1334
+ var size = geometry.getSize(viewOrient).get2D();
1335
+ var spacing = geometry.getSpacing(viewOrient).get2D();
1336
+ var width = size.x * spacing.x;
1337
+ if (width > maxSize.x) {
1338
+ maxSize.x = width;
1339
+ }
1340
+ var height = size.y * spacing.y;
1341
+ if (height > maxSize.y) {
1342
+ maxSize.y = height;
1343
+ }
1344
+ }
1345
+ layerGroup.fitToContainer(maxSize);
1315
1346
  }
1316
1347
 
1317
1348
  };
@@ -2807,7 +2838,8 @@ dwv.ctrl.ViewController = function (view) {
2807
2838
  /**
2808
2839
  * Can the data be scrolled?
2809
2840
  *
2810
- * @returns {boolean} True if the data has a third dimension greater than one.
2841
+ * @returns {boolean} True if the data has either the third dimension
2842
+ * or above greater than one.
2811
2843
  */
2812
2844
  this.canScroll = function () {
2813
2845
  return view.getImage().canScroll(view.getOrientation());
@@ -2953,22 +2985,36 @@ dwv.ctrl.ViewController = function (view) {
2953
2985
  * Scroll play: loop through all slices.
2954
2986
  */
2955
2987
  this.play = function () {
2988
+ // ensure data is scrollable: dim >= 3
2956
2989
  if (!this.canScroll()) {
2957
2990
  return;
2958
2991
  }
2959
2992
  if (playerID === null) {
2993
+ var image = view.getImage();
2960
2994
  var recommendedDisplayFrameRate =
2961
- view.getImage().getMeta().RecommendedDisplayFrameRate;
2995
+ image.getMeta().RecommendedDisplayFrameRate;
2962
2996
  var milliseconds = view.getPlaybackMilliseconds(
2963
2997
  recommendedDisplayFrameRate);
2998
+ var size = image.getGeometry().getSize();
2999
+ var canScroll3D = size.canScroll3D();
2964
3000
 
2965
3001
  playerID = setInterval(function () {
3002
+ var canDoMore = false;
3003
+ if (canScroll3D) {
3004
+ canDoMore = self.incrementScrollIndex();
3005
+ } else {
3006
+ canDoMore = self.incrementIndex(3);
3007
+ }
2966
3008
  // end of scroll, loop back
2967
- if (!self.incrementScrollIndex()) {
3009
+ if (!canDoMore) {
2968
3010
  var pos1 = self.getCurrentIndex();
2969
3011
  var values = pos1.getValues();
2970
3012
  var orientation = view.getOrientation();
2971
- values[orientation.getThirdColMajorDirection()] = 0;
3013
+ if (canScroll3D) {
3014
+ values[orientation.getThirdColMajorDirection()] = 0;
3015
+ } else {
3016
+ values[3] = 0;
3017
+ }
2972
3018
  var index = new dwv.math.Index(values);
2973
3019
  var geometry = view.getImage().getGeometry();
2974
3020
  self.setCurrentPosition(geometry.indexToWorld(index));
@@ -4398,7 +4444,7 @@ dwv.dicom = dwv.dicom || {};
4398
4444
  * @returns {string} The version of the library.
4399
4445
  */
4400
4446
  dwv.getVersion = function () {
4401
- return '0.30.3';
4447
+ return '0.30.7';
4402
4448
  };
4403
4449
 
4404
4450
  /**
@@ -11191,18 +11237,6 @@ dwv.gui.DrawLayer = function (containerDiv) {
11191
11237
  return containerDiv.id;
11192
11238
  };
11193
11239
 
11194
- /**
11195
- * Get the data full size, ie size * spacing.
11196
- *
11197
- * @returns {object} The full size as {x,y}.
11198
- */
11199
- this.getFullSize = function () {
11200
- return {
11201
- x: baseSize.x * baseSpacing.x,
11202
- y: baseSize.y * baseSpacing.y
11203
- };
11204
- };
11205
-
11206
11240
  /**
11207
11241
  * Get the layer base size (without scale).
11208
11242
  *
@@ -11342,19 +11376,17 @@ dwv.gui.DrawLayer = function (containerDiv) {
11342
11376
  * Fit the layer to its parent container.
11343
11377
  *
11344
11378
  * @param {number} fitScale1D The 1D fit scale.
11379
+ * @param {object} fitSize The fit size as {x,y}.
11345
11380
  */
11346
- this.fitToContainer = function (fitScale1D) {
11381
+ this.fitToContainer = function (fitScale1D, fitSize) {
11347
11382
  // update fit scale
11348
11383
  fitScale = {
11349
11384
  x: fitScale1D * baseSpacing.x,
11350
11385
  y: fitScale1D * baseSpacing.y
11351
11386
  };
11352
11387
  // update konva
11353
- var fullSize = this.getFullSize();
11354
- var width = Math.floor(fullSize.x * fitScale1D);
11355
- var height = Math.floor(fullSize.y * fitScale1D);
11356
- konvaStage.setWidth(width);
11357
- konvaStage.setHeight(height);
11388
+ konvaStage.setWidth(fitSize.x);
11389
+ konvaStage.setHeight(fitSize.y);
11358
11390
  // reset scale
11359
11391
  this.setScale({x: 1, y: 1, z: 1});
11360
11392
  };
@@ -12102,24 +12134,27 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
12102
12134
  /**
12103
12135
  * Fit the display to the size of the container.
12104
12136
  * To be called once the image is loaded.
12137
+ *
12138
+ * @param {object} realSize 2D real size (in mm) to fit provided as {x,y}.
12105
12139
  */
12106
- this.fitToContainer = function () {
12140
+ this.fitToContainer = function (realSize) {
12107
12141
  // check container size
12108
12142
  if (containerDiv.offsetWidth === 0 &&
12109
12143
  containerDiv.offsetHeight === 0) {
12110
12144
  throw new Error('Cannot fit to zero sized container.');
12111
12145
  }
12112
12146
  // find best fit
12113
- var fitScales = [];
12114
- for (var i = 0; i < layers.length; ++i) {
12115
- var fullSize = layers[i].getFullSize();
12116
- fitScales.push(containerDiv.offsetWidth / fullSize.x);
12117
- fitScales.push(containerDiv.offsetHeight / fullSize.y);
12118
- }
12119
- var fitScale = Math.min.apply(null, fitScales);
12147
+ var fitScale = Math.min(
12148
+ containerDiv.offsetWidth / realSize.x,
12149
+ containerDiv.offsetHeight / realSize.y
12150
+ );
12151
+ var fitSize = {
12152
+ x: Math.floor(realSize.x * fitScale),
12153
+ y: Math.floor(realSize.y * fitScale)
12154
+ };
12120
12155
  // apply to layers
12121
12156
  for (var j = 0; j < layers.length; ++j) {
12122
- layers[j].fitToContainer(fitScale);
12157
+ layers[j].fitToContainer(fitScale, fitSize);
12123
12158
  }
12124
12159
  };
12125
12160
 
@@ -13107,18 +13142,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13107
13142
  return containerDiv.id;
13108
13143
  };
13109
13144
 
13110
- /**
13111
- * Get the data full size, ie size * spacing.
13112
- *
13113
- * @returns {object} The full size as {x,y}.
13114
- */
13115
- this.getFullSize = function () {
13116
- return {
13117
- x: baseSize.x * baseSpacing.x,
13118
- y: baseSize.y * baseSpacing.y
13119
- };
13120
- };
13121
-
13122
13145
  /**
13123
13146
  * Get the layer base size (without scale).
13124
13147
  *
@@ -13218,6 +13241,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13218
13241
  ]);
13219
13242
  };
13220
13243
 
13244
+ /**
13245
+ * Remove scale from a display position.
13246
+ *
13247
+ * @param {number} x The X position.
13248
+ * @param {number} y The Y position.
13249
+ * @returns {object} The de-scaled position as {x,y}.
13250
+ */
13221
13251
  this.displayToPlaneScale = function (x, y) {
13222
13252
  return {
13223
13253
  x: x / scale.x,
@@ -13225,6 +13255,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13225
13255
  };
13226
13256
  };
13227
13257
 
13258
+ /**
13259
+ * Get a plane position from a display position.
13260
+ *
13261
+ * @param {number} x The X position.
13262
+ * @param {number} y The Y position.
13263
+ * @returns {object} The plane position as {x,y}.
13264
+ */
13228
13265
  this.displayToPlanePos = function (x, y) {
13229
13266
  var deScaled = this.displayToPlaneScale(x, y);
13230
13267
  return {
@@ -13233,6 +13270,21 @@ dwv.gui.ViewLayer = function (containerDiv) {
13233
13270
  };
13234
13271
  };
13235
13272
 
13273
+ /**
13274
+ * Get a main plane position from a display position.
13275
+ *
13276
+ * @param {number} x The X position.
13277
+ * @param {number} y The Y position.
13278
+ * @returns {object} The main plane position as {x,y}.
13279
+ */
13280
+ this.displayToMainPlanePos = function (x, y) {
13281
+ var planePos = this.displayToPlanePos(x, y);
13282
+ return {
13283
+ x: planePos.x - baseOffset.x,
13284
+ y: planePos.y - baseOffset.y
13285
+ };
13286
+ };
13287
+
13236
13288
  /**
13237
13289
  * Display the layer.
13238
13290
  *
@@ -13337,6 +13389,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
13337
13389
  dataIndex = index;
13338
13390
 
13339
13391
  // create canvas
13392
+ // (canvas size is set in fitToContainer)
13340
13393
  canvas = document.createElement('canvas');
13341
13394
  containerDiv.appendChild(canvas);
13342
13395
 
@@ -13357,9 +13410,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13357
13410
  throw new Error('Cannot create canvas ' + baseSize.x + ', ' + baseSize.y);
13358
13411
  }
13359
13412
 
13360
- // canvas sizes
13361
- canvas.width = baseSize.x;
13362
- canvas.height = baseSize.y;
13363
13413
  // off screen canvas
13364
13414
  offscreenCanvas = document.createElement('canvas');
13365
13415
  offscreenCanvas.width = baseSize.x;
@@ -13376,17 +13426,17 @@ dwv.gui.ViewLayer = function (containerDiv) {
13376
13426
  * Fit the layer to its parent container.
13377
13427
  *
13378
13428
  * @param {number} fitScale1D The 1D fit scale.
13429
+ * @param {object} fitSize The fit size as {x,y}.
13379
13430
  */
13380
- this.fitToContainer = function (fitScale1D) {
13431
+ this.fitToContainer = function (fitScale1D, fitSize) {
13381
13432
  // update fit scale
13382
13433
  fitScale = {
13383
13434
  x: fitScale1D * baseSpacing.x,
13384
13435
  y: fitScale1D * baseSpacing.y
13385
13436
  };
13386
- // update canvas
13387
- var fullSize = this.getFullSize();
13388
- var width = Math.floor(fullSize.x * fitScale1D);
13389
- var height = Math.floor(fullSize.y * fitScale1D);
13437
+ // new canvas size
13438
+ var width = fitSize.x;
13439
+ var height = fitSize.y;
13390
13440
  if (!dwv.gui.canCreateCanvas(width, height)) {
13391
13441
  throw new Error('Cannot resize canvas ' + width + ', ' + height);
13392
13442
  }
@@ -17737,13 +17787,12 @@ dwv.image.Size.prototype.moreThanOne = function (dimension) {
17737
17787
  };
17738
17788
 
17739
17789
  /**
17740
- * Check if the third direction of an orientation matrix has a size
17741
- * of more than one.
17790
+ * Check if the associated data is scrollable in 3D.
17742
17791
  *
17743
17792
  * @param {dwv.math.Matrix33} viewOrientation The orientation matrix.
17744
17793
  * @returns {boolean} True if scrollable.
17745
17794
  */
17746
- dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17795
+ dwv.image.Size.prototype.canScroll3D = function (viewOrientation) {
17747
17796
  var dimension = 2;
17748
17797
  if (typeof viewOrientation !== 'undefined') {
17749
17798
  dimension = viewOrientation.getThirdColMajorDirection();
@@ -17751,6 +17800,22 @@ dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17751
17800
  return this.moreThanOne(dimension);
17752
17801
  };
17753
17802
 
17803
+ /**
17804
+ * Check if the associated data is scrollable: either in 3D or
17805
+ * in other directions.
17806
+ *
17807
+ * @param {dwv.math.Matrix33} viewOrientation The orientation matrix.
17808
+ * @returns {boolean} True if scrollable.
17809
+ */
17810
+ dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17811
+ var canScroll = this.canScroll3D(viewOrientation);
17812
+ // check possible other dimensions
17813
+ for (var i = 3; i < this.length(); ++i) {
17814
+ canScroll = canScroll || this.moreThanOne(i);
17815
+ }
17816
+ return canScroll;
17817
+ };
17818
+
17754
17819
  /**
17755
17820
  * Get the size of a given dimension.
17756
17821
  *
@@ -31006,9 +31071,9 @@ dwv.tool.Scroll = function (app) {
31006
31071
  if (xMove && imageSize.moreThanOne(3)) {
31007
31072
  // update view controller
31008
31073
  if (diffX > 0) {
31009
- viewController.decrementIndex(3);
31010
- } else {
31011
31074
  viewController.incrementIndex(3);
31075
+ } else {
31076
+ viewController.decrementIndex(3);
31012
31077
  }
31013
31078
  }
31014
31079
 
@@ -31642,8 +31707,9 @@ dwv.tool.ZoomAndPan = function (app) {
31642
31707
  // zoom mode
31643
31708
  var zoom = (lineRatio - 1) / 2;
31644
31709
  if (Math.abs(zoom) % 0.1 <= 0.05) {
31645
- var planePos = viewLayer.displayToPlanePos(event._x, event._y);
31646
- var center = viewController.getPositionFromPlanePoint(planePos);
31710
+ var planePos = viewLayer.displayToMainPlanePos(
31711
+ self.midPoint.getX(), self.midPoint.getY());
31712
+ var center = viewController.getPlanePositionFromPlanePoint(planePos);
31647
31713
  layerGroup.addScale(zoom, center);
31648
31714
  layerGroup.draw();
31649
31715
  }
@@ -31720,7 +31786,7 @@ dwv.tool.ZoomAndPan = function (app) {
31720
31786
  var layerGroup = app.getLayerGroupById(layerDetails.groupId);
31721
31787
  var viewLayer = layerGroup.getActiveViewLayer();
31722
31788
  var viewController = viewLayer.getViewController();
31723
- var planePos = viewLayer.displayToPlanePos(event._x, event._y);
31789
+ var planePos = viewLayer.displayToMainPlanePos(event._x, event._y);
31724
31790
  var center = viewController.getPlanePositionFromPlanePoint(planePos);
31725
31791
  layerGroup.addScale(step, center);
31726
31792
  layerGroup.draw();
@@ -32351,12 +32417,12 @@ var dwv = dwv || {};
32351
32417
  */
32352
32418
  var i18next = i18next || {};
32353
32419
  /**
32354
- * The i18nextXHRBackend namespace.
32420
+ * The i18nextHttpBackend namespace.
32355
32421
  *
32356
- * @external i18nextXHRBackend
32357
- * @see https://github.com/i18next/i18next-xhr-backend
32422
+ * @external i18nextHttpBackend
32423
+ * @see https://github.com/i18next/i18next-http-backend
32358
32424
  */
32359
- var i18nextXHRBackend = i18nextXHRBackend || {};
32425
+ var i18nextHttpBackend = i18nextHttpBackend || {};
32360
32426
  /**
32361
32427
  * The i18nextBrowserLanguageDetector namespace.
32362
32428
  *
@@ -32390,8 +32456,8 @@ dwv.i18nInitialise = function (language, localesPath) {
32390
32456
  load: 'languageOnly',
32391
32457
  backend: {loadPath: lpath + '/locales/{{lng}}/{{ns}}.json'}
32392
32458
  };
32393
- // use the XHR backend to get translation files
32394
- var i18n = i18next.use(i18nextXHRBackend);
32459
+ // use the HTTP backend to get translation files
32460
+ var i18n = i18next.use(i18nextHttpBackend);
32395
32461
  // use browser language or the specified one
32396
32462
  if (lng === 'auto') {
32397
32463
  i18n.use(i18nextBrowserLanguageDetector);
@@ -34031,6 +34097,8 @@ dwv.utils.ThreadPool = function (poolSize) {
34031
34097
  // use input thread to run the waiting task
34032
34098
  workerThread.run(workerTask);
34033
34099
  } else {
34100
+ // stop the worker
34101
+ workerThread.stop();
34034
34102
  // no task to run, add to free list
34035
34103
  freeThreads.push(workerThread);
34036
34104
  // remove from running list