dwv 0.37.0-beta.5 → 0.37.0-beta.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.
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>DICOM dump diff</title>
5
+ <meta charset="UTF-8">
6
+ <link rel="icon" href="../../favicon.ico"/>
7
+ <link rel="stylesheet"
8
+ href="../../../node_modules/diff2html/bundles/css/diff2html.min.css">
9
+ <style>
10
+ body { font-family: Arial, Helvetica, sans-serif; }
11
+ fieldset { background: whitesmoke; border: 1px solid grey; }
12
+ #output { margin-top: 10px; }
13
+ </style>
14
+ </head>
15
+
16
+ <body>
17
+
18
+ <h1>DWV DICOM dump diff</h1>
19
+
20
+ <p>Load two DICOM files: they will be parsed, their tags dumped as text
21
+ and the two dumps compared side by side.</p>
22
+
23
+ <fieldset>
24
+ <label for="infile0">DICOM file 1: </label>
25
+ <input id="infile0" type="file" name="file0">
26
+ <br>&nbsp;
27
+ <br><label for="infile1">DICOM file 2: </label>
28
+ <input id="infile1" type="file" name="file1">
29
+ </fieldset>
30
+
31
+ <div id="output"></div>
32
+
33
+ </body>
34
+ </html>
@@ -0,0 +1,97 @@
1
+ import {DicomParser} from '../../../src/dicom/dicomParser.js';
2
+ import {dcmdump} from '../../../src/dicom/dicomElementsWrapper.js';
3
+ import {createTwoFilesPatch} from 'diff';
4
+ import {Diff2HtmlUI} from 'diff2html/lib-esm/ui/js/diff2html-ui-base.js';
5
+
6
+ // dcmdump of file 1
7
+ let _dump0 = null;
8
+ // dcmdump of file 2
9
+ let _dump1 = null;
10
+ // name of file 1
11
+ let _fileName0 = 'file1.dcm';
12
+ // name of file 2
13
+ let _fileName1 = 'file2.dcm';
14
+
15
+ /**
16
+ * Setup.
17
+ */
18
+ function setup() {
19
+ const infile0Input = document.getElementById('infile0');
20
+ infile0Input.onchange = (event) => onInputDICOMFile(event, 0);
21
+ const infile1Input = document.getElementById('infile1');
22
+ infile1Input.onchange = (event) => onInputDICOMFile(event, 1);
23
+ }
24
+
25
+ /**
26
+ * Handle input DICOM file.
27
+ *
28
+ * @param {object} event The input field event.
29
+ * @param {number} index The file index (0 or 1).
30
+ */
31
+ function onInputDICOMFile(event, index) {
32
+ if (event.target.files.length === 0) {
33
+ return;
34
+ }
35
+ const file = event.target.files[0];
36
+ const reader = new FileReader();
37
+ reader.onload = (readerEvent) =>
38
+ onLoadDICOMFile(readerEvent, index, file.name);
39
+ reader.readAsArrayBuffer(file);
40
+ }
41
+
42
+ /**
43
+ * Handle DICOM file load.
44
+ *
45
+ * @param {object} event The onload event.
46
+ * @param {number} index The file index (0 or 1).
47
+ * @param {string} fileName The name of the loaded file.
48
+ */
49
+ function onLoadDICOMFile(event, index, fileName) {
50
+ const parser = new DicomParser();
51
+ try {
52
+ parser.parse(event.target.result);
53
+ } catch (error) {
54
+ console.error(error);
55
+ alert(`Error parsing DICOM file "${fileName}": ${error.message}`);
56
+ return;
57
+ }
58
+ const dump = dcmdump(parser.getDicomElements());
59
+ if (index === 0) {
60
+ _dump0 = dump;
61
+ _fileName0 = fileName;
62
+ } else {
63
+ _dump1 = dump;
64
+ _fileName1 = fileName;
65
+ }
66
+ updateDiff();
67
+ }
68
+
69
+ /**
70
+ * Update the diff output using the two loaded dumps.
71
+ */
72
+ function updateDiff() {
73
+ const output = document.getElementById('output');
74
+ output.innerHTML = '';
75
+ if (_dump0 === null || _dump1 === null) {
76
+ return;
77
+ }
78
+ // use a context covering the full dumps so unchanged tags are shown too
79
+ const maxLines = Math.max(
80
+ _dump0.split('\n').length, _dump1.split('\n').length);
81
+ const patch = createTwoFilesPatch(
82
+ _fileName0, _fileName1, _dump0, _dump1, '', '',
83
+ {context: maxLines});
84
+ const diff2htmlUi = new Diff2HtmlUI(output, patch, {
85
+ drawFileList: false,
86
+ matching: 'none',
87
+ outputFormat: 'side-by-side',
88
+ // no highlight.js instance provided, disable syntax highlighting
89
+ highlight: false
90
+ });
91
+ diff2htmlUi.draw();
92
+ }
93
+
94
+ // ---------------------------------------------
95
+
96
+ // launch
97
+ setup();
package/dev/index.html CHANGED
@@ -27,7 +27,8 @@ body { font-family: Arial, Helvetica, sans-serif; }
27
27
  <a href="./visual/index-rle.html">DICOM rle</a></li>
28
28
  <li>DICOM: <a href="./dicom/pages/anonymiser.html">anonymiser</a>,
29
29
  <a href="./dicom/pages/generator.html">generator</a>,
30
- <a href="./dicom/pages/synthetic-data.html">synthetic-data</a></li>
30
+ <a href="./dicom/pages/synthetic-data.html">synthetic-data</a>,
31
+ <a href="./dicom/pages/diff.html">diff</a></li>
31
32
  <li>Benchmark: <a href="./bench/bench.html">dicom</a></li>
32
33
  <li>Image: <a href="./image/pages/colourmaps.html">colour maps</a></li>
33
34
  </ul>