mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: @idraw/core add point translate func
This commit is contained in:
parent
3c628b5c01
commit
b70eebcdc0
5 changed files with 63 additions and 14 deletions
|
|
@ -1,10 +1,10 @@
|
|||
# @idraw/core
|
||||
|
||||
* [] BUG: Select area calculate elements error
|
||||
* [] Support gradient color
|
||||
* [] Move elements that in selected-area
|
||||
* [] Listen keyboard action
|
||||
* [] Keep all num two decimals
|
||||
* [x] BUG: Select area calculate elements error
|
||||
* [x] Move elements that in selected-area
|
||||
* [x] Area select
|
||||
* [x] Lock Element
|
||||
* [x] FireFox's Compatibility Question (And Safair Browser)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import Board from '../src';
|
|||
|
||||
describe('@idraw/board', () => {
|
||||
|
||||
|
||||
document.body.innerHTML = `
|
||||
<div id="mount"></div>
|
||||
`;
|
||||
|
|
@ -22,20 +21,21 @@ describe('@idraw/board', () => {
|
|||
const mount = document.querySelector('#mount') as HTMLDivElement;
|
||||
const board = new Board(mount, opts);
|
||||
|
||||
test('scroll', async () => {
|
||||
|
||||
board.scale(transform.scale);
|
||||
board.scrollX(transform.scrollX);
|
||||
board.scrollY(transform.scrollY);
|
||||
board.draw();
|
||||
board.scale(transform.scale);
|
||||
board.scrollX(transform.scrollX);
|
||||
board.scrollY(transform.scrollY);
|
||||
board.draw();
|
||||
|
||||
const p1 = {x: 400, y: 300};
|
||||
const p2 = {x: 300, y: 200};
|
||||
const p1 = {x: 400, y: 300};
|
||||
const p2 = {x: 300, y: 200};
|
||||
|
||||
test('pointScreenToContext', async () => {
|
||||
expect(board.pointScreenToContext(p1)).toStrictEqual(p2);
|
||||
});
|
||||
|
||||
test('pointContextToScreen', async () => {
|
||||
expect(board.pointContextToScreen(p2)).toStrictEqual(p1);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
41
packages/core/__tests__/lib/point.test.ts
Normal file
41
packages/core/__tests__/lib/point.test.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import IDraw from '../../src';
|
||||
|
||||
describe('@idraw/core', () => {
|
||||
|
||||
document.body.innerHTML = `
|
||||
<div id="mount"></div>
|
||||
`;
|
||||
const opts = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
contextWidth: 600,
|
||||
contextHeight: 400,
|
||||
devicePixelRatio: 4,
|
||||
canScroll: true,
|
||||
};
|
||||
const transform = {
|
||||
scale: 2,
|
||||
scrollX: -200,
|
||||
scrollY: -100,
|
||||
};
|
||||
const mount = document.querySelector('#mount') as HTMLDivElement;
|
||||
const idraw = new IDraw(mount, opts);
|
||||
|
||||
idraw.scale(transform.scale);
|
||||
idraw.scrollX(transform.scrollX);
|
||||
idraw.scrollY(transform.scrollY);
|
||||
idraw.draw();
|
||||
|
||||
const p1 = {x: 400, y: 300};
|
||||
const p2 = {x: 300, y: 200};
|
||||
|
||||
test('pointScreenToContext', async () => {
|
||||
expect(idraw.pointScreenToContext(p1)).toStrictEqual(p2);
|
||||
});
|
||||
|
||||
test('pointContextToScreen', async () => {
|
||||
expect(idraw.pointContextToScreen(p2)).toStrictEqual(p1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -224,6 +224,14 @@ class Core {
|
|||
this[_coreEvent].off(key, callback);
|
||||
}
|
||||
|
||||
pointScreenToContext(p: TypePoint) {
|
||||
return this[_board].pointScreenToContext(p);
|
||||
}
|
||||
|
||||
pointContextToScreen(p: TypePoint) {
|
||||
return this[_board].pointContextToScreen(p);
|
||||
}
|
||||
|
||||
__getBoardContext(): TypeContext {
|
||||
return this[_board].getContext();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ export class Helper implements TypeHelper {
|
|||
private _coreConfig: TypeConfigStrict;
|
||||
private _ctx: TypeContext;
|
||||
private _board: Board;
|
||||
private _areaStart: TypePoint = { x: 0, y: 0};
|
||||
private _areaEnd: TypePoint = { x: 0, y: 0};
|
||||
private _areaStart: TypePoint = { x: 0, y: 0 };
|
||||
private _areaEnd: TypePoint = { x: 0, y: 0 };
|
||||
|
||||
constructor(board: Board, config: TypeConfigStrict) {
|
||||
this._board = board;
|
||||
|
|
|
|||
Loading…
Reference in a new issue