From e74dc43c0a7ef6255c86083168c4cc8d05cd211c Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sat, 21 Oct 2017 20:22:34 +0200 Subject: [PATCH 1/6] Docs: Moved end block in all html documentation files to partial (#3597) * Added partial, tested with some pages * Docs: Moved end block in all html documentation files to partiel This rcConsolidatersd common footer in all documentation files to a partial. I'm hoping this serves as an example for others to isolate more common blocks (the menu would be the perfect candidate). It's straightforward work. --- docs/data/dataset.html | 16 +--------------- docs/data/dataview.html | 19 ++++--------------- docs/data/index.html | 19 ++++--------------- docs/graph2d/index.html | 19 ++++--------------- docs/graph3d/index.html | 19 ++++--------------- docs/network/configure.html | 19 ++++--------------- docs/network/edges.html | 19 ++++--------------- docs/network/groups.html | 19 ++++--------------- docs/network/index.html | 16 +--------------- docs/network/interaction.html | 19 ++++--------------- docs/network/layout.html | 19 ++++--------------- docs/network/manipulation.html | 19 ++++--------------- docs/network/nodes.html | 19 ++++--------------- docs/network/physics.html | 19 ++++--------------- docs/timeline/index.html | 19 ++++--------------- docs/tmpl/html-foot.tmpl | 15 +++++++++++++++ 16 files changed, 69 insertions(+), 225 deletions(-) create mode 100644 docs/tmpl/html-foot.tmpl diff --git a/docs/data/dataset.html b/docs/data/dataset.html index b78fb2fe..4a1698e0 100644 --- a/docs/data/dataset.html +++ b/docs/data/dataset.html @@ -933,18 +933,4 @@ var positiveBalance = dataset.get({ - - - - - - - - - - - - - - + diff --git a/docs/data/dataview.html b/docs/data/dataview.html index 9a98f7f2..1e3319e5 100644 --- a/docs/data/dataview.html +++ b/docs/data/dataview.html @@ -1,3 +1,6 @@ + @@ -396,18 +399,4 @@ view.on('*', function (event, properties, senderId) { - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/data/index.html b/docs/data/index.html index 12523f9d..110e7417 100644 --- a/docs/data/index.html +++ b/docs/data/index.html @@ -1,3 +1,6 @@ + @@ -121,18 +124,4 @@ - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/graph2d/index.html b/docs/graph2d/index.html index dd8baadd..5a02640d 100644 --- a/docs/graph2d/index.html +++ b/docs/graph2d/index.html @@ -1,3 +1,6 @@ + @@ -1500,18 +1503,4 @@ var options = { - - - - - - - - - - - - - - + diff --git a/docs/graph3d/index.html b/docs/graph3d/index.html index 19e63b9b..30565ddf 100644 --- a/docs/graph3d/index.html +++ b/docs/graph3d/index.html @@ -1,3 +1,6 @@ + @@ -961,18 +964,4 @@ graph3d.on('cameraPositionChange', onCameraPositionChange); - - - - - - - - - - - - - - + diff --git a/docs/network/configure.html b/docs/network/configure.html index 98be9e16..84616071 100644 --- a/docs/network/configure.html +++ b/docs/network/configure.html @@ -1,3 +1,6 @@ + @@ -176,18 +179,4 @@ function (option, path) { - - - - - - - - - - - - - - + diff --git a/docs/network/edges.html b/docs/network/edges.html index 7d4ae05a..8a901da3 100644 --- a/docs/network/edges.html +++ b/docs/network/edges.html @@ -1,3 +1,6 @@ + @@ -999,18 +1002,4 @@ var options: { - - - - - - - - - - - - - - + diff --git a/docs/network/groups.html b/docs/network/groups.html index caa8d178..bfbaab0b 100644 --- a/docs/network/groups.html +++ b/docs/network/groups.html @@ -1,3 +1,6 @@ + @@ -160,18 +163,4 @@ var options = { - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/network/index.html b/docs/network/index.html index 23ce1cfb..10e79783 100644 --- a/docs/network/index.html +++ b/docs/network/index.html @@ -1696,18 +1696,4 @@ var network = new vis.Network(container, data, options); - - - - - - - - - - - - - - + diff --git a/docs/network/interaction.html b/docs/network/interaction.html index 5483636b..23cad0ea 100644 --- a/docs/network/interaction.html +++ b/docs/network/interaction.html @@ -1,3 +1,6 @@ + @@ -155,18 +158,4 @@ network.setOptions(options); - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/network/layout.html b/docs/network/layout.html index 3b38048b..7100d4f5 100644 --- a/docs/network/layout.html +++ b/docs/network/layout.html @@ -1,3 +1,6 @@ + @@ -152,18 +155,4 @@ network.setOptions(options); - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/network/manipulation.html b/docs/network/manipulation.html index 95f9fc88..bebf6888 100644 --- a/docs/network/manipulation.html +++ b/docs/network/manipulation.html @@ -1,3 +1,6 @@ + @@ -187,18 +190,4 @@ var options = { - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/network/nodes.html b/docs/network/nodes.html index ca2d9397..7b527046 100644 --- a/docs/network/nodes.html +++ b/docs/network/nodes.html @@ -1,3 +1,6 @@ + @@ -1091,18 +1094,4 @@ mySize = minSize + diff * scale; - - - - - - - - - - - - - - + diff --git a/docs/network/physics.html b/docs/network/physics.html index c8fe9920..408bf4c7 100644 --- a/docs/network/physics.html +++ b/docs/network/physics.html @@ -1,3 +1,6 @@ + @@ -207,18 +210,4 @@ network.setOptions(options); - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 03e53cfe..3fd3ae65 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -1,3 +1,6 @@ + @@ -2166,18 +2169,4 @@ var options = { - - - - - - - - - - - - - - + diff --git a/docs/tmpl/html-foot.tmpl b/docs/tmpl/html-foot.tmpl new file mode 100644 index 00000000..fd3a494a --- /dev/null +++ b/docs/tmpl/html-foot.tmpl @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + \ No newline at end of file From 8e929e3543344b98a09276d55fa7d993501638cd Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Mon, 23 Oct 2017 06:56:35 +0200 Subject: [PATCH 2/6] Moved navbar elements in all html documentation files to partial (#3604) * Moved navbar elements in all html documentation files to partial This consolidates the common menu elements in all documentation files to a partial. * Moved test-exclamation mark --- docs/data/dataset.html | 2 +- docs/data/dataview.html | 47 +----------------------------- docs/data/index.html | 47 +----------------------------- docs/graph2d/index.html | 52 +--------------------------------- docs/graph3d/index.html | 47 +----------------------------- docs/network/configure.html | 52 +--------------------------------- docs/network/edges.html | 52 +--------------------------------- docs/network/groups.html | 52 +--------------------------------- docs/network/index.html | 52 +--------------------------------- docs/network/interaction.html | 47 +----------------------------- docs/network/layout.html | 50 +------------------------------- docs/network/manipulation.html | 47 +----------------------------- docs/network/nodes.html | 52 +--------------------------------- docs/network/physics.html | 47 +----------------------------- docs/timeline/index.html | 34 +--------------------- docs/tmpl/navbar.tmpl | 3 +- 16 files changed, 16 insertions(+), 667 deletions(-) diff --git a/docs/data/dataset.html b/docs/data/dataset.html index 4a1698e0..a47d204f 100644 --- a/docs/data/dataset.html +++ b/docs/data/dataset.html @@ -5,7 +5,7 @@ - +

DataSet

diff --git a/docs/data/dataview.html b/docs/data/dataview.html index 1e3319e5..67bc0920 100644 --- a/docs/data/dataview.html +++ b/docs/data/dataview.html @@ -38,52 +38,7 @@ - - - - +

DataView

diff --git a/docs/data/index.html b/docs/data/index.html index 110e7417..eb99f728 100644 --- a/docs/data/index.html +++ b/docs/data/index.html @@ -38,52 +38,7 @@ - - - - +

Data

diff --git a/docs/graph2d/index.html b/docs/graph2d/index.html index 5a02640d..ebe15083 100644 --- a/docs/graph2d/index.html +++ b/docs/graph2d/index.html @@ -81,57 +81,7 @@ - - - - - +

Graph2d

diff --git a/docs/graph3d/index.html b/docs/graph3d/index.html index 30565ddf..7a4d6e3a 100644 --- a/docs/graph3d/index.html +++ b/docs/graph3d/index.html @@ -38,52 +38,7 @@ - - - - +

Graph3d

diff --git a/docs/network/configure.html b/docs/network/configure.html index 84616071..7a7690fe 100644 --- a/docs/network/configure.html +++ b/docs/network/configure.html @@ -44,57 +44,7 @@ - - - - - +

Network - configure

diff --git a/docs/network/edges.html b/docs/network/edges.html index 8a901da3..fdf5e48e 100644 --- a/docs/network/edges.html +++ b/docs/network/edges.html @@ -44,57 +44,7 @@ - - - - - +

Network - edges

diff --git a/docs/network/groups.html b/docs/network/groups.html index bfbaab0b..7bf6bd10 100644 --- a/docs/network/groups.html +++ b/docs/network/groups.html @@ -42,57 +42,7 @@ - - - - - +

Network - groups

diff --git a/docs/network/index.html b/docs/network/index.html index 10e79783..f60ca719 100644 --- a/docs/network/index.html +++ b/docs/network/index.html @@ -73,57 +73,7 @@ - - - - - +

Network

diff --git a/docs/network/interaction.html b/docs/network/interaction.html index 23cad0ea..4be1c97b 100644 --- a/docs/network/interaction.html +++ b/docs/network/interaction.html @@ -37,52 +37,7 @@ - - - - +

Network - interaction

Used for all user interaction with the network. Handles mouse and touch events as well as the navigation buttons and the popups.

diff --git a/docs/network/layout.html b/docs/network/layout.html index 7100d4f5..2b11a890 100644 --- a/docs/network/layout.html +++ b/docs/network/layout.html @@ -38,55 +38,7 @@ - - - - - - +

Network - layout

Acts as the camera that looks on the canvas. Does the animation, zooming and focusing.

diff --git a/docs/network/manipulation.html b/docs/network/manipulation.html index bebf6888..d426ceb9 100644 --- a/docs/network/manipulation.html +++ b/docs/network/manipulation.html @@ -37,52 +37,7 @@ - - - - +

Network - manipulation

Acts as the camera that looks on the canvas. Does the animation, zooming and focusing.

diff --git a/docs/network/nodes.html b/docs/network/nodes.html index 7b527046..c0c0fff2 100644 --- a/docs/network/nodes.html +++ b/docs/network/nodes.html @@ -38,57 +38,7 @@ - - - - - +

Network - nodes

diff --git a/docs/network/physics.html b/docs/network/physics.html index 408bf4c7..c7defd61 100644 --- a/docs/network/physics.html +++ b/docs/network/physics.html @@ -38,52 +38,7 @@ - - - - +

Network - physics

Handles the physics simulation, moving the nodes and edges to show them clearly.

diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 3fd3ae65..29789149 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -44,39 +44,7 @@ - - - - - +

Timeline

diff --git a/docs/tmpl/navbar.tmpl b/docs/tmpl/navbar.tmpl index b1f8da08..884f7aa3 100644 --- a/docs/tmpl/navbar.tmpl +++ b/docs/tmpl/navbar.tmpl @@ -1,5 +1,4 @@
- \ No newline at end of file + From cdff6b12f30dde163f0ce291e609b15af38e9b77 Mon Sep 17 00:00:00 2001 From: yoavdamri Date: Mon, 23 Oct 2017 21:56:05 +0300 Subject: [PATCH 3/6] Network feature: background style for edges (#3606) * background docs * edge background * Update edges.html * Update EdgeBase.js --- docs/network/edges.html | 38 +++++++++++ examples/network/edgeStyles/background.html | 67 +++++++++++++++++++ lib/network/modules/EdgesHandler.js | 6 ++ lib/network/modules/components/Edge.js | 7 +- .../components/edges/util/BezierEdgeBase.js | 2 + .../modules/components/edges/util/EdgeBase.js | 56 ++++++++++++++++ lib/network/options.js | 7 ++ 7 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 examples/network/edgeStyles/background.html diff --git a/docs/network/edges.html b/docs/network/edges.html index fdf5e48e..8efddbc5 100644 --- a/docs/network/edges.html +++ b/docs/network/edges.html @@ -252,6 +252,44 @@ network.setOptions(options); true When false, the edge stops at the arrow. This can be useful if you have thick lines and you want the arrow to end in a point. Middle arrows are not affected by this. + + background + Object or Boolean + Object + When true, a background will be under the edge using the default settings. This can be further defined by supplying + an object. + + + + background.enabled + Boolean + false + Toggle the display of backgrounds. If this option is not defined, it is set to true if any of the properties + in this object are defined. + + + + background.color + String + 'rgba(111,111,111,0.5)' + The color size of the background as a string. Supported formats are 'rgb(255,255,255)', 'rgba(255,255,255,1)' and '#FFFFFF'. + + + background.size + Number + 10 + The blur size of the background. + + + background.dashes + Array or Boolean + false + When true, the background will be drawn as a dashed line. You can customize the dashes by supplying an Array. + Array formart: Array of numbers, gap length, dash length, gap length, dash length, ... etc. The array is + repeated until the distance is filled. + When using dashed lines in IE versions older than 11, the line will be drawn straight, not smooth. + + chosen Object or Boolean diff --git a/examples/network/edgeStyles/background.html b/examples/network/edgeStyles/background.html new file mode 100644 index 00000000..88ba71ed --- /dev/null +++ b/examples/network/edgeStyles/background.html @@ -0,0 +1,67 @@ + + + + Network | Edge background + + + + + + + + +

+ Edge background. +

+ +
+ + + + + + diff --git a/lib/network/modules/EdgesHandler.js b/lib/network/modules/EdgesHandler.js index 2cad9bc6..d90fcf92 100644 --- a/lib/network/modules/EdgesHandler.js +++ b/lib/network/modules/EdgesHandler.js @@ -103,6 +103,12 @@ class EdgesHandler { x:5, y:5 }, + background:{ + enabled: false, + color: 'rgba(111,111,111,1)', + size:10, + dashes: false + }, smooth: { enabled: true, type: "dynamic", diff --git a/lib/network/modules/components/Edge.js b/lib/network/modules/components/Edge.js index 7cc0f8f2..2b3d2046 100644 --- a/lib/network/modules/components/Edge.js +++ b/lib/network/modules/components/Edge.js @@ -147,6 +147,7 @@ class Edge { util.mergeOptions(parentOptions, newOptions, 'smooth', globalOptions); util.mergeOptions(parentOptions, newOptions, 'shadow', globalOptions); + util.mergeOptions(parentOptions, newOptions, 'background', globalOptions); if (newOptions.dashes !== undefined && newOptions.dashes !== null) { parentOptions.dashes = newOptions.dashes; @@ -270,7 +271,11 @@ class Edge { shadowX: this.options.shadow.x, shadowY: this.options.shadow.y, dashes: this.options.dashes, - width: this.options.width + width: this.options.width, + background: this.options.background.enabled, + backgroundColor: this.options.background.color, + backgroundSize: this.options.background.size, + backgroundDashes: this.options.background.dashes }; if (this.selected || this.hover) { if (this.chooser === true) { diff --git a/lib/network/modules/components/edges/util/BezierEdgeBase.js b/lib/network/modules/components/edges/util/BezierEdgeBase.js index f3442d3a..576b76bb 100644 --- a/lib/network/modules/components/edges/util/BezierEdgeBase.js +++ b/lib/network/modules/components/edges/util/BezierEdgeBase.js @@ -140,6 +140,8 @@ class BezierEdgeBase extends EdgeBase { // fallback to normal straight edge ctx.lineTo(this.toPoint.x, this.toPoint.y); } + // draw a background + this.drawBackground(ctx, values); // draw shadow if enabled this.enableShadow(ctx, values); diff --git a/lib/network/modules/components/edges/util/EdgeBase.js b/lib/network/modules/components/edges/util/EdgeBase.js index 8987c740..3230c350 100644 --- a/lib/network/modules/components/edges/util/EdgeBase.js +++ b/lib/network/modules/components/edges/util/EdgeBase.js @@ -592,6 +592,62 @@ class EdgeBase { ctx.shadowOffsetY = 0; } } + + /** + * + * @param {CanvasRenderingContext2D} ctx + * @param {{toArrow: boolean, toArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), toArrowType: *, middleArrow: boolean, middleArrowScale: (number|allOptions.edges.arrows.middle.scaleFactor|{number}|Array), middleArrowType: (allOptions.edges.arrows.middle.type|{string}|string|*), fromArrow: boolean, fromArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), fromArrowType: *, arrowStrikethrough: (*|boolean|allOptions.edges.arrowStrikethrough|{boolean}), color: undefined, inheritsColor: (string|string|string|allOptions.edges.color.inherit|{string, boolean}|Array|*), opacity: *, hidden: *, length: *, shadow: *, shadowColor: *, shadowSize: *, shadowX: *, shadowY: *, dashes: (*|boolean|Array|allOptions.edges.dashes|{boolean, array}), width: *}} values + */ + drawBackground(ctx, values) { + if (values.background !== false) { + let attrs = ['strokeStyle', 'lineWidth', 'dashes']; + let origCtxAttr = {}; + // save original line attrs + attrs.forEach(function(attrname) { + origCtxAttr[attrname] = ctx[attrname]; + }); + + ctx.strokeStyle = values.backgroundColor; + ctx.lineWidth = values.backgroundSize; + this.setStrokeDashed(ctx, values.backgroundDashes); + + ctx.stroke(); + + // restore original line attrs + attrs.forEach(function(attrname) { + ctx[attrname] = origCtxAttr[attrname]; + }); + this.setStrokeDashed(ctx, values.dashes); + } + } + + /** + * + * @param {CanvasRenderingContext2D} ctx + * @param {boolean|Array} dashes + */ + setStrokeDashed(ctx, dashes) { + if (dashes !== false) { + if (ctx.setLineDash !== undefined) { + let pattern = [5, 5]; + if (Array.isArray(dashes) === true) { + pattern = dashes; + } + ctx.setLineDash(pattern); + } + else { + console.warn("setLineDash is not supported in this browser. The dashed stroke cannot be used."); + } + } + else { + if (ctx.setLineDash !== undefined) { + ctx.setLineDash([]); + } + else { + console.warn("setLineDash is not supported in this browser. The dashed stroke cannot be used."); + } + } + } } export default EdgeBase; diff --git a/lib/network/options.js b/lib/network/options.js index e0f23b1c..ac9dc793 100644 --- a/lib/network/options.js +++ b/lib/network/options.js @@ -32,6 +32,13 @@ let allOptions = { __type__: { string: ['from', 'to', 'middle'], object } }, arrowStrikethrough: { boolean: bool }, + background: { + enabled: { boolean: bool }, + color: { string }, + size: { number }, + dashes: { boolean: bool, array }, + __type__: { object, boolean: bool } + }, chosen: { label: { boolean: bool, 'function': 'function' }, edge: { boolean: bool, 'function': 'function' }, From 773d593ca950627840731c326a5ec53b66d64e14 Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sat, 28 Oct 2017 23:30:45 +0200 Subject: [PATCH 4/6] Unit tests: upgrade jsdom to v11 to fix breaking unit tests for Network (#3603) * First working version * Fix completed for jsdom getContext() issue * Fixed commenting for review --- .gitignore | 3 +++ .travis.yml | 1 + package.json | 5 ++-- test/Graph3d.test.js | 18 +++++--------- test/Label.test.js | 7 +----- test/Network.test.js | 20 ++------------- test/PointItem.test.js | 11 ++++++-- test/TimeStep.test.js | 12 ++++++--- test/TimelineRange.test.js | 12 ++++++--- test/canvas-mock.js | 51 ++++++++++++++++++++++++++++++++++++-- 10 files changed, 91 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index b56f5ddd..565ffeea 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ npm-debug.log .*.sw[op] .commits.tmp gen/ +.nyc_output/ +coverage/ +package-lock.json diff --git a/.travis.yml b/.travis.yml index cf090cb6..77067eff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - "6" + - "7" env: - CXX=g++-4.8 addons: diff --git a/package.json b/package.json index de2515f5..3cf18cfd 100644 --- a/package.json +++ b/package.json @@ -61,11 +61,10 @@ "gulp-rename": "^1.2.2", "gulp-util": "^3.0.8", "jsdoc": "^3.5.5", - "jsdom": "9.12.0", - "jsdom-global": "^2.1.1", + "jsdom": "11.3.0", + "jsdom-global": "^3.0.2", "merge-stream": "^1.0.1", "mocha": "^3.4.2", - "mocha-jsdom": "^1.1.0", "nyc": "^11.2.1", "rimraf": "^2.6.1", "test-console": "^1.0.0", diff --git a/test/Graph3d.test.js b/test/Graph3d.test.js index c9bf2c5a..6b0643de 100644 --- a/test/Graph3d.test.js +++ b/test/Graph3d.test.js @@ -11,16 +11,16 @@ var now = new Date(); describe('Graph3d', function () { before(function() { - //console.log('before!'); - this.jsdom_global = jsdom_global( - "
", - { skipWindowCheck: true} - ); - canvasMockify(window); + this.jsdom_global = canvasMockify("
"); this.container = document.getElementById('mygraph'); }); + after(function() { + this.jsdom_global(); + }); + + it('should pass validation for the default options', function () { assert(Graph3d.DEFAULTS !== undefined); @@ -61,10 +61,4 @@ describe('Graph3d', function () { graph.setOptions({ style: 'bar'}); // Call should just work, no exception thrown assert.equal(graph.style, BAR_STYLE, "Style not set to expected 'bar'"); }); - - - after(function() { - //console.log('after!'); - this.jsdom_global(); - }); }); diff --git a/test/Label.test.js b/test/Label.test.js index 8f2cf52a..73794edb 100644 --- a/test/Label.test.js +++ b/test/Label.test.js @@ -13,7 +13,6 @@ var assert = require('assert'); var Label = require('../lib/network/modules/components/shared/Label').default; var NodesHandler = require('../lib/network/modules/NodesHandler').default; var util = require('../lib/util'); -var jsdom_global = require('jsdom-global'); var canvasMockify = require('./canvas-mock'); var DataSet = require('../lib/DataSet'); var Network = require('../lib/network/Network'); @@ -322,11 +321,7 @@ describe('Network Label', function() { **************************************************************/ before(function() { - this.jsdom_global = jsdom_global( - "
", - { skipWindowCheck: true} - ); - canvasMockify(window); + this.jsdom_global = canvasMockify("
"); this.container = document.getElementById('mynetwork'); }); diff --git a/test/Network.test.js b/test/Network.test.js index 425621e6..98c7e665 100644 --- a/test/Network.test.js +++ b/test/Network.test.js @@ -16,7 +16,6 @@ var DataSet = require('../lib/DataSet'); var Network = require('../lib/network/Network'); var stdout = require('test-console').stdout; var Validator = require("./../lib/shared/Validator").default; -var jsdom_global = require('jsdom-global'); var canvasMockify = require('./canvas-mock'); var {allOptions, configureOptions} = require('./../lib/network/options.js'); //var {printStyle} = require('./../lib/shared/Validator'); @@ -222,31 +221,16 @@ function checkFontProperties(fontItem, checkStrict = true) { } - - - describe('Network', function () { before(function() { - this.jsdom_global = jsdom_global( - "
", - { skipWindowCheck: true} - ); - canvasMockify(window); + this.jsdom_global = canvasMockify("
"); this.container = document.getElementById('mynetwork'); }); after(function() { - try { - this.jsdom_global(); - } catch(e) { - if (e.message() === 'window is undefined') { - console.warning("'" + e.message() + "' happened again"); - } else { - throw e; - } - } + this.jsdom_global(); }); diff --git a/test/PointItem.test.js b/test/PointItem.test.js index 9d2c333d..043f5df9 100644 --- a/test/PointItem.test.js +++ b/test/PointItem.test.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsdom = require('mocha-jsdom'); +var jsdom_global = require('jsdom-global'); var moment = require('../lib/module/moment'); var PointItem = require("../lib/timeline/component/item/PointItem"); var Range = require('../lib/timeline/Range'); @@ -7,9 +7,16 @@ var TestSupport = require('./TestSupport'); describe('Timeline PointItem', function () { - jsdom(); var now = moment(); + before(function() { + this.jsdom_global = jsdom_global(); + }); + + after(function() { + this.jsdom_global(); + }); + it('should initialize with minimal data', function() { var pointItem = new PointItem({start: now.toDate()}, null, null); assert.equal(pointItem.props.content.height, 0); diff --git a/test/TimeStep.test.js b/test/TimeStep.test.js index 7f3aa5a2..0410163d 100644 --- a/test/TimeStep.test.js +++ b/test/TimeStep.test.js @@ -1,12 +1,18 @@ var assert = require('assert'); -var jsdom = require('mocha-jsdom'); +var jsdom_global = require('jsdom-global'); var moment = require('../lib/module/moment'); var TimeStep = require('../lib/timeline/TimeStep'); var TestSupport = require('./TestSupport'); describe('TimeStep', function () { - jsdom(); + before(function() { + this.jsdom_global = jsdom_global(); + }); + + after(function() { + this.jsdom_global(); + }); it('should work with just start and end dates', function () { var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5)); @@ -85,4 +91,4 @@ describe('TimeStep', function () { assert.equal(timestep.getCurrent().unix(), moment("2017-04-03T01:00:00.000").unix(), "should have the right value after a step"); }); -}); \ No newline at end of file +}); diff --git a/test/TimelineRange.test.js b/test/TimelineRange.test.js index 933e5f99..7be5489a 100644 --- a/test/TimelineRange.test.js +++ b/test/TimelineRange.test.js @@ -1,12 +1,18 @@ var assert = require('assert'); -var jsdom = require('mocha-jsdom'); +var jsdom_global = require('jsdom-global'); var moment = require('../lib/module/moment'); var Range = require('../lib/timeline/Range'); var TestSupport = require('./TestSupport'); describe('Timeline Range', function () { - jsdom(); + before(function() { + this.jsdom_global = jsdom_global(); + }); + + after(function() { + this.jsdom_global(); + }); it('should have start default before now', function () { var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0).valueOf(); @@ -37,4 +43,4 @@ describe('Timeline Range', function () { range.setRange(new Date(2017, 0, 26, 13, 26, 3, 320), new Date(2017, 0, 26, 13, 26, 4, 320), false, false, null); assert.equal(range.getMillisecondsPerPixel(), 1, "one second over 1000 pixels"); }); -}); \ No newline at end of file +}); diff --git a/test/canvas-mock.js b/test/canvas-mock.js index fa7a08f9..e75cab4d 100644 --- a/test/canvas-mock.js +++ b/test/canvas-mock.js @@ -3,6 +3,8 @@ * * Adapted from: https://github.com/Cristy94/canvas-mock */ +var jsdom = require('jsdom'); +var jsdom_global = require('jsdom-global'); var canvasMock; // Use one canvas instance for all calls to createElement('canvas'); @@ -59,10 +61,11 @@ function replaceCanvasContext (el) { * The override is only done if there is no 2D context already present. * This allows for normal running in a browser, and for node.js the usage of 'canvas'. * - * @param {object} the current global window object. This can possible come from module 'jsdom', + * @param {object} the current global window object. This can possibly come from module 'jsdom', * when running under node.js. + * @private */ -function mockify(window) { +function overrideCreateElement(window) { var d = window.document; var f = window.document.createElement; @@ -87,4 +90,48 @@ function mockify(window) { }; } + +/** + * Initialize the mock, jsdom and jsdom_global for unit test usage. + * + * Suppresses a warning from `jsdom` on usage of `getContext()`. A mock definition is added for + * it, so the message is not relevant. + * + * @param {string} [html=''] html definitions which should be added to the jsdom definition + * @returns {function} function to call in after(), to clean up for `jsdom_global` + */ +function mockify(html = '') { + // Start of message that we want to suppress. + let msg = '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) { + //console.error('all is well'); + } else { + // All other messages pass through + console.error(msg); + } + } + }; + + // Using the global catch instead of specific event handler, because I couldn't get them to work + virtualConsole.sendTo(myConsole); + + let cleanupFunction = jsdom_global( + html, + { skipWindowCheck: true, virtualConsole: virtualConsole} + ); + + overrideCreateElement(window); // The actual initialization of canvas-mock + + return cleanupFunction; +} + + module.exports = mockify; From 508af93d8cd366b40bfd1a2f86f616e4db7b6c1a Mon Sep 17 00:00:00 2001 From: Lewis B Date: Sun, 29 Oct 2017 07:32:01 +1000 Subject: [PATCH 5/6] Fix currentTimeTick table in docs (#3627) --- docs/timeline/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 29789149..14e71561 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -1568,6 +1568,7 @@ timeline.off('select', onSelect); currentTimeTick + Has no properties Fired when the current time bar redraws. The rate depends on the zoom level. From bd668c5a60a29944b3de4364f27f93c04e5ff8b7 Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sat, 28 Oct 2017 23:42:06 +0200 Subject: [PATCH 6/6] Docs : fixes and enhancements for the documentation template. (#3596) * Docs : fixes and enhancements for the documentation template. This is an evolutionary update for the `jsdoc` document generation. - Added functionality to retrieval of data comments - Added partial for generating documentation in the method tables. - Moved commenting to source for `Network#clusterOutliers`. This was used as a case example. - Adjustment to CSS to get the decription text margins same as original - Added step to generate documentation to release checklist - Fixed some commenting which `jsdoc` couldn't handle * Fixes for linting --- docs/css/style.css | 9 ++++ docs/network/index.html | 45 +------------------ docs/publish.js | 30 +++++++++++-- docs/tmpl/renderMethod.tmpl | 18 ++++++++ lib/network/Network.js | 9 ++++ .../components/shared/LabelSplitter.js | 6 ++- misc/RELEASE_CHECKLIST_TEMPLATE.md | 5 ++- 7 files changed, 72 insertions(+), 50 deletions(-) create mode 100644 docs/tmpl/renderMethod.tmpl diff --git a/docs/css/style.css b/docs/css/style.css index 3a1d060e..1e9d4cc8 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -191,6 +191,15 @@ td.indent2 { padding-left:50px !important; } +td p:first-child { + margin-top: 0; +} + +td p:last-child { + margin-bottom: 0; +} + + pre.options { max-width:600px; } diff --git a/docs/network/index.html b/docs/network/index.html index f60ca719..b641d69b 100644 --- a/docs/network/index.html +++ b/docs/network/index.html @@ -552,51 +552,10 @@ var locales = { The options object is described for clusterByConnection and does the same here. - - clusterOutliers( - [Object options]) - - - Returns: none - This method will cluster all nodes with 1 edge with their respective connected node. - The options object is explained in full below. - - - - - - - This comes from the source! - - - Returns: - - - - - - findNode( - String/Number nodeId) - - - Returns: Array - Nodes can be in clusters. Clusters can also be in clusters. This function returns and array of - nodeIds showing where the node is. + + -

- If any nodeId in the chain, especially the first passed in as a parameter, is not present in - the current nodes list, an empty array is returned. - -

Example: - cluster 'A' contains cluster 'B', - cluster 'B' contains cluster 'C', - cluster 'C' contains node 'fred'. - network.clustering.findNode('fred') will return ['A','B','C','fred']. - - getClusteredEdges( String baseEdgeId) diff --git a/docs/publish.js b/docs/publish.js index f500e366..938da486 100644 --- a/docs/publish.js +++ b/docs/publish.js @@ -54,15 +54,37 @@ function createRenderer(fromDir, data) { */ renderer.getComment = function(methodName) { var tmp = data().filter({longname: methodName}).get()[0]; - //console.log(JSON.stringify(tmp)); + + if (tmp === undefined) { + throw new Error('Could not find jsdoc for: ' + methodName); + } + + // NOTE: Following does not show up with `gulp docs`, need to do call directly + // console.log(JSON.stringify(tmp, null, 2)); // Some restructuring, to adapt it to the docs layout // This needs some work to make it handle 0 and > 1 parameters - var param = tmp.params[0]; - var prototype = tmp.name + '(' + param.type.names.join('|') + ' ' + param.name + ')'; - var returns = tmp.returns[0].type.names; + var paramText = ""; + if (tmp.params !== undefined && tmp.params.length > 0) { + let param = tmp.params[0]; + let tmpText = param.type.names.join('|') + ' ' + param.name; + if (param.optional === true) { + tmpText = '[' + tmpText + ']'; + } + paramText = '' + tmpText + ''; + } + var prototype = tmp.name + '(' + paramText + ')'; + + var returns = 'none'; + if (tmp.returns !== undefined && tmp.returns.length > 0) { + let name = tmp.returns[0].type.names[0]; + if (name !== "undefined") { + returns = name; + } + } return { + name: tmp.name, prototype: prototype, returns: returns, description: tmp.description diff --git a/docs/tmpl/renderMethod.tmpl b/docs/tmpl/renderMethod.tmpl new file mode 100644 index 00000000..b218e7c1 --- /dev/null +++ b/docs/tmpl/renderMethod.tmpl @@ -0,0 +1,18 @@ + + + + + + + Returns: + + + + \ No newline at end of file diff --git a/lib/network/Network.js b/lib/network/Network.js index b45baf0a..f0f3a240 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -497,7 +497,16 @@ Network.prototype.cluster = function() {return this.clustering.clust Network.prototype.getNodesInCluster = function() {return this.clustering.getNodesInCluster.apply(this.clustering,arguments);}; Network.prototype.clusterByConnection = function() {return this.clustering.clusterByConnection.apply(this.clustering,arguments);}; Network.prototype.clusterByHubsize = function() {return this.clustering.clusterByHubsize.apply(this.clustering,arguments);}; + +/** + * This method will cluster all nodes with 1 edge with their respective connected node. + * The options object is explained in full below. + * + * @param {object} [options] + * @returns {undefined} + */ Network.prototype.clusterOutliers = function() {return this.clustering.clusterOutliers.apply(this.clustering,arguments);}; + Network.prototype.getSeed = function() {return this.layoutEngine.getSeed.apply(this.layoutEngine,arguments);}; Network.prototype.enableEditMode = function() {return this.manipulation.enableEditMode.apply(this.manipulation,arguments);}; Network.prototype.disableEditMode = function() {return this.manipulation.disableEditMode.apply(this.manipulation,arguments);}; diff --git a/lib/network/modules/components/shared/LabelSplitter.js b/lib/network/modules/components/shared/LabelSplitter.js index 75ad77b6..5ef0fc6d 100644 --- a/lib/network/modules/components/shared/LabelSplitter.js +++ b/lib/network/modules/components/shared/LabelSplitter.js @@ -243,8 +243,12 @@ class MarkupAccumulator { /** * Create a regular expression for the tag if it isn't already one. * + * The return value is an array `[RegExp, number]`, with exactly two value, where: + * - RegExp is the regular expression to use + * - number is the lenth of the input string to match + * * @param {string|RegExp} tag string to match in text - * @returns {[RegExp, number]} regular expression to use and length of input string to match + * @returns {Array} regular expression to use and length of input string to match * @private */ prepareRegExp(tag) { diff --git a/misc/RELEASE_CHECKLIST_TEMPLATE.md b/misc/RELEASE_CHECKLIST_TEMPLATE.md index 8369c1b6..b2c92e02 100644 --- a/misc/RELEASE_CHECKLIST_TEMPLATE.md +++ b/misc/RELEASE_CHECKLIST_TEMPLATE.md @@ -66,7 +66,8 @@ If we would merge the development branch would overwrite this. To solve this we ## Update website - [ ] update the gh-pages branch: `git checkout gh-pages && git pull && git checkout -b "gh-pages_vX.Y.Z"` - [ ] Copy the `dist` folder from the `master` branch to the `github-pages` branch in another directory, overwriting existing files: `cp -rf ../vis_vX.Y.Z/vis/dist .` -- [ ] Copy the `docs` folder from the `master` branch to the `github-pages` branch in another directory, overwriting existing files: `cp -rf ../vis_vX.Y.Z/vis/docs .` +- [ ] Generate the documentation: `gulp docs` +- [ ] Copy the `gen/docs` folder from the `master` branch to the `github-pages` branch in another directory, overwriting existing files: `cp -rf ../vis_vX.Y.Z/vis/gen/docs .` - [ ] Copy the `examples` folder from the `master` branch to the `github-pages` branch in another directory, overwriting existing files: `cp -rf ../vis_vX.Y.Z/vis/examples .` - [ ] Check if there are new or updated examples, and update the gallery screenshots accordingly. - [ ] Update the library version number in the `index.html` page. @@ -83,4 +84,4 @@ If we would merge the development branch would overwrite this. To solve this we - [ ] FORCE-Push the branches to github: `git push --force && git push --tag` - [ ] [Re-Enable branch protection](https://github.com/almende/vis/settings/branches/develop) (enable ALL checkboxes) for `develop`. -DONE! \ No newline at end of file +DONE!