dwv 0.31.0-rc.0 → 0.31.1

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/dist/dwv.js CHANGED
@@ -1,13 +1,10 @@
1
- /*! dwv 0.31.0-rc.0 2023-02-24 11:35:58 */
1
+ /*! dwv 0.31.1 2023-04-27 19:37:50 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
5
5
  if (typeof define === 'function' && define.amd) {
6
6
  // AMD. Register as an anonymous module.
7
7
  define([
8
- 'i18next',
9
- 'i18next-http-backend',
10
- 'i18next-browser-languagedetector',
11
8
  'jszip',
12
9
  'konva',
13
10
  'magic-wand-tool'
@@ -19,9 +16,6 @@
19
16
 
20
17
  // Konva: requires 'canvas'
21
18
  module.exports = factory(
22
- require('i18next'),
23
- require('i18next-http-backend'),
24
- require('i18next-browser-languagedetector'),
25
19
  require('jszip'),
26
20
  require('konva/cmj'),
27
21
  require('magic-wand-tool')
@@ -29,18 +23,12 @@
29
23
  } else {
30
24
  // Browser globals (root is window)
31
25
  root.dwv = factory(
32
- root.i18next,
33
- root.i18nextHttpBackend,
34
- root.i18nextBrowserLanguageDetector,
35
26
  root.JSZip,
36
27
  root.Konva,
37
28
  root.MagicWand
38
29
  );
39
30
  }
40
31
  }(this, function (
41
- i18next,
42
- i18nextHttpBackend,
43
- i18nextBrowserLanguageDetector,
44
32
  JSZip,
45
33
  Konva,
46
34
  MagicWand) {
@@ -57,16 +45,6 @@
57
45
  return typeof mod !== 'undefined' &&
58
46
  typeof mod.default !== 'undefined';
59
47
  }
60
- // i18next (>v17) comes as a module, see #862
61
- if (isEsmModule(i18next)) {
62
- i18next = i18next.default;
63
- }
64
- if (isEsmModule(i18nextHttpBackend)) {
65
- i18nextHttpBackend = i18nextHttpBackend.default;
66
- }
67
- if (isEsmModule(i18nextBrowserLanguageDetector)) {
68
- i18nextBrowserLanguageDetector = i18nextBrowserLanguageDetector.default;
69
- }
70
48
  // Konva (>=v8) comes as a module, see #1044
71
49
  if (isEsmModule(Konva)) {
72
50
  Konva = Konva.default;
@@ -1369,10 +1347,11 @@ dwv.App = function () {
1369
1347
  }
1370
1348
 
1371
1349
  // optional draw layer
1350
+ var drawLayer;
1372
1351
  if (toolboxController && toolboxController.hasTool('Draw')) {
1373
- var dl = layerGroup.addDrawLayer();
1374
- dl.initialise(size2D, spacing2D, dataIndex);
1375
- dl.setPlaneHelper(viewLayer.getViewController().getPlaneHelper());
1352
+ drawLayer = layerGroup.addDrawLayer();
1353
+ drawLayer.initialise(size2D, spacing2D, dataIndex);
1354
+ drawLayer.setPlaneHelper(viewLayer.getViewController().getPlaneHelper());
1376
1355
  }
1377
1356
 
1378
1357
  // sync layers position
@@ -1399,11 +1378,17 @@ dwv.App = function () {
1399
1378
  // flip offset Y for axial aquired data
1400
1379
  if (dataViewConfig.orientation !== 'axial') {
1401
1380
  viewLayer.addFlipOffsetY();
1381
+ if (typeof drawLayer !== 'undefined') {
1382
+ drawLayer.addFlipOffsetY();
1383
+ }
1402
1384
  }
1403
1385
  } else if (major === 0) {
1404
1386
  // flip offset X for sagittal aquired data
1405
1387
  if (dataViewConfig.orientation !== 'sagittal') {
1406
1388
  viewLayer.addFlipOffsetX();
1389
+ if (typeof drawLayer !== 'undefined') {
1390
+ drawLayer.addFlipOffsetX();
1391
+ }
1407
1392
  }
1408
1393
  }
1409
1394
  }
@@ -1417,6 +1402,9 @@ dwv.App = function () {
1417
1402
  layerGroup.flipScaleZ();
1418
1403
  } else {
1419
1404
  viewLayer.setScale(layerGroup.getScale());
1405
+ if (typeof drawLayer !== 'undefined') {
1406
+ drawLayer.setScale(layerGroup.getScale());
1407
+ }
1420
1408
  }
1421
1409
  } else {
1422
1410
  if (major === 0) {
@@ -1424,10 +1412,16 @@ dwv.App = function () {
1424
1412
  layerGroup.flipScaleZ();
1425
1413
  } else {
1426
1414
  viewLayer.setScale(layerGroup.getScale());
1415
+ if (typeof drawLayer !== 'undefined') {
1416
+ drawLayer.setScale(layerGroup.getScale());
1417
+ }
1427
1418
  }
1428
1419
  }
1429
1420
  } else {
1430
1421
  viewLayer.setScale(layerGroup.getScale());
1422
+ if (typeof drawLayer !== 'undefined') {
1423
+ drawLayer.setScale(layerGroup.getScale());
1424
+ }
1431
1425
  }
1432
1426
 
1433
1427
  }
@@ -4755,7 +4749,7 @@ dwv.dicom = dwv.dicom || {};
4755
4749
  * @returns {string} The version of the library.
4756
4750
  */
