new require("zrender/shape/tool/PathProxy")()
shape/util/PathProxy.js, line 54
Path 代理,可以在buildPath
中用于替代ctx
, 会保存每个path操作的命令到pathCommands属性中
可以用于 isInsidePath 判断以及获取boundingRect
Example
var SomeShape = function() {
this._pathProxy = new PathProxy();
...
}
SomeShape.prototype.buildPath = function(ctx, style) {
this._pathProxy.begin(ctx);
.moveTo(style.x, style.y);
.lineTo(style.x1, style.y1);
...
.closePath();
},
SomeShape.prototype.getRect = function(style) {
if (!style._rect) {
// 这里必须要在 buildPath 之后才能调用
style._rect = this._pathProxy.fastBoundingRect();
}
return this.style._rect;
},
SomeShape.prototype.isCover = function(x, y) {
var rect = this.getRect(this.style);
if (x >= rect.x
&& x <= (rect.x + rect.width)
&& y >= rect.y
&& y <= (rect.y + rect.height)
) {
return area.isInsidePath(
this._pathProxy.pathCommands, 0, 'fill', x, y
);
}
}
Members
-
pathCommandsArray.<Object>
-
Path描述的数组,用于
isInsidePath
的判断
Methods
-
arc(cx, cy, r, startAngle, endAngle, anticlockwise){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 205 -
Name Type Description cx
number cy
number r
number startAngle
number endAngle
number anticlockwise
boolean -
begin(ctx){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 130 -
Name Type Description ctx
CanvasRenderingContext2D -
bezierCurveTo(x1, y1, x2, y2, x3, y3){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 173 -
Name Type Description x1
number y1
number x2
number y2
number x3
number y3
number -
closePath(){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 234 -
-
fastBoundingRect(){Object}
shape/util/PathProxy.js, line 72 -
快速计算Path包围盒(并不是最小包围盒)
-
isEmpty(){boolean}
shape/util/PathProxy.js, line 246 -
是否没有Path命令
-
lineTo(x, y){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 156 -
Name Type Description x
number y
number -
moveTo(x, y){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 143 -
Name Type Description x
number y
number -
quadraticCurveTo(x1, y1, x2, y2){module:zrender/shape/util/PathProxy}
shape/util/PathProxy.js, line 188 -
Name Type Description x1
number y1
number x2
number y2
number