Skip to content

Commit

Permalink
little optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
erik168 committed Jun 24, 2014
1 parent 604ee42 commit be24850
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions src/util/shape/Candle.js
Expand Up @@ -60,6 +60,7 @@ define(function (require) {
_numberOrder : function (a, b) {
return b - a;
},

/**
* 创建矩形路径
* @param {Context2D} ctx Canvas 2D上下文
Expand All @@ -79,31 +80,28 @@ define(function (require) {
);
ctx.moveTo(style.x, yList[1]);
ctx.lineTo(style.x, yList[0]);
return;
},

/**
* 返回矩形区域,用于局部刷新和文字定位
* @param {Object} style
*/
getRect : function (style) {
if (style.__rect) {
return style.__rect;
}
var lineWidth;
if (style.brushType == 'stroke' || style.brushType == 'fill') {
lineWidth = style.lineWidth || 1;
}
else {
lineWidth = 0;
if (!style.__rect) {
var lineWidth = 0;
if (style.brushType == 'stroke' || style.brushType == 'fill') {
lineWidth = style.lineWidth || 1;
}

var yList = zrUtil.clone(style.y).sort(this._numberOrder);
style.__rect = {
x : Math.round(style.x - style.width / 2 - lineWidth / 2),
y : Math.round(yList[3] - lineWidth / 2),
width : style.width + lineWidth,
height : yList[0] - yList[3] + lineWidth
};
}
var yList = zrUtil.clone(style.y).sort(this._numberOrder);
style.__rect = {
x : Math.round(style.x - style.width / 2 - lineWidth / 2),
y : Math.round(yList[3] - lineWidth / 2),
width : style.width + lineWidth,
height : yList[0] - yList[3] + lineWidth
};

return style.__rect;
},

Expand All @@ -118,16 +116,11 @@ define(function (require) {
if (!rect) {
rect = this.style.__rect = this.getRect(this.style);
}
if (x >= rect.x

return x >= rect.x
&& x <= (rect.x + rect.width)
&& y >= rect.y
&& y <= (rect.y + rect.height)
) {
// 矩形内
return true;
}

return false;
&& y <= (rect.y + rect.height);
}
};

Expand Down

0 comments on commit be24850

Please sign in to comment.