4757
4751
  dwv.getVersion = function () {
4758
- return '0.31.0-rc.0';
4752
+ return '0.31.1';
4759
4753
  };
4760
4754
 
4761
4755
  /**
@@ -12910,6 +12904,14 @@ dwv.gui.DrawLayer = function (containerDiv) {
12910
12904
  */
12911
12905
  var zoomOffset = {x: 0, y: 0};
12912
12906
 
12907
+ /**
12908
+ * The flip offset.
12909
+ *
12910
+ * @private
12911
+ * @type {object}
12912
+ */
12913
+ var flipOffset = {x: 0, y: 0};
12914
+
12913
12915
  /**
12914
12916
  * The draw controller.
12915
12917
  *
@@ -13026,6 +13028,36 @@ dwv.gui.DrawLayer = function (containerDiv) {
13026
13028
  konvaStage.opacity(Math.min(Math.max(alpha, 0), 1));
13027
13029
  };
13028
13030
 
13031
+ /**
13032
+ * Add a flip offset along the layer X axis.
13033
+ */
13034
+ this.addFlipOffsetX = function () {
13035
+ // flip scale is handled by layer group
13036
+ // flip offset
13037
+ var scale = konvaStage.scale();
13038
+ var size = konvaStage.size();
13039
+ flipOffset.x += size.width / scale.x;
13040
+ // apply
13041
+ var offset = konvaStage.offset();
13042
+ offset.x += flipOffset.x;
13043
+ konvaStage.offset(offset);
13044
+ };
13045
+
13046
+ /**
13047
+ * Add a flip offset along the layer Y axis.
13048
+ */
13049
+ this.addFlipOffsetY = function () {
13050
+ // flip scale is handled by layer group
13051
+ // flip offset
13052
+ var scale = konvaStage.scale();
13053
+ var size = konvaStage.size();
13054
+ flipOffset.y += size.height / scale.y;
13055
+ // apply
13056
+ var offset = konvaStage.offset();
13057
+ offset.y += flipOffset.y;
13058
+ konvaStage.offset(offset);
13059
+ };
13060
+
13029
13061
  /**
13030
13062
  * Set the layer scale.
13031
13063
  *
@@ -13093,8 +13125,10 @@ dwv.gui.DrawLayer = function (containerDiv) {
13093
13125
  this.setOffset = function (newOffset) {
13094
13126
  var planeNewOffset = planeHelper.getPlaneOffsetFromOffset3D(newOffset);
13095
13127
  konvaStage.offset({
13096
- x: viewOffset.x + baseOffset.x + zoomOffset.x + planeNewOffset.x,
13097
- y: viewOffset.y + baseOffset.y + zoomOffset.y + planeNewOffset.y
13128
+ x: planeNewOffset.x +
13129
+ viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
13130
+ y: planeNewOffset.y +
13131
+ viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
13098
13132
  });
13099
13133
  };
13100
13134
 
@@ -13221,8 +13255,8 @@ dwv.gui.DrawLayer = function (containerDiv) {
13221
13255
  y: fitOffset.y / fitScale.y
13222
13256
  };
13223
13257
  konvaStage.offset({
13224
- x: viewOffset.x + baseOffset.x + zoomOffset.x,
13225
- y: viewOffset.y + baseOffset.y + zoomOffset.y
13258
+ x: viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
13259
+ y: viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
13226
13260
  });
13227
13261
  };
13228
13262
 
@@ -15889,6 +15923,8 @@ dwv.gui.ViewLayer = function (containerDiv) {
15889
15923
  needsDraw = true;
15890
15924
  }
15891
15925
 
15926
+ // previous fit scale
15927
+ var previousFitScale = fitScale;
15892
15928
  // previous scale without fit
15893
15929
  var previousScale = {
15894
15930
  x: scale.x / fitScale.x,
@@ -15917,9 +15953,19 @@ dwv.gui.ViewLayer = function (containerDiv) {
15917
15953
  x: fitOffset.x / newFitScale.x,
15918
15954
  y: fitOffset.y / newFitScale.y
15919
15955
  };
15956
+ var newFlipOffset = {
15957
+ x: flipOffset.x * previousFitScale.x / newFitScale.x,
15958
+ y: flipOffset.y * previousFitScale.y / newFitScale.y
15959
+ };
15920
15960
  // check if different
15921
- if (viewOffset.x !== newViewOffset.x || viewOffset.y !== newViewOffset.y) {
15961
+ if (viewOffset.x !== newViewOffset.x ||
15962
+ viewOffset.y !== newViewOffset.y ||
15963
+ flipOffset.x !== newFlipOffset.x ||
15964
+ flipOffset.y !== newFlipOffset.y) {
15965
+ // update private local offsets
15966
+ flipOffset = newFlipOffset;
15922
15967
  viewOffset = newViewOffset;
15968
+ // update global offset
15923
15969
  offset = {
15924
15970
  x: viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
15925
15971
  y: viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
@@ -21229,6 +21275,15 @@ dwv.image.MaskFactory.prototype.create = function (
21229
21275
  dwv.logger.warn(
21230
21276
  'Using larger real world epsilon in SEG pos pat adding'
21231
21277
  );
21278
+ } else {
21279
+ // try even larger epsilon
21280
+ res = value > dwv.math.REAL_WORLD_EPSILON * 100;
21281
+ if (!res) {
21282
+ // warn if epsilon < value < epsilon * 100
21283
+ dwv.logger.warn(
21284
+ 'Using even larger real world epsilon in SEG pos pat adding'
21285
+ );
21286
+ }
21232
21287
  }
21233
21288
  }
21234
21289
  return res;
@@ -23389,7 +23444,7 @@ dwv.image.ViewFactory.prototype.create = function (dicomElements, image) {
23389
23444
  for (var key in dwv.tool.defaultpresets[modality]) {
23390
23445
  var preset = dwv.tool.defaultpresets[modality][key];
23391
23446
  windowPresets[key] = {
23392
- wl: new dwv.image.WindowLevel(preset.center, preset.width),
23447
+ wl: [new dwv.image.WindowLevel(preset.center, preset.width)],
23393
23448
  name: key
23394
23449
  };
23395
23450
  }
@@ -30886,6 +30941,37 @@ dwv.tool.Draw = function (app) {
30886
30941
  */
