Browse Source

Fixes issue 3321 by ensuring labels are drawn as part of initial cons… (#3646)

* Fixes issue 3321 by ensuring labels are drawn as part of initial construction of the DataAxis

* Simplify test and remove support for node 6

* Exclude test coverage from regular test runs
develop
macleodbroad-wf 7 years ago
committed by Yotam Berkowitz
parent
commit
da387f3107
6 changed files with 74 additions and 4 deletions
  1. +0
    -1
      .travis.yml
  2. +4
    -1
      lib/timeline/component/DataAxis.js
  3. +1
    -1
      package.json
  4. +43
    -0
      test/DataAxis.test.js
  5. +1
    -1
      test/Label.test.js
  6. +25
    -0
      test/canvas-mock.js

+ 0
- 1
.travis.yml View File

@ -1,6 +1,5 @@
language: node_js language: node_js
node_js: node_js:
- "6"
- "7" - "7"
env: env:
- CXX=g++-4.8 - CXX=g++-4.8

+ 4
- 1
lib/timeline/component/DataAxis.js View File

@ -82,6 +82,9 @@ function DataAxis(body, options, svg, linegraphOptions) {
// create the HTML DOM // create the HTML DOM
this._create(); this._create();
if (this.scale == undefined) {
this._redrawLabels();
}
this.framework = {svg: this.svg, svgElements: this.svgElements, options: this.options, groups: this.groups}; this.framework = {svg: this.svg, svgElements: this.svgElements, options: this.options, groups: this.groups};
var me = this; 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) { DataAxis.prototype._redrawLine = function (y, orientation, className, offset, width) {
if (this.master === true) { 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.className = className;
line.innerHTML = ''; line.innerHTML = '';

+ 1
- 1
package.json View File

@ -26,7 +26,7 @@
], ],
"main": "./dist/vis.js", "main": "./dist/vis.js",
"scripts": { "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", "test-cov": "nyc --reporter=lcov mocha --compilers js:babel-core/register",
"build": "gulp", "build": "gulp",
"lint": "gulp lint", "lint": "gulp lint",

+ 43
- 0
test/DataAxis.test.js View File

@ -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("<svg id='svg'></svg>");
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)));
});
});
});

+ 1
- 1
test/Label.test.js View File

@ -54,7 +54,7 @@ describe('Network Label', function() {
emitter: { emitter: {
on: function() {} on: function() {}
} }
}
};
var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() ); var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() );
//console.log(JSON.stringify(nodesHandler.options, null, 2)); //console.log(JSON.stringify(nodesHandler.options, null, 2));

+ 25
- 0
test/canvas-mock.js View File

@ -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. * 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 overrideCreateElement(window); // The actual initialization of canvas-mock
overrideCreateElementNS(window);
return cleanupFunction; return cleanupFunction;
} }

Loading…
Cancel
Save