2021-07-16 16:41:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright [2015] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2021-12-04 01:11:17 +01:00
|
|
|
import { $assert } from '@wisemapping/core-js';
|
2021-12-02 01:41:56 +01:00
|
|
|
import TopicConfig from './TopicConfig';
|
|
|
|
import DragTopic from './DragTopic';
|
2021-09-07 22:31:46 +02:00
|
|
|
|
|
|
|
const NodeGraph = new Class(
|
2021-10-05 02:05:34 +02:00
|
|
|
/** @lends NodeGraph */ {
|
|
|
|
/**
|
2021-09-07 22:31:46 +02:00
|
|
|
* @constructs
|
|
|
|
* @param {mindplot.model.NodeModel} nodeModel
|
|
|
|
* @param {Object<Number, String, Boolean>} options
|
|
|
|
* @throws will throw an error if nodeModel is null or undefined
|
|
|
|
*/
|
2021-10-05 02:05:34 +02:00
|
|
|
initialize(nodeModel, options) {
|
|
|
|
$assert(nodeModel, 'model can not be null');
|
|
|
|
|
|
|
|
this._options = options;
|
|
|
|
this._mouseEvents = true;
|
|
|
|
this.setModel(nodeModel);
|
|
|
|
this._onFocus = false;
|
|
|
|
this._size = { width: 50, height: 20 };
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @return true if option is set to read-only */
|
|
|
|
isReadOnly() {
|
|
|
|
return this._options.readOnly;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @return model type */
|
|
|
|
getType() {
|
|
|
|
const model = this.getModel();
|
|
|
|
return model.getType();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2021-09-07 22:31:46 +02:00
|
|
|
* @param {String} id
|
|
|
|
* @throws will throw an error if the topic id is not a number
|
|
|
|
*/
|
2021-10-05 02:05:34 +02:00
|
|
|
setId(id) {
|
|
|
|
$assert(typeof topic.getId() === 'number', `id is not a number:${id}`);
|
|
|
|
this.getModel().setId(id);
|
|
|
|
},
|
2021-09-07 22:31:46 +02:00
|
|
|
|
2021-10-05 02:05:34 +02:00
|
|
|
_set2DElement(elem2d) {
|
|
|
|
this._elem2d = elem2d;
|
|
|
|
},
|
2021-09-07 22:31:46 +02:00
|
|
|
|
2021-10-05 02:05:34 +02:00
|
|
|
/**
|
2021-09-07 22:31:46 +02:00
|
|
|
* @return 2D element
|
|
|
|
* @throws will throw an error if the element is null or undefined within node graph
|
|
|
|
*/
|
2021-10-05 02:05:34 +02:00
|
|
|
get2DElement() {
|
|
|
|
$assert(this._elem2d, 'NodeGraph has not been initialized properly');
|
|
|
|
return this._elem2d;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @abstract */
|
|
|
|
setPosition(point, fireEvent) {
|
2021-12-02 01:41:56 +01:00
|
|
|
throw new Error('Unsupported operation');
|
2021-10-05 02:05:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
addEvent(type, listener) {
|
|
|
|
const elem = this.get2DElement();
|
|
|
|
elem.addEvent(type, listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
removeEvent(type, listener) {
|
|
|
|
const elem = this.get2DElement();
|
|
|
|
elem.removeEvent(type, listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
fireEvent(type, event) {
|
|
|
|
const elem = this.get2DElement();
|
|
|
|
elem.trigger(type, event);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
setMouseEventsEnabled(isEnabled) {
|
|
|
|
this._mouseEvents = isEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
isMouseEventsEnabled() {
|
|
|
|
return this._mouseEvents;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @return {Object<Number>} size */
|
|
|
|
getSize() {
|
|
|
|
return this._size;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @param {Object<Number>} size */
|
|
|
|
setSize(size) {
|
2021-12-02 01:41:56 +01:00
|
|
|
this._size.width = parseInt(size.width, 10);
|
|
|
|
this._size.height = parseInt(size.height, 10);
|
2021-10-05 02:05:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2021-09-07 22:31:46 +02:00
|
|
|
* @return {mindplot.model.NodeModel} the node model
|
|
|
|
*/
|
2021-10-05 02:05:34 +02:00
|
|
|
getModel() {
|
|
|
|
$assert(this._model, 'Model has not been initialized yet');
|
|
|
|
return this._model;
|
|
|
|
},
|
2021-09-07 22:31:46 +02:00
|
|
|
|
2021-10-05 02:05:34 +02:00
|
|
|
/**
|
2021-09-07 22:31:46 +02:00
|
|
|
* @param {mindplot.NodeModel} model the node model
|
|
|
|
* @throws will throw an error if model is null or undefined
|
|
|
|
*/
|
2021-10-05 02:05:34 +02:00
|
|
|
setModel(model) {
|
|
|
|
$assert(model, 'Model can not be null');
|
|
|
|
this._model = model;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
getId() {
|
|
|
|
return this._model.getId();
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
setOnFocus(focus) {
|
2021-12-02 01:41:56 +01:00
|
|
|
if (this._onFocus !== focus) {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._onFocus = focus;
|
|
|
|
const outerShape = this.getOuterShape();
|
|
|
|
if (focus) {
|
2021-12-02 01:41:56 +01:00
|
|
|
outerShape.setFill(TopicConfig.OUTER_SHAPE_ATTRIBUTES_FOCUS.fillColor);
|
2021-10-05 02:05:34 +02:00
|
|
|
outerShape.setOpacity(1);
|
|
|
|
} else {
|
2021-12-02 01:41:56 +01:00
|
|
|
outerShape.setFill(TopicConfig.OUTER_SHAPE_ATTRIBUTES.fillColor);
|
2021-10-05 02:05:34 +02:00
|
|
|
outerShape.setOpacity(0);
|
|
|
|
}
|
|
|
|
this.setCursor('move');
|
|
|
|
|
|
|
|
// In any case, always try to hide the editor ...
|
|
|
|
this.closeEditors();
|
|
|
|
|
|
|
|
// Fire event ...
|
|
|
|
this.fireEvent(focus ? 'ontfocus' : 'ontblur', this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** @return {Boolean} true if the node graph is on focus */
|
|
|
|
isOnFocus() {
|
|
|
|
return this._onFocus;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
dispose(workspace) {
|
|
|
|
this.setOnFocus(false);
|
|
|
|
workspace.removeChild(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
createDragNode(layoutManager) {
|
|
|
|
const dragShape = this._buildDragShape();
|
|
|
|
return new DragTopic(dragShape, this, layoutManager);
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildDragShape() {
|
|
|
|
$assert(false, '_buildDragShape must be implemented by all nodes.');
|
|
|
|
},
|
|
|
|
|
|
|
|
/** */
|
|
|
|
getPosition() {
|
|
|
|
const model = this.getModel();
|
|
|
|
return model.getPosition();
|
|
|
|
},
|
|
|
|
},
|
2021-09-07 22:31:46 +02:00
|
|
|
);
|
2021-07-16 16:41:58 +02:00
|
|
|
|
|
|
|
export default NodeGraph;
|