30887
30942
  var lastPoint = null;
30888
30943
 
30944
+ /**
30945
+ * Active shape, ie shape with mouse over.
30946
+ *
30947
+ * @private
30948
+ * @type {object}
30949
+ */
30950
+ var activeShapeGroup;
30951
+
30952
+ /**
30953
+ * Original mouse cursor.
30954
+ *
30955
+ * @private
30956
+ * @type {string}
30957
+ */
30958
+ var originalCursor;
30959
+
30960
+ /**
30961
+ * Mouse cursor.
30962
+ *
30963
+ * @private
30964
+ * @type {string}
30965
+ */
30966
+ var mouseOverCursor = 'pointer';
30967
+
30968
+ /**
30969
+ * Scroll wheel handler.
30970
+ *
30971
+ * @type {dwv.tool.ScrollWheel}
30972
+ */
30973
+ var scrollWhell = new dwv.tool.ScrollWheel(app);
30974
+
30889
30975
  /**
30890
30976
  * Shape editor.
30891
30977
  *
@@ -31153,6 +31239,15 @@ dwv.tool.Draw = function (app) {
31153
31239
  self.dblclick(event);
31154
31240
  };
31155
31241
 
31242
+ /**
31243
+ * Handle mouse wheel event.
31244
+ *
31245
+ * @param {object} event The mouse wheel event.
31246
+ */
31247
+ this.wheel = function (event) {
31248
+ scrollWhell.wheel(event);
31249
+ };
31250
+
31156
31251
  /**
31157
31252
  * Handle key down event.
31158
31253
  *
@@ -31285,12 +31380,13 @@ dwv.tool.Draw = function (app) {
31285
31380
  shapeEditor.disable();
31286
31381
  shapeEditor.setShape(null);
31287
31382
  shapeEditor.setViewController(null);
31288
- document.body.style.cursor = 'default';
31289
31383
  // get the current draw layer
31290
31384
  var layerGroup = app.getActiveLayerGroup();
31291
31385
  activateCurrentPositionShapes(flag, layerGroup);
31292
31386
  // listen to app change to update the draw layer
31293
31387
  if (flag) {
31388
+ // store cursor
31389
+ originalCursor = document.body.style.cursor;
31294
31390
  // TODO: merge with drawController.activateDrawLayer?
31295
31391
  app.addEventListener('positionchange', function () {
31296
31392
  updateDrawLayer(layerGroup);
@@ -31298,6 +31394,11 @@ dwv.tool.Draw = function (app) {
31298
31394
  // same for colour
31299
31395
  this.setFeatures({lineColour: this.style.getLineColour()});
31300
31396
  } else {
31397
+ // reset shape and cursor
31398
+ resetActiveShapeGroup();
31399
+ // reset local var
31400
+ originalCursor = undefined;
31401
+ // remove listeners
31301
31402
  app.removeEventListener('positionchange', function () {
31302
31403
  updateDrawLayer(layerGroup);
31303
31404
  });
@@ -31384,6 +31485,24 @@ dwv.tool.Draw = function (app) {
31384
31485
  };
31385
31486
  }
31386
31487
 
31488
+ /**
31489
+ * Reset the active shape group and mouse cursor to their original state.
31490
+ */
31491
+ function resetActiveShapeGroup() {
31492
+ if (typeof originalCursor !== 'undefined') {
31493
+ document.body.style.cursor = originalCursor;
31494
+ }
31495
+ if (typeof activeShapeGroup !== 'undefined') {
31496
+ activeShapeGroup.opacity(1);
31497
+ var colour = self.style.getLineColour();
31498
+ activeShapeGroup.getChildren(dwv.draw.canNodeChangeColour).forEach(
31499
+ function (ashape) {
31500
+ ashape.stroke(colour);
31501
+ }
31502
+ );
31503
+ }
31504
+ }
31505
+
31387
31506
  /**
31388
31507
  * Set shape group on properties.
31389
31508
  *
@@ -31391,13 +31510,24 @@ dwv.tool.Draw = function (app) {
31391
31510
  * @param {dwv.gui.LayerGroup} layerGroup The origin layer group.
31392
31511
  */
31393
31512
  this.setShapeOn = function (shapeGroup, layerGroup) {
31394
- // mouse over styling
31513
+ // adapt shape and cursor when mouse over
31514
+ var mouseOnShape = function () {
31515
+ document.body.style.cursor = mouseOverCursor;
31516
+ shapeGroup.opacity(0.75);
31517
+ };
31518
+ // mouse over event hanlding
31395
31519
  shapeGroup.on('mouseover', function () {
31396
- document.body.style.cursor = 'pointer';
31520
+ // save local vars
31521
+ activeShapeGroup = shapeGroup;
31522
+ // adapt shape
31523
+ mouseOnShape();
31397
31524
  });
31398
- // mouse out styling
31525
+ // mouse out event hanlding
31399
31526
  shapeGroup.on('mouseout', function () {
31400
- document.body.style.cursor = 'default';
31527
+ // reset shape
31528
+ resetActiveShapeGroup();
31529
+ // reset local vars
31530
+ activeShapeGroup = undefined;
31401
31531
  });
31402
31532
 
31403
31533
  var drawLayer = layerGroup.getActiveDrawLayer();
@@ -31487,9 +31617,14 @@ dwv.tool.Draw = function (app) {
31487
31617
  });
