mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 14:47:56 +01:00
Migrate workspace to TS
This commit is contained in:
parent
f5cab1fc60
commit
1bebfa3dff
@ -222,7 +222,7 @@ class Designer extends Events {
|
|||||||
* @param {{width:Number, height:Number}} size
|
* @param {{width:Number, height:Number}} size
|
||||||
* sets width and height of the workspace
|
* sets width and height of the workspace
|
||||||
*/
|
*/
|
||||||
setViewPort(size) {
|
setViewPort(size: { height: number, width: number }) {
|
||||||
this._workspace.setViewPort(size);
|
this._workspace.setViewPort(size);
|
||||||
const model = this.getModel();
|
const model = this.getModel();
|
||||||
this._workspace.setZoom(model.getZoom(), true);
|
this._workspace.setZoom(model.getZoom(), true);
|
||||||
|
@ -40,22 +40,22 @@ class DesignerModel extends Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @param {Number} zoom number between 0.3 and 1.9 to set the zoom to */
|
/** @param {Number} zoom number between 0.3 and 1.9 to set the zoom to */
|
||||||
setZoom(zoom:number) {
|
setZoom(zoom: number) {
|
||||||
this._zoom = zoom;
|
this._zoom = zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link mindplot.Topic[]} all topics */
|
/** @return {@link mindplot.Topic[]} all topics */
|
||||||
getTopics() {
|
getTopics(): Topic[] {
|
||||||
return this._topics;
|
return this._topics;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {mindplot.Relationship[]} all relationships */
|
/** @return {mindplot.Relationship[]} all relationships */
|
||||||
getRelationships() {
|
getRelationships(): Relationship[] {
|
||||||
return this._relationships;
|
return this._relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {mindplot.CentralTopic} the central topic */
|
/** @return {mindplot.CentralTopic} the central topic */
|
||||||
getCentralTopic() {
|
getCentralTopic(): Topic {
|
||||||
const topics = this.getTopics();
|
const topics = this.getTopics();
|
||||||
return topics[0];
|
return topics[0];
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ class DesignerModel extends Events {
|
|||||||
/**
|
/**
|
||||||
* @return {mindplot.Relationship[]} selected relationships
|
* @return {mindplot.Relationship[]} selected relationships
|
||||||
*/
|
*/
|
||||||
filterSelectedRelationships() {
|
filterSelectedRelationships(): Relationship[] {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < this._relationships.length; i++) {
|
for (let i = 0; i < this._relationships.length; i++) {
|
||||||
if (this._relationships[i].isOnFocus()) {
|
if (this._relationships[i].isOnFocus()) {
|
||||||
@ -87,7 +87,7 @@ class DesignerModel extends Events {
|
|||||||
/**
|
/**
|
||||||
* @return {Array.<mindplot.Relationship, mindplot.Topic>} all topics and relationships
|
* @return {Array.<mindplot.Relationship, mindplot.Topic>} all topics and relationships
|
||||||
*/
|
*/
|
||||||
getEntities() {
|
getEntities(): (Relationship | Topic)[] {
|
||||||
let result = [].concat(this._topics);
|
let result = [].concat(this._topics);
|
||||||
result = result.concat(this._relationships);
|
result = result.concat(this._relationships);
|
||||||
return result;
|
return result;
|
||||||
@ -117,7 +117,7 @@ class DesignerModel extends Events {
|
|||||||
* @throws will throw an error if topic is null or undefined
|
* @throws will throw an error if topic is null or undefined
|
||||||
* @throws will throw an error if the topic's id is not a number
|
* @throws will throw an error if the topic's id is not a number
|
||||||
*/
|
*/
|
||||||
addTopic(topic) {
|
addTopic(topic: Topic): void {
|
||||||
$assert(topic, 'topic can not be null');
|
$assert(topic, 'topic can not be null');
|
||||||
$assert(typeof topic.getId() === 'number', `id is not a number:${topic.getId()}`);
|
$assert(typeof topic.getId() === 'number', `id is not a number:${topic.getId()}`);
|
||||||
this._topics.push(topic);
|
this._topics.push(topic);
|
||||||
@ -128,7 +128,7 @@ class DesignerModel extends Events {
|
|||||||
* @param {mindplot.Relationship} rel the relationship to add
|
* @param {mindplot.Relationship} rel the relationship to add
|
||||||
* @throws will throw an error if rel is null or undefined
|
* @throws will throw an error if rel is null or undefined
|
||||||
*/
|
*/
|
||||||
addRelationship(rel) {
|
addRelationship(rel: Relationship): void {
|
||||||
$assert(rel, 'rel can not be null');
|
$assert(rel, 'rel can not be null');
|
||||||
this._relationships.push(rel);
|
this._relationships.push(rel);
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ class DesignerModel extends Events {
|
|||||||
* @param {String} id the id of the topic to be retrieved
|
* @param {String} id the id of the topic to be retrieved
|
||||||
* @return {mindplot.Topic} the topic with the respective id
|
* @return {mindplot.Topic} the topic with the respective id
|
||||||
*/
|
*/
|
||||||
findTopicById(id:Number):Topic {
|
findTopicById(id: Number): Topic {
|
||||||
let result = null;
|
let result = null;
|
||||||
for (let i = 0; i < this._topics.length; i++) {
|
for (let i = 0; i < this._topics.length; i++) {
|
||||||
const topic = this._topics[i];
|
const topic = this._topics[i];
|
||||||
|
@ -3,6 +3,6 @@ export type DesignerOptions = {
|
|||||||
zoom: number,
|
zoom: number,
|
||||||
size: { height: number, witdh: number },
|
size: { height: number, witdh: number },
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
viewPort: { height: number, witdh: number },
|
viewPort: { height: number, width: number },
|
||||||
};
|
};
|
||||||
|
|
@ -17,9 +17,19 @@
|
|||||||
*/
|
*/
|
||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import { Workspace as Workspace2D } from '@wisemapping/web2d';
|
import { Workspace as Workspace2D } from '@wisemapping/web2d';
|
||||||
|
import ScreenManager from './ScreenManager';
|
||||||
|
|
||||||
class Workspace {
|
class Workspace {
|
||||||
constructor(screenManager, zoom, isReadOnly) {
|
_zoom: number;
|
||||||
|
_screenManager: ScreenManager;
|
||||||
|
_isReadOnly: boolean;
|
||||||
|
_screenWidth: number;
|
||||||
|
_screenHeight: number;
|
||||||
|
_workspace: Workspace2D;
|
||||||
|
_eventsEnabled: boolean;
|
||||||
|
_viewPort: { height: number, width: number };
|
||||||
|
|
||||||
|
constructor(screenManager: ScreenManager, zoom: number, isReadOnly: boolean) {
|
||||||
// Create a suitable container ...
|
// Create a suitable container ...
|
||||||
$assert(screenManager, 'Div container can not be null');
|
$assert(screenManager, 'Div container can not be null');
|
||||||
$assert(zoom, 'zoom container can not be null');
|
$assert(zoom, 'zoom container can not be null');
|
||||||
@ -99,7 +109,7 @@ class Workspace {
|
|||||||
return this._workspace.getCoordSize();
|
return this._workspace.getCoordSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
setZoom(zoom, center) {
|
setZoom(zoom: number, center: boolean = false) {
|
||||||
this._zoom = zoom;
|
this._zoom = zoom;
|
||||||
const workspace = this._workspace;
|
const workspace = this._workspace;
|
||||||
|
|
||||||
@ -128,8 +138,8 @@ class Workspace {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const coordOrigin = workspace.getCoordOrigin();
|
const coordOrigin = workspace.getCoordOrigin();
|
||||||
coordOriginX = coordOrigin.x;
|
coordOriginX = coordOrigin.x / 2;
|
||||||
coordOriginY = coordOrigin.y;
|
coordOriginY = coordOrigin.y / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace.setCoordOrigin(coordOriginX, coordOriginY);
|
workspace.setCoordOrigin(coordOriginX, coordOriginY);
|
||||||
@ -142,15 +152,15 @@ class Workspace {
|
|||||||
this._screenManager.fireEvent('update');
|
this._screenManager.fireEvent('update');
|
||||||
}
|
}
|
||||||
|
|
||||||
getScreenManager() {
|
getScreenManager(): ScreenManager {
|
||||||
return this._screenManager;
|
return this._screenManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
enableWorkspaceEvents(value) {
|
enableWorkspaceEvents(value: boolean) {
|
||||||
this._eventsEnabled = value;
|
this._eventsEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
isWorkspaceEventsEnabled() {
|
isWorkspaceEventsEnabled(): boolean {
|
||||||
return this._eventsEnabled;
|
return this._eventsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +168,7 @@ class Workspace {
|
|||||||
return this._workspace.getSVGElement();
|
return this._workspace.getSVGElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
_registerDragEvents() {
|
private _registerDragEvents() {
|
||||||
const workspace = this._workspace;
|
const workspace = this._workspace;
|
||||||
const screenManager = this._screenManager;
|
const screenManager = this._screenManager;
|
||||||
const mWorkspace = this;
|
const mWorkspace = this;
|
||||||
@ -218,7 +228,7 @@ class Workspace {
|
|||||||
screenManager.addEvent('mousedown', mouseDownListener);
|
screenManager.addEvent('mousedown', mouseDownListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
setViewPort(size) {
|
setViewPort(size:{ height: number, width: number }) {
|
||||||
this._viewPort = size;
|
this._viewPort = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -223,7 +223,7 @@ class Menu extends IMenu {
|
|||||||
.then((url: string) => {
|
.then((url: string) => {
|
||||||
// Create hidden anchor to force download ...
|
// Create hidden anchor to force download ...
|
||||||
const anchor: HTMLAnchorElement = document.createElement('a');
|
const anchor: HTMLAnchorElement = document.createElement('a');
|
||||||
anchor.style.display = 'none';
|
anchor.style.display = 'display: none';
|
||||||
anchor.download = `${mapId}.${formatExtension}`;
|
anchor.download = `${mapId}.${formatExtension}`;
|
||||||
anchor.href = url;
|
anchor.href = url;
|
||||||
document.body.appendChild(anchor);
|
document.body.appendChild(anchor);
|
||||||
|
Loading…
Reference in New Issue
Block a user