Skip to content

Commit

Permalink
Merge branch 'v0.32'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Mar 18, 2024
2 parents f7522e9 + 84dc309 commit 085f3db
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 58 deletions.
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v0.32.4](https://github.com/ivmartel/dwv/releases/tag/v0.32.4) - 18/03/2024

### Fixed

- event.preventDefault for wheel events [#1632](https://github.com/ivmartel/dwv/issues/1632)

## [v0.32.3](https://github.com/ivmartel/dwv/releases/tag/v0.32.3) - 22/09/2023

### Added

- Add support for writing DICOM with unknown VR [#1507](https://github.com/ivmartel/dwv/issues/1481)

## [v0.32.2](https://github.com/ivmartel/dwv/releases/tag/v0.32.2) - 04/09/2023

### Added
Expand Down
36 changes: 21 additions & 15 deletions dist/dwv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export declare function addTagsToDictionary(group: string, tags: object): void;
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* const options = new dwv.AppOptions(viewConfigs);
* app.init(options);
* // load dicom data
* app.loadURLs([
Expand Down Expand Up @@ -170,9 +170,9 @@ export declare class App {
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* const options = new dwv.AppOptions(viewConfigs);
* options.viewOnFirstLoadItem = false;
* app.init(options);
* // render button
Expand Down Expand Up @@ -721,18 +721,24 @@ export declare class DicomParser {
* DICOM writer.
*
* @example
* // add link to html
* const link = document.createElement("a");
* link.appendChild(document.createTextNode("download"));
* const div = document.getElementById("dwv");
* div.appendChild(link);
* // XMLHttpRequest onload callback
* const onload = function (event) {
* const parser = new DicomParser();
* const parser = new dwv.DicomParser();
* parser.parse(event.target.response);
* // create writer with parser data elements
* const writer = new DicomWriter(parser.getDicomElements());
* // create modified buffer and put it in a Blol
* const blob = new Blob([writer.getBuffer()], {type: 'application/dicom'});
* // example download link
* const element = document.getElementById("download");
* element.href = URL.createObjectURL(blob);
* element.download = "anonym.dcm";
* // create writer
* const writer = new dwv.DicomWriter();
* // get buffer using default rules
* const dicomBuffer = writer.getBuffer(parser.getDicomElements());
* // create blob
* const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
* // add blob to download link
* link.href = URL.createObjectURL(blob);
* link.download = "anonym.dcm";
* };
* // DICOM file request
* const request = new XMLHttpRequest();
Expand Down Expand Up @@ -2832,9 +2838,9 @@ export declare class Vector3D {
* const dicomParser = new dwv.DicomParser();
* dicomParser.parse(event.target.response);
* // create the image object
* const image = createImage(dicomParser.getDicomElements());
* const image = dwv.createImage(dicomParser.getDicomElements());
* // create the view
* const view = createView(dicomParser.getDicomElements(), image);
* const view = dwv.createView(dicomParser.getDicomElements(), image);
* // setup canvas
* const canvas = document.createElement('canvas');
* canvas.width = 256;
Expand Down
2 changes: 1 addition & 1 deletion dist/dwv.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dwv.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dwv",
"version": "0.32.2",
"version": "0.32.4",
"description": "DICOM Web Viewer.",
"keywords": [
"DICOM",
Expand Down
4 changes: 2 additions & 2 deletions resources/doc/jsdoc.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"package": "package.json",
"theme_opts": {
"title": "DWV",
"footer": "<i>Documentation generated for dwv v0.32.2.</i>",
"footer": "<i>Documentation generated for dwv v0.32.4.</i>",
"sections": [
"Tutorials",
"Namespaces",
Expand All @@ -50,7 +50,7 @@
"codepen": {
"enable_for": ["examples"],
"options": {
"js_external": "https://github.com/ivmartel/dwv/releases/download/v0.32.2/dwv-0.32.2.min.js",
"js_external": "https://github.com/ivmartel/dwv/releases/download/v0.32.4/dwv-0.32.4.min.js",
"html": "<div id='dwv'><div id='layerGroup0'></div></div>"
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/doc/tutorials/examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Fiddle

Some fiddles for you to play... Some are bundled with the code, scroll below the method arguments to see the example code.
Some fiddles for you to play... Some are bundled with the code, scroll below the method arguments to see the example code. They all use the `dwv` prefix since the example are run in a pure javascript environment. This is not necessary in an es6 environment where you use the names defined when you import the classes.

DICOM parsing:
* [parser example #1](./DicomParser.html#DicomParser): parse DICOM data and display a tag
Expand Down
8 changes: 4 additions & 4 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export class AppOptions {
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* const options = new dwv.AppOptions(viewConfigs);
* app.init(options);
* // load dicom data
* app.loadURLs([
Expand Down Expand Up @@ -464,9 +464,9 @@ export class App {
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* const options = new dwv.AppOptions(viewConfigs);
* options.viewOnFirstLoadItem = false;
* app.init(options);
* // render button
Expand Down
21 changes: 20 additions & 1 deletion src/dicom/dicomParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {DataElement} from '../dicom/dataElement';
* @returns {string} The version of the library.
*/
export function getDwvVersion() {
return '0.32.2';
return '0.32.4';
}

/**
Expand Down Expand Up @@ -519,6 +519,18 @@ export function getDataElementPrefixByteSize(vr, isImplicit) {
return isImplicit ? 8 : is32bitVLVR(vr) ? 12 : 8;
}

/**
* Is the input VR a known VR.
*
* @param {string} vr The vr to test.
* @returns {boolean} True if known.
*/
function isKnownVR(vr) {
const extraVrTypes = ['NONE', 'ox', 'xx', 'xs'];
const knownTypes = Object.keys(vrTypes).concat(extraVrTypes);
return knownTypes.includes(vr);
}

/**
* DicomParser class.
*
Expand Down Expand Up @@ -799,6 +811,13 @@ export class DicomParser {
is32bitVL = true;
}

// check vr
if (!isKnownVR(vr)) {
logger.warn('Unknown VR: ' + vr +
' (for tag ' + tag.getKey() + '), treating as \'UN\'');
vr = 'UN';
}

// Value Length (VL)
let vl = 0;
if (is32bitVL) {
Expand Down
24 changes: 15 additions & 9 deletions src/dicom/dicomWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,24 @@ class DefaultTextEncoder {
* DICOM writer.
*
* @example
* // add link to html
* const link = document.createElement("a");
* link.appendChild(document.createTextNode("download"));
* const div = document.getElementById("dwv");
* div.appendChild(link);
* // XMLHttpRequest onload callback
* const onload = function (event) {
* const parser = new DicomParser();
* const parser = new dwv.DicomParser();
* parser.parse(event.target.response);
* // create writer with parser data elements
* const writer = new DicomWriter(parser.getDicomElements());
* // create modified buffer and put it in a Blol
* const blob = new Blob([writer.getBuffer()], {type: 'application/dicom'});
* // example download link
* const element = document.getElementById("download");
* element.href = URL.createObjectURL(blob);
* element.download = "anonym.dcm";
* // create writer
* const writer = new dwv.DicomWriter();
* // get buffer using default rules
* const dicomBuffer = writer.getBuffer(parser.getDicomElements());
* // create blob
* const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
* // add blob to download link
* link.href = URL.createObjectURL(blob);
* link.download = "anonym.dcm";
* };
* // DICOM file request
* const request = new XMLHttpRequest();
Expand Down
4 changes: 3 additions & 1 deletion src/gui/viewLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,10 @@ export class ViewLayer {
// interaction events
const names = InteractionEventNames;
for (let i = 0; i < names.length; ++i) {
const eventName = names[i];
const passive = eventName !== 'wheel';
this.#containerDiv.addEventListener(
names[i], this.#fireEvent, {passive: true});
names[i], this.#fireEvent, {passive: passive});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export function createView(elements, image) {
* const dicomParser = new dwv.DicomParser();
* dicomParser.parse(event.target.response);
* // create the image object
* const image = createImage(dicomParser.getDicomElements());
* const image = dwv.createImage(dicomParser.getDicomElements());
* // create the view
* const view = createView(dicomParser.getDicomElements(), image);
* const view = dwv.createView(dicomParser.getDicomElements(), image);
* // setup canvas
* const canvas = document.createElement('canvas');
* canvas.width = 256;
Expand Down
6 changes: 3 additions & 3 deletions src/tools/opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {App} from '../app/application';
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {Opacity: new ToolConfig()};
* const options = new dwv.AppOptions(viewConfigs);
* options.tools = {Opacity: new dwv.ToolConfig()};
* app.init(options);
* // activate tool
* app.addEventListener('load', function () {
Expand Down
14 changes: 7 additions & 7 deletions src/tools/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {App} from '../app/application';
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {Scroll: new ToolConfig()};
* const options = new dwv.AppOptions(viewConfigs);
* options.tools = {Scroll: new dwv.ToolConfig()};
* app.init(options);
* // activate tool
* app.addEventListener('load', function () {
Expand All @@ -33,10 +33,10 @@ import {App} from '../app/application';
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {Scroll: new ToolConfig()};
* const options = new dwv.AppOptions(viewConfigs);
* options.tools = {Scroll: new dwv.ToolConfig()};
* app.init(options);
* // create range
* const range = document.createElement('input');
Expand All @@ -51,7 +51,7 @@ import {App} from '../app/application';
* const index = vc.getCurrentIndex();
* const values = index.getValues();
* values[2] = this.value;
* vc.setCurrentIndex(new Index(values));
* vc.setCurrentIndex(new dwv.Index(values));
* }
* // activate tool and update range max on load
* app.addEventListener('load', function () {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/scrollWheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class ScrollWheel {
this.#wheelDeltaY = 0;
}

// prevent default page scroll
event.preventDefault();

const up = event.deltaY < 0 ? true : false;

const layerDetails = getLayerDetailsFromEvent(event);
Expand Down
6 changes: 3 additions & 3 deletions src/tools/windowLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {App} from '../app/application';
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {WindowLevel: new ToolConfig()};
* const options = new dwv.AppOptions(viewConfigs);
* options.tools = {WindowLevel: new dwv.ToolConfig()};
* app.init(options);
* // activate tool
* app.addEventListener('load', function () {
Expand Down
9 changes: 6 additions & 3 deletions src/tools/zoomPan.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {App} from '../app/application';
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {ZoomAndPan: new ToolConfig()};
* const options = new dwv.AppOptions(viewConfigs);
* options.tools = {ZoomAndPan: new dwv.ToolConfig()};
* app.init(options);
* // activate tool
* app.addEventListener('load', function () {
Expand Down Expand Up @@ -222,6 +222,9 @@ export class ZoomAndPan {
* @param {object} event The mouse wheel event.
*/
wheel = (event) => {
// prevent default page scroll
event.preventDefault();

const step = -event.deltaY / 500;

const layerDetails = getLayerDetailsFromEvent(event);
Expand Down
4 changes: 0 additions & 4 deletions src/utils/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ export function getFlags(inputStr) {
*
* @param {string} inputStr The input string.
* @param {object} values A object of {value, unit}.
* @example
* const values = {"length": { "value": 33, "unit": "cm" } };
* const str = "The length is: {length}.";
* const res = dwv.replaceFlags(str, values); // "The length is: 33 cm."
* @returns {string} The result string.
*/
export function replaceFlags(inputStr, values) {
Expand Down

0 comments on commit 085f3db

Please sign in to comment.