Browse Source

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

mbroad/issue-3321
MacLeod Broad 7 years ago
parent
commit
a46d8426ab
No known key found for this signature in database GPG Key ID: F1B295D13C3CC9CF
4 changed files with 76 additions and 2 deletions
  1. +4
    -1
      lib/timeline/component/DataAxis.js
  2. +46
    -0
      test/DataAxis.test.js
  3. +1
    -1
      test/Label.test.js
  4. +25
    -0
      test/canvas-mock.js

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

@ -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 = '';

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

@ -0,0 +1,46 @@
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("<div id='mygraph'></div><svg id='svg'></svg>");
this.container = document.getElementById('mygraph');
this.svg = this.container = document.getElementById('svg');
this.body = {
functions: {},
emitter: {
on: function() {}
}
};
});
afterEach(function() {
this.jsdom_global();
this.container.remove();
this.container = undefined;
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: {
on: function() {}
}
}
};
var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() );
//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.
@ -132,6 +155,8 @@ function mockify(html = '') {
overrideCreateElement(window); // The actual initialization of canvas-mock
overrideCreateElementNS(window);
return cleanupFunction;
}

Loading…
Cancel
Save