2013-03-16 14:35:40 +08:00
Test . Modules . LABEL = {
2013-03-20 00:03:18 +08:00
'add label' : function ( containerId ) {
2013-03-16 14:35:40 +08:00
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
2013-03-25 11:42:27 +08:00
var label = new Kinetic . Label ( {
2013-03-18 08:20:06 +08:00
x : 100 ,
y : 100 ,
2013-03-16 14:35:40 +08:00
draggable : true ,
2013-03-18 08:20:06 +08:00
text : {
2013-03-18 13:01:52 +08:00
text : '' ,
2013-03-16 14:35:40 +08:00
fontSize : 50 ,
2013-03-18 12:16:08 +08:00
//fontFamily: 'Calibri',
//fontStyle: 'normal',
2013-03-16 14:35:40 +08:00
lineHeight : 1.2 ,
2013-03-18 12:16:08 +08:00
//padding: 10,
2013-03-18 08:20:06 +08:00
fill : 'green'
} ,
2013-05-19 13:30:57 +08:00
tag : {
2013-03-16 14:35:40 +08:00
fill : '#bbb' ,
stroke : '#333' ,
shadowColor : 'black' ,
2013-03-18 08:20:06 +08:00
shadowBlur : 10 ,
2013-03-16 14:35:40 +08:00
shadowOffset : [ 10 , 10 ] ,
shadowOpacity : 0.2 ,
2013-03-18 08:20:06 +08:00
lineJoin : 'round' ,
2013-03-18 13:01:52 +08:00
pointerDirection : 'up' ,
2013-03-18 08:20:06 +08:00
pointerWidth : 20 ,
pointerHeight : 20 ,
cornerRadius : 5
2013-03-16 14:35:40 +08:00
}
} ) ;
layer . add ( label ) ;
stage . add ( layer ) ;
var beforeTextWidth = label . getText ( ) . getWidth ( ) ;
label . getText ( ) . setFontSize ( 100 ) ;
var afterTextWidth = label . getText ( ) . getWidth ( ) ;
2013-03-18 13:01:52 +08:00
//test(afterTextWidth > beforeTextWidth, 'label text width should have grown');
2013-03-16 14:35:40 +08:00
label . getText ( ) . setFontSize ( 50 ) ;
2013-03-18 13:01:52 +08:00
label . getText ( ) . setText ( 'Hello big world' ) ;
2013-03-16 14:35:40 +08:00
layer . draw ( ) ;
2013-03-24 15:14:42 +08:00
2013-05-18 02:46:06 +08:00
test ( label . getType ( ) === 'Group' , 'label should be a group' ) ;
test ( label . getClassName ( ) === 'Label' , 'label class name should be Label' ) ;
2013-05-21 00:42:16 +08:00
var json = label . toJSON ( ) ;
console . log ( json ) ;
} ,
'create label from json' : function ( containerId ) {
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var json = '{"attrs":{"x":100,"y":100,"draggable":true,"text":{"width":"auto","height":"auto","text":"Hello big world","fontSize":50,"lineHeight":1.2,"fill":"green"},"tag":{"fill":"#bbb","stroke":"#333","shadowColor":"black","shadowBlur":10,"shadowOffsetX":10,"shadowOffsetY":10,"shadowOpacity":0.2,"lineJoin":"round","pointerDirection":"up","pointerWidth":20,"pointerHeight":20,"cornerRadius":5}},"className":"Label","nodeType":"Group"}' ;
var layer = new Kinetic . Layer ( ) ;
var label = Kinetic . Node . create ( json ) ;
layer . add ( label ) ;
stage . add ( layer ) ;
2013-03-16 14:35:40 +08:00
}
2013-05-21 00:42:16 +08:00
2013-03-16 14:35:40 +08:00
} ;