parent
9a8fe88628
commit
dda0d1435d
|
@ -181,74 +181,53 @@ describe('Vislib Color Module Test Suite', function () {
|
|||
});
|
||||
|
||||
describe('Color Palette', function () {
|
||||
var num1 = 45;
|
||||
var num2 = 72;
|
||||
var num3 = 90;
|
||||
var string = 'Welcome';
|
||||
var bool = true;
|
||||
var nullValue = null;
|
||||
var emptyArr = [];
|
||||
var emptyObject = {};
|
||||
var notAValue;
|
||||
var createColorPalette;
|
||||
var colorPalette;
|
||||
var colorCount = 42;
|
||||
var colors;
|
||||
var colorFn;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
seedColors = Private(require('ui/vislib/components/color/seed_colors'));
|
||||
createColorPalette = Private(require('ui/vislib/components/color/color_palette'));
|
||||
colorPalette = createColorPalette(num1);
|
||||
colorFn = Private(require('ui/vislib/components/color/color_palette'));
|
||||
colors = colorFn(colorCount);
|
||||
}));
|
||||
|
||||
it('should throw an error if input is not a number', function () {
|
||||
expect(function () {
|
||||
createColorPalette(string);
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
createColorPalette(bool);
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
createColorPalette(nullValue);
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
createColorPalette(emptyArr);
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
createColorPalette(emptyObject);
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
createColorPalette(notAValue);
|
||||
}).to.throwError();
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof createColorPalette).to.be('function');
|
||||
expect(colorFn).to.be.a(Function);
|
||||
});
|
||||
|
||||
it('should return an array', function () {
|
||||
expect(colorPalette instanceof Array).to.be(true);
|
||||
expect(colors).to.be.a(Array);
|
||||
});
|
||||
|
||||
it('should return an array of the same length as the input', function () {
|
||||
expect(colorPalette.length).to.be(num1);
|
||||
expect(colors.length).to.be(colorCount);
|
||||
});
|
||||
|
||||
it('should return the seed color array when input length is 72', function () {
|
||||
expect(createColorPalette(num2)[71]).to.be(seedColors[71]);
|
||||
it('should use the seed colors first', function () {
|
||||
_.each(seedColors, function (color, i) {
|
||||
expect(color).to.equal(colors[i]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of the same length as the input when input is greater than 72', function () {
|
||||
expect(createColorPalette(num3).length).to.be(num3);
|
||||
it('should then generate a darker version of the seed', function () {
|
||||
var parsedSeed = d3.hsl(seedColors[0]);
|
||||
var parsedResult = d3.hsl(colors[seedColors.length]);
|
||||
expect(parsedResult.l).to.be.lessThan(parsedSeed.l);
|
||||
});
|
||||
|
||||
it('should create new darker colors when input is greater than 72', function () {
|
||||
expect(createColorPalette(num3)[72]).not.to.equal(seedColors[0]);
|
||||
it('followed by a lighter version', function () {
|
||||
var parsedSeed = d3.hsl(seedColors[0]);
|
||||
var parsedResult = d3.hsl(colors[seedColors.length * 2]);
|
||||
expect(parsedResult.l).to.be.greaterThan(parsedSeed.l);
|
||||
});
|
||||
|
||||
it('and then a darker version again', function () {
|
||||
var parsedSeed = d3.hsl(seedColors[0]);
|
||||
var parsedResult = d3.hsl(colors[seedColors.length * 3]);
|
||||
expect(parsedResult.l).to.be.lessThan(parsedSeed.l);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -59,7 +59,7 @@ define(function (require) {
|
|||
} else variation = -variation;
|
||||
}
|
||||
|
||||
colors[i] = scale(color, 'rgb', 1 + variation);
|
||||
colors[i] = scale(color, 'rgb', 1 + variation).toString();
|
||||
}
|
||||
return colors;
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ define(function () {
|
|||
|
||||
return function SeedColorUtilService() {
|
||||
return [
|
||||
'#7EB26D',
|
||||
'#EAB839',
|
||||
'#6ED0E0',
|
||||
'#EF843C',
|
||||
'#E24D42',
|
||||
'#1F78C1',
|
||||
'#BA43A9',
|
||||
'#705DA0'
|
||||
'#7eb26d',
|
||||
'#eab839',
|
||||
'#6ed0e0',
|
||||
'#ef843c',
|
||||
'#e24d42',
|
||||
'#1f78c1',
|
||||
'#ba43a9',
|
||||
'#705da0'
|
||||
];
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue