@bixi/label v9.9.9-beta6
快速开始
##1. 安装依赖
yarn add @bixi/label
2. 修改 angular.json
{
"architect": {
"build": {
"options": {
"assets": [
{
"glob": "**/*",
"input": "node_modules/@bixi/label/engine",
"output": "/bixi-label-engine"
}
]
}
}
}
}
3. 模块注册
import { BixiLabelModule } from '@bixi/label';
@NgModule({
imports: [
BixiLabelModule,
]
})
export class SharedModule { }
4. 组件使用
设计理念
Label Engine
标注引擎(通过 iframe 引入), 只负责单纯做两件的事:
- 标注图层的渲染
- 标注事件的监听
Label Hub
在使用标注器组件时候你需要先实例化一个标注控制器,然后将其传入标注组件,之后标注的所有事件都将会被它所接管,就像这样
import { LabelHub } from '@bixi/label';
@Component({
template: `
<bixi-label-core
engine="./source/index.html"
[hub]="hub">
</bixi-label-core>`
})
export class LabelHubDemoComponent{
hub = new LabelHub({
dev: true,
});
}
对于业务组件而言, LabelHub
就像是一个邮局,它可以告诉你有哪些事件发生,也允许你主动往它上面投递事件等待引擎处理,比如
export class LabelHubDemoComponent{
hub = new LabelHub({
dev: true,
});
ngOnInit() {
this.hub.pagination$.subscribe(({ pageNumber }) => {
console.warn('内部更改了页码', pageNumber);
})
}
pageChange() {
// 业务组件主动更改页码
this.hub.setPagination({
pageNumber: 2
});
}
}
LabelHub
对修改是封闭的,但是对扩展是完全开放的,我们将核心数据都实现了成员保护,只有当你需要完全定制 Hub 的时候,你可以继承它然后扩展它,就像下面这样可以实现 Hook 的功能
import { LabelHub } from '@bixi/label';
export class MyHub extends LabelHub {
constructor(options) {
super(options);
}
setZoom(zoom) {
console.warn('set zoom1', zoom);
this._api.setZoom(zoom);
console.warn('set zoom2', zoom);
}
}
但如果像上面这样仅仅是打印日志的话,那么你可以不必这么舍近求远,我们提供了开发模式,丰富的日志可以帮助你快速排查问题,而它仅需要一行配置
hub = new LabelHub({
dev: true
});
<bixi-label-core />
这是标注引擎的 Angular 封装,同时支持文本和表格标注
标注控制器
构造参数
名称 | 类型 | 描述 |
---|---|---|
dev | boolean | 开启开发模式,将会打印所有 hub 的核心方法执行过程,以及执行时间 |
logUnhandledEvents | boolean | 打印未处理事件 |
logAllEvents | boolean | 打印所有日志 |
logIgnoreEvents | string[] | 忽略的事件 |
成员属性
名称 | 类型 | 描述 |
---|---|---|
ready$ | BehaviorSubject<boolean> | 在标注引擎准备好标注的准备工作后触发 |
searchResult$ | BehaviorSubject<ISearchResult> | 搜索结果 |
pagination$ | BehaviorSubject<IPagination> | 页码 |
zoom$ | BehaviorSubject<number> | 缩放比 |
成员方法
名称 | 类型 | 描述 |
---|---|---|
init | (options: IInitOptions) => void | 初始化标注器 |
setLabels | (labels: ILabel[]) => void | 设置标注列表 |
setTables | (labels: any) => void | 设置表格标注列表 |
setPagination | (pagination: IPagination)=> void | 修改页码 |
setZoom | (zoom: number) => void | 修改缩放比 |
setLabelMode | (mode: LabelTextMode | LabelTableMode) => void | 修改标注模式 |
setPdfMode | (mode: PdfMode) => void | 修改引擎模式 |
search | (params: ISerarchParams) => void | 搜索 |
stopLabeling | () => void | 停止标注 |
restore | () => void | 丢掉临时标注重新渲染 |
scrollToLabelByUuid | (params: ISearchLabelByUuidParams) => void | 通过uuid滚动到某个标注 |
scrollToLabelByIndex | (params: ISearchLabelByIndexParams) => void | 通过索引跳转到某个标注 |
scrollToTableCell | (params: ISearchTableCellParams) => void | 通过坐标跳转到某个单元格 |
getTableMatrix | () => any | 获取表格标注数据 |
getViewport | () => IViewPort[] | 获取页面的显示相关信息 |
resetLabelsStyle | (params: ILabelStyle[]) => void | 重置已渲染标注填充色和边框 |
resetSelectedLabels | (params: string[]) => void | 重置选中的标注 |
getSelectedLabels | () => []ILabel | 获取所有被选中的标注数据 |
getDocContent | () => string | 获取文档文本内容 |
enableMergeOrSplitTables | (enable = false) => void | 是否启用跨页表格合并 |
类型定义
你可以在构建产物中获取类型,以上所有类型均在 @bixi/label
根级目录有导出
import { ILabel } from '@bixi/label';
const labels = ILabel[];
或者直接在源码中查看类型定义
标注组件
这是标注引擎的 Angular 封装,同时支持文本和表格标注
bixi-label-core
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
[engine] | 标注引擎地址 | string | ./bixi-label/index.html |
[hub] | 标注器控制器 | LabelHub | - |
[labelTooltipContent] | Tooltip 内容 | TemplateRef | - |
[labelTooltipDisabled] | 是否禁用 Tooltip | boolean | false |
[labelModalTitle] | 标注框标题 | string | - |
[labelModalContent] | 标注框内容 | TemplateRef | - |
[labelModalDisabled] | 是否禁用标注框 | boolean | false |
(startLabeling) | 开始标注事件 | EventEmitter<ILabelingEvent> | - |
(deleteLabels) | 删除标注事件 | EventEmitter<IDeleteLabelsEvent> | - |
(clickLabels) | 点击标注事件 | EventEmitter<IClickLabelsEvent> | - |
(pdfLoadFailed) | PDF 加载失败 | EventEmitter | - |
(mergeTables) | 合并跨页表格 | EventEmitter | - |
(splitTable) | 拆分跨页表格 | EventEmitter | - |
Type
interface IClickMetadata {
altKey: boolean;
ctrlKey: boolean;
metaKey: boolean;
shiftKey: boolean;
which: number;
}
export interface IClickOutsideEvent {
position: {
top: number;
left: number;
};
metadata: IClickMetadata;
}
interface ILabelsEvent {
data: ILabel[];
position: {
top: number;
left: number;
width: number;
height: number;
};
}
export type ILabelingEvent = ILabelsEvent;
export type IDeleteLabelsEvent = ILabelsEvent;
export type IHoverInLabelsEvent = ILabelsEvent;
export interface IClickLabelsEvent extends ILabelsEvent {
metadata: IClickMetadata;
}
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago