feat: @idraw/core add point translate func

This commit is contained in:
chenshenhai 2021-07-15 14:23:16 +08:00
parent 3c628b5c01
commit b70eebcdc0
5 changed files with 63 additions and 14 deletions

View file

@ -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)

View file

@ -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);
});
});

View 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);
});
});

View file

@ -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();
}

View file

@ -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;