提交 87fff498 编辑于 作者: wenxiangdong's avatar wenxiangdong
浏览文件

画板加载独立出来

上级 288f8303
......@@ -118,6 +118,11 @@ var DrawingPanel = /** @class */ (function () {
var ctx = this.canvas.getContext('2d');
ctx.clearRect(0, 0, this.options.width, this.options.height);
};
/**
* 写文字
* @param {string} text
* @param {Point} point
*/
DrawingPanel.prototype.drawText = function (text, point) {
var ctx = this.canvas.getContext('2d');
ctx.save();
......@@ -126,6 +131,10 @@ var DrawingPanel = /** @class */ (function () {
ctx.fillText(text, point.x, point.y);
ctx.restore();
};
/**
* 初始化画板
* @param {DrawingPanelOptions} options
*/
DrawingPanel.prototype.initCanvas = function (options) {
var canvas = this.canvas;
canvas.width = options.width;
......@@ -135,6 +144,11 @@ var DrawingPanel = /** @class */ (function () {
}
this.options = options;
};
/**
* 总体初始化
* @param {string} containerID
* @param {DrawingPanelOptions} options
*/
DrawingPanel.prototype.init = function (containerID, options) {
var container = document.getElementById(containerID);
if (!container) {
......
{"version":3,"file":"drawing-panel.js","sourceRoot":"","sources":["drawing-panel.ts"],"names":[],"mappings":";;AAAA,0CAAqC;AAGrC,kFAGoD;AACpD,iFAA8E;AAC9E,4CAA2C;AAc3C;IAaE,sBAAY,WAAmB,EAAE,OAA6B;QAA9D,iBAWC;QAsFD;;;;WAIG;QACK,iBAAY,GAAG,UAAC,KAAY,EAAE,SAAqB;YACzD,gBAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;YAC5C,IAAI,eAAe,GAAG,6CAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACnE,IAAI,KAAK,CAAC;YACV,IAAI,CAAC,eAAe,EAAE;gBACpB,SAAS;gBACT,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;aAChC;iBAAM;gBACL,IAAI,OAAO,CAAC,qDAAW,eAAe,CAAC,KAAK,iEAAY,CAAC,EAAE;oBACzD,KAAI,CAAC,aA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,CAAC;IACtB,sBAAS,GAAG,iBAAiB,CAAC;IA6K/C,mBAAC;CAAA,AAjLD,IAiLC;AAjLY,oCAAY"}
\ No newline at end of file
import logger from '../utils/logger';
import { DrawingTool } from './drawing-tool';
import { IDrawingTool } from './i-drawing-tool';
import { Point, Shape } from '../shape/shape';
import {
IPanelStateManager,
......@@ -26,7 +26,7 @@ export class DrawingPanel {
private static labelColor = 'tomato';
private static labelFont = 'bold 20px Arial';
private canvas: HTMLCanvasElement;
private drawingTool: DrawingTool;
private drawingTool: IDrawingTool;
private drawing: boolean;
private options: DrawingPanelOptions;
private stateManager: IPanelStateManager;
......@@ -47,7 +47,7 @@ export class DrawingPanel {
}
// 切换画图工具
public setDrawingTool(tool: DrawingTool) {
public setDrawingTool(tool: IDrawingTool) {
if (this.drawingTool) {
this.drawingTool.stop();
}
......@@ -154,6 +154,11 @@ export class DrawingPanel {
}
};
/**
* 写文字
* @param {string} text
* @param {Point} point
*/
private drawText(text: string, point: Point) {
const ctx = this.canvas.getContext('2d');
ctx.save();
......@@ -163,6 +168,10 @@ export class DrawingPanel {
ctx.restore();
}
/**
* 初始化画板
* @param {DrawingPanelOptions} options
*/
private initCanvas(options: DrawingPanelOptions) {
const canvas = this.canvas;
canvas.width = options.width;
......@@ -173,6 +182,11 @@ export class DrawingPanel {
this.options = options;
}
/**
* 总体初始化
* @param {string} containerID
* @param {DrawingPanelOptions} options
*/
private init(containerID: string, options: DrawingPanelOptions) {
const container = document.getElementById(containerID);
if (!container) {
......
import { DrawingTool } from './drawing-tool';
import { IDrawingTool } from './i-drawing-tool';
import { Shape } from '../shape/shape';
import logger from '../utils/logger';
import { PanelState } from '../panel-state-manager/panel-state-manager';
export class DrawingToolCustom implements DrawingTool{
export class DrawingToolCustom implements IDrawingTool{
drawing: boolean;
static counter: number = 0;
......
{"version":3,"file":"drawing-tool.js","sourceRoot":"","sources":["drawing-tool.ts"],"names":[],"mappings":""}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=drawing-tool.js.map
\ No newline at end of file
//# sourceMappingURL=i-drawing-tool.js.map
\ No newline at end of file
{"version":3,"file":"i-drawing-tool.js","sourceRoot":"","sources":["i-drawing-tool.ts"],"names":[],"mappings":""}
\ No newline at end of file
import { Shape } from '../shape/shape';
import { PanelState } from '../panel-state-manager/panel-state-manager';
export interface DrawingTool {
export interface IDrawingTool {
canvas: HTMLCanvasElement;
drawing: boolean;
init(onDrawingEnd?: (shape: Shape, lastState: PanelState) => void): void;
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var drawing_panel_1 = require("./drawing-panel");
var drawing_tool_custom_1 = require("./drawing-tool-custom");
var panel_state_manager_1 = require("../panel-state-manager/panel-state-manager");
var PanelLoader = /** @class */ (function () {
function PanelLoader() {
}
PanelLoader.createPanel = function () {
var panel = new drawing_panel_1.DrawingPanel(this.CONTAINER_ID, this.config);
panel.setDrawingTool(new this.dependendyMap.IDrawingTool(panel.getCanvas()));
panel.setStateManager(new this.dependendyMap.IPanelStateManager());
return panel;
};
PanelLoader.dependendyMap = {
IDrawingTool: drawing_tool_custom_1.DrawingToolCustom,
IPanelStateManager: panel_state_manager_1.PanelStateManagerByLocalStorage
};
PanelLoader.CONTAINER_ID = 'container';
PanelLoader.config = { width: 800, height: 600 };
return PanelLoader;
}());
exports.PanelLoader = PanelLoader;
//# sourceMappingURL=panel-loader.js.map
\ No newline at end of file
{"version":3,"file":"panel-loader.js","sourceRoot":"","sources":["panel-loader.ts"],"names":[],"mappings":";;AAAA,iDAA+C;AAC/C,6DAA0D;AAC1D,kFAA6F;AAE7F;IAAA;IAcA,CAAC;IANQ,uBAAW,GAAlB;QACE,IAAI,KAAK,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7D,KAAK,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC7E,KAAK,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IAZM,yBAAa,GAAG;QACrB,YAAY,EAAE,uCAAiB;QAC/B,kBAAkB,EAAE,qDAA+B;KACpD,CAAC;IACK,wBAAY,GAAG,WAAW,CAAC;IAC3B,kBAAM,GAAG,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC;IAQ5C,kBAAC;CAAA,AAdD,IAcC;AAdY,kCAAW"}
\ No newline at end of file
import { DrawingPanel } from './drawing-panel';
import { DrawingToolCustom } from './drawing-tool-custom';
import { PanelStateManagerByLocalStorage } from '../panel-state-manager/panel-state-manager';
export class PanelLoader {
static dependendyMap = {
IDrawingTool: DrawingToolCustom,
IPanelStateManager: PanelStateManagerByLocalStorage
};
static CONTAINER_ID = 'container';
static config = {width: 800, height: 600};
static createPanel(): DrawingPanel {
let panel = new DrawingPanel(this.CONTAINER_ID, this.config);
panel.setDrawingTool(new this.dependendyMap.IDrawingTool(panel.getCanvas()));
panel.setStateManager(new this.dependendyMap.IPanelStateManager());
return panel;
}
}
\ No newline at end of file
var dependencyPool = {};
function propertyInject(dependency) {
return function (target, propertyName) {
var constructor = dependencyPool[dependency];
if (!constructor) {
throw new Error("\u4F9D\u8D56" + dependency + "\u672A\u6CE8\u518C");
}
return new constructor();
};
}
function bind(name, constructor) {
}
//# sourceMappingURL=ioc.js.map
\ No newline at end of file
{"version":3,"file":"ioc.js","sourceRoot":"","sources":["ioc.ts"],"names":[],"mappings":"AAAA,IAAI,cAAc,GAA0C,EAAE,CAAC;AAE/D,SAAS,cAAc,CAAC,UAAU;IAChC,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,IAAI,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,iBAAK,UAAU,uBAAK,CAAC,CAAC;SACvC;QACD,OAAO,IAAI,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAA;AACH,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,WAAgC;AAE5D,CAAC"}
\ No newline at end of file
var dependencyPool: {[name: string]: FunctionConstructor} = {};
function propertyInject(dependency) {
return function (target: any, propertyName: string) {
let constructor = dependencyPool[dependency];
if (!constructor) {
throw new Error(`依赖${dependency}未注册`);
}
return new constructor();
}
}
function bind(name: string, constructor: FunctionConstructor) {
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var drawing_panel_1 = require("./drawing/drawing-panel");
var drawing_tool_custom_1 = require("./drawing/drawing-tool-custom");
var $ = require("jquery");
var logger_1 = require("./utils/logger");
var panel_state_manager_1 = require("./panel-state-manager/panel-state-manager");
var message_1 = require("./utils/message");
var panel_loader_1 = require("./drawing/panel-loader");
var tool;
var panel;
var states = [];
......@@ -13,12 +11,8 @@ var SAVE_BTN_ID = 'save-btn';
var NEW_BTN_ID = 'new-btn';
var STATE_LIST_ID = 'state-list';
var TAG = 'main.ts';
var CONTAINER_ID = 'container';
window.onload = function (e) {
panel = new drawing_panel_1.DrawingPanel(CONTAINER_ID, { width: 800, height: 600 });
tool = new drawing_tool_custom_1.DrawingToolCustom(panel.getCanvas());
panel.setDrawingTool(tool);
panel.setStateManager(new panel_state_manager_1.PanelStateManagerByLocalStorage());
panel = panel_loader_1.PanelLoader.createPanel();
// 初始列表
states = panel.getPanelStates();
refreshList();
......
{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,yDAAuD;AACvD,qEAAkE;AAClE,0BAA4B;AAC5B,yCAAoC;AACpC,iFAAwG;AACxG,2CAA0C;AAE1C,IAAI,IAAI,CAAC;AACT,IAAI,KAAmB,CAAC;AACxB,IAAI,MAAM,GAAiB,EAAE,CAAC;AAE9B,IAAM,WAAW,GAA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CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IATD,KAAkB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM;QAAnB,IAAI,KAAK,eAAA;gBAAL,KAAK;KASb;AACH,CAAC,CAAA"}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import * as $ from 'jquery';
import logger from './utils/logger';
import { PanelState, PanelStateManagerByLocalStorage } from './panel-state-manager/panel-state-manager';
import { Message } from './utils/message';
import { PanelLoader } from './drawing/panel-loader';
var tool;
var panel: DrawingPanel;
......@@ -13,14 +14,9 @@ const SAVE_BTN_ID = 'save-btn';
const NEW_BTN_ID = 'new-btn';
const STATE_LIST_ID = 'state-list';
const TAG = 'main.ts';
const CONTAINER_ID = 'container';
window.onload = (e) => {
panel = new DrawingPanel(CONTAINER_ID, {width: 800, height: 600});
tool = new DrawingToolCustom(panel.getCanvas());
panel.setDrawingTool(tool);
panel.setStateManager(new PanelStateManagerByLocalStorage());
panel = PanelLoader.createPanel();
// 初始列表
states = panel.getPanelStates();
refreshList();
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var line_1 = require("../shape/line");
var shape_recognition_util_1 = require("./shape-recognition-util");
var logger_1 = require("../utils/logger");
var LineRecognition = /** @class */ (function () {
function LineRecognition() {
}
LineRecognition.prototype.test = function (coordinates) {
var start = coordinates[0];
var end = coordinates[coordinates.length - 1];
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
var point = coordinates_1[_i];
var rate = this.calRate(start, end);
for (var i = 1; i < coordinates.length; i++) {
var point = coordinates[i];
var rate1 = this.calRate(point, start);
var rate2 = this.calRate(point, end);
logger_1.default.info(LineRecognition.name, rate1 + ":" + rate);
// 斜率相差超过一定数值则认为不在同一线上
if (Math.abs(rate1 - rate2) > LineRecognition.DIFF) {
if (!shape_recognition_util_1.Util.equal(rate1, rate, 0.2)) {
return undefined;
}
}
return new line_1.Line([start, end], new Date().getTime().toString());
};
LineRecognition.prototype.calRate = function (a, b) {
return (a.y - b.y) / (a.x - b.x);
// logger.info(LineRecognition.name, a, b);
if (a.x === b.x)
return Number.MAX_VALUE;
var rate = (a.y - b.y) / (a.x - b.x);
rate = Math.round(rate * 100);
return rate;
};
LineRecognition.DIFF = 3;
return LineRecognition;
}());
exports.LineRecognition = LineRecognition;
......
{"version":3,"file":"line-recognition.js","sourceRoot":"","sources":["line-recognition.ts"],"names":[],"mappings":";;AAEA,sCAAqC;AAErC;IAAA;IAwBA,CAAC;IAtBC,8BAAI,GAAJ,UAAK,WAAoB;QACvB,IAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAM,GAAG,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEhD,KAAkB,UAAW,EAAX,2BAAW,EAAX,yBAAW,EAAX,IAAW,EAAE;YAA1B,IAAI,KAAK,oBAAA;YACZ,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACvC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACrC,sBAAsB;YACtB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,eAAe,CAAC,IAAI,EAAE;gBAClD,OAAO,SAAS,CAAC;aAClB;SACF;QACD,OAAO,IAAI,WAAI,CACb,CAAC,KAAK,EAAE,GAAG,CAAC,EACZ,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAChC,CAAC;IACJ,CAAC;IAGO,iCAAO,GAAf,UAAgB,CAAQ,EAAE,CAAQ;QAChC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAtBc,oBAA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GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACH,sBAAC;AAAD,CAAC,AA7BD,IA6BC;AA7BY,0CAAe"}
\ No newline at end of file
import { ShapeRecognitionService } from './shape-recognition-service';
import { Point, Shape } from '../shape/shape';
import { Line } from '../shape/line';
import { Util } from './shape-recognition-util';
import logger from '../utils/logger';
export class LineRecognition implements ShapeRecognitionService{
private static DIFF = 3;
test(coordinates: Point[]): Shape {
const start = coordinates[0];
const end = coordinates[coordinates.length - 1];
const rate = this.calRate(start, end);
for (let point of coordinates) {
for (let i = 1; i < coordinates.length; i++) {
let point = coordinates[i];
let rate1 = this.calRate(point, start);
let rate2 = this.calRate(point, end);
logger.info(LineRecognition.name, `${rate1}:${rate}`);
// 斜率相差超过一定数值则认为不在同一线上
if (Math.abs(rate1 - rate2) > LineRecognition.DIFF) {
if (!Util.equal(rate1, rate, 0.2)) {
return undefined;
}
}
......@@ -24,6 +27,10 @@ export class LineRecognition implements ShapeRecognitionService{
private calRate(a: Point, b: Point) {
return (a.y - b.y) / (a.x - b.x);
// logger.info(LineRecognition.name, a, b);
if (a.x === b.x) return Number.MAX_VALUE;
let rate = (a.y - b.y) / (a.x - b.x);
rate = Math.round(rate * 100);
return rate;
}
}
\ No newline at end of file
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册