Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

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

Merged
merged 3 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "6"
- "7"
env:
- CXX=g++-4.8
Expand Down
5 changes: 4 additions & 1 deletion lib/timeline/component/DataAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions test/DataAxis.test.js
Original file line number Diff line number Diff line change
@@ -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)));
});
});
});
2 changes: 1 addition & 1 deletion test/Label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions test/canvas-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -132,6 +155,8 @@ function mockify(html = '') {

overrideCreateElement(window); // The actual initialization of canvas-mock

overrideCreateElementNS(window);

return cleanupFunction;
}

Expand Down