Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Jun 24, 2014
1 parent f2d0fe9 commit ac96799
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 81 deletions.
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,22 @@ Kity 是一个易用、直观、现代的矢量图形库。帮助你快速在页

<script type="text/javascript">
var paper = new kity.Paper('kity_paper');
var rect = paper.put(new kity.Rect());
var text = paper.put(new kity.Text());
var text = new kity.Text('Hello, kity!')
.fill('white');
text.setContent('hello kity!');
text.fill('white');
text.setX(100);
text.setY(200);
paper.addShape(text);
var box = text
.getBoundaryBox()
.expand(-15, -10, 15, 10);
var rect = new kity.Rect()
.setBox(box)
.setRadius(5)
.fill('blue');
paper.addShape(rect);
rect.setBox(text.getBoundaryBox().expand(-15, -10, 15, 10));
rect.setRadius(5);
rect.fill('blue');
</script>
```

![Hello Kity](doc/image/hello-kity.png)

更详细的使用方法请参考 [wiki](https://github.com/fex-team/kity/wiki)

## 贡献
Expand Down
35 changes: 12 additions & 23 deletions dist/kity.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ define("core/class", [], function(require, exports) {
return this;
};
Class.prototype.getType = function() {
return this.__KityClassName || this.constructor.name;
return this.__KityClassName;
};
Class.prototype.getClass = function() {
return this.constructor;
Expand All @@ -914,9 +914,9 @@ define("core/class", [], function(require, exports) {
}
var KITY_INHERIT_FLAG = "__KITY_INHERIT_FLAG_" + +new Date();
function inherit(constructor, BaseClass, classname) {
var KityClass = constructor;
var KityClass = eval("(function " + classname + "( __inherit__flag ) {" + "if( __inherit__flag != KITY_INHERIT_FLAG ) {" + "KityClass.__KityConstructor.apply(this, arguments);" + "}" + "this.__KityClassName = KityClass.__KityClassName;" + "})");
KityClass.__KityConstructor = constructor;
KityClass.prototype = Object.create(BaseClass.prototype);
KityClass.prototype = new BaseClass(KITY_INHERIT_FLAG);
for (var methodName in BaseClass.prototype) {
if (BaseClass.prototype.hasOwnProperty(methodName) && methodName.indexOf("__Kity") !== 0) {
KityClass.prototype[methodName] = BaseClass.prototype[methodName];
Expand Down Expand Up @@ -1668,7 +1668,7 @@ define("graphic/box", [ "core/class" ], function(require, exports, module) {
return new Box(xMin, yMin, xMax - xMin, yMax - yMin);
},
expand: function(ex, ey, ew, eh) {
return new Box(this.x + ex, this.y + ey, this.width + ew, this.height + eh);
return new Box(this.x + ex, this.y + ey, this.width - ex + ew, this.height - ey + eh);
},
valueOf: function() {
return [ this.x, this.y, this.width, this.height ];
Expand Down Expand Up @@ -4294,6 +4294,9 @@ define("graphic/paper", [ "core/class", "core/utils", "graphic/svg", "graphic/co
}
return parent;
},
isAttached: function() {
return !!this.getPaper();
},
whenPaperReady: function(fn) {
var me = this;
function check() {
Expand Down Expand Up @@ -4750,7 +4753,7 @@ define("graphic/radialgradientbrush", [ "graphic/gradientbrush", "graphic/svg",
}
});
});
define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/box", "graphic/path", "graphic/shape", "graphic/svg", "graphic/geometry", "graphic/shapecontainer", "graphic/container" ], function(require, exports, module) {
define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/box", "graphic/path", "graphic/shape", "graphic/svg", "graphic/geometry" ], function(require, exports, module) {
var RectUtils = {}, Utils = require("core/utils"), Point = require("graphic/point"), Box = require("graphic/box");
Utils.extend(RectUtils, {
//根据传递进来的width、height和radius属性,
Expand Down Expand Up @@ -4863,8 +4866,6 @@ define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/b
return this.update();
}
});
var ShapeContainer = require("graphic/shapecontainer");
ShapeContainer.creators.rect = Rect;
return Rect;
});
define("graphic/regularpolygon", [ "graphic/point", "core/class", "graphic/path", "core/utils", "graphic/shape", "graphic/svg", "graphic/geometry" ], function(require, exports, module) {
Expand Down Expand Up @@ -5159,24 +5160,9 @@ define("graphic/shape", [ "graphic/svg", "core/utils", "graphic/eventhandler", "
define("graphic/shapecontainer", [ "graphic/container", "core/class", "core/utils", "graphic/shape", "graphic/svg", "graphic/eventhandler", "graphic/styled", "graphic/data", "graphic/matrix", "graphic/pen", "graphic/box" ], function(require, exports, module) {
var Container = require("graphic/container");
var utils = require("core/utils");
function construct(constructor, args) {
var obj = Object.create(constructor.prototype);
constructor.apply(obj, args);
return obj;
}
var ShapeContainer = require("core/class").createClass("ShapeContainer", {
base: Container,
isShapeContainer: true,
create: function(name) {
var CreatorClass = ShapeContainer.creators[name];
if (CreatorClass) {
var args = Array.prototype.slice.call(arguments, 1);
var shape = construct(CreatorClass, args);
this.addShape(shape);
return shape;
}
return null;
},
/* private */
handleAdd: function(shape, index) {
var parent = this.getShapeNode();
Expand Down Expand Up @@ -5218,6 +5204,10 @@ define("graphic/shapecontainer", [ "graphic/container", "core/class", "core/util
addShape: function(shape, index) {
return this.addItem(shape, index);
},
put: function(shape) {
this.addShape(shape);
return shape;
},
appendShape: function(shape) {
return this.addShape(shape);
},
Expand Down Expand Up @@ -5321,7 +5311,6 @@ define("graphic/shapecontainer", [ "graphic/container", "core/class", "core/util
return this;
}
});
ShapeContainer.creators = {};
return ShapeContainer;
});
/*
Expand Down
8 changes: 4 additions & 4 deletions dist/kity.min.js

Large diffs are not rendered by default.

Binary file added doc/images/hello-kity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 9 additions & 15 deletions example/first.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
<script type="text/javascript">
var paper = new kity.Paper('kity_paper');

var text = new kity.Text('Hello, kity!')
.fill('white')
.setX(100)
.setY(200);
var rect = paper.put(new kity.Rect());
var text = paper.put(new kity.Text());

paper.addShape(text);
text.setContent('hello kity!');
text.fill('white');
text.setX(100);
text.setY(200);

var box = text
.getBoundaryBox()
.expand(-15, -10, 15, 10);

var rect = new kity.Rect()
.setBox(box)
.setRadius(5)
.fill('blue');

paper.addShape(rect);
rect.setBox(text.getBoundaryBox().expand(-15, -10, 15, 10));
rect.setRadius(5);
rect.fill('blue');
</script>
</html>
2 changes: 1 addition & 1 deletion src/graphic/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define(function(require, exports, module) {
},

expand: function(ex, ey, ew, eh) {
return new Box(this.x + ex, this.y + ey, this.width + ew, this.height + eh);
return new Box(this.x + ex, this.y + ey, this.width - ex + ew, this.height - ey + eh);
},

valueOf: function() {
Expand Down
3 changes: 3 additions & 0 deletions src/graphic/paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ define(function(require, exports, module) {
}
return parent;
},
isAttached: function() {
return !!this.getPaper();
},
whenPaperReady: function(fn) {
var me = this;

Expand Down
4 changes: 0 additions & 4 deletions src/graphic/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ define(function(require, exports, module) {

});

var ShapeContainer = require('graphic/shapecontainer');

ShapeContainer.creators.rect = Rect;

return Rect;

});
25 changes: 5 additions & 20 deletions src/graphic/shapecontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@ define(function(require, exports, module) {
var Container = require('graphic/container');
var utils = require('core/utils');

function construct(constructor, args) {
var obj = Object.create(constructor.prototype);
constructor.apply(obj, args);
return obj;
}

var ShapeContainer = require('core/class').createClass('ShapeContainer', {
base: Container,

isShapeContainer: true,

create: function(name) {

var CreatorClass = ShapeContainer.creators[name];
if (CreatorClass) {
var args = Array.prototype.slice.call(arguments, 1);
var shape = construct(CreatorClass, args);
this.addShape(shape);
return shape;
}
return null;
},

/* private */
handleAdd: function(shape, index) {
var parent = this.getShapeNode();
Expand Down Expand Up @@ -71,6 +53,11 @@ define(function(require, exports, module) {
return this.addItem(shape, index);
},

put: function(shape) {
this.addShape(shape);
return shape;
},

appendShape: function(shape) {
return this.addShape(shape);
},
Expand Down Expand Up @@ -189,8 +176,6 @@ define(function(require, exports, module) {
}
});

ShapeContainer.creators = {};

return ShapeContainer;

});

0 comments on commit ac96799

Please sign in to comment.