forked from apache/echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* zrender | ||
* | ||
* @author Kener (@Kener-林峰, linzhifeng@baidu.com) | ||
* | ||
* shape类:支持半平滑的polygon,折线面积图使用 | ||
* 可配图形属性: | ||
{ | ||
// 基础属性 | ||
shape : 'halfSmoothPolygon', // 必须,shape类标识,需要显式指定 | ||
id : {string}, // 必须,图形唯一标识,可通过zrender实例方法newShapeId生成 | ||
zlevel : {number}, // 默认为0,z层level,决定绘画在哪层canvas中 | ||
invisible : {boolean}, // 默认为false,是否可见 | ||
// 样式属性,默认状态样式样式属性 | ||
style : { | ||
pointList : {Array}, // 必须,多边形各个顶角坐标 | ||
brushType : {string}, // 默认为fill,绘画方式 | ||
// fill(填充) | stroke(描边) | both(填充+描边) | ||
color : {color}, // 默认为'#000',填充颜色,支持rgba | ||
strokeColor : {color}, // 默认为'#000',描边颜色(轮廓),支持rgba | ||
lineWidth : {number}, // 默认为1,线条宽度,描边下有效 | ||
opacity : {number}, // 默认为1,透明度设置,如果color为rgba,则最终透明度效果叠加 | ||
shadowBlur : {number}, // 默认为0,阴影模糊度,大于0有效 | ||
shadowColor : {color}, // 默认为'#000',阴影色彩,支持rgba | ||
shadowOffsetX : {number}, // 默认为0,阴影横向偏移,正值往右,负值往左 | ||
shadowOffsetY : {number}, // 默认为0,阴影纵向偏移,正值往下,负值往上 | ||
text : {string}, // 默认为null,附加文本 | ||
textFont : {string}, // 默认为null,附加文本样式,eg:'bold 18px verdana' | ||
textPosition : {string}, // 默认为top,附加文本位置。 | ||
// inside | left | right | top | bottom | ||
textAlign : {string}, // 默认根据textPosition自动设置,附加文本水平对齐。 | ||
// start | end | left | right | center | ||
textBaseline : {string}, // 默认根据textPosition自动设置,附加文本垂直对齐。 | ||
// top | bottom | middle | | ||
// alphabetic | hanging | ideographic | ||
textColor : {color}, // 默认根据textPosition自动设置,默认策略如下,附加文本颜色 | ||
// 'inside' ? '#fff' : color | ||
}, | ||
// 样式属性,高亮样式属性,当不存在highlightStyle时使用基于默认样式扩展显示 | ||
highlightStyle : { | ||
// 同style | ||
} | ||
// 交互属性,详见shape.Base | ||
// 事件属性,详见shape.Base | ||
} | ||
例子: | ||
{ | ||
shape : 'halfSmoothPolygon', | ||
id : '123456', | ||
zlevel : 1, | ||
style : { | ||
pointList : [[10, 10], [300, 20], [298, 400], [50, 450]] | ||
color : '#eee', | ||
text : 'Baidu' | ||
}, | ||
myName : 'kener', // 可自带任何有效自定义属性 | ||
clickable : true, | ||
onClick : function(eventPacket) { | ||
alert(eventPacket.target.myName); | ||
} | ||
} | ||
*/ | ||
define( | ||
function(require) { | ||
function HalfSmoothPolygon() { | ||
this.type = 'halfSmoothPolygon'; | ||
} | ||
|
||
HalfSmoothPolygon.prototype = { | ||
/** | ||
* 创建多边形路径 | ||
* @param {Context2D} ctx Canvas 2D上下文 | ||
* @param {Object} style 样式 | ||
*/ | ||
buildPath : function(ctx, style) { | ||
var pointList = style.pointList; | ||
if (pointList.length < 2) { | ||
// 少于2个点就不画了~ | ||
return; | ||
} | ||
if (style.smooth) { | ||
var controlPoints = this.smoothBezier( | ||
pointList.slice(0, -2), style.smooth | ||
); | ||
|
||
ctx.moveTo(pointList[0][0], pointList[0][1]); | ||
var cp1; | ||
var cp2; | ||
var p; | ||
var l = pointList.length; | ||
for (var i = 0; i < l - 3; i++) { | ||
cp1 = controlPoints[i * 2]; | ||
cp2 = controlPoints[i * 2 + 1]; | ||
p = pointList[i + 1]; | ||
ctx.bezierCurveTo( | ||
cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1] | ||
); | ||
} | ||
ctx.lineTo(pointList[l - 2][0], pointList[l - 2][1]); | ||
ctx.lineTo(pointList[l - 1][0], pointList[l - 1][1]); | ||
ctx.lineTo(pointList[0][0], pointList[0][1]); | ||
} | ||
else { | ||
require('zrender/shape').get('polygon').buildPath( | ||
ctx, style | ||
); | ||
} | ||
return; | ||
} | ||
}; | ||
|
||
require('zrender/shape/base').derive(HalfSmoothPolygon); | ||
require('zrender/shape').define( | ||
'halfSmoothPolygon', new HalfSmoothPolygon() | ||
); | ||
|
||
return HalfSmoothPolygon; | ||
} | ||
); |