Skip to content

Commit

Permalink
Fix #251
Browse files Browse the repository at this point in the history
  • Loading branch information
vladminsky committed Oct 4, 2016
1 parent cf3b59e commit 6253705
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 6 additions & 7 deletions plugins/legend.js
Expand Up @@ -504,13 +504,9 @@
});
},

_generateColorMap: function (domain) {
_generateColorMap: function (domain, defBrewer) {

var limit = 20;

var defBrewer = utils.range(limit).map(function (i) {
return 'color20-' + (1 + i);
});
var limit = defBrewer.length; // 20;

return domain.reduce(function (memo, val, i) {
memo[val] = defBrewer[i % limit];
Expand Down Expand Up @@ -538,7 +534,10 @@
.domain();

if (!scaleConfig.brewer || Array.isArray(scaleConfig.brewer)) {
scaleConfig.brewer = self._generateColorMap(fullLegendDomain);
var defBrewer = scaleConfig.brewer || utils.range(20).map(function (i) {
return 'color20-' + (1 + i);
});
scaleConfig.brewer = self._generateColorMap(fullLegendDomain, defBrewer);
}

self._legendOrderState[c] = fullLegendDomain.reduce(function (memo, x, i) {
Expand Down
10 changes: 10 additions & 0 deletions test/legend-plugin.test.js
Expand Up @@ -283,6 +283,11 @@ define(function (require) {
y: 'y',
color: 'color',
plugins: [legend()],
guide: {
color: {
brewer: ['#ff0000', '#00ff00', '#0000ff', '#000000']
}
},

dimensions: {
x: {type: 'measure'},
Expand Down Expand Up @@ -328,6 +333,11 @@ define(function (require) {
expect(getText(nodeList[1])).to.equal('B');
expect(getText(nodeList[2])).to.equal('No color');
expect(getText(nodeList[3])).to.equal('C');

expect(d3.rgb(nodeList[0].style.backgroundColor).toString()).to.equal(d3.rgb('#ff0000').toString());
expect(d3.rgb(nodeList[1].style.backgroundColor).toString()).to.equal(d3.rgb('#00ff00').toString());
expect(d3.rgb(nodeList[2].style.backgroundColor).toString()).to.equal(d3.rgb('#0000ff').toString());
expect(d3.rgb(nodeList[3].style.backgroundColor).toString()).to.equal(d3.rgb('#000000').toString());
});
},
{
Expand Down

0 comments on commit 6253705

Please sign in to comment.