-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
446 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import * as _ from 'lodash'; | ||
import EventEmitter from '@antv/event-emitter'; | ||
import { uuid } from '../utils/uuid'; | ||
import { MATRIX } from '../utils/const'; | ||
import { IElement, IEventEmitter, IMatrixValue, IMaxtrix } from '../types'; | ||
|
||
/** | ||
* 图形画布中的容器元素,可以包含有子元素 | ||
*/ | ||
export class Group extends EventEmitter implements IEventEmitter, IElement, IMaxtrix { | ||
|
||
/** | ||
* 元素的 id,自动生成 | ||
*/ | ||
public id: string = uuid(); | ||
|
||
/** | ||
* 元素的 tag,自动根据元素类型设置 | ||
*/ | ||
public tag: string = 'group'; | ||
|
||
/** | ||
* 类型,用于查找元素 | ||
*/ | ||
public className: string = ''; | ||
|
||
/** | ||
* 元素的 attributes 配置 | ||
*/ | ||
public attributes: Record<string, any> = {}; | ||
|
||
/** | ||
* 当前的 matrix 数据,默认设置为初始的矩阵 | ||
*/ | ||
public matrix: IMatrixValue = MATRIX; | ||
|
||
/** | ||
* 子元素 | ||
*/ | ||
public children: IElement[]; | ||
|
||
/** | ||
* 获取属性 | ||
* @param key | ||
*/ | ||
public getAttribute(key: string) { | ||
return _.get(this.attributes, key); | ||
} | ||
|
||
/** | ||
* 设置属性 | ||
* @param key | ||
* @param value | ||
*/ | ||
public setAttribute(key: string, value: any) { | ||
return _.set(this.attributes, key, value); | ||
} | ||
|
||
/** | ||
* 删除属性 | ||
* @param key | ||
*/ | ||
public removeAttribute(key: string) { | ||
return _.unset(this.attributes, key); | ||
} | ||
|
||
/** | ||
* 通过 id 查找 | ||
*/ | ||
public getElementById(id: string) { | ||
return this as any as IElement; | ||
} | ||
|
||
/** | ||
* 通过 class name 查找数组 | ||
*/ | ||
public getEelementsByClassName(className: string) { | ||
return [] | ||
} | ||
|
||
/** | ||
* 通过 tag 查找 | ||
*/ | ||
public getEelementsByTag(tag: string) { | ||
return []; | ||
} | ||
|
||
/** | ||
* 添加子元素 | ||
*/ | ||
public add() {} | ||
|
||
/** | ||
* 删除子元素 | ||
*/ | ||
public remove() {} | ||
|
||
/** | ||
* 移动到 x y 位置 | ||
* @param x | ||
* @param y | ||
*/ | ||
public moveTo(x: number, y: number) { | ||
return this.matrix; | ||
} | ||
|
||
/** | ||
* 移动 x y 位移 | ||
* @param x | ||
* @param y | ||
*/ | ||
public moveBy(x: number, y: number) { | ||
return this.matrix; | ||
} | ||
|
||
/** | ||
* 放大缩小到 x y | ||
* @param x | ||
* @param y | ||
*/ | ||
public scaleTo(x: number, y: number) { | ||
return this.matrix; | ||
} | ||
|
||
/** | ||
* 放大缩小 x y 比例 | ||
* @param x | ||
* @param y | ||
*/ | ||
public scaleBy(x: number, y: number) { | ||
return this.matrix; | ||
} | ||
|
||
/** | ||
* 旋转到 angle 角度 | ||
* @param angle | ||
*/ | ||
public rotateTo(angle: number) { | ||
return this.matrix; | ||
} | ||
|
||
/** | ||
* 旋转 angle 角度 | ||
* @param angle | ||
*/ | ||
public rotateBy(angle: number) { | ||
return this.matrix; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class Shape { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export class Graph {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export const VERSION = '0.1.0'; | ||
|
||
export { Graph } from './graph'; | ||
|
||
export * from './core'; | ||
|
||
// 辅助函数 | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as _ from 'lodash'; | ||
import { uuid } from '../utils/uuid'; | ||
|
||
/** | ||
* 提供类似 HTML Element 的 API 方法 | ||
*/ | ||
|
||
export interface IElement { | ||
|
||
/** | ||
* id | ||
*/ | ||
readonly id: string; | ||
|
||
/** | ||
* 类型 tag | ||
*/ | ||
readonly tag: string; | ||
|
||
/** | ||
* class name | ||
*/ | ||
readonly className?: string; | ||
|
||
/** | ||
* 属性配置 | ||
*/ | ||
readonly attributes: Record<string, any>; | ||
|
||
/** | ||
* 子元素 | ||
*/ | ||
readonly children: IElement[]; | ||
|
||
/** | ||
* 获取属性 | ||
* @param key | ||
*/ | ||
readonly getAttribute: (key: string) => any; | ||
|
||
/** | ||
* 设置属性 | ||
* @param key | ||
* @param value | ||
*/ | ||
readonly setAttribute: (key: string, value: any) => void; | ||
|
||
/** | ||
* 删除属性 | ||
* @param key | ||
*/ | ||
readonly removeAttribute: (key: string) => void; | ||
|
||
/** | ||
* 通过 id 查找 | ||
*/ | ||
readonly getElementById: (id: string) => IElement; | ||
|
||
/** | ||
* 通过 class name 查找数组 | ||
*/ | ||
readonly getEelementsByClassName: (className: string) => IElement[]; | ||
|
||
/** | ||
* 通过 tag 查找 | ||
*/ | ||
readonly getEelementsByTag: (tag: string) => IElement[]; | ||
|
||
/** | ||
* 添加子元素 | ||
*/ | ||
readonly add: (element: IElement) => void; | ||
|
||
/** | ||
* 删除子元素 | ||
*/ | ||
readonly remove: (element: IElement) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 提供事件 event emitter 能力接口 | ||
*/ | ||
export interface IEventEmitter { | ||
/** | ||
* 监听事件 | ||
* @param eventName | ||
* @param cb | ||
* @param once | ||
*/ | ||
on(eventName: string, cb: Function, once?: boolean): void; | ||
|
||
/** | ||
* 监听一次事件 | ||
* @param eventName | ||
* @param cb | ||
*/ | ||
once(eventName: string, cb: Function): void; | ||
|
||
/** | ||
* 取消监听事件 | ||
* @param eventName | ||
* @param cb | ||
*/ | ||
off(eventName?: string, cb?: Function): void; | ||
|
||
/** | ||
* 触发事件 | ||
*/ | ||
emit: (eventName: string, ...params: any[]) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { IElement } from './element'; | ||
export { IEventEmitter } from './event-emitter'; | ||
export { IMaxtrix, IMatrixValue } from './matrix'; | ||
export { IRenderable } from './renderable'; |
Oops, something went wrong.