')
@@ -476,10 +476,10 @@ class LabelSplitter {
* @returns {Array}
*/
splitMarkdownBlocks(text) {
- let s = new MarkupAccumulator(text);
+ const s = new MarkupAccumulator(text);
let beginable = true;
- let parseOverride = (ch) => {
+ const parseOverride = (ch) => {
if (/\\/.test(ch)) {
if (s.position < this.text.length + 1) {
s.position++;
@@ -499,9 +499,9 @@ class LabelSplitter {
}
while (s.position < s.text.length) {
- let ch = s.text.charAt(s.position);
+ const ch = s.text.charAt(s.position);
- let parsed = s.parseWS(ch)
+ const parsed = s.parseWS(ch)
|| parseOverride(ch)
|| ((beginable || s.spacing) && (
s.parseStartTag('bold', '*')
@@ -531,7 +531,7 @@ class LabelSplitter {
* @private
*/
splitBlocks(text, markupSystem) {
- let system = this.decodeMarkupSystem(markupSystem);
+ const system = this.decodeMarkupSystem(markupSystem);
if (system === 'none') {
return [{
text: text,
@@ -551,7 +551,7 @@ class LabelSplitter {
* @private
*/
overMaxWidth(text) {
- let width = this.ctx.measureText(text).width;
+ const width = this.ctx.measureText(text).width;
return (this.lines.curWidth() + width > this.parent.fontOptions.maxWdt);
}
@@ -569,8 +569,8 @@ class LabelSplitter {
let w = 0;
while (w < words.length) {
- let pre = (text === '') ? '' : ' ';
- let newText = text + pre + words[w];
+ const pre = (text === '') ? '' : ' ';
+ const newText = text + pre + words[w];
if (this.overMaxWidth(newText)) break;
text = newText;
@@ -630,10 +630,10 @@ class LabelSplitter {
if (w === 0) {
// Special case: the first word is already larger than the max width.
- let word = words[0];
+ const word = words[0];
// Break the word to the largest part that fits the line
- let x = this.getLongestFitWord(word);
+ const x = this.getLongestFitWord(word);
this.lines.newLine(word.slice(0, x), mod);
// Adjust the word, so that the rest will be done next iteration
@@ -647,7 +647,7 @@ class LabelSplitter {
newW++;
}
- let text = words.slice(0, w).join("");
+ const text = words.slice(0, w).join("");
if (w == words.length && appendLast) {
this.lines.append(text, mod);
diff --git a/lib/network/options.js b/lib/network/options.js
index 34542290af..bf8a7cf89b 100644
--- a/lib/network/options.js
+++ b/lib/network/options.js
@@ -5,16 +5,16 @@
* __any__ means that the name of the property does not matter.
* __type__ is a required field for all objects and contains the allowed types of all objects
*/
-let string = 'string';
-let bool = 'boolean';
-let number = 'number';
-let array = 'array';
-let object = 'object'; // should only be in a __type__ property
-let dom = 'dom';
-let any = 'any';
+const string = 'string';
+const bool = 'boolean';
+const number = 'number';
+const array = 'array';
+const object = 'object'; // should only be in a __type__ property
+const dom = 'dom';
+const any = 'any';
// List of endpoints
-let endPoints = [
+const endPoints = [
"arrow",
"bar",
"box",
@@ -29,7 +29,7 @@ let endPoints = [
"vee"
];
-let allOptions = {
+const allOptions = {
configure: {
enabled: { boolean: bool },
filter: { boolean: bool, string, array, 'function': 'function' },
@@ -518,7 +518,7 @@ allOptions.manipulation.controlNodeStyle = allOptions.nodes;
* The first value says this will be a color picker not a dropdown menu. The
* next value is the initial color.
*/
-let configureOptions = {
+const configureOptions = {
nodes: {
borderWidth: [1, 0, 10, 1],
borderWidthSelected: [2, 0, 10, 1],
diff --git a/lib/shared/Activator.js b/lib/shared/Activator.js
index 56891910ba..fa5bdb817f 100644
--- a/lib/shared/Activator.js
+++ b/lib/shared/Activator.js
@@ -31,7 +31,7 @@ function Activator(container) {
this.hammer.on('tap', this._onTapOverlay.bind(this));
// block all touch events (except tap)
- var events = [
+ const events = [
'tap', 'doubletap', 'press',
'pinch',
'pan', 'panstart', 'panmove', 'panend'
diff --git a/lib/shared/ColorPicker.js b/lib/shared/ColorPicker.js
index 0b2c46003a..2227a5f774 100644
--- a/lib/shared/ColorPicker.js
+++ b/lib/shared/ColorPicker.js
@@ -13,7 +13,7 @@ import {
} from 'vis-util/esnext';
-var htmlColors = {black: '#000000', navy: '#000080', darkblue: '#00008B', mediumblue: '#0000CD', blue: '#0000FF', darkgreen: '#006400', green: '#008000', teal: '#008080', darkcyan: '#008B8B', deepskyblue: '#00BFFF', darkturquoise: '#00CED1', mediumspringgreen: '#00FA9A', lime: '#00FF00', springgreen: '#00FF7F', aqua: '#00FFFF', cyan: '#00FFFF', midnightblue: '#191970', dodgerblue: '#1E90FF', lightseagreen: '#20B2AA', forestgreen: '#228B22', seagreen: '#2E8B57', darkslategray: '#2F4F4F', limegreen: '#32CD32', mediumseagreen: '#3CB371', turquoise: '#40E0D0', royalblue: '#4169E1', steelblue: '#4682B4', darkslateblue: '#483D8B', mediumturquoise: '#48D1CC', indigo: '#4B0082', darkolivegreen: '#556B2F', cadetblue: '#5F9EA0', cornflowerblue: '#6495ED', mediumaquamarine: '#66CDAA', dimgray: '#696969', slateblue: '#6A5ACD', olivedrab: '#6B8E23', slategray: '#708090', lightslategray: '#778899', mediumslateblue: '#7B68EE', lawngreen: '#7CFC00', chartreuse: '#7FFF00', aquamarine: '#7FFFD4', maroon: '#800000', purple: '#800080', olive: '#808000', gray: '#808080', skyblue: '#87CEEB', lightskyblue: '#87CEFA', blueviolet: '#8A2BE2', darkred: '#8B0000', darkmagenta: '#8B008B', saddlebrown: '#8B4513', darkseagreen: '#8FBC8F', lightgreen: '#90EE90', mediumpurple: '#9370D8', darkviolet: '#9400D3', palegreen: '#98FB98', darkorchid: '#9932CC', yellowgreen: '#9ACD32', sienna: '#A0522D', brown: '#A52A2A', darkgray: '#A9A9A9', lightblue: '#ADD8E6', greenyellow: '#ADFF2F', paleturquoise: '#AFEEEE', lightsteelblue: '#B0C4DE', powderblue: '#B0E0E6', firebrick: '#B22222', darkgoldenrod: '#B8860B', mediumorchid: '#BA55D3', rosybrown: '#BC8F8F', darkkhaki: '#BDB76B', silver: '#C0C0C0', mediumvioletred: '#C71585', indianred: '#CD5C5C', peru: '#CD853F', chocolate: '#D2691E', tan: '#D2B48C', lightgrey: '#D3D3D3', palevioletred: '#D87093', thistle: '#D8BFD8', orchid: '#DA70D6', goldenrod: '#DAA520', crimson: '#DC143C', gainsboro: '#DCDCDC', plum: '#DDA0DD', burlywood: '#DEB887', lightcyan: '#E0FFFF', lavender: '#E6E6FA', darksalmon: '#E9967A', violet: '#EE82EE', palegoldenrod: '#EEE8AA', lightcoral: '#F08080', khaki: '#F0E68C', aliceblue: '#F0F8FF', honeydew: '#F0FFF0', azure: '#F0FFFF', sandybrown: '#F4A460', wheat: '#F5DEB3', beige: '#F5F5DC', whitesmoke: '#F5F5F5', mintcream: '#F5FFFA', ghostwhite: '#F8F8FF', salmon: '#FA8072', antiquewhite: '#FAEBD7', linen: '#FAF0E6', lightgoldenrodyellow: '#FAFAD2', oldlace: '#FDF5E6', red: '#FF0000', fuchsia: '#FF00FF', magenta: '#FF00FF', deeppink: '#FF1493', orangered: '#FF4500', tomato: '#FF6347', hotpink: '#FF69B4', coral: '#FF7F50', darkorange: '#FF8C00', lightsalmon: '#FFA07A', orange: '#FFA500', lightpink: '#FFB6C1', pink: '#FFC0CB', gold: '#FFD700', peachpuff: '#FFDAB9', navajowhite: '#FFDEAD', moccasin: '#FFE4B5', bisque: '#FFE4C4', mistyrose: '#FFE4E1', blanchedalmond: '#FFEBCD', papayawhip: '#FFEFD5', lavenderblush: '#FFF0F5', seashell: '#FFF5EE', cornsilk: '#FFF8DC', lemonchiffon: '#FFFACD', floralwhite: '#FFFAF0', snow: '#FFFAFA', yellow: '#FFFF00', lightyellow: '#FFFFE0', ivory: '#FFFFF0', white: '#FFFFFF'};
+const htmlColors = {black: '#000000', navy: '#000080', darkblue: '#00008B', mediumblue: '#0000CD', blue: '#0000FF', darkgreen: '#006400', green: '#008000', teal: '#008080', darkcyan: '#008B8B', deepskyblue: '#00BFFF', darkturquoise: '#00CED1', mediumspringgreen: '#00FA9A', lime: '#00FF00', springgreen: '#00FF7F', aqua: '#00FFFF', cyan: '#00FFFF', midnightblue: '#191970', dodgerblue: '#1E90FF', lightseagreen: '#20B2AA', forestgreen: '#228B22', seagreen: '#2E8B57', darkslategray: '#2F4F4F', limegreen: '#32CD32', mediumseagreen: '#3CB371', turquoise: '#40E0D0', royalblue: '#4169E1', steelblue: '#4682B4', darkslateblue: '#483D8B', mediumturquoise: '#48D1CC', indigo: '#4B0082', darkolivegreen: '#556B2F', cadetblue: '#5F9EA0', cornflowerblue: '#6495ED', mediumaquamarine: '#66CDAA', dimgray: '#696969', slateblue: '#6A5ACD', olivedrab: '#6B8E23', slategray: '#708090', lightslategray: '#778899', mediumslateblue: '#7B68EE', lawngreen: '#7CFC00', chartreuse: '#7FFF00', aquamarine: '#7FFFD4', maroon: '#800000', purple: '#800080', olive: '#808000', gray: '#808080', skyblue: '#87CEEB', lightskyblue: '#87CEFA', blueviolet: '#8A2BE2', darkred: '#8B0000', darkmagenta: '#8B008B', saddlebrown: '#8B4513', darkseagreen: '#8FBC8F', lightgreen: '#90EE90', mediumpurple: '#9370D8', darkviolet: '#9400D3', palegreen: '#98FB98', darkorchid: '#9932CC', yellowgreen: '#9ACD32', sienna: '#A0522D', brown: '#A52A2A', darkgray: '#A9A9A9', lightblue: '#ADD8E6', greenyellow: '#ADFF2F', paleturquoise: '#AFEEEE', lightsteelblue: '#B0C4DE', powderblue: '#B0E0E6', firebrick: '#B22222', darkgoldenrod: '#B8860B', mediumorchid: '#BA55D3', rosybrown: '#BC8F8F', darkkhaki: '#BDB76B', silver: '#C0C0C0', mediumvioletred: '#C71585', indianred: '#CD5C5C', peru: '#CD853F', chocolate: '#D2691E', tan: '#D2B48C', lightgrey: '#D3D3D3', palevioletred: '#D87093', thistle: '#D8BFD8', orchid: '#DA70D6', goldenrod: '#DAA520', crimson: '#DC143C', gainsboro: '#DCDCDC', plum: '#DDA0DD', burlywood: '#DEB887', lightcyan: '#E0FFFF', lavender: '#E6E6FA', darksalmon: '#E9967A', violet: '#EE82EE', palegoldenrod: '#EEE8AA', lightcoral: '#F08080', khaki: '#F0E68C', aliceblue: '#F0F8FF', honeydew: '#F0FFF0', azure: '#F0FFFF', sandybrown: '#F4A460', wheat: '#F5DEB3', beige: '#F5F5DC', whitesmoke: '#F5F5F5', mintcream: '#F5FFFA', ghostwhite: '#F8F8FF', salmon: '#FA8072', antiquewhite: '#FAEBD7', linen: '#FAF0E6', lightgoldenrodyellow: '#FAFAD2', oldlace: '#FDF5E6', red: '#FF0000', fuchsia: '#FF00FF', magenta: '#FF00FF', deeppink: '#FF1493', orangered: '#FF4500', tomato: '#FF6347', hotpink: '#FF69B4', coral: '#FF7F50', darkorange: '#FF8C00', lightsalmon: '#FFA07A', orange: '#FFA500', lightpink: '#FFB6C1', pink: '#FFC0CB', gold: '#FFD700', peachpuff: '#FFDAB9', navajowhite: '#FFDEAD', moccasin: '#FFE4B5', bisque: '#FFE4C4', mistyrose: '#FFE4E1', blanchedalmond: '#FFEBCD', papayawhip: '#FFEFD5', lavenderblush: '#FFF0F5', seashell: '#FFF5EE', cornsilk: '#FFF8DC', lemonchiffon: '#FFFACD', floralwhite: '#FFFAF0', snow: '#FFFAFA', yellow: '#FFFF00', lightyellow: '#FFFFE0', ivory: '#FFFFF0', white: '#FFFFFF'};
/**
* @param {number} [pixelRatio=1]
@@ -117,7 +117,7 @@ class ColorPicker {
let rgba;
// if a html color shorthand is used, convert to hex
- var htmlColor = this._isColorString(color);
+ const htmlColor = this._isColorString(color);
if (htmlColor !== undefined) {
color = htmlColor;
}
@@ -125,22 +125,22 @@ class ColorPicker {
// check format
if (isString(color) === true) {
if (isValidRGB(color) === true) {
- let rgbaArray = color.substr(4).substr(0, color.length - 5).split(',');
+ const rgbaArray = color.substr(4).substr(0, color.length - 5).split(',');
rgba = {r:rgbaArray[0], g:rgbaArray[1], b:rgbaArray[2], a:1.0};
}
else if (isValidRGBA(color) === true) {
- let rgbaArray = color.substr(5).substr(0, color.length - 6).split(',');
+ const rgbaArray = color.substr(5).substr(0, color.length - 6).split(',');
rgba = {r:rgbaArray[0], g:rgbaArray[1], b:rgbaArray[2], a:rgbaArray[3]};
}
else if (isValidHex(color) === true) {
- let rgbObj = hexToRGB(color);
+ const rgbObj = hexToRGB(color);
rgba = {r:rgbObj.r, g:rgbObj.g, b:rgbObj.b, a:1.0};
}
}
else {
if (color instanceof Object) {
if (color.r !== undefined && color.g !== undefined && color.b !== undefined) {
- let alpha = color.a !== undefined ? color.a : '1.0';
+ const alpha = color.a !== undefined ? color.a : '1.0';
rgba = {r:color.r, g:color.g, b:color.b, a:alpha};
}
}
@@ -251,12 +251,12 @@ class ColorPicker {
}
this.color = rgba;
- let hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
+ const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
- let angleConvert = 2 * Math.PI;
- let radius = this.r * hsv.s;
- let x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h);
- let y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h);
+ const angleConvert = 2 * Math.PI;
+ const radius = this.r * hsv.s;
+ const x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h);
+ const y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h);
this.colorPickerSelector.style.left = x - 0.5 * this.colorPickerSelector.clientWidth + 'px';
this.colorPickerSelector.style.top = y - 0.5 * this.colorPickerSelector.clientHeight + 'px';
@@ -282,9 +282,9 @@ class ColorPicker {
* @private
*/
_setBrightness(value) {
- let hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
+ const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
hsv.v = value / 100;
- let rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
+ const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
rgba['a'] = this.color.a;
this.color = rgba;
this._updatePicker();
@@ -297,8 +297,8 @@ class ColorPicker {
* @private
*/
_updatePicker(rgba = this.color) {
- let hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
- let ctx = this.colorPickerCanvas.getContext('2d');
+ const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
+ const ctx = this.colorPickerCanvas.getContext('2d');
if (this.pixelRation === undefined) {
this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
@@ -309,8 +309,8 @@ class ColorPicker {
ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
// clear the canvas
- let w = this.colorPickerCanvas.clientWidth;
- let h = this.colorPickerCanvas.clientHeight;
+ const w = this.colorPickerCanvas.clientWidth;
+ const h = this.colorPickerCanvas.clientHeight;
ctx.clearRect(0, 0, w, h);
ctx.putImageData(this.hueCircle, 0,0);
@@ -357,7 +357,7 @@ class ColorPicker {
this.colorPickerDiv.appendChild(this.colorPickerCanvas);
if (!this.colorPickerCanvas.getContext) {
- let noCanvas = document.createElement( 'DIV' );
+ const noCanvas = document.createElement( 'DIV' );
noCanvas.style.color = 'red';
noCanvas.style.fontWeight = 'bold' ;
noCanvas.style.padding = '10px';
@@ -365,7 +365,7 @@ class ColorPicker {
this.colorPickerCanvas.appendChild(noCanvas);
}
else {
- let ctx = this.colorPickerCanvas.getContext("2d");
+ const ctx = this.colorPickerCanvas.getContext("2d");
this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
@@ -410,7 +410,7 @@ class ColorPicker {
this.opacityDiv.appendChild(this.opacityRange);
this.brightnessDiv.appendChild(this.brightnessRange);
- var me = this;
+ const me = this;
this.opacityRange.onchange = function () {me._setOpacity(this.value);};
this.opacityRange.oninput = function () {me._setOpacity(this.value);};
this.brightnessRange.onchange = function () {me._setBrightness(this.value);};
@@ -492,7 +492,7 @@ class ColorPicker {
*/
_generateHueCircle() {
if (this.generated === false) {
- let ctx = this.colorPickerCanvas.getContext('2d');
+ const ctx = this.colorPickerCanvas.getContext('2d');
if (this.pixelRation === undefined) {
this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
@@ -503,8 +503,8 @@ class ColorPicker {
ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
// clear the canvas
- let w = this.colorPickerCanvas.clientWidth;
- let h = this.colorPickerCanvas.clientHeight;
+ const w = this.colorPickerCanvas.clientWidth;
+ const h = this.colorPickerCanvas.clientHeight;
ctx.clearRect(0, 0, w, h);
@@ -512,9 +512,9 @@ class ColorPicker {
let x, y, hue, sat;
this.centerCoordinates = {x: w * 0.5, y: h * 0.5};
this.r = 0.49 * w;
- let angleConvert = (2 * Math.PI) / 360;
- let hfac = 1 / 360;
- let sfac = 1 / this.r;
+ const angleConvert = (2 * Math.PI) / 360;
+ const hfac = 1 / 360;
+ const sfac = 1 / this.r;
let rgb;
for (hue = 0; hue < 360; hue++) {
for (sat = 0; sat < this.r; sat++) {
@@ -542,21 +542,21 @@ class ColorPicker {
* @private
*/
_moveSelector(event) {
- let rect = this.colorPickerDiv.getBoundingClientRect();
- let left = event.center.x - rect.left;
- let top = event.center.y - rect.top;
+ const rect = this.colorPickerDiv.getBoundingClientRect();
+ const left = event.center.x - rect.left;
+ const top = event.center.y - rect.top;
- let centerY = 0.5 * this.colorPickerDiv.clientHeight;
- let centerX = 0.5 * this.colorPickerDiv.clientWidth;
+ const centerY = 0.5 * this.colorPickerDiv.clientHeight;
+ const centerX = 0.5 * this.colorPickerDiv.clientWidth;
- let x = left - centerX;
- let y = top - centerY;
+ const x = left - centerX;
+ const y = top - centerY;
- let angle = Math.atan2(x,y);
- let radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX);
+ const angle = Math.atan2(x,y);
+ const radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX);
- let newTop = Math.cos(angle) * radius + centerY;
- let newLeft = Math.sin(angle) * radius + centerX;
+ const newTop = Math.cos(angle) * radius + centerY;
+ const newLeft = Math.sin(angle) * radius + centerX;
this.colorPickerSelector.style.top = newTop - 0.5 * this.colorPickerSelector.clientHeight + 'px';
this.colorPickerSelector.style.left = newLeft - 0.5 * this.colorPickerSelector.clientWidth + 'px';
@@ -564,11 +564,11 @@ class ColorPicker {
// set color
let h = angle / (2 * Math.PI);
h = h < 0 ? h + 1 : h;
- let s = radius / this.r;
- let hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
+ const s = radius / this.r;
+ const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
hsv.h = h;
hsv.s = s;
- let rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
+ const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
rgba['a'] = this.color.a;
this.color = rgba;
diff --git a/lib/shared/Configurator.js b/lib/shared/Configurator.js
index 3a1710e7c5..1c8c083742 100644
--- a/lib/shared/Configurator.js
+++ b/lib/shared/Configurator.js
@@ -124,11 +124,11 @@ class Configurator {
this._clean();
this.changedOptions = [];
- let filter = this.options.filter;
+ const filter = this.options.filter;
let counter = 0;
let show = false;
- for (let option in this.configureOptions) {
- if (this.configureOptions.hasOwnProperty(option)) {
+ for (const option in this.configureOptions) {
+ if (Object.prototype.hasOwnProperty.call(this.configureOptions, option)) {
this.allowCreation = false;
show = false;
if (typeof filter === 'function') {
@@ -169,7 +169,7 @@ class Configurator {
this.wrapper = document.createElement('div');
this.wrapper.className = 'vis-configuration-wrapper';
this.container.appendChild(this.wrapper);
- for (var i = 0; i < this.domElements.length; i++) {
+ for (let i = 0; i < this.domElements.length; i++) {
this.wrapper.appendChild(this.domElements[i]);
}
@@ -182,7 +182,7 @@ class Configurator {
* @private
*/
_clean() {
- for (var i = 0; i < this.domElements.length; i++) {
+ for (let i = 0; i < this.domElements.length; i++) {
this.wrapper.removeChild(this.domElements[i]);
}
@@ -226,7 +226,7 @@ class Configurator {
*/
_makeItem(path, ...domElements) {
if (this.allowCreation === true) {
- let item = document.createElement('div');
+ const item = document.createElement('div');
item.className = 'vis-configuration vis-config-item vis-config-s' + path.length;
domElements.forEach((element) => {
item.appendChild(element);
@@ -244,7 +244,7 @@ class Configurator {
* @private
*/
_makeHeader(name) {
- let div = document.createElement('div');
+ const div = document.createElement('div');
div.className = 'vis-configuration vis-config-header';
div.innerHTML = name;
this._makeItem([],div);
@@ -260,7 +260,7 @@ class Configurator {
* @private
*/
_makeLabel(name, path, objectLabel = false) {
- let div = document.createElement('div');
+ const div = document.createElement('div');
div.className = 'vis-configuration vis-config-label vis-config-s' + path.length;
if (objectLabel === true) {
div.innerHTML = '' + name + ':';
@@ -280,7 +280,7 @@ class Configurator {
* @private
*/
_makeDropdown(arr, value, path) {
- let select = document.createElement('select');
+ const select = document.createElement('select');
select.className = 'vis-configuration vis-config-select';
let selectedValue = 0;
if (value !== undefined) {
@@ -290,7 +290,7 @@ class Configurator {
}
for (let i = 0; i < arr.length; i++) {
- let option = document.createElement('option');
+ const option = document.createElement('option');
option.value = arr[i];
if (i === selectedValue) {
option.selected = 'selected';
@@ -299,10 +299,10 @@ class Configurator {
select.appendChild(option);
}
- let me = this;
+ const me = this;
select.onchange = function () {me._update(this.value, path);};
- let label = this._makeLabel(path[path.length-1], path);
+ const label = this._makeLabel(path[path.length-1], path);
this._makeItem(path, label, select);
}
@@ -315,11 +315,11 @@ class Configurator {
* @private
*/
_makeRange(arr, value, path) {
- let defaultValue = arr[0];
- let min = arr[1];
- let max = arr[2];
- let step = arr[3];
- let range = document.createElement('input');
+ const defaultValue = arr[0];
+ const min = arr[1];
+ const max = arr[2];
+ const step = arr[3];
+ const range = document.createElement('input');
range.className = 'vis-configuration vis-config-range';
try {
range.type = 'range'; // not supported on IE9
@@ -335,7 +335,7 @@ class Configurator {
let popupValue = 0;
if (value !== undefined) {
- let factor = 1.20;
+ const factor = 1.20;
if (value < 0 && value * factor < min) {
range.min = Math.ceil(value * factor);
popupValue = range.min;
@@ -357,16 +357,16 @@ class Configurator {
range.value = defaultValue;
}
- let input = document.createElement('input');
+ const input = document.createElement('input');
input.className = 'vis-configuration vis-config-rangeinput';
input.value = range.value;
- var me = this;
+ const me = this;
range.onchange = function () {input.value = this.value; me._update(Number(this.value), path);};
range.oninput = function () {input.value = this.value; };
- let label = this._makeLabel(path[path.length-1], path);
- let itemIndex = this._makeItem(path, label, range, input);
+ const label = this._makeLabel(path[path.length-1], path);
+ const itemIndex = this._makeItem(path, label, range, input);
// if a popup is needed AND it has not been shown for this value, show it.
if (popupString !== '' && this.popupHistory[itemIndex] !== popupValue) {
@@ -381,7 +381,7 @@ class Configurator {
*/
_makeButton() {
if (this.options.showButton === true) {
- let generateButton = document.createElement('div');
+ const generateButton = document.createElement('div');
generateButton.className = 'vis-configuration vis-config-button';
generateButton.innerHTML = 'generate options';
generateButton.onclick = () => {this._printOptions();};
@@ -405,7 +405,7 @@ class Configurator {
*/
_setupPopup(string, index) {
if (this.initialized === true && this.allowCreation === true && this.popupCounter < this.popupLimit) {
- let div = document.createElement("div");
+ const div = document.createElement("div");
div.id = "vis-configuration-popup";
div.className = "vis-configuration-popup";
div.innerHTML = string;
@@ -436,8 +436,8 @@ class Configurator {
*/
_showPopupIfNeeded() {
if (this.popupDiv.html !== undefined) {
- let correspondingElement = this.domElements[this.popupDiv.index];
- let rect = correspondingElement.getBoundingClientRect();
+ const correspondingElement = this.domElements[this.popupDiv.index];
+ const rect = correspondingElement.getBoundingClientRect();
this.popupDiv.html.style.left = rect.left + "px";
this.popupDiv.html.style.top = rect.top - 30 + "px"; // 30 is the height;
document.body.appendChild(this.popupDiv.html)
@@ -458,7 +458,7 @@ class Configurator {
* @private
*/
_makeCheckbox(defaultValue, value, path) {
- var checkbox = document.createElement('input');
+ const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'vis-configuration vis-config-checkbox';
checkbox.checked = defaultValue;
@@ -476,10 +476,10 @@ class Configurator {
}
}
- let me = this;
+ const me = this;
checkbox.onchange = function() {me._update(this.checked, path)};
- let label = this._makeLabel(path[path.length-1], path);
+ const label = this._makeLabel(path[path.length-1], path);
this._makeItem(path, label, checkbox);
}
@@ -491,7 +491,7 @@ class Configurator {
* @private
*/
_makeTextInput(defaultValue, value, path) {
- var checkbox = document.createElement('input');
+ const checkbox = document.createElement('input');
checkbox.type = 'text';
checkbox.className = 'vis-configuration vis-config-text';
checkbox.value = value;
@@ -499,10 +499,10 @@ class Configurator {
this.changedOptions.push({path:path, value:value});
}
- let me = this;
+ const me = this;
checkbox.onchange = function() {me._update(this.value, path)};
- let label = this._makeLabel(path[path.length-1], path);
+ const label = this._makeLabel(path[path.length-1], path);
this._makeItem(path, label, checkbox);
}
@@ -515,8 +515,8 @@ class Configurator {
* @private
*/
_makeColorField(arr, value, path) {
- let defaultColor = arr[1];
- let div = document.createElement('div');
+ const defaultColor = arr[1];
+ const div = document.createElement('div');
value = value === undefined ? defaultColor : value;
if (value !== 'none') {
@@ -532,7 +532,7 @@ class Configurator {
this._showColorPicker(value,div,path);
};
- let label = this._makeLabel(path[path.length-1], path);
+ const label = this._makeLabel(path[path.length-1], path);
this._makeItem(path,label, div);
}
@@ -553,7 +553,7 @@ class Configurator {
this.colorPicker.setColor(value);
this.colorPicker.setUpdateCallback((color) => {
- let colorString = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')';
+ const colorString = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')';
div.style.backgroundColor = colorString;
this._update(colorString,path);
});
@@ -577,13 +577,13 @@ class Configurator {
*/
_handleObject(obj, path = [], checkOnly = false) {
let show = false;
- let filter = this.options.filter;
+ const filter = this.options.filter;
let visibleInSet = false;
- for (let subObj in obj) {
- if (obj.hasOwnProperty(subObj)) {
+ for (const subObj in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, subObj)) {
show = true;
- let item = obj[subObj];
- let newPath = copyAndExtendArray(path, subObj);
+ const item = obj[subObj];
+ const newPath = copyAndExtendArray(path, subObj);
if (typeof filter === 'function') {
show = filter(subObj,path);
@@ -599,7 +599,7 @@ class Configurator {
if (show !== false) {
visibleInSet = true;
- let value = this._getValue(newPath);
+ const value = this._getValue(newPath);
if (item instanceof Array) {
this._handleArray(item, value, newPath);
@@ -622,10 +622,10 @@ class Configurator {
if (draw === true) {
// initially collapse options with an disabled enabled option.
if (item.enabled !== undefined) {
- let enabledPath = copyAndExtendArray(newPath, 'enabled');
- let enabledValue = this._getValue(enabledPath);
+ const enabledPath = copyAndExtendArray(newPath, 'enabled');
+ const enabledValue = this._getValue(enabledPath);
if (enabledValue === true) {
- let label = this._makeLabel(subObj, newPath, true);
+ const label = this._makeLabel(subObj, newPath, true);
this._makeItem(newPath, label);
visibleInSet = this._handleObject(item, newPath) || visibleInSet;
}
@@ -634,7 +634,7 @@ class Configurator {
}
}
else {
- let label = this._makeLabel(subObj, newPath, true);
+ const label = this._makeLabel(subObj, newPath, true);
this._makeItem(newPath, label);
visibleInSet = this._handleObject(item, newPath) || visibleInSet;
}
@@ -681,7 +681,7 @@ class Configurator {
* @private
*/
_update(value, path) {
- let options = this._constructOptions(value,path);
+ const options = this._constructOptions(value,path);
if (this.parent.body && this.parent.body.emitter && this.parent.body.emitter.emit) {
this.parent.body.emitter.emit("configChange", options);
@@ -726,7 +726,7 @@ class Configurator {
* @private
*/
_printOptions() {
- let options = this.getOptions();
+ const options = this.getOptions();
this.optionsContainer.innerHTML = 'var options = ' + JSON.stringify(options, null, 2) + '
';
}
@@ -735,8 +735,8 @@ class Configurator {
* @returns {{}} options
*/
getOptions() {
- let options = {};
- for (var i = 0; i < this.changedOptions.length; i++) {
+ const options = {};
+ for (let i = 0; i < this.changedOptions.length; i++) {
this._constructOptions(this.changedOptions[i].value, this.changedOptions[i].path, options)
}
return options;
diff --git a/lib/shared/Popup.js b/lib/shared/Popup.js
index 9b0104e000..e5634121cb 100644
--- a/lib/shared/Popup.js
+++ b/lib/shared/Popup.js
@@ -56,15 +56,15 @@ class Popup {
}
if (doShow === true) {
- var height = this.frame.clientHeight;
- var width = this.frame.clientWidth;
- var maxHeight = this.frame.parentNode.clientHeight;
- var maxWidth = this.frame.parentNode.clientWidth;
+ const height = this.frame.clientHeight;
+ const width = this.frame.clientWidth;
+ const maxHeight = this.frame.parentNode.clientHeight;
+ const maxWidth = this.frame.parentNode.clientWidth;
- var left = 0, top = 0;
+ let left = 0, top = 0;
if (this.overflowMethod == 'flip') {
- var isLeft = false, isTop = true; // Where around the position it's located
+ let isLeft = false, isTop = true; // Where around the position it's located
if (this.y - height < this.padding) {
isTop = false;
diff --git a/lib/shared/Validator.js b/lib/shared/Validator.js
index 3f08b0dfe2..a3b413500c 100644
--- a/lib/shared/Validator.js
+++ b/lib/shared/Validator.js
@@ -2,7 +2,7 @@ import { copyAndExtendArray, copyArray } from 'vis-util/esnext';
let errorFound = false;
let allOptions;
-let printStyle = 'background: #FFeeee; color: #dd0000';
+const printStyle = 'background: #FFeeee; color: #dd0000';
/**
* Used to validate options.
*/
@@ -41,8 +41,8 @@ class Validator {
* @static
*/
static parse(options, referenceOptions, path) {
- for (let option in options) {
- if (options.hasOwnProperty(option)) {
+ for (const option in options) {
+ if (Object.prototype.hasOwnProperty.call(options, option)) {
Validator.check(option, options, referenceOptions, path);
}
}
@@ -103,12 +103,12 @@ class Validator {
* @static
*/
static checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path) {
- let log = function(message) {
+ const log = function(message) {
console.log('%c' + message + Validator.printLocation(path, option), printStyle);
};
- let optionType = Validator.getType(options[option]);
- let refOptionType = refOptionObj[optionType];
+ const optionType = Validator.getType(options[option]);
+ const refOptionType = refOptionObj[optionType];
if (refOptionType !== undefined) {
// if the type is correct, we check if it is supposed to be one of a few select values
@@ -139,7 +139,7 @@ class Validator {
* @static
*/
static getType(object) {
- var type = typeof object;
+ const type = typeof object;
if (type === 'object') {
if (object === null) {
@@ -190,11 +190,11 @@ class Validator {
* @static
*/
static getSuggestion(option, options, path) {
- let localSearch = Validator.findInOptions(option,options,path,false);
- let globalSearch = Validator.findInOptions(option,allOptions,[],true);
+ const localSearch = Validator.findInOptions(option,options,path,false);
+ const globalSearch = Validator.findInOptions(option,allOptions,[],true);
- let localSearchThreshold = 8;
- let globalSearchThreshold = 4;
+ const localSearchThreshold = 8;
+ const globalSearchThreshold = 4;
let msg;
if (localSearch.indexMatch !== undefined) {
@@ -232,12 +232,12 @@ class Validator {
let min = 1e9;
let closestMatch = '';
let closestMatchPath = [];
- let lowerCaseOption = option.toLowerCase();
+ const lowerCaseOption = option.toLowerCase();
let indexMatch = undefined;
- for (let op in options) { // eslint-disable-line guard-for-in
+ for (const op in options) { // eslint-disable-line guard-for-in
let distance;
if (options[op].__type__ !== undefined && recursive === true) {
- let result = Validator.findInOptions(option, options[op], copyAndExtendArray(path,op));
+ const result = Validator.findInOptions(option, options[op], copyAndExtendArray(path,op));
if (min > result.distance) {
closestMatch = result.closestMatch;
closestMatchPath = result.path;
@@ -319,16 +319,16 @@ class Validator {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
- var matrix = [];
+ const matrix = [];
// increment along the first column of each row
- var i;
+ let i;
for (i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
// increment each column in the first row
- var j;
+ let j;
for (j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
diff --git a/package.json b/package.json
index 0aca023ba4..170b24b77a 100644
--- a/package.json
+++ b/package.json
@@ -68,9 +68,7 @@
"build:watch": "rollup --watch --config rollup.build.js",
"prepublishOnly": "npm run build",
"generate-examples-index": "generate-examples-index --config generate-examples-index.json",
- "lint": "npm run lint:js && npm run lint:ts",
- "lint:js": "eslint '{lib,test}/**/*.js'",
- "lint:ts": "eslint '{cypress,lib,test}/**/*.ts'",
+ "lint": "eslint --ext js,json,ts cypress examples lib test",
"clean": "rimraf \"declarations\" \"dist\" \"examples/index.html\" \"examples/thumbnails\" \"peer\" \"standalone\" \"styles\" \"vis-network*\" \"cypress/{fixtures,integration,pages,support}/**/*.js{,.map}\" \"cypress/snapshots/{actual,diff}/*\"",
"postinstall": "opencollective postinstall || exit 0"
},
diff --git a/test/Configurator.test.js b/test/Configurator.test.js
index c107118fd4..687c8a9f1c 100644
--- a/test/Configurator.test.js
+++ b/test/Configurator.test.js
@@ -1,19 +1,18 @@
-var assert = require('assert');
-var jsdom_global = require('jsdom-global');
+const assert = require('assert');
-var canvasMockify = require('./canvas-mock');
-var Configurator = require('../lib/shared/Configurator').default;
-var Network = require('../lib/network/Network');
-var { allOptions, configureOptions } = require('../lib/network/options.js');
+const canvasMockify = require('./canvas-mock');
+const Configurator = require('../lib/shared/Configurator').default;
+const Network = require('../lib/network/Network');
+const { configureOptions } = require('../lib/network/options.js');
describe('Configurator', function () {
beforeEach(function() {
- this.jsdom_global = canvasMockify("");
+ this.jsdomGlobalCleanup = canvasMockify("");
this.container = document.getElementById('mynetwork');
});
afterEach(function() {
- this.jsdom_global();
+ this.jsdomGlobalCleanup();
this.container.remove();
this.container = undefined;
});
@@ -21,7 +20,7 @@ describe('Configurator', function () {
describe('constructor', function () {
it('sets extends options with default options', function () {
- var config = new Configurator();
+ const config = new Configurator();
assert.deepEqual(config.options, config.defaultOptions);
});
});
@@ -29,34 +28,34 @@ describe('Configurator', function () {
describe('setOptions', function () {
it('with undefined will not modify defaults', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions();
assert.deepEqual(config.options, config.defaultOptions);
});
it('with undefined will set enabled to false', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.options.enabled = false;
config.setOptions();
assert.equal(config.options.enabled, false);
});
it('with string sets filter and set enabled to true', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions('stringFilter!');
assert.equal(config.options.filter, 'stringFilter!');
assert.equal(config.options.enabled, true);
});
it('with array sets filter and set enabled to true', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions(['array', 'Filter', '!']);
assert.equal(config.options.filter, 'array,Filter,!');
assert.equal(config.options.enabled, true);
});
it('with object sets filter', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions(
{container: 'newContainer',
filter: 'newFilter',
@@ -70,31 +69,31 @@ describe('Configurator', function () {
});
it('with object and filter is false enabled will be false', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions({filter: false});
assert.equal(config.options.enabled, false);
});
it('with boolean true sets filter', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions(true);
assert.equal(config.options.enabled, true);
});
it('with boolean false sets filter', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions(false);
assert.equal(config.options.enabled, false);
});
it('with function sets filter', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setOptions(function () {});
assert.equal(config.options.enabled, true);
});
it('with null raises exception', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
assert.throws(function () {config.setOptions(null)}, TypeError, null);
});
@@ -103,13 +102,13 @@ describe('Configurator', function () {
describe('setModuleOptions', function () {
it('creates no new dom elements if enabled is false', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.setModuleOptions();
assert.equal(this.container.children.length, 0);
});
it('adds div with vis-configuration-wrapper class when enabled', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.options.enabled = true;
config.setModuleOptions();
assert.equal(this.container.children.length, 1);
@@ -117,7 +116,7 @@ describe('Configurator', function () {
});
it('overwrites config.container with config.options.container', function () {
- var config = new Configurator(Network, this.container);
+ const config = new Configurator(Network, this.container);
config.options.enabled = true;
config.options.container = document.getElementById('other');
config.setModuleOptions();
@@ -130,8 +129,8 @@ describe('Configurator', function () {
describe('getOptions', function () {
xit('creates no new dom elements if enabled is false', function () {
- var config = new Configurator(Network, this.container, configureOptions);
- var options = config.getOptions();
+ const config = new Configurator(Network, this.container, configureOptions);
+ config.getOptions();
});
});
});
diff --git a/test/Label.test.js b/test/Label.test.js
index c78176b452..2189b00127 100644
--- a/test/Label.test.js
+++ b/test/Label.test.js
@@ -1,3 +1,6 @@
+/* eslint require-jsdoc: "off" */
+/* eslint valid-jsdoc: "off" */
+
/**
* TODO - add tests for:
* ====
@@ -51,14 +54,14 @@ describe('Network Label', function() {
* NOTE: these are options at the node-level
*/
function getOptions(options = {}) {
- var body = {
+ const body = {
functions: {},
emitter: {
on: function() {}
}
};
- var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() );
+ const nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() );
//console.log(JSON.stringify(nodesHandler.options, null, 2));
return nodesHandler.options;
@@ -72,7 +75,7 @@ describe('Network Label', function() {
* Within blocks, only the text is compared
*/
function checkBlocks(returned, expected) {
- let showBlocks = () => {
+ const showBlocks = () => {
return '\nreturned: ' + JSON.stringify(returned, null, 2) + '\n' +
'expected: ' + JSON.stringify(expected, null, 2);
}
@@ -80,13 +83,13 @@ describe('Network Label', function() {
assert.equal(expected.lines.length, returned.lines.length, 'Number of lines does not match, ' + showBlocks());
for (let i = 0; i < returned.lines.length; ++i) {
- let retLine = returned.lines[i];
- let expLine = expected.lines[i];
+ const retLine = returned.lines[i];
+ const expLine = expected.lines[i];
assert(retLine.blocks.length === expLine.blocks.length, 'Number of blocks does not match, ' + showBlocks());
for (let j = 0; j < retLine.blocks.length; ++j) {
- let retBlock = retLine.blocks[j];
- let expBlock = expLine.blocks[j];
+ const retBlock = retLine.blocks[j];
+ const expBlock = expLine.blocks[j];
assert(retBlock.text === expBlock.text, 'Text does not match, ' + showBlocks());
@@ -104,10 +107,10 @@ describe('Network Label', function() {
function checkProcessedLabels(label, text, expected) {
- var ctx = new DummyContext();
+ const ctx = new DummyContext();
- for (var i in text) {
- var ret = label._processLabelText(ctx, false, false, text[i]);
+ for (const i of Object.keys(text)) {
+ const ret = label._processLabelText(ctx, false, false, text[i]);
//console.log(JSON.stringify(ret, null, 2));
checkBlocks(ret, expected[i]);
}
@@ -118,7 +121,7 @@ describe('Network Label', function() {
* Test data
**************************************************************/
- var normal_text = [
+ const normal_text = [
"label text",
"label\nwith\nnewlines",
"OnereallylongwordthatshouldgooverwidthConstraint.maximumifdefined",
@@ -126,12 +129,12 @@ describe('Network Label', function() {
"Reallyoneenormouslylargelabel withtwobigwordsgoingoverwayovermax"
]
- var html_text = [
+ const html_text = [
"label with some
multi tags",
"label with some
\n multi tags\n and newlines" // NB spaces around \n's
];
- var markdown_text = [
+ const markdown_text = [
"label *with* `some` _multi *tags*_",
"label *with* `some` \n _multi *tags*_\n and newlines" // NB spaces around \n's
];
@@ -141,7 +144,7 @@ describe('Network Label', function() {
* Expected Results
**************************************************************/
- var normal_expected = [{
+ const normal_expected = [{
// In first item, width/height kept in for reference
width: 120,
height: 14,
@@ -179,7 +182,7 @@ describe('Network Label', function() {
const indexWidthConstrained = 2; // index of first item that will be different with max width set
- var normal_widthConstraint_expected = normal_expected.slice(0, indexWidthConstrained);
+ const normal_widthConstraint_expected = normal_expected.slice(0, indexWidthConstrained);
Array.prototype.push.apply(normal_widthConstraint_expected, [{
lines: [{
blocks: [{text: "Onereallylongwordthatshoul"}]
@@ -213,7 +216,7 @@ describe('Network Label', function() {
}]);
- var html_unchanged_expected = [{
+ const html_unchanged_expected = [{
lines: [{
blocks: [{text: "label with some
multi tags"}]
}]
@@ -227,7 +230,7 @@ describe('Network Label', function() {
}]
}];
- var html_widthConstraint_unchanged = [{
+ const html_widthConstraint_unchanged = [{
lines: [{
blocks: [{text: "label with"}]
}, {
@@ -252,7 +255,7 @@ describe('Network Label', function() {
}];
- var markdown_unchanged_expected = [{
+ const markdown_unchanged_expected = [{
lines: [{
blocks: [{text: "label *with* `some` _multi *tags*_"}]
}]
@@ -267,7 +270,7 @@ describe('Network Label', function() {
}];
- var markdown_widthConstraint_expected= [{
+ const markdown_widthConstraint_expected= [{
lines: [{
blocks: [{text: "label *with* `some`"}]
}, {
@@ -284,7 +287,7 @@ describe('Network Label', function() {
}];
- var multi_expected = [{
+ const multi_expected = [{
lines: [{
blocks: [
{text: "label "},
@@ -334,7 +337,7 @@ describe('Network Label', function() {
it('parses normal text labels', function (done) {
- var label = new Label({}, getOptions());
+ const label = new Label({}, getOptions());
checkProcessedLabels(label, normal_text , normal_expected);
checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged
@@ -345,10 +348,10 @@ describe('Network Label', function() {
it('parses html labels', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
options.font.multi = true; // TODO: also test 'html', also test illegal value here
- var label = new Label({}, options);
+ const label = new Label({}, options);
checkProcessedLabels(label, normal_text , normal_expected); // normal as usual
checkProcessedLabels(label, html_text , multi_expected);
@@ -359,10 +362,10 @@ describe('Network Label', function() {
it('parses markdown labels', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
options.font.multi = 'markdown'; // TODO: also test 'md', also test illegal value here
- var label = new Label({}, options);
+ const label = new Label({}, options);
checkProcessedLabels(label, normal_text , normal_expected); // normal as usual
checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged
@@ -373,7 +376,7 @@ describe('Network Label', function() {
it('handles normal text with widthConstraint.maximum', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
//
// What the user would set:
@@ -386,7 +389,7 @@ describe('Network Label', function() {
//
options.font.maxWdt = 300;
- var label = new Label({}, options);
+ let label = new Label({}, options);
checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
checkProcessedLabels(label, html_text , html_widthConstraint_unchanged); // html unchanged
@@ -402,11 +405,11 @@ describe('Network Label', function() {
it('handles html tags with widthConstraint.maximum', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
options.font.multi = true;
options.font.maxWdt = 300;
- var label = new Label({}, options);
+ let label = new Label({}, options);
checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
checkProcessedLabels(label, html_text , multi_expected);
@@ -422,11 +425,11 @@ describe('Network Label', function() {
it('handles markdown tags with widthConstraint.maximum', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
options.font.multi = 'markdown';
options.font.maxWdt = 300;
- var label = new Label({}, options);
+ const label = new Label({}, options);
checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
checkProcessedLabels(label, html_text , html_widthConstraint_unchanged);
@@ -456,7 +459,7 @@ describe('Multi-Fonts', function() {
describe('Node Labels', function() {
function createNodeNetwork(newOptions) {
- var dataNodes = [
+ const dataNodes = [
{id: 0, label: '0'},
{id: 1, label: '1'},
{id: 2, label: '2', group: 'group1'},
@@ -473,13 +476,13 @@ describe('Node Labels', function() {
];
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: new DataSet(dataNodes),
edges: []
};
- var options = {
+ const options = {
nodes: {
font: {
multi: true
@@ -499,7 +502,7 @@ describe('Node Labels', function() {
util.deepExtend(options, newOptions);
}
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
return [network, data, options];
}
@@ -511,8 +514,8 @@ describe('Node Labels', function() {
* - using multi-font option 'color' for test, the rest should work analogously
*/
it('respects the font option precedence', function (done) {
- var [network, data, options] = createNodeNetwork();
- var h = new HelperNode(network);
+ const [network] = createNodeNetwork();
+ const h = new HelperNode(network);
assert.equal(h.modBold(0).color, '#343434'); // Default value
assert.equal(h.modBold(1).color, '#343434'); // Default value
@@ -525,8 +528,8 @@ describe('Node Labels', function() {
it('handles dynamic data and option updates', function (done) {
- var [network, data, options] = createNodeNetwork();
- var h = new HelperNode(network);
+ const [network, data] = createNodeNetwork();
+ const h = new HelperNode(network);
//
// Change some node values dynamically
@@ -597,15 +600,15 @@ describe('Node Labels', function() {
it('handles normal font values in default options', function (done) {
- var newOptions = {
+ const newOptions = {
nodes: {
font: {
color: 'purple' // Override the default value
}
},
};
- var [network, data, options] = createNodeNetwork(newOptions);
- var h = new HelperNode(network);
+ const [network] = createNodeNetwork(newOptions);
+ const h = new HelperNode(network);
assert.equal(h.modBold(0).color, 'purple'); // Nodes value
assert.equal(h.modBold(1).color, 'purple'); // Nodes value
@@ -618,7 +621,7 @@ describe('Node Labels', function() {
it('handles multi-font values in default options/groups', function (done) {
- var newOptions = {
+ const newOptions = {
nodes: {
font: {
color: 'purple' // This set value should be overridden
@@ -633,8 +636,8 @@ describe('Node Labels', function() {
}
};
- var [network, data, options] = createNodeNetwork(newOptions);
- var h = new HelperNode(network);
+ const [network, , options] = createNodeNetwork(newOptions);
+ const h = new HelperNode(network);
assert(options.nodes.font.multi);
assert.equal(h.modBold(0).color, 'yellow'); // bold value
@@ -652,14 +655,14 @@ describe('Node Labels', function() {
describe('Edge Labels', function() {
function createEdgeNetwork(newOptions) {
- var dataNodes = [
+ const dataNodes = [
{id: 1, label: '1'},
{id: 2, label: '2'},
{id: 3, label: '3'},
{id: 4, label: '4'},
];
- var dataEdges = [
+ const dataEdges = [
{id: 1, from: 1, to: 2, label: '1'},
{id: 2, from: 1, to: 4, label: '2',
font: {
@@ -674,13 +677,13 @@ describe('Edge Labels', function() {
];
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: new DataSet(dataNodes),
edges: new DataSet(dataEdges),
};
- var options = {
+ const options = {
edges: {
font: {
multi: true
@@ -692,7 +695,7 @@ describe('Edge Labels', function() {
util.deepExtend(options, newOptions);
}
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
return [network, data, options];
}
@@ -720,8 +723,8 @@ describe('Edge Labels', function() {
* - edges have no groups
*/
it('respects the font option precedence', function (done) {
- var [network, data, options] = createEdgeNetwork();
- var h = new HelperEdge(network);
+ const [network] = createEdgeNetwork();
+ const h = new HelperEdge(network);
assert.equal(h.modBold(1).color, '#343434'); // Default value
assert.equal(h.modBold(2).color, 'green'); // Local value overrides default
@@ -732,8 +735,8 @@ describe('Edge Labels', function() {
it('handles dynamic data and option updates', function (done) {
- var [network, data, options] = createEdgeNetwork();
- var h = new HelperEdge(network);
+ const [network, data] = createEdgeNetwork();
+ const h = new HelperEdge(network);
data.edges.update([
{id: 3, font: { bold: { color: 'orange'}}},
@@ -764,15 +767,15 @@ describe('Edge Labels', function() {
it('handles font values in default options', function (done) {
- var newOptions = {
+ const newOptions = {
edges: {
font: {
color: 'purple' // Override the default value
}
},
};
- var [network, data, options] = createEdgeNetwork(newOptions);
- var h = new HelperEdge(network);
+ const [network] = createEdgeNetwork(newOptions);
+ const h = new HelperEdge(network);
assert.equal(h.modBold(1).color, 'purple'); // Nodes value
assert.equal(h.modBold(2).color, 'green'); // Local value overrides all
@@ -786,7 +789,7 @@ describe('Edge Labels', function() {
describe('Shorthand Font Options', function() {
- var testFonts = {
+ const testFonts = {
'default': {color: '#343434', face: 'arial' , size: 14},
'monodef': {color: '#343434', face: 'monospace', size: 15},
'font1' : {color: '#010101', face: 'Font1' , size: 1},
@@ -800,7 +803,7 @@ describe('Shorthand Font Options', function() {
function checkFont(opt, expectedLabel) {
- var expected = testFonts[expectedLabel];
+ const expected = testFonts[expectedLabel];
util.forEach(expected, (item, key) => {
assert.equal(opt[key], item);
@@ -809,23 +812,23 @@ describe('Shorthand Font Options', function() {
function createNetwork() {
- var dataNodes = [
+ const dataNodes = [
{id: 1, label: '1'},
{id: 2, label: '2', group: 'group1'},
{id: 3, label: '3', group: 'group2'},
{id: 4, label: '4', font: '5px Font5 #050505'},
];
- var dataEdges = [];
+ const dataEdges = [];
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: new DataSet(dataNodes),
edges: new DataSet(dataEdges),
};
- var options = {
+ const options = {
nodes: {
font: {
multi: true,
@@ -845,19 +848,19 @@ describe('Shorthand Font Options', function() {
}
};
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
return [network, data];
}
it('handles shorthand options correctly', function (done) {
- var [network, data] = createNetwork();
- var h = new HelperNode(network);
+ const [network] = createNetwork();
+ const h = new HelperNode(network);
// NOTE: 'mono' has its own global default font and size, which will
// trump any other font values set.
- var opt = h.fontOption(1);
+ let opt = h.fontOption(1);
checkFont(opt, 'default');
checkFont(opt.bold, 'font1');
checkFont(opt.ital, 'font2');
@@ -920,7 +923,7 @@ describe('Shorthand Font Options', function() {
}
- function dynamicAdd2(network, data) {
+ function dynamicAdd2(network) {
network.setOptions({
nodes: {
font: '7 Font7 #070707' // Note: this kills the font.multi, bold and ital settings!
@@ -930,11 +933,11 @@ describe('Shorthand Font Options', function() {
it('deals with dynamic data and option updates for shorthand', function (done) {
- var [network, data] = createNetwork();
- var h = new HelperNode(network);
+ const [network, data] = createNetwork();
+ const h = new HelperNode(network);
dynamicAdd1(network, data);
- var opt = h.fontOption(1);
+ let opt = h.fontOption(1);
checkFont(opt, 'font5'); // New base font
checkFont(opt.bold, 'font1');
checkFont(opt.ital, 'font4'); // New global node default
@@ -968,12 +971,12 @@ describe('Shorthand Font Options', function() {
it('deals with dynamic change of global node default', function (done) {
- var [network, data] = createNetwork();
- var h = new HelperNode(network);
+ const [network, data] = createNetwork();
+ const h = new HelperNode(network);
dynamicAdd1(network, data); // Accumulate data of dynamic add
dynamicAdd2(network, data);
- var opt = h.fontOption(1);
+ let opt = h.fontOption(1);
checkFont(opt, 'font5'); // Node instance value
checkFont(opt.bold, 'font5'); // bold def removed from global default node
checkFont(opt.ital, 'font5'); // idem
@@ -1010,8 +1013,8 @@ describe('Shorthand Font Options', function() {
it('deals with dynamic delete of shorthand options', function (done) {
- var [network, data] = createNetwork();
- var h = new HelperNode(network);
+ const [network, data] = createNetwork();
+ const h = new HelperNode(network);
dynamicAdd1(network, data); // Accumulate data of previous dynamic steps
dynamicAdd2(network, data); // idem
@@ -1020,7 +1023,7 @@ describe('Shorthand Font Options', function() {
{id: 4, font: { bold: null}},
]);
- var opt;
+ let opt;
/*
// Interesting: following flagged as error in options parsing, avoiding it for that reason
@@ -1078,8 +1081,8 @@ describe('Shorthand Font Options', function() {
/**
* Helper function for easily accessing font options in a node
*/
- var fontOption = (index) => {
- var nodes = network.body.nodes;
+ const fontOption = (index) => {
+ const nodes = network.body.nodes;
return nodes[index].labelModule.fontOptions;
};
@@ -1087,12 +1090,12 @@ describe('Shorthand Font Options', function() {
/**
* Helper function for easily accessing bold options in a node
*/
- var modBold = (index) => {
+ const modBold = (index) => {
return fontOption(index).bold;
};
- var dataNodes = [
+ const dataNodes = [
{id: 1, label: '1', group: 'group1'},
{
// From example 1 in #3408
@@ -1110,13 +1113,13 @@ describe('Shorthand Font Options', function() {
];
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: new DataSet(dataNodes),
edges: []
};
- var options = {
+ const options = {
groups: {
group1: {
font: {
@@ -1143,7 +1146,7 @@ describe('Shorthand Font Options', function() {
},
};
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
assert.equal(modBold(1).color, 'red'); // Group value
assert(fontOption(1).multi); // Group value
@@ -1190,9 +1193,9 @@ describe('Shorthand Font Options', function() {
it('compresses spaces for Multi-Font', function (done) {
- var options = getOptions(options);
+ let options = getOptions();
- var text = [
+ const text = [
"Too many spaces here!",
"one two three four five six .",
"This thing:\n - could be\n - a kind\n - of list", // multifont: 2 spaces at start line reduced to 1
@@ -1202,9 +1205,9 @@ describe('Shorthand Font Options', function() {
//
// multifont disabled: spaces are preserved
//
- var label = new Label({}, options);
+ let label = new Label({}, options);
- var expected = [{
+ const expected = [{
lines: [{
blocks: [{text: "Too many spaces here!"}],
}]
@@ -1231,9 +1234,9 @@ describe('Shorthand Font Options', function() {
// multifont disabled width maxwidth: spaces are preserved
//
options.font.maxWdt = 300;
- var label = new Label({}, options);
+ label = new Label({}, options);
- var expected_maxwidth = [{
+ const expected_maxwidth = [{
lines: [{
blocks: [{text: "Too many spaces"}],
}, {
@@ -1267,9 +1270,9 @@ describe('Shorthand Font Options', function() {
//
options = getOptions(options);
options.font.multi = true;
- var label = new Label({}, options);
+ label = new Label({}, options);
- var expected_multifont = [{
+ const expected_multifont = [{
lines: [{
blocks: [{text: "Too many spaces here!"}],
}]
@@ -1296,9 +1299,9 @@ describe('Shorthand Font Options', function() {
// multifont enabled with max width: spaces are compressed
//
options.font.maxWdt = 300;
- var label = new Label({}, options);
+ label = new Label({}, options);
- var expected_multifont_maxwidth = [{
+ const expected_multifont_maxwidth = [{
lines: [{
blocks: [{text: "Too many spaces"}],
}, {
@@ -1330,7 +1333,7 @@ describe('Shorthand Font Options', function() {
it('parses single huge word on line with preceding whitespace when max width set', function (done) {
- var options = getOptions(options);
+ const options = getOptions();
options.font.maxWdt = 300;
assert.equal(options.font.multi, false);
@@ -1339,7 +1342,7 @@ describe('Shorthand Font Options', function() {
*
* Allows negative indexing, counting from back (ruby style)
*/
- let splitAt = (text, pos, getFirst) => {
+ const splitAt = (text, pos, getFirst) => {
if (pos < 0) pos = text.length + pos;
if (getFirst) {
@@ -1349,16 +1352,16 @@ describe('Shorthand Font Options', function() {
}
};
- var label = new Label({}, options);
- var longWord = "asd;lkfja;lfkdj;alkjfd;alskfj";
+ let label = new Label({}, options);
+ const longWord = "asd;lkfja;lfkdj;alkjfd;alskfj";
- var text = [
+ const text = [
"Mind the space!\n " + longWord,
"Mind the empty line!\n\n" + longWord,
"Mind the dos empty line!\r\n\r\n" + longWord
];
- var expected = [{
+ const expected = [{
lines: [{
blocks: [{text: "Mind the space!"}]
}, {
@@ -1401,7 +1404,7 @@ describe('Shorthand Font Options', function() {
// Multi font enabled. For current case, output should be identical to no multi font
//
options.font.multi = true;
- var label = new Label({}, options);
+ label = new Label({}, options);
checkProcessedLabels(label, text, expected);
done();
@@ -1416,7 +1419,7 @@ describe('Shorthand Font Options', function() {
* NOTE: boolean shorthand values for widthConstraint and heightConstraint do nothing.
*/
it('Sets the width/height constraints in the font label options', function (done) {
- var nodes = [
+ const nodes = [
{ id: 100, label: 'node 100'},
{ id: 210, group: 'group1', label: 'node 210'},
{ id: 211, widthConstraint: { minimum: 120 }, label: 'node 211'},
@@ -1433,19 +1436,19 @@ describe('Shorthand Font Options', function() {
{ id: 402, heightConstraint: { minimum: 100, valign: 'bottom' }, label: 'node 402'}
];
- var edges = [
+ const edges = [
{ id: 1, from: 100, to: 210, label: "edge 1"},
{ id: 2, widthConstraint: 80, from: 210, to: 211, label: "edge 2"},
{ id: 3, heightConstraint: 90, from: 100, to: 220, label: "edge 3"},
{ id: 4, from: 401, to: 402, widthConstraint: { maximum: 150 }, label: "edge 12"},
];
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: nodes,
edges: edges
};
- var options = {
+ const options = {
edges: {
font: {
size: 12
@@ -1485,9 +1488,9 @@ describe('Shorthand Font Options', function() {
enabled: false
}
};
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
- var nodes_expected = [
+ const nodes_expected = [
{ nodeId: 100, minWdt: -1, maxWdt: 200, minHgt: -1, valign: 'middle'},
{ nodeId: 210, minWdt: -1, maxWdt: 130, minHgt: -1, valign: 'middle'},
{ nodeId: 211, minWdt: 120, maxWdt: 200, minHgt: -1, valign: 'middle'},
@@ -1510,7 +1513,7 @@ describe('Shorthand Font Options', function() {
//
// There is a lot of repetitiveness here. Perhaps using a direct copy of the
// example should be let go.
- var edges_expected = [
+ const edges_expected = [
{ id: 1, minWdt: -1, maxWdt: 90, minHgt: -1, valign: 'middle'},
{ id: 2, minWdt: 80, maxWdt: 80, minHgt: -1, valign: 'middle'},
{ id: 3, minWdt: -1, maxWdt: 90, minHgt: 90, valign: 'middle'},
@@ -1518,7 +1521,7 @@ describe('Shorthand Font Options', function() {
];
- let assertConstraints = (expected, fontOptions, label) => {
+ const assertConstraints = (expected, fontOptions, label) => {
assert.equal(expected.minWdt, fontOptions.minWdt, 'Incorrect min width' + label);
assert.equal(expected.maxWdt, fontOptions.maxWdt, 'Incorrect max width' + label);
assert.equal(expected.minHgt, fontOptions.minHgt, 'Incorrect min height' + label);
@@ -1528,23 +1531,23 @@ describe('Shorthand Font Options', function() {
// Check nodes
util.forEach(nodes_expected, function(expected) {
- let networkNode = network.body.nodes[expected.nodeId];
+ const networkNode = network.body.nodes[expected.nodeId];
assert(networkNode !== undefined && networkNode !== null, 'node not found for id: ' + expected.nodeId);
- let fontOptions = networkNode.labelModule.fontOptions;
+ const fontOptions = networkNode.labelModule.fontOptions;
- var label = ' for node id: ' + expected.nodeId;
+ const label = ' for node id: ' + expected.nodeId;
assertConstraints(expected, fontOptions, label);
});
// Check edges
util.forEach(edges_expected, function(expected) {
- let networkEdge = network.body.edges[expected.id];
+ const networkEdge = network.body.edges[expected.id];
- var label = ' for edge id: ' + expected.id;
+ const label = ' for edge id: ' + expected.id;
assert(networkEdge !== undefined, 'Edge not found' + label);
- let fontOptions = networkEdge.labelModule.fontOptions;
+ const fontOptions = networkEdge.labelModule.fontOptions;
assertConstraints(expected, fontOptions, label);
});
@@ -1553,21 +1556,21 @@ describe('Shorthand Font Options', function() {
it('deals with null labels and other awkward values', function (done) {
- var ctx = new DummyContext();
- var options = getOptions({});
+ const ctx = new DummyContext();
+ let options = getOptions({});
- var checkHandling = (label, index, text) => {
+ const checkHandling = (label, index, text) => {
assert.doesNotThrow(() => {label.getTextSize(ctx, false, false)}, "Unexpected throw for " + text + " " + index);
//label.getTextSize(ctx, false, false); // Use this to determine the error thrown
// There should not be a label for any of the cases
//
- let labelVal = label.elementOptions.label;
- let validLabel = (typeof labelVal === 'string' && labelVal !== '');
+ const labelVal = label.elementOptions.label;
+ const validLabel = (typeof labelVal === 'string' && labelVal !== '');
assert(!validLabel, "Unexpected label value '" + labelVal+ "' for " + text +" " + index);
};
- var nodes = [
+ const nodes = [
{id: 1},
{id: 2, label: null},
{id: 3, label: undefined},
@@ -1577,7 +1580,7 @@ describe('Shorthand Font Options', function() {
{id: 7, label: 3.419},
];
- var edges = [
+ const edges = [
{from: 1, to: 2, label: null},
{from: 1, to: 3, label: undefined},
{from: 1, to: 4, label: {a: 42}},
@@ -1592,14 +1595,14 @@ describe('Shorthand Font Options', function() {
// Node labels
for (let i = 0; i < nodes.length; ++i) {
- let label = new Label(null, nodes[i], false);
+ const label = new Label(null, nodes[i], false);
checkHandling(label, i, 'node');
}
// Edge labels
for (let i = 0; i < edges.length; ++i) {
- let label = new Label(null, edges[i], true);
+ const label = new Label(null, edges[i], true);
checkHandling(label, i, 'edge');
}
@@ -1610,33 +1613,33 @@ describe('Shorthand Font Options', function() {
// In the example, only `label:null` was present. The weird thing is that it fails
// in the example, but succeeds in the unit tests.
// Kept in for regression testing.
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: new DataSet(nodes),
edges: new DataSet(edges)
};
- var options = {};
- var network = new Network(container, data, options);
+ options = {};
+ new Network(container, data, options);
done()
})
describe('visible function', function() {
it('correctly determines label is not visible when label is invalid', function(done) {
- var invalidLabel = ''
+ const invalidLabel = ''
assert(
!isValidLabel(invalidLabel),
'An empty string should be identified as an invalid label'
)
- var body = {
+ const body = {
view: {
scale: 1
}
}
- var options = {
+ const options = {
label: invalidLabel,
font: {
size: 12
@@ -1648,7 +1651,7 @@ describe('Shorthand Font Options', function() {
}
}
- var label = new Label(body, options)
+ const label = new Label(body, options)
label.size.width = 1
label.size.height = 1
diff --git a/test/Network.test.js b/test/Network.test.js
index a80fea0ad7..d14d0cacee 100644
--- a/test/Network.test.js
+++ b/test/Network.test.js
@@ -1,3 +1,7 @@
+/* eslint-disable require-jsdoc */
+/* eslint-disable valid-jsdoc */
+/* eslint-disable guard-for-in */
+
/**
*
* Useful during debugging
@@ -32,8 +36,8 @@ function merge (a, b) {
}
if (b) {
- for (var name in b) {
- if (b.hasOwnProperty(name)) {
+ for (const name in b) {
+ if (Object.prototype.hasOwnProperty.call(b, name)) {
if (typeof b[name] === 'object') {
a[name] = merge(a[name], b[name]);
} else {
@@ -54,9 +58,9 @@ function include(list, context) {
list = [list];
}
- for (var n in list) {
- var path = list[n];
- var arr = [fs.readFileSync(path) + ''];
+ for (const n in list) {
+ const path = list[n];
+ const arr = [fs.readFileSync(path) + ''];
eval.apply(context, arr);
}
}
@@ -71,10 +75,10 @@ function include(list, context) {
* For reference, this is the sample network of issue #1218
*/
function createSampleNetwork(options) {
- var NumInitialNodes = 8;
- var NumInitialEdges = 6;
+ const NumInitialNodes = 8;
+ const NumInitialEdges = 6;
- var nodes = new DataSet([
+ const nodes = new DataSet([
{id: 1, label: '1'},
{id: 2, label: '2'},
{id: 3, label: '3'},
@@ -84,7 +88,7 @@ function createSampleNetwork(options) {
{id: 13, label: '13'},
{id: 14, label: '14'},
]);
- var edges = new DataSet([
+ const edges = new DataSet([
{ from: 1, to: 2, label: '1 to 2' },
{ from: 2, to: 3, label: '2 to 3' },
{ from: 3, to: 4, label: '3 to 4' },
@@ -94,13 +98,13 @@ function createSampleNetwork(options) {
]);
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: nodes,
edges: edges
};
- var defaultOptions = {
+ const defaultOptions = {
layout: {
randomSeed: 8
},
@@ -113,7 +117,7 @@ function createSampleNetwork(options) {
options = merge(defaultOptions, options);
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
assertNumNodes(network, NumInitialNodes);
assertNumEdges(network, NumInitialEdges);
@@ -131,7 +135,7 @@ function createSampleNetwork(options) {
* a cluster is made of two nodes, each from one of the sub-networks.
*/
function createCluster(network) {
- var clusterOptionsByData = {
+ const clusterOptionsByData = {
joinCondition: function(node) {
if (node.id == 1 || node.id == 11) return true;
return false;
@@ -145,6 +149,7 @@ function createCluster(network) {
/**
* Display node/edge state, useful during debugging
*/
+// eslint-disable-next-line no-unused-vars
function log(network) {
console.log(Object.keys(network.body.nodes));
console.log(network.body.nodeIndices);
@@ -176,12 +181,12 @@ function assertNumEdges(network, expectedPresent, expectedVisible) {
};
function assertEdgeLabels(network, originalEdgesDataSet, assertMessagePrefix) {
- let originalIds = originalEdgesDataSet.getIds()
+ const originalIds = originalEdgesDataSet.getIds()
for (let index = 0; index < originalIds.length; index++) {
- let id = originalIds[index]
- let expectedOriginalEdge = originalEdgesDataSet.get(id)
- let currentNetworkEdge = network.body.edges[id]
+ const id = originalIds[index]
+ const expectedOriginalEdge = originalEdgesDataSet.get(id)
+ const currentNetworkEdge = network.body.edges[id]
assert.equal(
currentNetworkEdge.options.label,
@@ -199,7 +204,7 @@ function assertEdgeLabels(network, originalEdgesDataSet, assertMessagePrefix) {
* If any assertion fails here, all code in Network handling fonts should be checked.
*/
function checkFontProperties(fontItem, checkStrict = true) {
- var knownProperties = [
+ const knownProperties = [
'color',
'size',
'face',
@@ -216,18 +221,18 @@ function checkFontProperties(fontItem, checkStrict = true) {
];
// All properties in fontItem should be known
- for (var prop in fontItem) {
+ for (const prop in fontItem) {
if (prop === '__type__') continue; // Skip special field in options definition
- if (!fontItem.hasOwnProperty(prop)) continue;
+ if (!Object.prototype.hasOwnProperty.call(fontItem, prop)) continue;
assert(knownProperties.indexOf(prop) !== -1, "Unknown font option '" + prop + "'");
}
if (!checkStrict) return;
// All known properties should be present
- var keys = Object.keys(fontItem);
- for (var n in knownProperties) {
- var prop = knownProperties[n];
+ const keys = Object.keys(fontItem);
+ for (const n in knownProperties) {
+ const prop = knownProperties[n];
assert(keys.indexOf(prop) !== -1, "Missing known font option '" + prop + "'");
}
}
@@ -254,14 +259,15 @@ describe('Network', function () {
* Simplify network creation for local tests
*/
function createNetwork(options) {
- var [network, data, numNodes, numEdges] = createSampleNetwork(options);
+ // eslint-disable-next-line no-unused-vars
+ const [network] = createSampleNetwork(options);
return network;
}
function firstNode(network) {
- for (var id in network.body.nodes) {
+ for (const id in network.body.nodes) {
return network.body.nodes[id];
}
@@ -269,7 +275,7 @@ describe('Network', function () {
}
function firstEdge(network) {
- for (var id in network.body.edges) {
+ for (const id in network.body.edges) {
return network.body.edges[id];
}
@@ -301,7 +307,7 @@ describe('Network', function () {
* Helper function for clustering
*/
function clusterTo(network, clusterId, nodeList, allowSingle) {
- var options = {
+ const options = {
joinCondition: function(node) {
return nodeList.indexOf(node.id) !== -1;
},
@@ -324,13 +330,13 @@ describe('Network', function () {
* The real deterrent is eslint rule 'guard-for-in`.
*/
it('can deal with added fields in Array.prototype', function (done) {
- var canvas = window.document.createElement('canvas');
+ window.document.createElement('canvas');
Array.prototype.foo = 1; // Just add anything to the prototype
Object.prototype.bar = 2; // Let's screw up hashes as well
// The network should just run without throwing errors
try {
- var [network, data, numNodes, numEdges] = createSampleNetwork({});
+ const [network, data] = createSampleNetwork({});
// Do some stuff to trigger more errors
clusterTo(network, 'c1', [1,2,3]);
@@ -359,20 +365,20 @@ describe('Network', function () {
* TODO: extend test for all API calls with options, see #3548
*/
it('does not change the options object passed to fit()', function() {
- var [network, data, numNodes, numEdges] = createSampleNetwork({});
- var options = {};
+ const [network] = createSampleNetwork({});
+ const options = {};
network.fit(options);
// options should still be empty
- for (var prop in options) {
- assert(!options.hasOwnProperty(prop), 'No properties should be present in options, detected property: ' + prop);
+ for (const prop in options) {
+ assert(!Object.prototype.hasOwnProperty.call(options, prop), 'No properties should be present in options, detected property: ' + prop);
}
});
it('does not crash when dataChanged is triggered when setting options on first initialization ', function() {
// The init should succeed without an error thrown.
- var options = {
+ let options = {
nodes: {
physics: false // any value here triggered the error
}
@@ -395,17 +401,17 @@ describe('Network', function () {
it('can deal with null data', function() {
// While we're at it, try out other silly values as well
// All the following are wrong, but none should lead to a crash
- var awkwardData = [
+ const awkwardData = [
null,
[1,2,3],
42,
'meow'
];
- var container = document.getElementById('mynetwork');
+ const container = document.getElementById('mynetwork');
- for (var n = 0; n < awkwardData.length; ++n) {
- var network = new Network(container, awkwardData[n], {}); // Should not throw
+ for (let n = 0; n < awkwardData.length; ++n) {
+ new Network(container, awkwardData[n], {}); // Should not throw
}
});
@@ -413,7 +419,7 @@ describe('Network', function () {
describe('Node', function () {
it('has known font options', function () {
- var network = createNetwork({});
+ const network = createNetwork({});
checkFontProperties(network.nodesHandler.defaultOptions.font);
checkFontProperties(allOptions.nodes.font);
checkFontProperties(configureOptions.nodes.font, false);
@@ -426,8 +432,8 @@ describe('Node', function () {
*/
it('properly handles choosify input', function () {
// check defaults
- var options = {};
- var network = createNetwork(options);
+ let options = {};
+ let network = createNetwork(options);
checkChooserValues(firstNode(network), true, true);
// There's no point in checking invalid values here; these are detected by the options parser
@@ -445,13 +451,13 @@ describe('Node', function () {
options = {nodes: {chosen: {
node:true,
- label: function(value, id, selected, hovering) {}
+ label: function() {}
}}};
network = createNetwork(options);
checkChooserValues(firstNode(network), true, 'function');
options = {nodes: {chosen: {
- node: function(value, id, selected, hovering) {},
+ node: function() {},
label:false,
}}};
network = createNetwork(options);
@@ -463,7 +469,7 @@ describe('Node', function () {
describe('Edge', function () {
it('has known font options', function () {
- var network = createNetwork({});
+ const network = createNetwork({});
checkFontProperties(network.edgesHandler.defaultOptions.font);
checkFontProperties(allOptions.edges.font);
checkFontProperties(configureOptions.edges.font, false);
@@ -476,8 +482,8 @@ describe('Edge', function () {
*/
it('properly handles choosify input', function () {
// check defaults
- var options = {};
- var network = createNetwork(options);
+ let options = {};
+ let network = createNetwork(options);
checkChooserValues(firstEdge(network), true, true);
// There's no point in checking invalid values here; these are detected by the options parser
@@ -495,13 +501,13 @@ describe('Edge', function () {
options = {edges: {chosen: {
edge:true,
- label: function(value, id, selected, hovering) {}
+ label: function() {}
}}};
network = createNetwork(options);
checkChooserValues(firstEdge(network), true, 'function');
options = {edges: {chosen: {
- edge: function(value, id, selected, hovering) {},
+ edge: function() {},
label:false,
}}};
network = createNetwork(options);
@@ -513,14 +519,14 @@ describe('Edge', function () {
* Support routine for next unit test
*/
function createDataforColorChange() {
- var nodes = new DataSet([
+ const nodes = new DataSet([
{id: 1, label: 'Node 1' }, // group:'Group1'},
{id: 2, label: 'Node 2', group:'Group2'},
{id: 3, label: 'Node 3'},
]);
// create an array with edges
- var edges = new DataSet([
+ const edges = new DataSet([
{id: 1, from: 1, to: 2},
{id: 2, from: 1, to: 3, color: { inherit: 'to'}},
{id: 3, from: 3, to: 3, color: { color: '#00FF00'}},
@@ -528,7 +534,7 @@ describe('Edge', function () {
]);
- var data = {
+ const data = {
nodes: nodes,
edges: edges
};
@@ -544,16 +550,16 @@ describe('Edge', function () {
* We test the updates the color options in the general edges options here.
*/
it('sets inherit color option for edges on call to Network.setOptions()', function () {
- var container = document.getElementById('mynetwork');
- var data = createDataforColorChange();
+ const container = document.getElementById('mynetwork');
+ const data = createDataforColorChange();
- var options = {
+ const options = {
"edges" : { "color" : { "inherit" : "to" } },
};
// Test passing options on init.
- var network = new Network(container, data, options);
- var edges = network.body.edges;
+ let network = new Network(container, data, options);
+ let edges = network.body.edges;
assert.equal(edges[1].options.color.inherit, 'to'); // new default
assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
assert.equal(edges[3].options.color.inherit, false); // has explicit color
@@ -597,12 +603,12 @@ describe('Edge', function () {
it('sets inherit color option for specific edge', function () {
- var container = document.getElementById('mynetwork');
- var data = createDataforColorChange();
+ const container = document.getElementById('mynetwork');
+ const data = createDataforColorChange();
// Check no options
- var network = new Network(container, data, {});
- var edges = network.body.edges;
+ const network = new Network(container, data, {});
+ const edges = network.body.edges;
assert.equal(edges[1].options.color.inherit, 'from'); // default
assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
assert.equal(edges[3].options.color.inherit, false); // has explicit color
@@ -621,19 +627,19 @@ describe('Edge', function () {
* Perhaps TODO: add unit test for passing string value for color option
*/
it('sets color value for edges on call to Network.setOptions()', function () {
- var container = document.getElementById('mynetwork');
- var data = createDataforColorChange();
+ const container = document.getElementById('mynetwork');
+ const data = createDataforColorChange();
- var defaultColor = '#848484'; // From defaults
- var color = '#FF0000';
+ const defaultColor = '#848484'; // From defaults
+ const color = '#FF0000';
- var options = {
+ const options = {
"edges" : { "color" : { "color" : color } },
};
// Test passing options on init.
- var network = new Network(container, data, options);
- var edges = network.body.edges;
+ let network = new Network(container, data, options);
+ let edges = network.body.edges;
assert.equal(edges[1].options.color.color, color);
assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit
assert.equal(edges[2].options.color.color, color);
@@ -674,25 +680,25 @@ describe('Edge', function () {
* Checking to make sure edges that become unconnected due to node removal get reconnected
*/
it.skip('has reconnected edges (problems since mocha 4)', function (done) {
- var node1 = {id:1, label:"test1"};
- var node2 = {id:2, label:"test2"};
- var nodes = new DataSet([node1, node2]);
+ const node1 = {id:1, label:"test1"};
+ const node2 = {id:2, label:"test2"};
+ const nodes = new DataSet([node1, node2]);
- var edge = {id:1, from: 1, to:2};
- var edges = new DataSet([edge]);
+ const edge = {id:1, from: 1, to:2};
+ const edges = new DataSet([edge]);
- var data = {
+ const data = {
nodes: nodes,
edges: edges
};
- var container = document.getElementById('mynetwork');
- var network = new Network(container, data);
+ const container = document.getElementById('mynetwork');
+ const network = new Network(container, data);
//remove node causing edge to become disconnected
nodes.remove(node2.id);
- var foundEdge = network.body.edges[edge.id];
+ let foundEdge = network.body.edges[edge.id];
assert.ok(foundEdge===undefined, "edge is still in state cache");
@@ -710,7 +716,9 @@ describe('Edge', function () {
describe('Clustering', function () {
it('properly handles options allowSingleNodeCluster', function() {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
data.edges.update({from: 1, to: 11,});
numEdges += 1;
assertNumNodes(network, numNodes);
@@ -755,7 +763,9 @@ describe('Clustering', function () {
it('removes nested clusters with allowSingleNodeCluster === true', function() {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
// Create a chain of nested clusters, three deep
clusterTo(network, 'c1', [4], true);
clusterTo(network, 'c2', ['c1'], true);
@@ -784,7 +794,9 @@ describe('Clustering', function () {
* Check on fix for #1218
*/
it('connects a new edge to a clustering node instead of the clustered node', function () {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
createCluster(network);
numNodes += 1; // A clustering node is now hiding two nodes
@@ -813,7 +825,9 @@ describe('Clustering', function () {
*/
it('can uncluster a clustered node when a node is removed that has an edge to that cluster', function () {
// NOTE: this block is same as previous test
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
createCluster(network);
numNodes += 1; // A clustering node is now hiding two nodes
@@ -851,9 +865,11 @@ describe('Clustering', function () {
* Check on fix for #1291
*/
it('can remove a node inside a cluster and then open that cluster', function () {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
- var clusterOptionsByData = {
+ const clusterOptionsByData = {
joinCondition: function(node) {
if (node.id == 1 || node.id == 2 || node.id == 3) return true;
return false;
@@ -890,7 +906,7 @@ describe('Clustering', function () {
*/
function createOutlierGraph() {
// create an array with nodes
- var nodes = new DataSet([
+ const nodes = new DataSet([
{id: 1, label: '1', group:'Group1'},
{id: 2, label: '2', group:'Group2'},
{id: 3, label: '3', group:'Group3'},
@@ -899,7 +915,7 @@ describe('Clustering', function () {
]);
// create an array with edges
- var edges = new DataSet([
+ const edges = new DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
@@ -907,12 +923,12 @@ describe('Clustering', function () {
]);
// create a network
- var container = document.getElementById('mynetwork');
- var data = {
+ const container = document.getElementById('mynetwork');
+ const data = {
nodes: nodes,
edges: edges
};
- var options = {
+ const options = {
"groups" : {
"Group1" : { level:1 },
"Group2" : { level:2 },
@@ -921,7 +937,7 @@ describe('Clustering', function () {
}
};
- var network = new Network (container, data, options);
+ const network = new Network (container, data, options);
return network;
}
@@ -941,15 +957,15 @@ describe('Clustering', function () {
* within nodes.clustering; strictly, speaking, the array and its items
* are collections, so order should not matter.
*/
- var collectClusters = function(network) {
- var clusters = [];
- for(var n in network.body.nodes) {
- var node = network.body.nodes[n];
+ const collectClusters = function(network) {
+ const clusters = [];
+ for(const n in network.body.nodes) {
+ const node = network.body.nodes[n];
if (node.containedNodes === undefined) continue; // clusters only
// Collect id's of nodes in the cluster
- var nodes = [];
- for(var m in node.containedNodes) {
+ const nodes = [];
+ for(const m in node.containedNodes) {
nodes.push(m);
}
clusters.push(nodes);
@@ -971,15 +987,15 @@ describe('Clustering', function () {
* This comparison depends on the ordering; better
* would be to treat the items and values as collections.
*/
- var compareClusterInfo = function(recieved, expected) {
+ const compareClusterInfo = function(recieved, expected) {
if (recieved.length !== expected.length) return false;
- for (var n = 0; n < recieved.length; ++n) {
- var itema = recieved[n];
- var itemb = expected[n];
+ for (let n = 0; n < recieved.length; ++n) {
+ const itema = recieved[n];
+ const itemb = expected[n];
if (itema.length !== itemb.length) return false;
- for (var m = 0; m < itema.length; ++m) {
+ for (let m = 0; m < itema.length; ++m) {
if (itema[m] != itemb[m]) return false; // != because values can be string or number
}
}
@@ -988,10 +1004,10 @@ describe('Clustering', function () {
}
- var assertJoinCondition = function(joinCondition, expected) {
- var network = createOutlierGraph();
+ const assertJoinCondition = function(joinCondition, expected) {
+ const network = createOutlierGraph();
network.clusterOutliers({joinCondition: joinCondition});
- var recieved = collectClusters(network);
+ const recieved = collectClusters(network);
//console.log(recieved);
assert(compareClusterInfo(recieved, expected),
@@ -1000,14 +1016,11 @@ describe('Clustering', function () {
};
- // Should cluster 3,4,5:
- var joinAll_ = function(n) { return true ; }
-
// Should cluster none:
- var joinNone_ = function(n) { return false ; }
+ const joinNone_ = function() { return false ; }
// Should cluster 4 & 5:
- var joinLevel_ = function(n) { return n.level > 3 ; }
+ const joinLevel_ = function(n) { return n.level > 3 ; }
assertJoinCondition(undefined , [[1,3],[2,4,5]]);
assertJoinCondition(null , [[1,3],[2,4,5]]);
@@ -1024,7 +1037,9 @@ describe('Clustering', function () {
* Helper function, created nested clusters, three deep
*/
function createNetwork1() {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ const sampleNetwork = createSampleNetwork();
+ const [network, data] = sampleNetwork;
+ let [, , numNodes, numEdges] = sampleNetwork;
clusterTo(network, 'c1', [3,4]);
numNodes += 1; // new cluster node
@@ -1054,7 +1069,7 @@ describe('Clustering', function () {
it('opens clusters automatically when nodes deleted', function () {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ let [network, data, numNodes, numEdges] = createSampleNetwork();
// Simple case: cluster of two nodes, delete one node
clusterTo(network, 'c1', [3,4]);
@@ -1116,7 +1131,7 @@ describe('Clustering', function () {
* This is the 'simple' case.
*/
it('properly opens 1-level clusters', function () {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ let [network, data, numNodes, numEdges] = createSampleNetwork();
assertEdgeLabels(network, data.edges, "New sample network");
// Pedantic: make a cluster of everything
@@ -1201,7 +1216,7 @@ describe('Clustering', function () {
* The test uses clustering three levels deep and opens the middle one.
*/
it('properly opens clustered clusters', function () {
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ let [network, data, numNodes, numEdges] = createSampleNetwork();
assertEdgeLabels(network, data.edges, "New sample network");
data.edges.update({ from: 1, to: 11, label: "1 to 11" })
@@ -1229,12 +1244,12 @@ describe('Clustering', function () {
numEdges -= 1;
assertNumNodes(network, numNodes, numNodes - 5);
assertNumEdges(network, numEdges, numEdges - 5);
- assertEdgeLabels(network, data.edges, "c2 clustered cluster opened")
+ assertEdgeLabels(network, data.edges, "c2 clustered cluster opened");
//
// Same, with one external connection to cluster
//
- var [network, data, numNodes, numEdges] = createSampleNetwork();
+ ([network, data, numNodes, numEdges] = createSampleNetwork());
data.edges.update({from: 1, to: 11, label: "1 to 11"});
data.edges.update({from: 2, to: 12, label: "2 to 12"});
numEdges += 2;
@@ -1313,7 +1328,7 @@ describe('on node.js', function () {
assert(this.container !== null, 'Container div not found');
// The following should now just plain succeed
- var [network, data] = createSampleNetwork();
+ const [network] = createSampleNetwork();
assert.equal(Object.keys(network.body.nodes).length, 8);
assert.equal(Object.keys(network.body.edges).length, 6);
@@ -1324,27 +1339,30 @@ describe('runs example ', function () {
function loadExample(path, noPhysics) {
include(path, this);
- var container = document.getElementById('mynetwork');
+ const container = document.getElementById('mynetwork');
// create a network
- var data = {
+ const data = {
+ /* eslint-disable no-undef */
nodes: new DataSet(nodes),
+ /* eslint-disable no-undef */
edges: new DataSet(edges)
};
if (noPhysics) {
// Avoid excessive processor time due to load.
// We're just interested that the load itself is good
+ /* eslint-disable no-undef */
options.physics = false;
}
- var network = new Network(container, data, options);
+ const network = new Network(container, data, options);
return network;
};
it('basicUsage', function () {
- var network = loadExample('./test/network/basicUsage.js');
+ const network = loadExample('./test/network/basicUsage.js');
//console.log(Object.keys(network.body.edges));
// Count in following also contains the helper nodes for dynamic edges
@@ -1357,7 +1375,7 @@ describe('runs example ', function () {
// This is a huge example (which is why it's tested here!), so it takes a long time to load.
this.timeout(15000);
- var network = loadExample('./examples/network/datasources/WorldCup2014.js', true);
+ const network = loadExample('./examples/network/datasources/WorldCup2014.js', true);
// Count in following also contains the helper nodes for dynamic edges
assert.equal(Object.keys(network.body.nodes).length, 9964);
@@ -1368,7 +1386,7 @@ describe('runs example ', function () {
// This actually failed to load, added for this reason
it.skip('disassemblerExample (problems since mocha 4)', function () {
- var network = loadExample('./examples/network/exampleApplications/disassemblerExample.js');
+ const network = loadExample('./examples/network/exampleApplications/disassemblerExample.js');
// console.log(Object.keys(network.body.nodes));
// console.log(Object.keys(network.body.edges));
diff --git a/test/canvas-mock.js b/test/canvas-mock.js
index 5136568ee1..32c3a28ac2 100644
--- a/test/canvas-mock.js
+++ b/test/canvas-mock.js
@@ -3,12 +3,17 @@
*
* Adapted from: https://github.com/Cristy94/canvas-mock
*/
-var jsdom = require('jsdom');
-var jsdom_global = require('jsdom-global');
+const jsdom = require('jsdom');
+const jsdom_global = require('jsdom-global');
-var canvasMock; // Use one canvas instance for all calls to createElement('canvas');
+let canvasMock; // Use one canvas instance for all calls to createElement('canvas');
+/**
+ * Replace element's getContext method with a do nothing mock.
+ *
+ * @param {HTMLElement} el - The element whose getContext will be mocked.
+ */
function replaceCanvasContext (el) {
el.getContext = function() {
return {
@@ -68,12 +73,12 @@ function replaceCanvasContext (el) {
* @private
*/
function overrideCreateElement(window) {
- var d = window.document;
- var f = window.document.createElement;
+ const d = window.document;
+ const f = window.document.createElement;
// Check if 2D context already present. That happens either when running in a browser,
// or this is node.js with 'canvas' installed.
- var ctx = d.createElement('canvas').getContext('2d');
+ const ctx = d.createElement('canvas').getContext('2d');
if (ctx !== null && ctx !== undefined) {
//console.log('2D context is present, no need to override');
return;
@@ -102,12 +107,12 @@ function overrideCreateElement(window) {
* @private
*/
function overrideCreateElementNS(window) {
- var d = window.document;
- var f = window.document.createElementNS;
+ const d = window.document;
+ const f = window.document.createElementNS;
window.document.createElementNS = function(namespaceURI, qualifiedName) {
if (namespaceURI === 'http://www.w3.org/2000/svg') {
- var result = f.call(d, namespaceURI, qualifiedName);
+ const result = f.call(d, namespaceURI, qualifiedName);
if (result.style == undefined) {
result.style = {};
return result;
@@ -127,20 +132,20 @@ function overrideCreateElementNS(window) {
*/
function mockify(html = '') {
// Start of message that we want to suppress.
- let msg = 'Error: Not implemented: HTMLCanvasElement.prototype.getContext'
+ const consoleErrorMessageToSuppress = 'Error: Not implemented: HTMLCanvasElement.prototype.getContext'
+ ' (without installing the canvas npm package)';
// Override default virtual console of jsdom
const virtualConsole = new jsdom.VirtualConsole();
// Set up a simple 'mock' console output. Only 'error' needs to be overridden
- let myConsole = {
- error: (msg) => {
- if (msg.indexOf(msg) === 0) {
+ const myConsole = {
+ error: (message) => {
+ if (message.indexOf(consoleErrorMessageToSuppress) === 0) {
//console.error('all is well');
} else {
// All other messages pass through
- console.error(msg);
+ console.error(consoleErrorMessageToSuppress);
}
}
};
@@ -148,7 +153,7 @@ function mockify(html = '') {
// Using the global catch instead of specific event handler, because I couldn't get them to work
virtualConsole.sendTo(myConsole);
- let cleanupFunction = jsdom_global(
+ const cleanupFunction = jsdom_global(
html,
{ skipWindowCheck: true, virtualConsole: virtualConsole}
);
diff --git a/test/dotparser.test.js b/test/dotparser.test.js
index c9c6412b6e..b48ba22841 100644
--- a/test/dotparser.test.js
+++ b/test/dotparser.test.js
@@ -1,4 +1,4 @@
-var assert = require('assert'),
+const assert = require('assert'),
fs = require('fs'),
dot = require('../lib/network/dotparser.js');
@@ -8,7 +8,7 @@ describe('dotparser', function () {
fs.readFile('test/dot.txt', function (err, data) {
data = String(data);
- var graph = dot.parseDOT(data);
+ const graph = dot.parseDOT(data);
assert.deepEqual(graph, {
"type": "digraph",
@@ -188,11 +188,11 @@ describe('dotparser', function () {
* DOT-format examples taken from #3015
*/
it('properly handles newline escape sequences in strings', function (done) {
- var data = 'dinetwork {1 [label="new\\nline"];}';
+ let data = 'dinetwork {1 [label="new\\nline"];}';
data = String(data);
- var graph = dot.parseDOT(data);
+ const graph = dot.parseDOT(data);
assert.deepEqual(graph, {
"id": "dinetwork",
@@ -208,7 +208,7 @@ describe('dotparser', function () {
// Note the double backslashes
- var data2 = 'digraph {' + "\n" +
+ let data2 = 'digraph {' + "\n" +
' 3 [color="#0d2b7c", label="query:1230:add_q\\n0.005283\\n6.83%\\n(0.0001)\\n(0.13%)\\n17×"];' + "\n" +
' 3 -> 7 [color="#0d2a7b", fontcolor="#0d2a7b", label="0.005128\\n6.63%\\n17×"];' + "\n" +
' 5 [color="#0d1976", label="urlresolvers:537:reverse\\n0.00219\\n2.83%\\n(0.000193)\\n(0.25%)\\n29×"];' + "\n" +
@@ -216,7 +216,7 @@ describe('dotparser', function () {
data2 = String(data2);
- var graph2 = dot.parseDOT(data2);
+ const graph2 = dot.parseDOT(data2);
//console.log(JSON.stringify(graph, null, 2));
assert.deepEqual(graph2, {
diff --git a/test/network/basicUsage.js b/test/network/basicUsage.js
index 85808210ad..e6701cc712 100644
--- a/test/network/basicUsage.js
+++ b/test/network/basicUsage.js
@@ -1,3 +1,8 @@
+// These variables will be injected into a function that will use them.
+/* eslint no-unused-vars: "off" */
+// Const won't work here, only var.
+/* eslint no-var: "off" */
+
// Network from `basicUsage` example
// create an array with nodes
diff --git a/tsconfig.code.json b/tsconfig.code.json
index 713b5fc205..4603e2efe6 100644
--- a/tsconfig.code.json
+++ b/tsconfig.code.json
@@ -3,5 +3,5 @@
"compilerOptions": {
"noImplicitAny": false
},
- "exclude": ["test"]
+ "include": ["lib"]
}
diff --git a/tsconfig.declarations.json b/tsconfig.declarations.json
index 79e8a6c772..3728ad158c 100644
--- a/tsconfig.declarations.json
+++ b/tsconfig.declarations.json
@@ -7,5 +7,5 @@
"emitDeclarationOnly": true,
"noImplicitAny": false
},
- "exclude": ["cypress", "test"]
+ "include": ["lib"]
}
diff --git a/tsconfig.json b/tsconfig.json
index 82ced6c357..0f7ceceaac 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -13,6 +13,5 @@
"strict": true,
"target": "esnext"
},
- "exclude": ["node_modules", "**/__tests__/*"],
- "include": ["cypress", "lib", "test"]
+ "exclude": ["node_modules", "**/__tests__/*"]
}
diff --git a/tsconfig.lint.json b/tsconfig.lint.json
new file mode 100644
index 0000000000..289d9dfa08
--- /dev/null
+++ b/tsconfig.lint.json
@@ -0,0 +1,4 @@
+{
+ "extends": "./tsconfig",
+ "include": [".*.js", ".*.json", ".*.ts", "**/*.js", "**/*.json", "**/*.ts"]
+}
diff --git a/tsconfig.types.json b/tsconfig.types.json
index 5c82e0795b..f18ad4d07d 100644
--- a/tsconfig.types.json
+++ b/tsconfig.types.json
@@ -7,5 +7,5 @@
"emitDeclarationOnly": true,
"noImplicitAny": false
},
- "exclude": ["cypress", "test"]
+ "include": ["lib"]
}