new require("zrender/shape/Text")(options)
Name | Type | Description |
---|---|---|
options |
Object |
Example
var Text = require('zrender/shape/Text');
var shape = new Text({
style: {
text: 'Label',
x: 100,
y: 100,
textFont: '14px Arial'
}
});
zr.addShape(shape);
Members
-
highlightStylemodule:zrender/shape/Text~ITextStyle
-
文字高亮绘制样式
-
文字绘制样式
-
inherited idstring
-
Shape id, 全局唯一
-
inherited readonlyparentmodule:zrender/Group
-
父节点
- 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
-
getRect(style){module:zrender/shape/Base~IBoundingRect}
shape/Text.js, line 168 -
返回文字包围盒矩形
Name Type Description style
module:zrender/shape/Text~ITextStyle -
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 buildPath(ctx, style)
shape/Base.js, line 470 -
构建绘制的Path
Name Type Description ctx
CanvasRenderingContext2D style
module:zrender/shape/Base~IBaseShapeStyle -
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
-
ITextStyleObject
-
Properties:
Name Type Argument Default Description x
number 横坐标
y
number 纵坐标
text
string 文本内容
maxWidth
number <optional>
null 最大宽度限制
textFont
string <optional>
附加文本样式,eg:'bold 18px verdana'
textAlign
string <optional>
可以是start, end, left, right, center
textBaseline
string <optional>
默认根据textPosition自动设置,附加文本垂直对齐。 可以是top, bottom, middle, alphabetic, hanging, ideographic
brushType
string <optional>
'fill' color
string <optional>
'#000000' 填充颜色
strokeColor
string <optional>
'#000000' 描边颜色
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 阴影纵向偏移
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