fix: category mapper different length of domain and value

This commit is contained in:
Yanyan-Wang 2018-08-15 15:52:58 +08:00
parent f59275d720
commit ea6cf127d9
3 changed files with 41 additions and 44 deletions

View File

@ -99,7 +99,7 @@
"screenshot": "node ./bin/screenshot.js",
"start": "npm run dev",
"test": "torch --compile --renderer --recursive ./test/unit",
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/plugins/",
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/plugins/tool.mapper-spec.js",
"watch": "webpack --config webpack-dev.config.js",
"win-dev": "node ./bin/win-dev.js"
},

View File

@ -146,11 +146,7 @@ class Plugin {
domain = this._trainNumberScale(itemType, data);
}
}
const rangeLength = range.length;
const domainLength = domain.length;
if (rangeLength !== domainLength && scaleType === 'Category') {
throw new Error('please set the same length of range to the domain!');
}
if (domainLength === 2 && domain[0] === domain[1]) {
if (domain[0] > 0) {
domain[0] = 0;

View File

@ -72,48 +72,49 @@ describe('node size mapper test', () => {
});
describe('node color mapper domain length test', () => {
const fn = function() {
const nodeSizeMapper = new Mapper('node', 'class', 'color', [ '#ff0000', '#00ff00' ], {
legendCfg: {
layout: 'vertical'
}
});
const data = {
nodes: [{
id: 'node1',
x: 100,
y: 200,
class: 'class1'
}, {
id: 'node2',
x: 300,
y: 200,
class: 'class2'
}, {
id: 'node3',
x: 400,
y: 200,
class: 'class3'
}],
edges: [{
target: 'node2',
source: 'node1'
}]
};
const div = document.createElement('div');
document.body.appendChild(div);
const graph = new G6.Graph({
container: div,
width: 500,
height: 500,
plugins: [ nodeSizeMapper ]
});
graph.read(data);
graph.destroy();
const nodeSizeMapper = new Mapper('node', 'class', 'color', [ '#ff0000', '#00ff00' ], {
legendCfg: {
layout: 'vertical'
}
});
const data = {
nodes: [{
id: 'node1',
x: 100,
y: 200,
class: 'class1'
}, {
id: 'node2',
x: 300,
y: 200,
class: 'class2'
}, {
id: 'node3',
x: 400,
y: 200,
class: 'class3'
}],
edges: [{
target: 'node2',
source: 'node1'
}]
};
const div = document.createElement('div');
document.body.appendChild(div);
const graph = new G6.Graph({
container: div,
width: 500,
height: 500,
plugins: [ nodeSizeMapper ]
});
graph.read(data);
it('legend render', () => {
expect(fn).to.Throw();
expect(graph.find('node3').getModel().color).eql('#ff0000');
});
it('legend destroy', () => {
graph.destroy();
expect(div.innerHTML).eql('');
});
});