线条(Line)
线条元素用于绘制直线,支持自定义描边颜色和线宽。常用于创建分隔线、引导线、表格边框等。线条元素没有 fill 属性。
安装
typescript
import { LinePlugin } from 'vkedit'
host.installPlugin('line-plugin', LinePlugin)安装后,工具栏会显示线条按钮。点击按钮后在画布上拖拽即可创建线条。
通过代码创建
typescript
import { AddElementCommand } from 'vkedit'
const elementManager = host.getPlugin('element-manager-plugin')
const line = elementManager.createElement('line')
// 设置位置(毫米)
line.xmm = 10
line.ymm = 10
// wmm 为线长,hmm 为线宽(毫米)
line.wmm = 50
line.hmm = 0.5
// 设置描边颜色
line.stroke = '#333333'
host.executeCommand(new AddElementCommand(host, line))线条的宽高含义
线条元素的 wmm 表示线长,hmm 表示线宽(即描边宽度)。线条始终为水平方向,通过 rotation 属性可旋转方向。
属性
基础属性(继承自 BaseGraphicElement)
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
xmm | number | 5 | X 坐标(毫米) |
ymm | number | 5 | Y 坐标(毫米) |
wmm | number | 10 | 线长(毫米) |
hmm | number | 0.2 | 线宽 / 描边宽度(毫米) |
rotation | number | 0 | 旋转角度(度) |
visible | boolean | true | 是否可见 |
locked | boolean | false | 是否锁定 |
draggable | boolean | true | 是否可拖拽 |
线条特有属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
stroke | string | 'black' | 描边颜色 |
线条无 fill 属性
线条元素仅支持描边(stroke),不支持填充(fill)。设置 fill 属性不会产生效果。