From ea6cf127d9e1f284aff039b850d88b6935e5bc80 Mon Sep 17 00:00:00 2001 From: Yanyan-Wang Date: Wed, 15 Aug 2018 15:52:58 +0800 Subject: [PATCH] fix: category mapper different length of domain and value --- package.json | 2 +- plugins/tool.mapper/index.js | 4 -- test/unit/plugins/tool.mapper-spec.js | 79 ++++++++++++++------------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index da0bc45294..51bf655af9 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/plugins/tool.mapper/index.js b/plugins/tool.mapper/index.js index 831d6e2468..e0529b542c 100644 --- a/plugins/tool.mapper/index.js +++ b/plugins/tool.mapper/index.js @@ -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; diff --git a/test/unit/plugins/tool.mapper-spec.js b/test/unit/plugins/tool.mapper-spec.js index 8648bba5ba..e101555d25 100644 --- a/test/unit/plugins/tool.mapper-spec.js +++ b/test/unit/plugins/tool.mapper-spec.js @@ -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(''); }); });