Dimensions.
This commit is contained in:
parent
c21a763dc7
commit
0f65b869fd
@ -68,42 +68,42 @@ tree.functions = {
|
||||
saturate: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.s += amount.value / 100;
|
||||
hsl.s += amount.value;
|
||||
hsl.s = clamp(hsl.s);
|
||||
return hsla(hsl);
|
||||
},
|
||||
desaturate: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.s -= amount.value / 100;
|
||||
hsl.s -= amount.value;
|
||||
hsl.s = clamp(hsl.s);
|
||||
return hsla(hsl);
|
||||
},
|
||||
lighten: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.l += amount.value / 100;
|
||||
hsl.l += amount.value;
|
||||
hsl.l = clamp(hsl.l);
|
||||
return hsla(hsl);
|
||||
},
|
||||
darken: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.l -= amount.value / 100;
|
||||
hsl.l -= amount.value;
|
||||
hsl.l = clamp(hsl.l);
|
||||
return hsla(hsl);
|
||||
},
|
||||
fadein: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.a += amount.value / 100;
|
||||
hsl.a += amount.value;
|
||||
hsl.a = clamp(hsl.a);
|
||||
return hsla(hsl);
|
||||
},
|
||||
fadeout: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.a -= amount.value / 100;
|
||||
hsl.a -= amount.value;
|
||||
hsl.a = clamp(hsl.a);
|
||||
return hsla(hsl);
|
||||
},
|
||||
@ -127,7 +127,7 @@ tree.functions = {
|
||||
// http://sass-lang.com
|
||||
//
|
||||
mix: function (color1, color2, weight) {
|
||||
var p = weight.value / 100.0;
|
||||
var p = weight.value;
|
||||
var w = p * 2 - 1;
|
||||
var a = color1.toHSL().a - color2.toHSL().a;
|
||||
|
||||
|
@ -45,6 +45,11 @@ tree.Dimension.prototype = {
|
||||
this.unit = 'px';
|
||||
}
|
||||
|
||||
if (this.unit == '%') {
|
||||
this.value /= 100;
|
||||
this.unit = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
toColor: function() {
|
||||
|
12
test/dimension.text.js
Normal file
12
test/dimension.text.js
Normal file
@ -0,0 +1,12 @@
|
||||
var assert = require('assert');
|
||||
var tree = require('../lib/carto/tree.js');
|
||||
require('../lib/carto/tree/dimension');
|
||||
|
||||
describe('Dimension', function() {
|
||||
it('should support percentages', function() {
|
||||
assert.equal((new tree.Dimension(2, '%')).ev({}).value, 0.02);
|
||||
assert.equal((new tree.Dimension(20, '%')).ev({}).value, 0.20);
|
||||
assert.equal((new tree.Dimension(100, '%')).ev({}).value, 1);
|
||||
assert.equal((new tree.Dimension(0, '%')).ev({}).value, 0);
|
||||
});
|
||||
});
|
@ -12,7 +12,7 @@ describe('Operation', function() {
|
||||
var env = { ppi:72, error:function(err) { console.log(err.message); } };
|
||||
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(2), new tree.Dimension(10, "%") ]);
|
||||
assert.equal(o.ev(env).value, 2.2);
|
||||
assert.equal(o.ev(env).value, 2.1);
|
||||
});
|
||||
|
||||
it('should work with units', function() {
|
||||
@ -21,10 +21,10 @@ describe('Operation', function() {
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(2.54, 'cm'), new tree.Dimension(0.0254, 'm') ]);
|
||||
assert.equal(o.ev(env).value, 144);
|
||||
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(25.4, 'mm'), new tree.Dimension(72, 'pt') ]);
|
||||
o = new tree.Operation("+", [ new tree.Dimension(25.4, 'mm'), new tree.Dimension(72, 'pt') ]);
|
||||
assert.equal(o.ev(env).value, 144);
|
||||
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(72, 'pt'), new tree.Dimension(6, 'pc') ]);
|
||||
o = new tree.Operation("+", [ new tree.Dimension(72, 'pt'), new tree.Dimension(6, 'pc') ]);
|
||||
assert.equal(o.ev(env).value, 144);
|
||||
});
|
||||
|
||||
@ -34,12 +34,10 @@ describe('Operation', function() {
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(2.54, 'cm'), new tree.Dimension(0.0254, 'm') ]);
|
||||
assert.equal(o.ev(env).value, 600);
|
||||
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(25.4, 'mm'), new tree.Dimension(72, 'pt') ]);
|
||||
o = new tree.Operation("+", [ new tree.Dimension(25.4, 'mm'), new tree.Dimension(72, 'pt') ]);
|
||||
assert.equal(o.ev(env).value, 600);
|
||||
|
||||
var o = new tree.Operation("+", [ new tree.Dimension(72, 'pt'), new tree.Dimension(6, 'pc') ]);
|
||||
o = new tree.Operation("+", [ new tree.Dimension(72, 'pt'), new tree.Dimension(6, 'pc') ]);
|
||||
assert.equal(o.ev(env).value, 600);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user