31488
31618
  // drag end event handling
31489
31619
  shapeGroup.on('dragend.draw', function (event) {
31490
- var pos = {x: this.x(), y: this.y()};
31491
31620
  // remove trash
31492
31621
  trash.remove();
31622
+ // activate(false) will also trigger a dragend.draw
31623
+ if (typeof event === 'undefined' ||
31624
+ typeof event.evt === 'undefined') {
31625
+ return;
31626
+ }
31627
+ var pos = {x: this.x(), y: this.y()};
31493
31628
  // delete case
31494
31629
  var offset = dwv.gui.getEventOffset(event.evt)[0];
31495
31630
  var eventPos = getRealPosition(offset, layerGroup);
@@ -31510,7 +31645,7 @@ dwv.tool.Draw = function (app) {
31510
31645
  ashape.stroke(colour);
31511
31646
  });
31512
31647
  // reset cursor
31513
- document.body.style.cursor = 'default';
31648
+ document.body.style.cursor = originalCursor;
31514
31649
  // delete command
31515
31650
  var delcmd = new dwv.tool.DeleteGroupCommand(this,
31516
31651
  shapeDisplayName, konvaLayer);
@@ -31625,6 +31760,9 @@ dwv.tool.Draw = function (app) {
31625
31760
  }
31626
31761
  this.shapeName = features.shapeName;
31627
31762
  }
31763
+ if (typeof features.mouseOverCursor !== 'undefined') {
31764
+ mouseOverCursor = features.mouseOverCursor;
31765
+ }
31628
31766
  };
31629
31767
 
31630
31768
  /**
@@ -31696,24 +31834,6 @@ dwv.tool.Draw = function (app) {
31696
31834
 
31697
31835
  }; // Draw class
31698
31836
 
31699
- /**
31700
- * Help for this tool.
31701
- *
31702
- * @returns {object} The help content.
31703
- */
31704
- dwv.tool.Draw.prototype.getHelpKeys = function () {
31705
- return {
31706
- title: 'tool.Draw.name',
31707
- brief: 'tool.Draw.brief',
31708
- mouse: {
31709
- mouse_drag: 'tool.Draw.mouse_drag'
31710
- },
31711
- touch: {
31712
- touch_drag: 'tool.Draw.touch_drag'
31713
- }
31714
- };
31715
- };
31716
-
31717
31837
  /**
31718
31838
  * Check if the shape is in the shape list.
31719
31839
  *
@@ -32202,6 +32322,7 @@ var Konva = Konva || {};
32202
32322
  * @returns {object} The default anchor shape.
32203
32323
  */
