diff --git a/HISTORY.md b/HISTORY.md index 410b41b9..2733b91b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,11 +6,12 @@ http://visjs.org ### General - Fixed #893, #911: the `clickToUse` option of Network, Graph2d, and Network - was blocking click events in the web page. + was blocking click events in the web page. ### Timeline - Improved function `fit()` to take into account the actual width of items. +- Fixed #897: Timeline option `{snap: null}` did give a validation error. ### Graph2D diff --git a/lib/network/options.js b/lib/network/options.js index cf8c69f0..fcaf7fc5 100644 --- a/lib/network/options.js +++ b/lib/network/options.js @@ -11,18 +11,16 @@ let number = 'number'; let array = 'array'; let object = 'object'; // should only be in a __type__ property let dom = 'dom'; -let fn = 'function'; -let undef = 'undefined'; -let any = 'any' +let any = 'any'; let allOptions = { configure: { enabled: {boolean}, - filter: {boolean,string,array,fn}, + filter: {boolean,string,array,'function': 'function'}, container: {dom}, showButton: {boolean}, - __type__: {object,boolean,string,array,fn} + __type__: {object,boolean,string,array,'function': 'function'} }, edges: { arrows: { @@ -51,9 +49,9 @@ let allOptions = { __type__: {object,string} }, hidden: {boolean}, - hoverWidth: {fn,number}, - label: {string,undef}, - length: {number,undef}, + hoverWidth: {'function': 'function',number}, + label: {string,'undefined': 'undefined'}, + length: {number,'undefined': 'undefined'}, physics: {boolean}, scaling: { min: {number}, @@ -66,10 +64,10 @@ let allOptions = { drawThreshold: {number}, __type__: {object,boolean} }, - customScalingFunction: {fn}, + customScalingFunction: {'function': 'function'}, __type__: {object} }, - selectionWidth: {fn,number}, + selectionWidth: {'function': 'function',number}, selfReferenceSize: {number}, shadow: { enabled: {boolean}, @@ -84,9 +82,9 @@ let allOptions = { roundness: {number}, __type__: {object,boolean} }, - title: {string, undef}, + title: {string, 'undefined': 'undefined'}, width: {number}, - value: {number, undef}, + value: {number, 'undefined': 'undefined'}, __type__: {object} }, groups: { @@ -116,7 +114,7 @@ let allOptions = { __type__: {object} }, layout: { - randomSeed: {undef,number}, + randomSeed: {'undefined': 'undefined',number}, hierarchical: { enabled: {boolean}, levelSeparation: {number}, @@ -129,19 +127,19 @@ let allOptions = { manipulation: { enabled: {boolean}, initiallyActive: {boolean}, - addNode: {boolean,fn}, - addEdge: {boolean,fn}, - editNode: {fn}, - editEdge: {boolean,fn}, - deleteNode: {boolean,fn}, - deleteEdge: {boolean,fn}, + addNode: {boolean,'function': 'function'}, + addEdge: {boolean,'function': 'function'}, + editNode: {'function': 'function'}, + editEdge: {boolean,'function': 'function'}, + deleteNode: {boolean,'function': 'function'}, + deleteEdge: {boolean,'function': 'function'}, controlNodeStyle: 'get from nodes, will be overwritten below', __type__: {object,boolean} }, nodes: { borderWidth: {number}, - borderWidthSelected: {number,undef}, - brokenImage: {string,undef}, + borderWidthSelected: {number,'undefined': 'undefined'}, + brokenImage: {string,'undefined': 'undefined'}, color: { border: {string}, background: {string}, @@ -171,7 +169,7 @@ let allOptions = { strokeColor: {string}, __type__: {object,string} }, - group: {string,number,undef}, + group: {string,number,'undefined': 'undefined'}, hidden: {boolean}, icon: { face: {string}, @@ -181,9 +179,9 @@ let allOptions = { __type__: {object} }, id: {string, number}, - image: {string,undef}, // --> URL - label: {string,undef}, - level: {number,undef}, + image: {string,'undefined': 'undefined'}, // --> URL + label: {string,'undefined': 'undefined'}, + level: {number,'undefined': 'undefined'}, mass: {number}, physics: {boolean}, scaling: { @@ -197,7 +195,7 @@ let allOptions = { drawThreshold: {number}, __type__: {object, boolean} }, - customScalingFunction: {fn}, + customScalingFunction: {'function': 'function'}, __type__: {object} }, shadow: { @@ -209,8 +207,8 @@ let allOptions = { }, shape: {string:['ellipse', 'circle', 'database', 'box', 'text','image', 'circularImage','diamond', 'dot', 'star', 'triangle', 'triangleDown', 'square','icon']}, size: {number}, - title: {string,undef}, - value: {number,undef}, + title: {string,'undefined': 'undefined'}, + value: {number,'undefined': 'undefined'}, x: {number}, y: {number}, __type__: {object} diff --git a/lib/shared/Validator.js b/lib/shared/Validator.js index 2af6889b..f9d79670 100644 --- a/lib/shared/Validator.js +++ b/lib/shared/Validator.js @@ -84,6 +84,7 @@ class Validator { static checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path) { let optionType = Validator.getType(options[option]); let refOptionType = refOptionObj[optionType]; + console.log('checkFields', optionType, refOptionType, refOptionObj) if (refOptionType !== undefined) { // if the type is correct, we check if it is supposed to be one of a few select values if (Validator.getType(refOptionType) === 'array') { @@ -102,18 +103,10 @@ class Validator { Validator.parse(options[option], referenceOptions[referenceOption], path); } } - else { - if (refOptionObj['undef'] !== undefined && optionType === 'undefined') { - // item is undefined, which is allowed - } - else if (refOptionObj['fn'] !== undefined && optionType === 'function') { - // item is a function, which is allowed - } - else if (refOptionObj['any'] === undefined) { - // type of the field is incorrect and the field cannot be any - console.log('%cInvalid type received for "' + option + '". Expected: ' + Validator.print(Object.keys(refOptionObj)) + '. Received [' + optionType + '] "' + options[option] + '"' + Validator.printLocation(path, option), printStyle); - errorFound = true; - } + else if (refOptionObj['any'] === undefined) { + // type of the field is incorrect and the field cannot be any + console.log('%cInvalid type received for "' + option + '". Expected: ' + Validator.print(Object.keys(refOptionObj)) + '. Received [' + optionType + '] "' + options[option] + '"' + Validator.printLocation(path, option), printStyle); + errorFound = true; } } diff --git a/lib/timeline/optionsGraph2d.js b/lib/timeline/optionsGraph2d.js index 2f73fc99..28ecec72 100644 --- a/lib/timeline/optionsGraph2d.js +++ b/lib/timeline/optionsGraph2d.js @@ -13,18 +13,15 @@ let date = 'date'; let object = 'object'; // should only be in a __type__ property let dom = 'dom'; let moment = 'moment'; -let fn = 'function'; -let nada = 'null'; -let undef = 'undefined'; let any = 'any'; let allOptions = { configure: { enabled: {boolean}, - filter: {boolean,fn}, + filter: {boolean,'function': 'function'}, container: {dom}, - __type__: {object,boolean,fn} + __type__: {object,boolean,'function': 'function'} }, //globals : @@ -67,13 +64,13 @@ let allOptions = { alignZeros: {boolean}, left:{ range: {min:{number},max:{number},__type__: {object}}, - format: {fn}, + format: {'function': 'function'}, title: {text:{string,number},style:{string},__type__: {object}}, __type__: {object} }, right:{ range: {min:{number},max:{number},__type__: {object}}, - format: {fn}, + format: {'function': 'function'}, title: {text:{string,number},style:{string},__type__: {object}}, __type__: {object} }, @@ -104,25 +101,25 @@ let allOptions = { end: {number, date, string, moment}, format: { minorLabels: { - millisecond: {string,undef}, - second: {string,undef}, - minute: {string,undef}, - hour: {string,undef}, - weekday: {string,undef}, - day: {string,undef}, - month: {string,undef}, - year: {string,undef}, + millisecond: {string,'undefined': 'undefined'}, + second: {string,'undefined': 'undefined'}, + minute: {string,'undefined': 'undefined'}, + hour: {string,'undefined': 'undefined'}, + weekday: {string,'undefined': 'undefined'}, + day: {string,'undefined': 'undefined'}, + month: {string,'undefined': 'undefined'}, + year: {string,'undefined': 'undefined'}, __type__: {object} }, majorLabels: { - millisecond: {string,undef}, - second: {string,undef}, - minute: {string,undef}, - hour: {string,undef}, - weekday: {string,undef}, - day: {string,undef}, - month: {string,undef}, - year: {string,undef}, + millisecond: {string,'undefined': 'undefined'}, + second: {string,'undefined': 'undefined'}, + minute: {string,'undefined': 'undefined'}, + hour: {string,'undefined': 'undefined'}, + weekday: {string,'undefined': 'undefined'}, + day: {string,'undefined': 'undefined'}, + month: {string,'undefined': 'undefined'}, + year: {string,'undefined': 'undefined'}, __type__: {object} }, __type__: {object} @@ -146,8 +143,8 @@ let allOptions = { showMinorLabels: {boolean}, start: {date, number, string, moment}, timeAxis: { - scale: {string,undef}, - step: {number,undef}, + scale: {string,'undefined': 'undefined'}, + step: {number,'undefined': 'undefined'}, __type__: {object} }, width: {string, number}, @@ -190,12 +187,12 @@ let configureOptions = { visible: true, alignZeros: true, left:{ - //range: {min:undefined,max:undefined}, + //range: {min:'undefined': 'undefined'ined,max:'undefined': 'undefined'ined}, //format: function (value) {return value;}, title: {text:'',style:''} }, right:{ - //range: {min:undefined,max:undefined}, + //range: {min:'undefined': 'undefined'ined,max:'undefined': 'undefined'ined}, //format: function (value) {return value;}, title: {text:'',style:''} } diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index 413403e0..7082e8a5 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -13,18 +13,15 @@ let date = 'date'; let object = 'object'; // should only be in a __type__ property let dom = 'dom'; let moment = 'moment'; -let fn = 'function'; -let nada = 'null'; -let undef = 'undefined'; let any = 'any'; let allOptions = { configure: { enabled: {boolean}, - filter: {boolean,fn}, + filter: {boolean,'function': 'function'}, container: {dom}, - __type__: {object,boolean,fn} + __type__: {object,boolean,'function': 'function'} }, //globals : @@ -33,39 +30,39 @@ let allOptions = { clickToUse: {boolean}, dataAttributes: {string, array}, editable: { - add: {boolean, undef}, - remove: {boolean, undef}, - updateGroup: {boolean, undef}, - updateTime: {boolean, undef}, + add: {boolean, 'undefined': 'undefined'}, + remove: {boolean, 'undefined': 'undefined'}, + updateGroup: {boolean, 'undefined': 'undefined'}, + updateTime: {boolean, 'undefined': 'undefined'}, __type__: {boolean, object} }, end: {number, date, string, moment}, format: { minorLabels: { - millisecond: {string,undef}, - second: {string,undef}, - minute: {string,undef}, - hour: {string,undef}, - weekday: {string,undef}, - day: {string,undef}, - month: {string,undef}, - year: {string,undef}, + millisecond: {string,'undefined': 'undefined'}, + second: {string,'undefined': 'undefined'}, + minute: {string,'undefined': 'undefined'}, + hour: {string,'undefined': 'undefined'}, + weekday: {string,'undefined': 'undefined'}, + day: {string,'undefined': 'undefined'}, + month: {string,'undefined': 'undefined'}, + year: {string,'undefined': 'undefined'}, __type__: {object} }, majorLabels: { - millisecond: {string,undef}, - second: {string,undef}, - minute: {string,undef}, - hour: {string,undef}, - weekday: {string,undef}, - day: {string,undef}, - month: {string,undef}, - year: {string,undef}, + millisecond: {string,'undefined': 'undefined'}, + second: {string,'undefined': 'undefined'}, + minute: {string,'undefined': 'undefined'}, + hour: {string,'undefined': 'undefined'}, + weekday: {string,'undefined': 'undefined'}, + day: {string,'undefined': 'undefined'}, + month: {string,'undefined': 'undefined'}, + year: {string,'undefined': 'undefined'}, __type__: {object} }, __type__: {object} }, - groupOrder: {string, fn}, + groupOrder: {string, 'function': 'function'}, height: {string, number}, hiddenDates: {object, array}, locale:{string}, @@ -76,8 +73,8 @@ let allOptions = { margin: { axis: {number}, item: { - horizontal: {number,undef}, - vertical: {number,undef}, + horizontal: {number,'undefined': 'undefined'}, + vertical: {number,'undefined': 'undefined'}, __type__: {object,number} }, __type__: {object,number} @@ -88,15 +85,15 @@ let allOptions = { minHeight: {number, string}, moveable: {boolean}, multiselect: {boolean}, - onAdd: {fn}, - onUpdate: {fn}, - onMove: {fn}, - onMoving: {fn}, - onRemove: {fn}, - order: {fn}, + onAdd: {'function': 'function'}, + onUpdate: {'function': 'function'}, + onMove: {'function': 'function'}, + onMoving: {'function': 'function'}, + onRemove: {'function': 'function'}, + order: {'function': 'function'}, orientation: { - axis: {string,undef}, - item: {string,undef}, + axis: {string,'undefined': 'undefined'}, + item: {string,'undefined': 'undefined'}, __type__: {string, object} }, selectable: {boolean}, @@ -104,12 +101,12 @@ let allOptions = { showMajorLabels: {boolean}, showMinorLabels: {boolean}, stack: {boolean}, - snap: {fn, nada}, + snap: {'function': 'function', 'null': 'null'}, start: {date, number, string, moment}, - template: {fn}, + template: {'function': 'function'}, timeAxis: { - scale: {string,undef}, - step: {number,undef}, + scale: {string,'undefined': 'undefined'}, + step: {number,'undefined': 'undefined'}, __type__: {object} }, type: {string}, @@ -157,7 +154,7 @@ let configureOptions = { } }, - //groupOrder: {string, fn}, + //groupOrder: {string, 'function': 'function'}, height: '', //hiddenDates: {object, array}, locale: '', @@ -174,12 +171,12 @@ let configureOptions = { minHeight: '', moveable: false, multiselect: false, - //onAdd: {fn}, - //onUpdate: {fn}, - //onMove: {fn}, - //onMoving: {fn}, - //onRename: {fn}, - //order: {fn}, + //onAdd: {'function': 'function'}, + //onUpdate: {'function': 'function'}, + //onMove: {'function': 'function'}, + //onMoving: {'function': 'function'}, + //onRename: {'function': 'function'}, + //order: {'function': 'function'}, orientation: { axis: ['both', 'bottom', 'top'], item: ['bottom', 'top'] @@ -189,9 +186,9 @@ let configureOptions = { showMajorLabels: true, showMinorLabels: true, stack: true, - //snap: {fn, nada}, + //snap: {'function': 'function', nada}, start: '', - //template: {fn}, + //template: {'function': 'function'}, //timeAxis: { // scale: ['millisecond', 'second', 'minute', 'hour', 'weekday', 'day', 'month', 'year'], // step: [1, 1, 10, 1] diff --git a/test/timeline.html b/test/timeline.html index 1f8d2816..0158b433 100644 --- a/test/timeline.html +++ b/test/timeline.html @@ -162,6 +162,7 @@ 'hour': 'dddd D MMMM' } }, + snap: null, // timeAxis: { // scale: 'hour', // step: 2