Module: zrender/shape/Polygon

zrender/shape/Polygon

new require("zrender/shape/Polygon")(options)

shape/Polygon.js, line 54
Name Type Description
options Object

多边形

Author:
  • Kener (@Kener-林峰, kener.linfeng@gmail.com)

Example

var Polygon = require('zrender/shape/Polygon');
    var shape = new Polygon({
        style: {
            // 100x100的正方形
            pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
            color: 'blue'
        }
    });
    zr.addShape(shape);

Members

多边形高亮绘制样式

多边形绘制样式

inherited idstring

Shape id, 全局唯一

父节点

Default Value:
  • null

inherited positionArray.<number>

平移

Default Value:
  • [0, 0]

inherited rotationArray.<number>

旋转,可以通过数组二三项指定旋转的原点

Default Value:
  • [0, 0, 0]

inherited scaleArray.<number>

缩放,可以通过数组三四项指定缩放的原点

Default Value:
  • [1, 1, 0, 0]

Methods

buildPath(ctx, style)

shape/Polygon.js, line 76

创建多边形路径

Name Type Description
ctx CanvasRenderingContext2D
style module:zrender/shape/Polygon~IPolygonStyle

getRect(style){module:zrender/shape/Base~IBoundingRect}

shape/Polygon.js, line 167

计算返回多边形包围盒矩阵

Name Type Description
style module:zrender/shape/Polygon~IPolygonStyle

inherited afterBrush(ctx)

shape/Base.js, line 306

绘制后的处理

Name Type Description
ctx CanvasRenderingContext2D

inherited beforeBrush(ctx, isHighlight){Object}

shape/Base.js, line 270

具体绘制操作前的一些公共操作

Name Type Default Description
ctx CanvasRenderingContext2D
isHighlight boolean false optional

是否使用高亮属性

inherited bind(event, handler, context)

mixin/Eventful.js, line 50

绑定事件

Name Type Description
event string

事件名

handler function

事件处理函数

context Object optional

inherited brush(ctx, isHighlight, updateCallback)

shape/Base.js, line 240

绘制图形

Name Type Default Description
ctx CanvasRenderingContext2D
isHighlight boolean false optional

是否使用高亮属性

updateCallback function optional

需要异步加载资源的shape可以通过这个callback(e), 让painter更新视图,base.brush没用,需要的话重载brush

inherited decomposeTransform()

mixin/Transformable.js, line 217

分解transform矩阵到position, rotation, scale

inherited dispatch(type)

mixin/Eventful.js, line 110

事件分发

Name Type Description
type string

事件类型

inherited dispatchWithContext(type)

mixin/Eventful.js, line 156

带有context的事件分发, 最后一个参数是事件回调的context

Name Type Description
type string

事件类型

inherited drawText(ctx, style, normalStyle)

shape/Base.js, line 518

绘制附加文本

Name Type Description
ctx CanvasRenderingContext2D
style module:zrender/shape/Base~IBaseShapeStyle

样式

normalStyle module:zrender/shape/Base~IBaseShapeStyle

默认样式,用于定位文字显示

inherited drift(dx, dy)

shape/Base.js, line 432

移动位置

Name Type Description
dx number

横坐标变化

dy number

纵坐标变化

inherited getHighlightStyle(style, highlightStyle, brushTypeOnly)

shape/Base.js, line 378

根据默认样式扩展高亮样式

Name Type Description
style module:zrender/shape/Base~IBaseShapeStyle

默认样式

highlightStyle module:zrender/shape/Base~IBaseShapeStyle

高亮样式

brushTypeOnly string

inherited getTansform(x, y){Array.<number>}

shape/Base.js, line 444

变换鼠标位置到 shape 的局部坐标空间

Name Type Description
x number
y number

inherited isCover(x, y){boolean}

shape/Base.js, line 489

判断鼠标位置是否在图形内

Name Type Description
x number
y number

inherited isSilent(){boolean}

shape/Base.js, line 684

图形是否会触发事件

inherited lookAt(target)

mixin/Transformable.js, line 188

设置图形的朝向

Name Type Description
target Array.<number> | Float32Array

inherited one(event, handler, context)

mixin/Eventful.js, line 24

单次触发绑定,dispatch后销毁

Name Type Description
event string

事件名

handler function

响应函数

context Object

inherited setContext(ctx, style)

shape/Base.js, line 329

设置 fillStyle, strokeStyle, shadow 等通用绘制样式

Name Type Description
ctx CanvasRenderingContext2D
style module:zrender/shape/Base~IBaseShapeStyle

inherited setTransform(ctx)

mixin/Transformable.js, line 173

将自己的transform应用到context上

Name Type Description
ctx Context2D

inherited unbind(event, handler)

mixin/Eventful.js, line 75

解绑事件

Name Type Description
event string

事件名

handler function optional

事件处理函数

inherited updateTransform()

mixin/Transformable.js, line 80

判断是否需要有坐标变换,更新needTransform属性。 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵

Type Definitions

IPolygonStyleObject

Properties:
Name Type Argument Default Description
pointList string

多边形顶点数组

smooth string <optional>
''

是否做平滑插值, 平滑算法可以选择 bezier, spline

smoothConstraint number <optional>

平滑约束

brushType string <optional>
'fill'
color string <optional>
'#000000'

填充颜色

strokeColor string <optional>
'#000000'

描边颜色

lineCape string <optional>
'butt'

线帽样式,可以是 butt, round, square

lineWidth number <optional>
1

描边宽度

opacity number <optional>
1

绘制透明度

shadowBlur number <optional>
0

阴影模糊度,大于0有效

shadowColor string <optional>
'#000000'

阴影颜色

shadowOffsetX number <optional>
0

阴影横向偏移

shadowOffsetY number <optional>
0

阴影纵向偏移

text string <optional>

图形中的附加文本

textColor string <optional>
'#000000'

文本颜色

textFont string <optional>

附加文本样式,eg:'bold 18px verdana'

textPosition string <optional>
'end'

附加文本位置, 可以是 inside, left, right, top, bottom

textAlign string <optional>

默认根据textPosition自动设置,附加文本水平对齐。 可以是start, end, left, right, center

textBaseline string <optional>

默认根据textPosition自动设置,附加文本垂直对齐。 可以是top, bottom, middle, alphabetic, hanging, ideographic

Events

inherited onclick

mixin/Eventful.js, line 200
Type:
  • function
Default Value:
  • null

inherited ondragend

mixin/Eventful.js, line 240
Type:
  • function
Default Value:
  • null

inherited ondragenter

mixin/Eventful.js, line 245
Type:
  • function
Default Value:
  • null

inherited ondragleave

mixin/Eventful.js, line 250
Type:
  • function
Default Value:
  • null

inherited ondragover

mixin/Eventful.js, line 255
Type:
  • function
Default Value:
  • null

inherited ondragstart

mixin/Eventful.js, line 235
Type:
  • function
Default Value:
  • null

inherited ondrop

mixin/Eventful.js, line 260
Type:
  • function
Default Value:
  • null

inherited onmousedown

mixin/Eventful.js, line 225
Type:
  • function
Default Value:
  • null

inherited onmousemove

mixin/Eventful.js, line 215
Type:
  • function
Default Value:
  • null

inherited onmouseout

mixin/Eventful.js, line 210
Type:
  • function
Default Value:
  • null

inherited onmouseover

mixin/Eventful.js, line 205
Type:
  • function
Default Value:
  • null

inherited onmouseup

mixin/Eventful.js, line 230
Type:
  • function
Default Value:
  • null

inherited onmousewheel

mixin/Eventful.js, line 220
Type:
  • function
Default Value:
  • null