32204
32324
  dwv.tool.draw.getDefaultAnchor = function (x, y, id, style) {
32325
+ var radius = style.applyZoomScale(3);
32205
32326
  return new Konva.Ellipse({
32206
32327
  x: x,
32207
32328
  y: y,
@@ -32209,7 +32330,10 @@ dwv.tool.draw.getDefaultAnchor = function (x, y, id, style) {
32209
32330
  fill: 'rgba(100,100,100,0.7',
32210
32331
  strokeWidth: style.getStrokeWidth(),
32211
32332
  strokeScaleEnabled: false,
32212
- radius: style.applyZoomScale(3),
32333
+ radius: {
32334
+ x: Math.abs(radius.x),
32335
+ y: Math.abs(radius.y)
32336
+ },
32213
32337
  name: 'anchor',
32214
32338
  id: id,
32215
32339
  dragOnTop: false,
@@ -33087,18 +33211,6 @@ dwv.tool.Filter = function (app) {
33087
33211
 
33088
33212
  }; // class dwv.tool.Filter
33089
33213
 
33090
- /**
33091
- * Help for this tool.
33092
- *
33093
- * @returns {object} The help content.
33094
- */
33095
- dwv.tool.Filter.prototype.getHelpKeys = function () {
33096
- return {
33097
- title: 'tool.Filter.name',
33098
- brief: 'tool.Filter.brief'
33099
- };
33100
- };
33101
-
33102
33214
  /**
33103
33215
  * Get the selected filter.
33104
33216
  *
@@ -34026,24 +34138,6 @@ dwv.tool.Floodfill = function (app) {
34026
34138
 
34027
34139
  }; // Floodfill class
34028
34140
 
34029
- /**
34030
- * Help for this tool.
34031
- *
34032
- * @returns {object} The help content.
34033
- */
34034
- dwv.tool.Floodfill.prototype.getHelpKeys = function () {
34035
- return {
34036
- title: 'tool.Floodfill.name',
34037
- brief: 'tool.Floodfill.brief',
34038
- mouse: {
34039
- click: 'tool.Floodfill.click'
34040
- },
34041
- touch: {
34042
- tap: 'tool.Floodfill.tap'
34043
- }
34044
- };
34045
- };
34046
-
34047
34141
  /**
34048
34142
  * Set the tool live features: shape colour.
34049
34143
  *
@@ -34367,6 +34461,24 @@ dwv.tool.Livewire = function (app) {
34367
34461
  */
34368
34462
  var scissors = new dwv.math.Scissors();
34369
34463
 
34464
+ /**
34465
+ * Finish a livewire (roi) shape.
34466
+ */
34467
+ function finishShape() {
34468
+ // fire creation event (was not propagated during draw)
34469
+ fireEvent({
34470
+ type: 'drawcreate',
34471
+ id: shapeGroup.id()
34472
+ });
34473
+ // listen
34474
+ command.onExecute = fireEvent;
34475
+ command.onUndo = fireEvent;
34476
+ // save command in undo stack
34477
+ app.addToUndoStack(command);
34478
+ // set flag
34479
+ self.started = false;
34480
+ }
34481
+
34370
34482
  /**
34371
34483
  * Handle mouse down event.
34372
34484
  *
@@ -34403,17 +34515,8 @@ dwv.tool.Livewire = function (app) {
34403
34515
  // final point: at 'tolerance' of the initial point
34404
34516
  if ((Math.abs(index.get(0) - self.x0) < tolerance) &&
34405
34517
  (Math.abs(index.get(1) - self.y0) < tolerance)) {
34406
- // draw
34407
- self.mousemove(event);
34408
- // listen
34409
- command.onExecute = fireEvent;
34410
- command.onUndo = fireEvent;
34411
- // debug
34412
- dwv.logger.debug('[livewire] finialise path.');
34413
- // save command in undo stack
34414
- app.addToUndoStack(command);
34415
- // set flag
34416
- self.started = false;
34518
+ // finish
34519
+ finishShape();
34417
34520
  } else {
34418
34521
  // anchor point
34419
34522
  path = currentPath;
@@ -34445,7 +34548,6 @@ dwv.tool.Livewire = function (app) {
34445
34548
  // do the work
34446
34549
  var results = 0;
34447
34550
  var stop = false;
34448
- dwv.logger.debug('[livewire] getting ready...');
34449
34551
  while (!parentPoints[p.y][p.x] && !stop) {
34450
34552
  results = scissors.doWork();
34451
34553
 
@@ -34460,7 +34562,6 @@ dwv.tool.Livewire = function (app) {
34460
34562
  }
34461
34563
  }
34462
34564
  }
34463
- dwv.logger.debug('[livewire] ready!');
34464
34565
 
34465
34566
  // get the path
34466
34567
  currentPath = new dwv.math.Path();
@@ -34528,11 +34629,7 @@ dwv.tool.Livewire = function (app) {
34528
34629
  * @param {object} _event The double click event.
34529
34630
  */
34530
34631
  this.dblclick = function (_event) {
34531
- dwv.logger.debug('[livewire] dblclick');
34532
- // save command in undo stack
34533
- app.addToUndoStack(command);
34534
- // set flag
34535
- self.started = false;
34632
+ finishShape();
34536
34633
  };
34537
34634
 
34538
34635
  /**
@@ -34648,18 +34745,6 @@ dwv.tool.Livewire = function (app) {
34648
34745
 
34649
34746
  }; // Livewire class
34650
34747
 
34651
- /**
34652
- * Help for this tool.
34653
- *
34654
- * @returns {object} The help content.
34655
- */
34656
- dwv.tool.Livewire.prototype.getHelpKeys = function () {
34657
- return {
34658
- title: 'tool.Livewire.name',
34659
- brief: 'tool.Livewire.brief'
34660
- };
34661
- };
34662
-
34663
34748
  /**
34664
34749
  * Set the tool live features: shape colour.
34665
34750
  *
@@ -34712,6 +34797,13 @@ dwv.tool.Opacity = function (app) {
34712
34797
  */
34713
34798
  this.started = false;
34714
34799
 
34800
+ /**
34801
+ * Scroll wheel handler.
34802
+ *
34803
+ * @type {dwv.tool.ScrollWheel}
34804
+ */
34805
+ var scrollWhell = new dwv.tool.ScrollWheel(app);
34806
+
34715
34807
  /**
34716
34808
  * Handle mouse down event.
34717
34809
  *
@@ -34803,6 +34895,15 @@ dwv.tool.Opacity = function (app) {
34803
34895
  self.mouseup(event);
34804
34896
  };
34805
34897
 
34898
+ /**
34899
+ * Handle mouse wheel event.
34900
+ *
34901
+ * @param {object} event The mouse wheel event.
34902
+ */
34903
+ this.wheel = function (event) {
34904
+ scrollWhell.wheel(event);
34905
+ };
34906
+
34806
34907
  /**
34807
34908
  * Handle key down event.
34808
34909
  *
@@ -34831,24 +34932,6 @@ dwv.tool.Opacity = function (app) {
34831
34932
 
34832
34933
  }; // Opacity class
34833
34934
 
34834
- /**
34835
- * Help for this tool.
34836
- *
34837
- * @returns {object} The help content.
34838
- */
34839
- dwv.tool.Opacity.prototype.getHelpKeys = function () {
34840
- return {
34841
- title: 'tool.Opacity.name',
34842
- brief: 'tool.Opacity.brief',
34843
- mouse: {
34844
- mouse_drag: 'tool.Opacity.mouse_drag',
34845
- },
34846
- touch: {
34847
- touch_drag: 'tool.Opacity.touch_drag',
34848
- }
34849
- };
34850
- };
34851
-
34852
34935
  // namespaces
34853
34936
  var dwv = dwv || {};
34854
34937
  dwv.tool = dwv.tool || {};
@@ -36097,11 +36180,11 @@ dwv.tool.Scroll = function (app) {
36097
36180
  var touchTimerID = null;
36098
36181
 
36099
36182
  /**
36100
- * Accumulated wheel event deltaY.
36183
+ * Scroll wheel handler.
36101
36184
  *
36102
- * @type {number}
36185
+ * @type {dwv.tool.ScrollWheel}
36103
36186
  */
36104
- var wheelDeltaY = 0;
36187
+ var scrollWhell = new dwv.tool.ScrollWheel(app);
36105
36188
 
36106
36189
  /**
36107
36190
  * Option to show or not a value tooltip on mousemove.
@@ -36266,36 +36349,7 @@ dwv.tool.Scroll = function (app) {
36266
36349
  * @param {object} event The mouse wheel event.
36267
36350
  */
36268
36351
  this.wheel = function (event) {
36269
- // deltaMode (deltaY values on my machine...):
36270
- // - 0 (DOM_DELTA_PIXEL): chrome, deltaY mouse scroll = 53
36271
- // - 1 (DOM_DELTA_LINE): firefox, deltaY mouse scroll = 6
36272
- // - 2 (DOM_DELTA_PAGE): ??
36273
- // TODO: check scroll event
36274
- var scrollMin = 52;
36275
- if (event.deltaMode === 1) {
36276
- scrollMin = 5.99;
36277
- }
36278
- wheelDeltaY += event.deltaY;
36279
- if (Math.abs(wheelDeltaY) < scrollMin) {
36280
- return;
36281
- } else {
36282
- wheelDeltaY = 0;
36283
- }
36284
-
36285
- var up = false;
36286
- if (event.deltaY < 0) {
36287
- up = true;
36288
- }
36289
-
36290
- var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
36291
- var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
36292
- var viewController =
36293
- layerGroup.getActiveViewLayer().getViewController();
36294
- if (up) {
36295
- viewController.incrementScrollIndex();
36296
- } else {
36297
- viewController.decrementScrollIndex();
36298
- }
36352
+ scrollWhell.wheel(event);
36299
36353
  };
36300
36354
 
36301
36355
  /**
@@ -36401,25 +36455,69 @@ dwv.tool.Scroll = function (app) {
36401
36455
 
36402
36456
  }; // Scroll class
36403
36457
 
36458
+ // namespaces
36459
+ var dwv = dwv || {};
36460
+ dwv.tool = dwv.tool || {};
36461
+
36404
36462
  /**
36405
- * Help for this tool.
36463
+ * Scroll wheel class: provides a wheel event handler
36464
+ * that scroll the corresponding data.
36406
36465
  *
36407
- * @returns {object} The help content.
36466
+ * @class
36467
+ * @param {dwv.App} app The associated application.
36408
36468
  */
36409
- dwv.tool.Scroll.prototype.getHelpKeys = function () {
36410
- return {
36411
- title: 'tool.Scroll.name',
36412
- brief: 'tool.Scroll.brief',
36413
- mouse: {
36414
- mouse_drag: 'tool.Scroll.mouse_drag',
36415
- double_click: 'tool.Scroll.double_click'
36416
- },
36417
- touch: {
36418
- touch_drag: 'tool.Scroll.touch_drag',
36419
- tap_and_hold: 'tool.Scroll.tap_and_hold'
36469
+ dwv.tool.ScrollWheel = function (app) {
36470
+ /**
36471
+ * Accumulated wheel event deltaY.
36472
+ *
36473
+ * @type {number}
36474
+ */
36475
+ var wheelDeltaY = 0;
36476
+
36477
+ /**
36478
+ * Handle mouse wheel event.
36479
+ *
36480
+ * @param {object} event The mouse wheel event.
36481
+ */
36482
+ this.wheel = function (event) {
36483
+ // deltaMode (deltaY values on my machine...):
36484
+ // - 0 (DOM_DELTA_PIXEL): chrome, deltaY mouse scroll = 53
36485
+ // - 1 (DOM_DELTA_LINE): firefox, deltaY mouse scroll = 6
36486
+ // - 2 (DOM_DELTA_PAGE): ??
36487
+ // TODO: check scroll event
36488
+ var scrollMin = 52;
36489
+ if (event.deltaMode === 1) {
36490
+ scrollMin = 5.99;
36491
+ }
36492
+ wheelDeltaY += event.deltaY;
36493
+ if (Math.abs(wheelDeltaY) < scrollMin) {
36494
+ return;
36495
+ } else {
36496
+ wheelDeltaY = 0;
36497
+ }
36498
+
36499
+ var up = event.deltaY < 0 ? true : false;
36500
+
36501
+ var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
36502
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
36503
+ var viewController =
36504
+ layerGroup.getActiveViewLayer().getViewController();
36505
+ var imageSize = viewController.getImageSize();
36506
+ if (imageSize.canScroll3D()) {
36507
+ if (up) {
36508
+ viewController.incrementScrollIndex();
36509
+ } else {
36510
+ viewController.decrementScrollIndex();
36511
+ }
36512
+ } else if (imageSize.moreThanOne(3)) {
36513
+ if (up) {
36514
+ viewController.incrementIndex(3);
36515
+ } else {
36516
+ viewController.decrementIndex(3);
36517
+ }
36420
36518
  }
36421
36519
  };
36422
- };
36520
+ }; // ScrollWheel class
36423
36521
 
36424
36522
  // namespaces
36425
36523
  var dwv = dwv || {};
@@ -36624,6 +36722,13 @@ dwv.tool.WindowLevel = function (app) {
36624
36722
  */
36625
36723
  this.started = false;
36626
36724
 
36725
+ /**
36726
+ * Scroll wheel handler.
36727
+ *
36728
+ * @type {dwv.tool.ScrollWheel}
36729
+ */
36730
+ var scrollWhell = new dwv.tool.ScrollWheel(app);
36731
+
36627
36732
  /**
36628
36733
  * Handle mouse down event.
36629
36734
  *
@@ -36756,6 +36861,15 @@ dwv.tool.WindowLevel = function (app) {
36756
36861
  parseInt(viewController.getWindowLevel().width, 10));
36757
36862
  };
36758
36863
 
36864
+ /**
36865
+ * Handle mouse wheel event.
36866
+ *
36867
+ * @param {object} event The mouse wheel event.
36868
+ */
36869
+ this.wheel = function (event) {
36870
+ scrollWhell.wheel(event);
36871
+ };
36872
+
36759
36873
  /**
36760
36874
  * Handle key down event.
36761
36875
  *
@@ -36784,25 +36898,6 @@ dwv.tool.WindowLevel = function (app) {
36784
36898
 
36785
36899
  }; // WindowLevel class
36786
36900
 
36787
- /**
36788
- * Help for this tool.
36789
- *
36790
- * @returns {object} The help content.
36791
- */
36792
- dwv.tool.WindowLevel.prototype.getHelpKeys = function () {
36793
- return {
36794
- title: 'tool.WindowLevel.name',
36795
- brief: 'tool.WindowLevel.brief',
36796
- mouse: {
36797
- mouse_drag: 'tool.WindowLevel.mouse_drag',
36798
- double_click: 'tool.WindowLevel.double_click'
36799
- },
36800
- touch: {
36801
- touch_drag: 'tool.WindowLevel.touch_drag'
36802
- }
36803
- };
36804
- };
36805
-
36806
36901
  // namespaces
36807
36902
  var dwv = dwv || {};
36808
36903
  dwv.tool = dwv.tool || {};
@@ -37049,26 +37144,6 @@ dwv.tool.ZoomAndPan = function (app) {
37049
37144
 
37050
37145
  }; // ZoomAndPan class
37051
37146
 
37052
- /**
37053
- * Help for this tool.
37054
- *
37055
- * @returns {object} The help content.
37056
- */
37057
- dwv.tool.ZoomAndPan.prototype.getHelpKeys = function () {
37058
- return {
37059
- title: 'tool.ZoomAndPan.name',
37060
- brief: 'tool.ZoomAndPan.brief',
37061
- mouse: {
37062
- mouse_wheel: 'tool.ZoomAndPan.mouse_wheel',
37063
- mouse_drag: 'tool.ZoomAndPan.mouse_drag'
37064
- },
37065
- touch: {
37066
- twotouch_pinch: 'tool.ZoomAndPan.twotouch_pinch',
37067
- touch_drag: 'tool.ZoomAndPan.touch_drag'
37068
- }
37069
- };
37070
- };
37071
-
37072
37147
  /**
37073
37148
  * Initialise the tool.
37074
37149
  */
@@ -37979,189 +38054,29 @@ dwv.env.check = function () {
37979
38054
 
37980
38055
  // namespaces
37981
38056
  var dwv = dwv || {};
37982
- /**
37983
- * The i18next namespace.
37984
- *
37985
- * @external i18next
37986
- * @see https://www.i18next.com
37987
- */
37988
- var i18next = i18next || {};
37989
- /**
37990
- * The i18nextHttpBackend namespace.
37991
- *
37992
- * @external i18nextHttpBackend
37993
- * @see https://github.com/i18next/i18next-http-backend
37994
- */
37995
- var i18nextHttpBackend = i18nextHttpBackend || {};
37996
- /**
37997
- * The i18nextBrowserLanguageDetector namespace.
37998
- *
37999
- * @external i18nextBrowserLanguageDetector
38000
- * @see https://github.com/i18next/i18next-browser-languageDetector
38001
- */
38002
- var i18nextBrowserLanguageDetector = i18nextBrowserLanguageDetector || {};
38003
-
38004
- // This is mainly a wrapper around the i18next object.
38005
- // see its API: http://i18next.com/docs/api/
38006
-
38007
- // global locales path
38008
- dwv.i18nLocalesPath = null;
38009
-
38010
- /**
38011
- * Initialise i18n.
38012
- *
38013
- * @param {string} language The language to translate to. Defaults to 'auto' and
38014
- * gets the language from the browser.
38015
- * @param {string} localesPath Path to the locales directory.
38016
- */
38017
- dwv.i18nInitialise = function (language, localesPath) {
38018
- var lng = (typeof language === 'undefined') ? 'auto' : language;
38019
- var lpath = (typeof localesPath === 'undefined') ? '../..' : localesPath;
38020
- // store as global
38021
- dwv.i18nLocalesPath = lpath;
38022
- // i18n options: default 'en' language and
38023
- // only load language, not specialised (for ex en-GB)
38024
- var options = {
38025
- fallbackLng: 'en',
38026
- load: 'languageOnly',
38027
- backend: {loadPath: lpath + '/locales/{{lng}}/{{ns}}.json'}
38028
- };
38029
- // use the HTTP backend to get translation files
38030
- var i18n = i18next.use(i18nextHttpBackend);
38031
- // use browser language or the specified one
38032
- if (lng === 'auto') {
38033
- i18n.use(i18nextBrowserLanguageDetector);
38034
- } else {
38035
- options.lng = lng;
38036
- }
38037
- // init i18n: will be ready when the 'loaded' event is fired
38038
- i18n.init(options);
38039
- };
38040
-
38041
- /**
38042
- * Initialise i18n with recources as input.
38043
- *
38044
- * @param {string} language The language to translate to. Defaults to 'auto' and
38045
- * gets the language from the browser.
38046
- * @param {object} resources Languages provided as object.
38047
- */
38048
- dwv.i18nInitialiseWithResources = function (language, resources) {
38049
- var lng = (typeof language === 'undefined') ? 'auto' : language;
38050
- // i18n options: default 'en' language and
38051
- // only load language, not specialised (for ex en-GB)
38052
- var options = {
38053
- fallbackLng: 'en',
38054
- load: 'languageOnly',
38055
- resources: resources
38056
- };
38057
- // use browser language or the specified one
38058
- // init i18n: will be ready when the 'loaded' event is fired
38059
- if (lng === 'auto') {
38060
- var i18n = i18next.use(i18nextBrowserLanguageDetector);
38061
- i18n.init(options);
38062
- } else {
38063
- options.lng = lng;
38064
- i18next.init(options);
38065
- }
38066
- };
38067
-
38068
- /**
38069
- * Handle i18n 'initialized' event.
38070
- *
38071
- * @param {object} callback The callback function to call when i18n
38072
- * is initialised.
38073
- * It can take one argument that will be replaced with the i18n options.
38074
- */
38075
- dwv.i18nOnInitialised = function (callback) {
38076
- i18next.on('initialized', callback);
38077
- };
38078
-
38079
- /**
38080
- * Stop handling i18n load event.
38081
- */
38082
- dwv.i18nOffInitialised = function () {
38083
- i18next.off('initialized');
38084
- };
38085
-
38086
- /**
38087
- * Handle i18n failed load event.
38088
- *
38089
- * @param {object} callback The callback function to call when i18n is loaded.
38090
- * It can take three arguments: lng, ns and msg.
38091
- */
38092
- dwv.i18nOnFailedLoad = function (callback) {
38093
- i18next.on('failedLoading', callback);
38094
- };
38095
-
38096
- /**
38097
- * Stop handling i18n failed load event.
38098
- */
38099
- dwv.i18nOffFailedLoad = function () {
38100
- i18next.off('failedLoading');
38101
- };
38102
38057
 
38103
38058
  /**
38104
38059
  * Get the translated text.
38105
38060
  *
38106
38061
  * @param {string} key The key to the text entry.
38107
- * @param {object} options The translation options such as plural, context...
38108
- * @returns {string} The translated text.
38109
- */
38110
- dwv.i18n = function (key, options) {
38111
- return i18next.t(key, options);
38112
- };
38113
-
38114
- /**
38115
- * Check the existence of a translation.
38116
- *
38117
- * @param {string} key The key to the text entry.
38118
- * @param {object} options The translation options such as plural, context...
38119
- * @returns {boolean} True if the key has a translation.
38062
+ * @param {object} _options The translation options such as plural, context...
38063
+ * @returns {string|undefined} The translated text.
38120
38064
  */
38121
- dwv.i18nExists = function (key, options) {
38122
- return i18next.exists(key, options);
38123
- };
38124
-
38125
- /**
38126
- * Translate all data-i18n tags in the current html page. If an html tag defines
38127
- * the data-i18n attribute, its value will be used as key to find its
38128
- * corresponding text and will replace the content of the html tag.
38129
- */
38130
- dwv.i18nPage = function () {
38131
- // get all elements
38132
- var elements = document.getElementsByTagName('*');
38133
- // if the element defines data-i18n, replace its content with the tranlation
38134
- for (var i = 0; i < elements.length; ++i) {
38135
- if (typeof elements[i].dataset.i18n !== 'undefined') {
38136
- elements[i].innerHTML = dwv.i18n(elements[i].dataset.i18n);
38137
- }
38065
+ dwv.i18n = function (key, _options) {
38066
+ // defaut expects something like 'unit.cm2'
38067
+ var unit = {
38068
+ mm: 'mm',
38069
+ cm2: 'cm²',
38070
+ degree: '°'
38071
+ };
38072
+ var props = key.split('.');
38073
+ if (props.length !== 2) {
38074
+ throw new Error('Unexpected translation key length.');
38138
38075
  }
38139
- };
38140
-
38141
- /**
38142
- * Get the current locale resource path.
38143
- * Warning: to be used once i18next is initialised.
38144
- *
38145
- * @param {string} filename The file to locate.
38146
- * @returns {string} The path to the locale resource.
38147
- */
38148
- dwv.i18nGetLocalePath = function (filename) {
38149
- var lng = i18next.language.substring(0, 2);
38150
- return dwv.i18nLocalesPath +
38151
- '/locales/' + lng + '/' + filename;
38152
- };
38153
-
38154
- /**
38155
- * Get the current locale resource path.
38156
- * Warning: to be used once i18next is initialised.
38157
- *
38158
- * @param {string} filename The file to locate.
38159
- * @returns {string} The path to the locale resource.
38160
- */
38161
- dwv.i18nGetFallbackLocalePath = function (filename) {
38162
- var lng = i18next.languages[i18next.languages.length - 1].substring(0, 2);
38163
- return dwv.i18nLocalesPath +
38164
- '/locales/' + lng + '/' + filename;
38076
+ if (props[0] !== 'unit') {
38077
+ throw new Error('Unexpected translation key prefix.');
38078
+ }
38079
+ return unit[props[1]];
38165
38080
  };
38166
38081
 
38167
38082
  // namespaces