utils

dwv. utils

Classes

ListenerHandler
ThreadPool
WorkerTask
WorkerThread

Namespaces

logger

Members

(static) d65

Source:
See:

CIE Standard Illuminant D65

Methods

(static) capitaliseFirstLetter(string) → {string}

Source:

Capitalise the first letter of a string.

Parameters:
Name Type Description
string string

The string to capitalise the first letter.

Returns:

The new string.

Type
string

(static) cielabToCiexyz(triplet) → {object}

Source:
See:

Convert CIE LAB to CIE XYZ (standard illuminant D65, 2degree 1931).

Parameters:
Name Type Description
triplet object

CIE LAB triplet as {l,a,b}.

Returns:

CIE XYZ triplet as {x,y,z}.

Type
object

(static) cielabToSrgb(triplet) → {object}

Source:

Convert CIE LAB to sRGB (standard illuminant D65).

Parameters:
Name Type Description
triplet object

CIE LAB triplet as {l,a,b}.

Returns:

sRGB triplet as {r,g,b}.

Type
object

(static) ciexyzToCielab(triplet) → {object}

Source:
See:

Convert CIE XYZ to CIE LAB (standard illuminant D65, 2degree 1931).

Parameters:
Name Type Description
triplet object

CIE XYZ triplet as {x,y,z}.

Returns:

CIE LAB triplet as {l,a,b}.

Type
object

(static) ciexyzToSrgb(triplet) → {object}

Source:
See:

Convert CIE XYZ to sRGB.

Parameters:
Name Type Description
triplet object

CIE XYZ triplet as {x,y,z}.

Returns:

sRGB triplet as {r,g,b}.

Type
object

(static) colourNameToHex(name) → {string}

Source:

Get the hex code of a string colour for a colour used in pre dwv v0.17.

Parameters:
Name Type Description
name string

The name of a colour.

Returns:

The hex representing the colour.

Type
string

(static) decodeKeyValueUri(uri, replaceMode) → {Array}

Source:

Decode a Key/Value pair URI. If a key is repeated, the result be an array of base + each key.

Parameters:
Name Type Description
uri string

The URI to decode.

replaceMode string

The key replace more. replaceMode can be:

  • key (default): keep the key
  • other than key: do not use the key 'file' is a special case where the '?' of the query is not kept.
Returns:

The list of input file urls.

Type
Array

(static) decodeManifest(manifest, nslices) → {Array}

Source:

Decode an XML manifest.

Parameters:
Name Type Description
manifest object

The manifest to decode.

nslices number

The number of slices to load.

Returns:

The decoded manifest.

Type
Array

(static) decodeQuery(query, callback)

Source:

Generic URI query decoder. Supports manifest: [dwv root]?input=encodeURIComponent('[manifest file]')&type=manifest or encoded URI with base and key value/pairs: [dwv root]?input=encodeURIComponent([root]?key0=value0&key1=value1)

Parameters:
Name Type Description
query string

The query part to the input URI.

callback function

The function to call with the decoded file urls.

(static) endsWith(str, end) → {boolean}

Source:

Check if a string ends with the input element.

Parameters:
Name Type Description
str string

The input string.

end string

The searched ending.

Returns:

True if the input string ends with the seached ending.

Type
boolean

(static) getBrightness(rgbTriplet) → {number}

Source:
See:

Get the brightness of a RGB colour: calculates the luma (Y) of the YIQ colour space.

Parameters:
Name Type Description
rgbTriplet object

RGB triplet.

Returns:

The brightness ([0,1]).

Type
number

(static) getFileExtension(filePath) → {string}

Source:

Get a file extension: anything after the last dot. File name starting with a dot are discarded. Extensions are expected to contain at least one letter.

Parameters:
Name Type Description
filePath string

The file path containing the file name.

Returns:

The lower case file extension or null for none.

Type
string

(static) getFlags(inputStr) → {Array}

Source:

Get flags from an input string. Flags are words surrounded with curly braces.

