# tj-label-draw

> Label Draw

Latest version **0.3.0** (published 2023-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install tj-label-draw
pnpm add tj-label-draw
yarn add tj-label-draw
bun add tj-label-draw
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2023-01-29 |
| First published | 2022-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 75.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | damnshiny |
| Maintainers | damnshiny, lihewen |

## Links

- npm: https://www.npmjs.com/package/tj-label-draw
- npm.io page: https://npm.io/package/tj-label-draw

## Dependencies (1)

- [hotkeys-js](https://npm.io/package/hotkeys-js.md) ^3.8.8

## Recent versions

- 0.3.0 (latest) — 2023-01-29
- 0.2.0 — 2022-07-21
- 0.1.9 — 2022-06-14
- 0.1.8 — 2022-06-13
- 0.1.7 — 2022-06-13
- 0.1.6 — 2022-05-30
- 0.1.5 — 2022-05-30
- 0.1.4 — 2022-05-27
- 0.1.3 — 2022-05-26
- 0.1.2 — 2022-04-09
- 0.1.1 — 2022-04-09
- 0.1.0 — 2022-04-09

## README

<h3 size="7" align="center">
  Label Draw
</h3>

<p align="center">
  一个简单的标注库
</p>

<p align="center">
  <a href="https://www.npmjs.com/package/tj-label-draw">
    <img src="https://img.shields.io/npm/v/tj-label-draw?color=3fb883&amp;label=" alt="NPM version">
  </a>
</p>

<br>

## 安装

```
npm i tj-label-draw
```
## 用法
```js
import Label from 'label'

const label = new Label('#container', {
  width: 800,
  height: 400
  // 更多配置查看下方 Options
})

document.getElementById('btn').addEventListener(() => {
  // 创建标注 Polygon / Line / Rect
  label.createDraw('Polygon')
})
```

## Options
```ts
export interface LabelOption {
  width: number // 宽
  height: number // 高
  shortcutKey?: boolean // 开启快捷键
  closedGraphRevoke?: boolean // 闭合图形撤回操作，默认为 true，即可以撤回闭合图形，false 则闭合图形无法进行撤回
  canvasOption?: {
    lineColor?: string // 线颜色
    fillColor?: string // 填充颜色
  }
  hotkeyOption?: { // 快捷键配置，shortcutKey: true 时才会生效
    revokeKey?: string // 撤回快捷键配置, 默认 Mac: 'command+z' \ Window: 'ctrl+z'
    recoverKey?: string // 恢复快捷键配置 默认 Mac: 'command+shift+z' \ Window: 'ctrl+y'
    deleteKey?: string // 删除快捷键配置 默认 backspace
  }
}
```

## API
### createDraw
```js
  function(type, [option | position], [ option]): void
```

  * type 图形类型
    * `Line` 线段, `Polygon` 多边形, `Rect` 矩形
  * positions 图形默认绘制的位置信息 (可选)
  * option 其他配置 (可选)
    * name 图形名称 (可选)
    * drawOption
      * lineColor 线条颜色
      * fillColor 填充颜色

### delete
删除图形

```js
  function([name]): void
```

  * name 图形名称 (可选)

### revoke
撤销
### recover
恢复

### clear
清除画布

### getDrawInfo
获取绘制信息

### destroy
销毁

---
_Source: https://npm.io/package/tj-label-draw · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
