diff --git a/.travis.yml b/.travis.yml index 5c82cf0c..d6952fc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - "6" - "7" env: - CXX=g++-4.8 diff --git a/lib/timeline/component/DataAxis.js b/lib/timeline/component/DataAxis.js index d1dd69f1..8ad33eb2 100644 --- a/lib/timeline/component/DataAxis.js +++ b/lib/timeline/component/DataAxis.js @@ -82,6 +82,9 @@ function DataAxis(body, options, svg, linegraphOptions) { // create the HTML DOM this._create(); + if (this.scale == undefined) { + this._redrawLabels(); + } this.framework = {svg: this.svg, svgElements: this.svgElements, options: this.options, groups: this.groups}; var me = this; @@ -493,7 +496,7 @@ DataAxis.prototype._redrawLabel = function (y, text, orientation, className, cha */ DataAxis.prototype._redrawLine = function (y, orientation, className, offset, width) { if (this.master === true) { - var line = DOMutil.getDOMElement('div', this.DOMelements.lines, this.dom.lineContainer);//this.dom.redundant.lines.shift(); + var line = DOMutil.getDOMElement('div', this.DOMelements.lines, this.dom.lineContainer); //this.dom.redundant.lines.shift(); line.className = className; line.innerHTML = ''; diff --git a/package.json b/package.json index b92d607e..d1d991ab 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "main": "./dist/vis.js", "scripts": { - "test": "nyc mocha --compilers js:babel-core/register", + "test": "mocha --compilers js:babel-core/register", "test-cov": "nyc --reporter=lcov mocha --compilers js:babel-core/register", "build": "gulp", "lint": "gulp lint", diff --git a/test/DataAxis.test.js b/test/DataAxis.test.js new file mode 100644 index 00000000..84af62b3 --- /dev/null +++ b/test/DataAxis.test.js @@ -0,0 +1,43 @@ +var assert = require('assert'); +var jsdom_global = require('jsdom-global'); +var canvasMockify = require('./canvas-mock'); + +var DataAxis = require('../lib/timeline/component/DataAxis'); + +describe('DataAxis', function () { + beforeEach(function() { + this.jsdom_global = canvasMockify(""); + this.svg = this.container = document.getElementById('svg'); + this.body = { + functions: {}, + emitter: { + on: function() {} + } + }; + }); + + afterEach(function() { + this.jsdom_global(); + this.svg.remove(); + this.svg = undefined; + }); + + it('should work', function () { + var dataAxis = new DataAxis(this.body, {}, this.svg, {}); + + }); + + describe('screenToValue', function () { + it('can called be without an explicit redraw', function () { + var dataAxis = new DataAxis(this.body, {}, this.svg, {}); + assert(isNaN(dataAxis.screenToValue(77))); + }); + }); + + describe('convertValue', function () { + it('can called be without an explicit redraw', function () { + var dataAxis = new DataAxis(this.body, {}, this.svg, {}); + assert(isNaN(dataAxis.convertValue(77))); + }); + }); +}); diff --git a/test/Label.test.js b/test/Label.test.js index 73794edb..e0c3e064 100644 --- a/test/Label.test.js +++ b/test/Label.test.js @@ -54,7 +54,7 @@ describe('Network Label', function() { emitter: { on: function() {} } - } + }; var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() ); //console.log(JSON.stringify(nodesHandler.options, null, 2)); diff --git a/test/canvas-mock.js b/test/canvas-mock.js index 9ea5c535..5136568e 100644 --- a/test/canvas-mock.js +++ b/test/canvas-mock.js @@ -92,6 +92,29 @@ function overrideCreateElement(window) { }; } +/** + * 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 'style' + * property on a newly created svg element. + * + * @param {object} window - current global window object. This can possibly come from module 'jsdom', + * when running under node.js. + * @private + */ +function overrideCreateElementNS(window) { + var d = window.document; + var 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); + if (result.style == undefined) { + result.style = {}; + return result; + } + } + }; +} /** * Initialize the mock, jsdom and jsdom_global for unit test usage. @@ -132,6 +155,8 @@ function mockify(html = '') { overrideCreateElement(window); // The actual initialization of canvas-mock + overrideCreateElementNS(window); + return cleanupFunction; }