mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-14 03:07:57 +01:00
WIP
This commit is contained in:
parent
4b8012efa3
commit
5695c2ab6a
@ -16,6 +16,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { Mindmap } from "../..";
|
import { Mindmap } from "../..";
|
||||||
|
import INodeModel from "../model/INodeModel";
|
||||||
|
import LinkModel from "../model/LinkModel";
|
||||||
import NodeModel from "../model/NodeModel";
|
import NodeModel from "../model/NodeModel";
|
||||||
import Exporter from "./Exporter";
|
import Exporter from "./Exporter";
|
||||||
|
|
||||||
@ -37,12 +39,15 @@ class TxtExporter implements Exporter {
|
|||||||
return Promise.resolve(retult);
|
return Promise.resolve(retult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private traverseBranch(prefix: string, branches: Array<NodeModel>) {
|
private traverseBranch(prefix: string, branches: Array<INodeModel>) {
|
||||||
let result = '';
|
let result = '';
|
||||||
branches.forEach((node, index) => {
|
branches.forEach((node, index) => {
|
||||||
result = result + `${prefix}${index+1} ${node.getText()}`;
|
result = result + `${prefix}${index+1} ${node.getText()}`;
|
||||||
node.getFeatures().forEach((f)=>{
|
node.getFeatures().forEach((f)=>{
|
||||||
|
const type = f.getType();
|
||||||
|
if(type === 'link'){
|
||||||
|
result = result + ` [link: ${(f as LinkModel).getUrl}]`
|
||||||
|
}
|
||||||
});
|
});
|
||||||
result = result + '\n';
|
result = result + '\n';
|
||||||
|
|
||||||
|
@ -15,16 +15,23 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert } from '@wisemapping/core-js';
|
||||||
|
|
||||||
|
export type FeatureType = 'note' | 'link' | 'icon';
|
||||||
|
|
||||||
class FeatureModel {
|
class FeatureModel {
|
||||||
|
static _next_id = 0;
|
||||||
|
_id: number;
|
||||||
|
_type: FeatureType;
|
||||||
|
_attributes: {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructs
|
* @constructs
|
||||||
* @param type
|
* @param type
|
||||||
* @throws will throw an exception if type is null or undefined
|
* @throws will throw an exception if type is null or undefined
|
||||||
* assigns a unique id and the given type to the new model
|
* assigns a unique id and the given type to the new model
|
||||||
*/
|
*/
|
||||||
constructor(type) {
|
constructor(type: FeatureType) {
|
||||||
$assert(type, 'type can not be null');
|
$assert(type, 'type can not be null');
|
||||||
this._id = FeatureModel._nextUUID();
|
this._id = FeatureModel._nextUUID();
|
||||||
|
|
||||||
@ -77,19 +84,15 @@ class FeatureModel {
|
|||||||
this._id = id;
|
this._id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
getType(): FeatureType {
|
||||||
getType() {
|
|
||||||
return this._type;
|
return this._type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static _nextUUID(): number {
|
||||||
|
const result = FeatureModel._next_id + 1;
|
||||||
|
FeatureModel._next_id = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FeatureModel._nextUUID = function _nextUUID() {
|
|
||||||
if (!$defined(FeatureModel._uuid)) {
|
|
||||||
FeatureModel._uuid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FeatureModel._uuid += 1;
|
|
||||||
return FeatureModel._uuid;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FeatureModel;
|
export default FeatureModel;
|
@ -2,20 +2,25 @@ import { $assert } from '@wisemapping/core-js';
|
|||||||
import IconModel from './IconModel';
|
import IconModel from './IconModel';
|
||||||
import LinkModel from './LinkModel';
|
import LinkModel from './LinkModel';
|
||||||
import NoteModel from './NoteModel';
|
import NoteModel from './NoteModel';
|
||||||
import FeatureModel from './FeatureModel';
|
import FeatureModel, { FeatureType } from './FeatureModel';
|
||||||
|
|
||||||
|
|
||||||
|
interface NodeById {
|
||||||
|
id: FeatureType,
|
||||||
|
model: typeof FeatureModel;
|
||||||
|
}
|
||||||
|
|
||||||
class FeatureModelFactory {
|
class FeatureModelFactory {
|
||||||
|
static modelById: Array<NodeById> = [{
|
||||||
private static modelById = [{
|
id: 'icon',
|
||||||
id: IconModel.FEATURE_TYPE,
|
|
||||||
model: IconModel,
|
model: IconModel,
|
||||||
}, {
|
}, {
|
||||||
id: LinkModel.FEATURE_TYPE,
|
id: 'link',
|
||||||
model: LinkModel,
|
model: LinkModel,
|
||||||
}, {
|
}, {
|
||||||
id: NoteModel.FEATURE_TYPE,
|
id: 'note',
|
||||||
model: NoteModel,
|
model: NoteModel,
|
||||||
}] as const;
|
}];
|
||||||
|
|
||||||
static createModel(type: string, attributes): FeatureModel {
|
static createModel(type: string, attributes): FeatureModel {
|
||||||
$assert(type, 'type can not be null');
|
$assert(type, 'type can not be null');
|
||||||
|
@ -18,35 +18,36 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { $assert } from '@wisemapping/core-js';
|
import { $assert } from '@wisemapping/core-js';
|
||||||
|
import INodeModel, { NodeModelType as NodeType } from './INodeModel';
|
||||||
import NodeModel from './NodeModel';
|
import NodeModel from './NodeModel';
|
||||||
import RelationshipModel from './RelationshipModel';
|
import RelationshipModel from './RelationshipModel';
|
||||||
|
|
||||||
abstract class IMindmap {
|
abstract class IMindmap {
|
||||||
getCentralTopic(): NodeModel {
|
getCentralTopic(): INodeModel {
|
||||||
return this.getBranches()[0];
|
return this.getBranches()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract getDescription(): string;
|
abstract getDescription(): string;
|
||||||
|
|
||||||
abstract setDescription(value: string);
|
abstract setDescription(value: string): void;
|
||||||
|
|
||||||
abstract getId(): string
|
abstract getId(): string
|
||||||
|
|
||||||
abstract setId(id: string);
|
abstract setId(id: string): void;
|
||||||
|
|
||||||
abstract getVersion(): string;
|
abstract getVersion(): string;
|
||||||
|
|
||||||
abstract setVersion(version: string): void;
|
abstract setVersion(version: string): void;
|
||||||
|
|
||||||
abstract addBranch(nodeModel: NodeModel): void;
|
abstract addBranch(nodeModel: INodeModel): void;
|
||||||
|
|
||||||
abstract getBranches(): Array<NodeModel>;
|
abstract getBranches(): Array<INodeModel>;
|
||||||
|
|
||||||
abstract removeBranch(node: NodeModel): void;
|
abstract removeBranch(node: INodeModel): void;
|
||||||
|
|
||||||
abstract getRelationships(): Array<RelationshipModel>;
|
abstract getRelationships(): Array<RelationshipModel>;
|
||||||
|
|
||||||
connect(parent: NodeModel, child: NodeModel): void {
|
connect(parent: INodeModel, child: INodeModel): void {
|
||||||
// Child already has a parent ?
|
// Child already has a parent ?
|
||||||
$assert(!child.getParent(), 'Child model seems to be already connected');
|
$assert(!child.getParent(), 'Child model seems to be already connected');
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ abstract class IMindmap {
|
|||||||
* @throws will throw an error if child is null or undefined
|
* @throws will throw an error if child is null or undefined
|
||||||
* @throws will throw an error if child's parent cannot be found
|
* @throws will throw an error if child's parent cannot be found
|
||||||
*/
|
*/
|
||||||
disconnect(child: NodeModel): void {
|
disconnect(child: INodeModel): void {
|
||||||
const parent = child.getParent();
|
const parent = child.getParent();
|
||||||
$assert(child, 'Child can not be null.');
|
$assert(child, 'Child can not be null.');
|
||||||
$assert(parent, 'Child model seems to be already connected');
|
$assert(parent, 'Child model seems to be already connected');
|
||||||
@ -71,23 +72,15 @@ abstract class IMindmap {
|
|||||||
this.addBranch(child);
|
this.addBranch(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @abstract */
|
abstract hasAlreadyAdded(node: INodeModel): boolean;
|
||||||
hasAlreadyAdded(node) {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @abstract */
|
abstract createNode(type: NodeType, id: number):void;
|
||||||
createNode(type, id) {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract createRelationship(fromNode: NodeModel, toNode: NodeModel): void;
|
abstract createRelationship(fromNode: NodeModel, toNode: NodeModel): void;
|
||||||
|
|
||||||
abstract addRelationship(rel: RelationshipModel): void;
|
abstract addRelationship(rel: RelationshipModel): void;
|
||||||
|
|
||||||
deleteRelationship(relationship: RelationshipModel): void {
|
abstract deleteRelationship(relationship: RelationshipModel): void;
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
inspect() {
|
inspect() {
|
||||||
|
@ -17,47 +17,53 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
|
import FeatureModel from './FeatureModel';
|
||||||
|
import Mindmap from './Mindmap';
|
||||||
|
|
||||||
// regex taken from https://stackoverflow.com/a/34763398/58128
|
// regex taken from https://stackoverflow.com/a/34763398/58128
|
||||||
const parseJsObject = (str) => JSON.parse(str.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '));
|
const parseJsObject = (str: string) => JSON.parse(str.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '));
|
||||||
|
|
||||||
class INodeModel {
|
abstract class INodeModel {
|
||||||
constructor(mindmap) {
|
static MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE: number = 220;
|
||||||
|
static _next_uuid: number = 0;
|
||||||
|
|
||||||
|
_mindmap: Mindmap;
|
||||||
|
|
||||||
|
constructor(mindmap: Mindmap) {
|
||||||
$assert(mindmap && mindmap.getBranches, 'mindmap can not be null');
|
$assert(mindmap && mindmap.getBranches, 'mindmap can not be null');
|
||||||
this._mindmap = mindmap;
|
this._mindmap = mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
getId(): number {
|
||||||
getId() {
|
|
||||||
return this.getProperty('id');
|
return this.getProperty('id');
|
||||||
}
|
}
|
||||||
|
abstract getFeatures(): Array<FeatureModel>;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
setId(id) {
|
setId(id: number): void {
|
||||||
if (!$defined(id)) {
|
if (!$defined(id)) {
|
||||||
const newId = INodeModel._nextUUID();
|
const newId = INodeModel._nextUUID();
|
||||||
this.putProperty('id', newId);
|
this.putProperty('id', newId);
|
||||||
} else {
|
} else {
|
||||||
if (id > INodeModel._uuid) {
|
if (id > INodeModel._next_uuid) {
|
||||||
$assert(Number.isFinite(id));
|
$assert(Number.isFinite(id));
|
||||||
INodeModel._uuid = id;
|
INodeModel._next_uuid = id;
|
||||||
}
|
}
|
||||||
this.putProperty('id', id);
|
this.putProperty('id', id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
getType(): NodeModelType {
|
||||||
getType() {
|
|
||||||
return this.getProperty('type');
|
return this.getProperty('type');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
setType(type) {
|
setType(type: NodeModelType): void {
|
||||||
this.putProperty('type', type);
|
this.putProperty('type', type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
setText(text) {
|
setText(text: string): void {
|
||||||
this.putProperty('text', text);
|
this.putProperty('text', text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,39 +321,55 @@ class INodeModel {
|
|||||||
// console.log("After:" + mindmap.inspect());
|
// console.log("After:" + mindmap.inspect());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @abstract */
|
abstract getPropertiesKeys(): string[];
|
||||||
getPropertiesKeys() {
|
|
||||||
throw new Error('Unsupported operation');
|
abstract getProperty(key: string);
|
||||||
|
|
||||||
|
abstract putProperty(key: string, value: any): void;
|
||||||
|
|
||||||
|
abstract setParent(parent: INodeModel): void;
|
||||||
|
|
||||||
|
abstract getChildren(): INodeModel[];
|
||||||
|
|
||||||
|
abstract getParent(): INodeModel;
|
||||||
|
|
||||||
|
abstract clone(): INodeModel;
|
||||||
|
|
||||||
|
isChildNode(node: INodeModel): boolean {
|
||||||
|
let result = false;
|
||||||
|
if (node === this) {
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
const children = this.getChildren();
|
||||||
|
for (let i = 0; i < children.length; i++) {
|
||||||
|
const child = children[i];
|
||||||
|
result = child.isChildNode(node);
|
||||||
|
if (result) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @abstract */
|
findNodeById(id: number): INodeModel {
|
||||||
// eslint-disable-next-line no-unused-vars
|
$assert(Number.isFinite(id));
|
||||||
putProperty(key, value) {
|
let result = null;
|
||||||
throw new Error('Unsupported operation');
|
if (this.getId() === id) {
|
||||||
|
result = this;
|
||||||
|
} else {
|
||||||
|
const children = this.getChildren();
|
||||||
|
for (let i = 0; i < children.length; i++) {
|
||||||
|
const child = children[i];
|
||||||
|
result = child.findNodeById(id);
|
||||||
|
if (result) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @abstract */
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
setParent(parent) {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @abstract */
|
|
||||||
getChildren() {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @abstract */
|
|
||||||
getParent() {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @abstract */
|
|
||||||
clone() {
|
|
||||||
throw new Error('Unsupported operation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
inspect() {
|
inspect() {
|
||||||
let result = `{ type: ${this.getType()} , id: ${this.getId()} , text: ${this.getText()}`;
|
let result = `{ type: ${this.getType()} , id: ${this.getId()} , text: ${this.getText()}`;
|
||||||
|
|
||||||
@ -369,16 +391,14 @@ class INodeModel {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @abstract */
|
abstract removeChild(child: INodeModel);
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
removeChild(child) {
|
static _nextUUID(): number {
|
||||||
throw new Error('Unsupported operation');
|
INodeModel._next_uuid += 1;
|
||||||
}
|
return INodeModel._next_uuid;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {String}
|
|
||||||
*/
|
|
||||||
const TopicShape = {
|
const TopicShape = {
|
||||||
RECTANGLE: 'rectagle',
|
RECTANGLE: 'rectagle',
|
||||||
ROUNDED_RECT: 'rounded rectagle',
|
ROUNDED_RECT: 'rounded rectagle',
|
||||||
@ -387,38 +407,10 @@ const TopicShape = {
|
|||||||
IMAGE: 'image',
|
IMAGE: 'image',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export type NodeModelType = 'CentralTopic' | 'MainTopic';
|
||||||
* @constant
|
|
||||||
* @type {String}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
INodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic';
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @type {String}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
INodeModel.MAIN_TOPIC_TYPE = 'MainTopic';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @type {Number}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo: This method must be implemented. (unascribed)
|
* @todo: This method must be implemented. (unascribed)
|
||||||
*/
|
*/
|
||||||
INodeModel._nextUUID = () => {
|
|
||||||
if (!$defined(INodeModel._uuid)) {
|
|
||||||
INodeModel._uuid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
INodeModel._uuid += 1;
|
|
||||||
return INodeModel._uuid;
|
|
||||||
};
|
|
||||||
INodeModel._uuid = 0;
|
|
||||||
|
|
||||||
export { TopicShape };
|
export { TopicShape };
|
||||||
export default INodeModel;
|
export default INodeModel;
|
@ -20,27 +20,17 @@ import FeatureModel from './FeatureModel';
|
|||||||
|
|
||||||
class IconModel extends FeatureModel {
|
class IconModel extends FeatureModel {
|
||||||
constructor(attributes) {
|
constructor(attributes) {
|
||||||
super(IconModel.FEATURE_TYPE);
|
super('icon');
|
||||||
this.setIconType(attributes.id);
|
this.setIconType(attributes.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the icon type id */
|
getIconType(): string {
|
||||||
getIconType() {
|
|
||||||
return this.getAttribute('id');
|
return this.getAttribute('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {String} iconType the icon type id */
|
setIconType(iconType: string) {
|
||||||
setIconType(iconType) {
|
|
||||||
$assert(iconType, 'iconType id can not be null');
|
$assert(iconType, 'iconType id can not be null');
|
||||||
this.setAttribute('id', iconType);
|
this.setAttribute('id', iconType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @type {String}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
IconModel.FEATURE_TYPE = 'icon';
|
|
||||||
|
|
||||||
export default IconModel;
|
export default IconModel;
|
@ -20,7 +20,7 @@ import FeatureModel from './FeatureModel';
|
|||||||
|
|
||||||
class LinkModel extends FeatureModel {
|
class LinkModel extends FeatureModel {
|
||||||
constructor(attributes) {
|
constructor(attributes) {
|
||||||
super(LinkModel.FEATURE_TYPE);
|
super('link');
|
||||||
this.setUrl(attributes.url);
|
this.setUrl(attributes.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class LinkModel extends FeatureModel {
|
|||||||
* @param {String} url a URL provided by the user to set the link to
|
* @param {String} url a URL provided by the user to set the link to
|
||||||
* @throws will throw an error if url is null or undefined
|
* @throws will throw an error if url is null or undefined
|
||||||
*/
|
*/
|
||||||
setUrl(url) {
|
setUrl(url: string): void {
|
||||||
$assert(url, 'url can not be null');
|
$assert(url, 'url can not be null');
|
||||||
|
|
||||||
const fixedUrl = LinkModel._fixUrl(url);
|
const fixedUrl = LinkModel._fixUrl(url);
|
||||||
@ -44,7 +44,7 @@ class LinkModel extends FeatureModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// url format is already checked in LinkEditor.checkUrl
|
// url format is already checked in LinkEditor.checkUrl
|
||||||
static _fixUrl(url) {
|
static _fixUrl(url: string): string {
|
||||||
let result = url;
|
let result = url;
|
||||||
if (!result.includes('http://') && !result.includes('https://') && !result.includes('mailto://')) {
|
if (!result.includes('http://') && !result.includes('https://') && !result.includes('mailto://')) {
|
||||||
result = `http://${result}`;
|
result = `http://${result}`;
|
||||||
@ -61,12 +61,4 @@ class LinkModel extends FeatureModel {
|
|||||||
this.setAttribute('urlType', urlType);
|
this.setAttribute('urlType', urlType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @type {String}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
LinkModel.FEATURE_TYPE = 'link';
|
|
||||||
|
|
||||||
export default LinkModel;
|
export default LinkModel;
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import IMindmap from './IMindmap';
|
import IMindmap from './IMindmap';
|
||||||
import INodeModel from './INodeModel';
|
import INodeModel, { NodeModelType } from './INodeModel';
|
||||||
import NodeModel from './NodeModel';
|
import NodeModel from './NodeModel';
|
||||||
import RelationshipModel from './RelationshipModel';
|
import RelationshipModel from './RelationshipModel';
|
||||||
import ModelCodeName from '../persistence/ModelCodeName';
|
import ModelCodeName from '../persistence/ModelCodeName';
|
||||||
@ -79,10 +79,10 @@ class Mindmap extends IMindmap {
|
|||||||
$assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
|
$assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
|
||||||
const branches = this.getBranches();
|
const branches = this.getBranches();
|
||||||
if (branches.length === 0) {
|
if (branches.length === 0) {
|
||||||
$assert(nodeModel.getType() === INodeModel.CENTRAL_TOPIC_TYPE, 'First element must be the central topic');
|
$assert(nodeModel.getType() === 'CentralTopic', 'First element must be the central topic');
|
||||||
nodeModel.setPosition(0, 0);
|
nodeModel.setPosition(0, 0);
|
||||||
} else {
|
} else {
|
||||||
$assert(nodeModel.getType() !== INodeModel.CENTRAL_TOPIC_TYPE, 'Mindmaps only have one cental topic');
|
$assert(nodeModel.getType() !== 'CentralTopic', 'Mindmaps only have one cental topic');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._branches.push(nodeModel);
|
this._branches.push(nodeModel);
|
||||||
@ -91,7 +91,7 @@ class Mindmap extends IMindmap {
|
|||||||
/**
|
/**
|
||||||
* @param nodeModel
|
* @param nodeModel
|
||||||
*/
|
*/
|
||||||
removeBranch(nodeModel: NodeModel): void {
|
removeBranch(nodeModel: INodeModel): void {
|
||||||
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
|
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
|
||||||
this._branches = this._branches.filter((b) => b !== nodeModel);
|
this._branches = this._branches.filter((b) => b !== nodeModel);
|
||||||
}
|
}
|
||||||
@ -104,29 +104,22 @@ class Mindmap extends IMindmap {
|
|||||||
return this._relationships;
|
return this._relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param node
|
hasAlreadyAdded(node: NodeModel): boolean {
|
||||||
* @return {Boolean} true if node already exists
|
|
||||||
*/
|
|
||||||
hasAlreadyAdded(node: any) {
|
|
||||||
let result = false;
|
let result = false;
|
||||||
|
|
||||||
// Check in not connected nodes.
|
// Check in not connected nodes.
|
||||||
const branches = this._branches;
|
const branches = this._branches;
|
||||||
for (let i = 0; i < branches.length; i++) {
|
for (let i = 0; i < branches.length; i++) {
|
||||||
result = branches[i]._isChildNode(node);
|
result = branches[i].isChildNode(node);
|
||||||
if (result) {
|
if (result) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
createNode(type: NodeModelType = 'MainTopic', id: number) {
|
||||||
* @param type
|
|
||||||
* @param id
|
|
||||||
* @return the node model created
|
|
||||||
*/
|
|
||||||
createNode(type = INodeModel.MAIN_TOPIC_TYPE, id: number) {
|
|
||||||
return new NodeModel(type, this, id);
|
return new NodeModel(type, this, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +165,7 @@ class Mindmap extends IMindmap {
|
|||||||
|
|
||||||
static buildEmpty = (mapId: string) => {
|
static buildEmpty = (mapId: string) => {
|
||||||
const result = new Mindmap(mapId);
|
const result = new Mindmap(mapId);
|
||||||
const node = result.createNode(INodeModel.CENTRAL_TOPIC_TYPE, 0);
|
const node = result.createNode('CentralTopic', 0);
|
||||||
result.addBranch(node);
|
result.addBranch(node);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
@ -17,21 +17,28 @@
|
|||||||
*/
|
*/
|
||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import INodeModel from './INodeModel';
|
import INodeModel, { NodeModelType } from './INodeModel';
|
||||||
import FeatureModelFactory from './FeatureModelFactory';
|
import FeatureModelFactory from './FeatureModelFactory';
|
||||||
|
import FeatureModel from './FeatureModel';
|
||||||
|
import Mindmap from './Mindmap';
|
||||||
|
|
||||||
class NodeModel extends INodeModel {
|
class NodeModel extends INodeModel {
|
||||||
constructor(type, mindmap, id) {
|
_properties: {};
|
||||||
|
_children: INodeModel[];
|
||||||
|
_features: FeatureModel[];
|
||||||
|
_parent: INodeModel;
|
||||||
|
|
||||||
|
constructor(type: NodeModelType, mindmap: Mindmap, id: number) {
|
||||||
$assert(type, 'Node type can not be null');
|
$assert(type, 'Node type can not be null');
|
||||||
$assert(mindmap, 'mindmap can not be null');
|
$assert(mindmap, 'mindmap can not be null');
|
||||||
super(mindmap);
|
super(mindmap);
|
||||||
this._properties = {};
|
this._properties = {};
|
||||||
this.setId(id);
|
this.setId(id);
|
||||||
this.setType(type);
|
this.setType(type);
|
||||||
this.areChildrenShrunken(false);
|
this.areChildrenShrunken();
|
||||||
|
|
||||||
this._children = [];
|
this._children = [];
|
||||||
this._feature = [];
|
this._features = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,12 +56,12 @@ class NodeModel extends INodeModel {
|
|||||||
*/
|
*/
|
||||||
addFeature(feature) {
|
addFeature(feature) {
|
||||||
$assert(feature, 'feature can not be null');
|
$assert(feature, 'feature can not be null');
|
||||||
this._feature.push(feature);
|
this._features.push(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
getFeatures() {
|
getFeatures() {
|
||||||
return this._feature;
|
return this._features;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,9 +71,9 @@ class NodeModel extends INodeModel {
|
|||||||
*/
|
*/
|
||||||
removeFeature(feature) {
|
removeFeature(feature) {
|
||||||
$assert(feature, 'feature can not be null');
|
$assert(feature, 'feature can not be null');
|
||||||
const size = this._feature.length;
|
const size = this._features.length;
|
||||||
this._feature = this._feature.filter((f) => feature.getId() !== f.getId());
|
this._features = this._features.filter((f) => feature.getId() !== f.getId());
|
||||||
$assert(size - 1 === this._feature.length, 'Could not be removed ...');
|
$assert(size - 1 === this._features.length, 'Could not be removed ...');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,7 +82,7 @@ class NodeModel extends INodeModel {
|
|||||||
*/
|
*/
|
||||||
findFeatureByType(type) {
|
findFeatureByType(type) {
|
||||||
$assert(type, 'type can not be null');
|
$assert(type, 'type can not be null');
|
||||||
return this._feature.filter((feature) => feature.getType() === type);
|
return this._features.filter((feature) => feature.getType() === type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +93,7 @@ class NodeModel extends INodeModel {
|
|||||||
*/
|
*/
|
||||||
findFeatureById(id) {
|
findFeatureById(id) {
|
||||||
$assert($defined(id), 'id can not be null');
|
$assert($defined(id), 'id can not be null');
|
||||||
const result = this._feature.filter((feature) => feature.getId() === id);
|
const result = this._features.filter((feature) => feature.getId() === id);
|
||||||
$assert(result.length === 1, `Feature could not be found:${id}`);
|
$assert(result.length === 1, `Feature could not be found:${id}`);
|
||||||
return result[0];
|
return result[0];
|
||||||
}
|
}
|
||||||
@ -112,7 +119,7 @@ class NodeModel extends INodeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
getProperty(key) {
|
getProperty(key: string) {
|
||||||
$defined(key, 'key can not be null');
|
$defined(key, 'key can not be null');
|
||||||
const result = this._properties[key];
|
const result = this._properties[key];
|
||||||
return !$defined(result) ? null : result;
|
return !$defined(result) ? null : result;
|
||||||
@ -122,15 +129,15 @@ class NodeModel extends INodeModel {
|
|||||||
* @return {mindplot.model.NodeModel} an identical clone of the NodeModel
|
* @return {mindplot.model.NodeModel} an identical clone of the NodeModel
|
||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
const result = new NodeModel(this.getType(), this._mindmap);
|
const result = new NodeModel(this.getType(), this._mindmap, -1);
|
||||||
result._children = this._children.map((node) => {
|
result._children = this._children.map((node) => {
|
||||||
const cnode = node.clone();
|
const cnode = node.clone() as NodeModel;
|
||||||
cnode._parent = result;
|
cnode._parent = result;
|
||||||
return cnode;
|
return cnode;
|
||||||
});
|
});
|
||||||
|
|
||||||
result._properties = cloneDeep(this._properties);
|
result._properties = cloneDeep(this._properties);
|
||||||
result._feature = cloneDeep(this._feature);
|
result._features = cloneDeep(this._features);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,19 +145,19 @@ class NodeModel extends INodeModel {
|
|||||||
* Similar to clone, assign new id to the elements ...
|
* Similar to clone, assign new id to the elements ...
|
||||||
* @return {mindplot.model.NodeModel}
|
* @return {mindplot.model.NodeModel}
|
||||||
*/
|
*/
|
||||||
deepCopy() {
|
deepCopy(): NodeModel {
|
||||||
const result = new NodeModel(this.getType(), this._mindmap);
|
const result = new NodeModel(this.getType(), this._mindmap, -1);
|
||||||
result._children = this._children.map((node) => {
|
result._children = this._children.map((node) => {
|
||||||
const cnode = node.deepCopy();
|
const cnode = (node as NodeModel).deepCopy();
|
||||||
cnode._parent = result;
|
cnode._parent = result;
|
||||||
return cnode;
|
return cnode;
|
||||||
});
|
});
|
||||||
|
|
||||||
const id = result.getId();
|
const id = result.getId();
|
||||||
result._properties = Object.clone(this._properties);
|
result._properties = Object.assign({}, this._properties);
|
||||||
result.setId(id);
|
result.setId(id);
|
||||||
|
|
||||||
result._feature = this._feature.clone();
|
result._features = cloneDeep(this._features);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +165,7 @@ class NodeModel extends INodeModel {
|
|||||||
* @param {mindplot.model.NodeModel} child
|
* @param {mindplot.model.NodeModel} child
|
||||||
* @throws will throw an error if child is null, undefined or not a NodeModel object
|
* @throws will throw an error if child is null, undefined or not a NodeModel object
|
||||||
*/
|
*/
|
||||||
append(child) {
|
append(child: NodeModel) {
|
||||||
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
|
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
|
||||||
this._children.push(child);
|
this._children.push(child);
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
@ -169,7 +176,7 @@ class NodeModel extends INodeModel {
|
|||||||
* @param {mindplot.model.NodeModel} child
|
* @param {mindplot.model.NodeModel} child
|
||||||
* @throws will throw an error if child is null, undefined or not a NodeModel object
|
* @throws will throw an error if child is null, undefined or not a NodeModel object
|
||||||
*/
|
*/
|
||||||
removeChild(child) {
|
removeChild(child): void {
|
||||||
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.');
|
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.');
|
||||||
this._children = this._children.filter((c) => c !== child);
|
this._children = this._children.filter((c) => c !== child);
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
@ -192,44 +199,6 @@ class NodeModel extends INodeModel {
|
|||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
_isChildNode(node) {
|
|
||||||
let result = false;
|
|
||||||
if (node === this) {
|
|
||||||
result = true;
|
|
||||||
} else {
|
|
||||||
const children = this.getChildren();
|
|
||||||
for (let i = 0; i < children.length; i++) {
|
|
||||||
const child = children[i];
|
|
||||||
result = child._isChildNode(node);
|
|
||||||
if (result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @id
|
|
||||||
* @return {mindplot.model.NodeModel} the node with the respective id
|
|
||||||
*/
|
|
||||||
findNodeById(id) {
|
|
||||||
$assert(Number.isFinite(id));
|
|
||||||
let result = null;
|
|
||||||
if (this.getId() === id) {
|
|
||||||
result = this;
|
|
||||||
} else {
|
|
||||||
const children = this.getChildren();
|
|
||||||
for (let i = 0; i < children.length; i++) {
|
|
||||||
const child = children[i];
|
|
||||||
result = child.findNodeById(id);
|
|
||||||
if (result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NodeModel;
|
export default NodeModel;
|
@ -20,7 +20,7 @@ import FeatureModel from './FeatureModel';
|
|||||||
|
|
||||||
class NoteModel extends FeatureModel {
|
class NoteModel extends FeatureModel {
|
||||||
constructor(attributes) {
|
constructor(attributes) {
|
||||||
super(NoteModel.FEATURE_TYPE);
|
super('note');
|
||||||
const noteText = attributes.text ? attributes.text : ' ';
|
const noteText = attributes.text ? attributes.text : ' ';
|
||||||
this.setText(noteText);
|
this.setText(noteText);
|
||||||
}
|
}
|
||||||
@ -37,11 +37,4 @@ class NoteModel extends FeatureModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @type {String}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
NoteModel.FEATURE_TYPE = 'note';
|
|
||||||
|
|
||||||
export default NoteModel;
|
export default NoteModel;
|
@ -19,7 +19,17 @@ import { $assert, $defined } from '@wisemapping/core-js';
|
|||||||
import ConnectionLine from '../ConnectionLine';
|
import ConnectionLine from '../ConnectionLine';
|
||||||
|
|
||||||
class RelationshipModel {
|
class RelationshipModel {
|
||||||
constructor(sourceTopicId, targetTopicId) {
|
static _next_uuid: number = 0;
|
||||||
|
_id: number;
|
||||||
|
_sourceTargetId: number;
|
||||||
|
_targetTopicId: number;
|
||||||
|
_lineType: number;
|
||||||
|
_srcCtrlPoint: any;
|
||||||
|
_destCtrlPoint: any;
|
||||||
|
_endArrow: boolean;
|
||||||
|
_startArrow: boolean;
|
||||||
|
|
||||||
|
constructor(sourceTopicId: number, targetTopicId: number) {
|
||||||
$assert($defined(sourceTopicId), 'from node type can not be null');
|
$assert($defined(sourceTopicId), 'from node type can not be null');
|
||||||
$assert($defined(targetTopicId), 'to node type can not be null');
|
$assert($defined(targetTopicId), 'to node type can not be null');
|
||||||
$assert(Number.isFinite(sourceTopicId), 'sourceTopicId is not a number');
|
$assert(Number.isFinite(sourceTopicId), 'sourceTopicId is not a number');
|
||||||
@ -118,23 +128,19 @@ class RelationshipModel {
|
|||||||
/**
|
/**
|
||||||
* @return {String} textual information about the relationship's source and target node
|
* @return {String} textual information about the relationship's source and target node
|
||||||
*/
|
*/
|
||||||
inspect() {
|
inspect(): string {
|
||||||
return (
|
return (
|
||||||
`(fromNode:${this.getFromNode().getId()
|
`(fromNode:${this.getFromNode()
|
||||||
} , toNode: ${this.getToNode().getId()
|
} , toNode: ${this.getToNode()
|
||||||
})`
|
})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function _nextUUID() {
|
static _nextUUID() {
|
||||||
if (!$defined(RelationshipModel._uuid)) {
|
RelationshipModel._next_uuid += 1;
|
||||||
RelationshipModel._uuid = 0;
|
return RelationshipModel._next_uuid;
|
||||||
}
|
}
|
||||||
RelationshipModel._uuid += 1;
|
|
||||||
return RelationshipModel._uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RelationshipModel._nextUUID = _nextUUID;
|
|
||||||
|
|
||||||
export default RelationshipModel;
|
export default RelationshipModel;
|
Loading…
Reference in New Issue
Block a user