Parameters:
Name Type Description
inputStr string

The input string.

Returns:

An array of found flags.

Type
Array

(static) getRootPath(path) → {string}

Source:

Get the root of an input path. Splits using / as separator.

Parameters:
Name Type Description
path string

The input path

Returns:

The input path without its last part.

Type
string

(static) getShadowColour(hexColour) → {string}

Source:

Get the shadow colour of an input colour.

Parameters:
Name Type Description
hexColour string

The colour (as '#ab01ef').

Returns:

The shadow colour (white or black).

Type
string

(static) getUriQuery(uri) → {object}

Source:

Get the query part, split into an array, of an input URI. The URI scheme is: 'base?query#fragment'

Parameters:
Name Type Description
uri string

The input URI.

Returns:

The query part, split into an array, of the input URI.

Type
object

(static) getUrlFromUri(uri) → {URL}

Source:

Get an object URL from a string uri.

Parameters:
Name Type Description
uri string

A string representing the url.

Returns:

A URL object (full or simple depending upon platform). WANRING: returns an official URL or a simple URL depending on platform, see https://caniuse.com/#feat=url

Type
URL

(static) getUrlFromUriFull(uri) → {URL}

Source:

Get an full object URL from a string uri.

Parameters:
Name Type Description
uri string

A string representing the url.

Returns:

A URL object. WARNING: platform support dependent, see https://caniuse.com/#feat=url

Type
URL

(static) getUrlFromUriSimple(uri) → {URL}

Source:

Get an simple object URL from a string uri.

Parameters:
Name Type Description
uri string

A string representing the url.

Returns:

A simple URL object that exposes 'pathname' and 'searchParams.get()' WARNING: limited functionality, simple nmock of the URL object.

Type
URL

(static) hexToRgb(hexColour) → {object}

Source:

Convert a hexadecimal colour to RGB.

Parameters:
Name Type Description
hexColour string

The hexadecimal color as '#ab01ef'.

Returns:

RGB equivalent as {r,g,b}.

Type
object

(static) isArray(unknown) → {boolean}

Source:

Check if the input is an array.

Parameters:
Name Type Description
unknown *

The input to check.

Returns:

True if the input is an array. ref: https://github.com/jashkenas/underscore/blob/1.9.1/underscore.js#L1313-L1317

Type
boolean

(static) isDarkColour(hexColour) → {boolean}

Source:

Check if a colour given in hexadecimal format is dark.

Parameters:
Name Type Description
hexColour string

The colour (as '#ab01ef').

Returns:

True if the colour is dark (brightness < 0.5).

Type
boolean

(static) isObject(unknown) → {boolean}

Source:

Check if the input is a generic object, including arrays.

Parameters:
Name Type Description
unknown *

The input to check.

Returns:

True if the input is an object. ref: https://github.com/jashkenas/underscore/blob/1.9.1/underscore.js#L1319-L1323

Type
boolean

(static) labToUintLab(triplet) → {object}

Source:

CIE LAB value (L: [0, 100], a: [-128, 127], b: [-128, 127]) to unsigned int CIE LAB ([0, 65535]).

Parameters:
Name Type Description
triplet object

CIE XYZ triplet as {x,y,z} with CIE LAB range.

Returns:

CIE LAB triplet as {l,a,b} with unsigned range.

Type
object

(static) loadFromQuery(query, app)

Source:

Load from an input query

Parameters:
Name Type Description
query object

A query derived from an uri.

app object

The associated app that handles the load.

(static) loadFromUri(uri, app)

Source:

Load from an input uri

Parameters:
Name Type Description
uri string

The input uri, for example: 'window.location.href'.

app dwv.App

The associated app that handles the load.

(static) mergeObjects(obj1, obj2, idKey, valueKey) → {object}

Source:

