mirror of
https://github.com/konvajs/konva.git
synced 2026-01-24 13:57:25 +08:00
added new get*RGB(), get*R(), get*G(), and get*B() methods for fill, stroke, and shadowColor. Also added new Kinetic.Type.getRGB() utility
This commit is contained in:
@@ -27,6 +27,62 @@ Test.Modules.SHAPE = {
|
||||
testDataUrl(layer.toDataURL(), 'scaled rect with disabled stroke scale', 'probem with stroke scale disabling');
|
||||
},
|
||||
|
||||
'shape color components': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
var rect = new Kinetic.Rect({
|
||||
x: 200,
|
||||
y: 90,
|
||||
width: 100,
|
||||
height: 50,
|
||||
fill: 'green',
|
||||
stroke: 'red'
|
||||
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
|
||||
// test component getters
|
||||
test(rect.getFillRGB().r === 0, 'rect fill RGB.r should be 0');
|
||||
test(rect.getFillRGB().g === 128, 'rect fill RGB.g should be 128');
|
||||
test(rect.getFillRGB().b === 0, 'rect fill RGB.b should be 0');
|
||||
|
||||
test(rect.getFillR() === 0, 'rect fill r should be 0');
|
||||
test(rect.getFillG() === 128, 'rect fill g should be 128');
|
||||
test(rect.getFillB() === 0, 'rect fill b should be 0');
|
||||
|
||||
test(rect.getStrokeR() === 255, 'rect stroke r should be 255');
|
||||
test(rect.getStrokeG() === 0, 'rect stroke g should be 0');
|
||||
test(rect.getStrokeB() === 0, 'rect stroke b should be 0');
|
||||
|
||||
rect.setFill('#008000');
|
||||
rect.setStroke('#ff0000');
|
||||
|
||||
test(rect.getFillR() === 0, 'rect fill r should be 0');
|
||||
test(rect.getFillG() === 128, 'rect fill g should be 128');
|
||||
test(rect.getFillB() === 0, 'rect fill b should be 0');
|
||||
|
||||
test(rect.getStrokeR() === 255, 'rect stroke r should be 255');
|
||||
test(rect.getStrokeG() === 0, 'rect stroke g should be 0');
|
||||
test(rect.getStrokeB() === 0, 'rect stroke b should be 0');
|
||||
|
||||
rect.setFill('rgb(0,128,0)');
|
||||
rect.setStroke('rgb(255, 0, 0)');
|
||||
|
||||
test(rect.getFillR() === 0, 'rect fill r should be 0');
|
||||
test(rect.getFillG() === 128, 'rect fill g should be 128');
|
||||
test(rect.getFillB() === 0, 'rect fill b should be 0');
|
||||
|
||||
test(rect.getStrokeR() === 255, 'rect stroke r should be 255');
|
||||
test(rect.getStrokeG() === 0, 'rect stroke g should be 0');
|
||||
test(rect.getStrokeB() === 0, 'rect stroke b should be 0');
|
||||
},
|
||||
|
||||
'test intersects()': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
|
||||
34
tests/js/unit/typeTests.js
Normal file
34
tests/js/unit/typeTests.js
Normal file
@@ -0,0 +1,34 @@
|
||||
Test.Modules.TYPE = {
|
||||
'getRGB()': function() {
|
||||
var rgb = {};
|
||||
|
||||
// color strings
|
||||
rgb = Kinetic.Type.getRGB('red');
|
||||
test(rgb.r === 255, 'color string r should be 255');
|
||||
test(rgb.g === 0, 'color string g should be 0');
|
||||
test(rgb.b === 0, 'color string b should be 0');
|
||||
|
||||
rgb = Kinetic.Type.getRGB('pink');
|
||||
test(rgb.r === 255, 'color string r should be 255');
|
||||
test(rgb.g === 192, 'color string g should be 192');
|
||||
test(rgb.b === 203, 'color string b should be 203');
|
||||
|
||||
// hex
|
||||
rgb = Kinetic.Type.getRGB('#00ff00');
|
||||
test(rgb.r === 0, 'hex r should be 0');
|
||||
test(rgb.g === 255, 'hex g should be 255');
|
||||
test(rgb.b === 0, 'hex b should be 0');
|
||||
|
||||
// rgb color string
|
||||
rgb = Kinetic.Type.getRGB('rgb(255, 192, 203)');
|
||||
test(rgb.r === 255, 'rgb string r should be 255');
|
||||
test(rgb.g === 192, 'rgb string g should be 192');
|
||||
test(rgb.b === 203, 'rgb string b should be 203');
|
||||
|
||||
// default
|
||||
rgb = Kinetic.Type.getRGB('not a color');
|
||||
test(rgb.r === 0, 'default r should be 0');
|
||||
test(rgb.g === 0, 'default g should be 0');
|
||||
test(rgb.b === 0, 'default b should be 0');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user