Merge two similar objects. Objects need to be in the form of: { idKey: {valueKey: 0}, key0: {valueKey: "abc"}, key1: {valueKey: 33} } Merged objects will be in the form of: { idKey: {valueKey: [0,1,2], merged: true}, key0: {valueKey: { 0: {valueKey: "abc"}, 1: {valueKey: "def"}, 2: {valueKey: "ghi"} }}, key1: {valueKey: { 0: {valueKey: 33}, 1: {valueKey: 44}, 2: {valueKey: 55} }} }

Parameters:
Name Type Description
obj1 object

The first object, can be the result of a previous merge.

obj2 object

The second object.

idKey string

The key to use as index for duplicate values.

valueKey string

The key to use to access object values.

Returns:

The merged object.

Type
object

(static) MultiProgressHandler(callback)

Source:

Multiple progresses handler. Stores a multi dimensional list of progresses to allow to calculate a global progress.

Parameters:
Name Type Description
callback function

The function to pass the global progress to.

(static) objectToArray(obj) → {Array}

Source:

Dump an object to an array.

Parameters:
Name Type Description
obj object

The input object as: {key0: {}, key1: {}}

Returns:

The corresponding array: [{name: key0, {}}, {name: key1, {}}]

Type
Array

(static) replaceFlags(inputStr, values) → {string}

Source:

Replace flags in a input string. Flags are keywords surrounded with curly braces.

Example
var values = {"length": { "value": 33, "unit": "cm" } };
   var str = "The length is: {length}.";
   var res = dwv.utils.replaceFlags(str, values); // "The length is: 33 cm."
Parameters:
Name Type Description
inputStr string

The input string.

values object

A object of {value, unit}.

Returns:

The result string.

Type
string

(static) replaceFlags2(inputStr, values) → {string}

Source:

Replace flags in a input string. Flags are keywords surrounded with curly braces.

Example
var values = ["a", "b"];
   var str = "The length is: {v0}. The size is: {v1}";
   var res = dwv.utils.replaceFlags2(str, values);
   // "The length is: a. The size is: b"
Parameters:
Name Type Description
inputStr string

The input string.

values Array

An array of strings.

Returns:

The result string.

Type
string

(static) splitKeyValueString(inputStr) → {object}

Source:

Split key/value string: key0=val00&key0=val01&key1=val10 returns { key0 : [val00, val01], key1 : val1 }

Parameters:
Name Type Description
inputStr string

The string to split.

Returns:

The split string.

Type
object

(static) splitUri(uri) → {object}

Source:

Split an input URI: 'root?key0=val00&key0=val01&key1=val10' returns { base : root, query : [ key0 : [val00, val01], key1 : val1 ] } Returns an empty object if the input string is not correct (null, empty...) or if it is not a query string (no question mark).

Parameters:
Name Type Description
uri string

The string to split.

Returns:

The split string.

Type
object

(static) srgbToCielab(triplet) → {object}

Source:

Convert sRGB to CIE LAB (standard illuminant D65).

Parameters:
Name Type Description
triplet object

sRGB triplet as {r,g,b}.

Returns:

CIE LAB triplet as {l,a,b}.

Type
object

(static) srgbToCiexyz(triplet) → {object}

Source:
See:

Convert sRGB to CIE XYZ.

Parameters:
Name Type Description
triplet object

sRGB triplet as {r,g,b}.

Returns:

CIE XYZ triplet as {x,y,z}.

Type
object

(static) uintLabToLab(triplet) → {object}

Source:

Unsigned int CIE LAB value ([0, 65535]) to CIE LAB value (L: [0, 100], a: [-128, 127], b: [-128, 127]).

Parameters:
Name Type Description
triplet object

CIE LAB triplet as {l,a,b} with unsigned range.

Returns:

CIE LAB triplet as {l,a,b} with CIE LAB range.

Type
object

(static) ybrToRgb(y, cb, cr) → {object}

Source:
See:

Convert YBR to RGB.

Parameters:
Name Type Description
y number

The Y component.

cb number

The Cb component.

cr number

The Cr component.

Returns:

RGB equivalent as {r,g,b}.

Type
object