Mindplot module migration

This commit is contained in:
Ezequiel-Vega 2021-09-02 13:32:23 -03:00
parent d515e0bb57
commit 0567dedb88
37 changed files with 11320 additions and 3725 deletions

View File

@ -8,6 +8,6 @@ function coreJs() {
require('./Utils'); // eslint-disable-line require('./Utils'); // eslint-disable-line
global.Options = require('@wisemapping/mindplot/lib/components/Options'); global.Options = require('@wisemapping/mindplot/lib/components/Options');
global.BootstrapDialog = require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog'); global.BootstrapDialog = require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog');
//require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request'); require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request');
return global.core; // eslint-disable-line no-undef return global.core; // eslint-disable-line no-undef
} }

View File

@ -15,25 +15,25 @@
* 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.
*/ */
const Core = require('@wismapping/core-js') const Core = require('@wismapping/core-js');
const core = Core(); const core = Core();
const Topic = require('./Topic').default; const Topic = require('./Topic').default;
const Shape = require('./util/Shape').default; const Shape = require('./util/Shape').default;
const CentralTopic = new Class(/** @lends CentralTopic*/{ const CentralTopic = new Class(
/** @lends CentralTopic*/ {
Extends:Topic, Extends: Topic,
/** /**
* @extends mindplot.Topic * @extends mindplot.Topic
* @constructs * @constructs
* @param model * @param model
* @param options * @param options
*/ */
initialize:function (model, options) { initialize: function (model, options) {
this.parent(model, options); this.parent(model, options);
}, },
_registerEvents:function () { _registerEvents: function () {
this.parent(); this.parent();
// This disable the drag of the central topic. But solves the problem of deselecting the nodes when the screen is clicked. // This disable the drag of the central topic. But solves the problem of deselecting the nodes when the screen is clicked.
@ -43,41 +43,39 @@ const CentralTopic = new Class(/** @lends CentralTopic*/{
}, },
/** */ /** */
workoutIncomingConnectionPoint:function () { workoutIncomingConnectionPoint: function () {
return this.getPosition(); return this.getPosition();
}, },
/** */ /** */
setCursor:function (type) { setCursor: function (type) {
type = (type == 'move') ? 'default' : type; type = type == 'move' ? 'default' : type;
this.parent(type); this.parent(type);
}, },
/** */ /** */
updateTopicShape:function () { updateTopicShape: function () {},
},
_updatePositionOnChangeSize:function () {
_updatePositionOnChangeSize: function () {
// Center main topic ... // Center main topic ...
var zeroPoint = new core.Point(0, 0); var zeroPoint = new core.Point(0, 0);
this.setPosition(zeroPoint); this.setPosition(zeroPoint);
}, },
/** */ /** */
getShrinkConnector:function () { getShrinkConnector: function () {
return null; return null;
}, },
/** */ /** */
workoutOutgoingConnectionPoint:function (targetPosition) { workoutOutgoingConnectionPoint: function (targetPosition) {
$assert(targetPosition, 'targetPoint can not be null'); $assert(targetPosition, 'targetPoint can not be null');
var pos = this.getPosition(); var pos = this.getPosition();
var isAtRight = Shape.isAtRight(targetPosition, pos); var isAtRight = Shape.isAtRight(targetPosition, pos);
var size = this.getSize(); var size = this.getSize();
return Shape.calculateRectConnectionPoint(pos, size, !isAtRight); return Shape.calculateRectConnectionPoint(pos, size, !isAtRight);
},
} }
}); );
export default CentralTopic; export default CentralTopic;

View File

@ -21,7 +21,7 @@ const web2D = require('@wismapping/web2d');
const web2d = web2D(); const web2d = web2D();
const INodeModel = require('./model/INodeModel').default; const INodeModel = require('./model/INodeModel').default;
const { TopicShape } = require('./model/INodeModel').default; const { TopicShape } = require('./model/INodeModel');
const Topic = require('./Topic').default; const Topic = require('./Topic').default;
const ConnectionLine = new Class({ const ConnectionLine = new Class({

View File

@ -24,8 +24,7 @@ const Topic = require('./Topic').default;
const { TopicShape } = require('./model/INodeModel'); const { TopicShape } = require('./model/INodeModel');
const Shape = require('./util/Shape').default; const Shape = require('./util/Shape').default;
const MainTopic = new Class( const MainTopic = new Class(/** @lends MainTopic */ {
/** @lends MainTopic */ {
Extends: Topic, Extends: Topic,
/** /**
* @extends mindplot.Topic * @extends mindplot.Topic

View File

@ -31,7 +31,7 @@ const Messages = new Class({
}, },
}); });
global.$msg = function (key) { const $msg = function (key) {
if (!Messages.__bundle) { if (!Messages.__bundle) {
Messages.init('en'); Messages.init('en');
} }

View File

@ -201,6 +201,7 @@ const NodeGraph = new Class(
NodeGraph.create = function (nodeModel, options) { NodeGraph.create = function (nodeModel, options) {
const CentralTopic = require('./CentralTopic').default; const CentralTopic = require('./CentralTopic').default;
const MainTopic = require('./MainTopic').default; const MainTopic = require('./MainTopic').default;
$assert(nodeModel, 'Model can not be null'); $assert(nodeModel, 'Model can not be null');
var type = nodeModel.getType(); var type = nodeModel.getType();

View File

@ -15,14 +15,13 @@
* 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.
*/ */
const RichTextEditor = require('./Ri')
const TextEditor = require('./TextEditor').default; const TextEditor = require('./TextEditor').default;
const TextEditorFactory = {}; const TextEditorFactory = {};
TextEditorFactory.getTextEditorFromName = function (name) { TextEditorFactory.getTextEditorFromName = function (name) {
var editorClass = null; var editorClass = null;
if (name == "RichTextEditor") { if (name == 'RichTextEditor') {
editorClass = RichTextEditor; editorClass = RichTextEditor;
} else { } else {
editorClass = TextEditor; editorClass = TextEditor;

View File

@ -17,7 +17,6 @@
*/ */
const Events = require('./Events').default; const Events = require('./Events').default;
const MultilineTextEditor = require('./MultilineTextEditor').default; const MultilineTextEditor = require('./MultilineTextEditor').default;
//const TopicEvent = require('./Topic').default;
const { TopicShape } = require('./model/INodeModel'); const { TopicShape } = require('./model/INodeModel');
const TopicEventDispatcher = new Class({ const TopicEventDispatcher = new Class({

View File

@ -1,14 +1,16 @@
const acitonDispatcher = require('./ActionDispatcher').default; import LocalStorageManager from './LocalStorageManager';
const actionDispatcher = require('./ActionDispatcher').default;
const actionIcon = require('./ActionIcon').default; const actionIcon = require('./ActionIcon').default;
const centralTopic = require('./CentralTopic').default; const centralTopic = require('./CentralTopic').default;
const command = require('./Command').default; const command = require('./Command').default;
const connectionLine = require('./ConnectionLine').default; const connectionLine = require('./ConnectionLine').default;
const controlPoint = require('./ControlPoint').default; const controlPoint = require('./ControlPoint').default;
const designer = require('./Designer').default; const designer = require('./Designer').default;
const designerAcitonRun = require('./DesignerActionRunner').default; const designerActionRunner = require('./DesignerActionRunner').default;
const designerKeyboard = require('./DesignerKeyboard').default; const designerKeyboard = require('./DesignerKeyboard').default;
const desginerModel = require('./DesignerModel').default; const designerModal = require('./DesignerModel').default;
const desginerUndoManager = require('./DesignerUndoManager').default; const designerUndoManager = require('./DesignerUndoManager').default;
const dragConnector = require('./DragConnector').default; const dragConnector = require('./DragConnector').default;
const dragManager = require('./DragManager').default; const dragManager = require('./DragManager').default;
const dragPivot = require('./DragPivot').default; const dragPivot = require('./DragPivot').default;
@ -17,36 +19,28 @@ const editorOptions = require('./EditorOptions').default;
const editorProperties = require('./EditorProperties').default; const editorProperties = require('./EditorProperties').default;
const events = require('./Events').default; const events = require('./Events').default;
const footer = require('./footer'); const footer = require('./footer');
//const header =require('./header'); const header = require('./header');
const icon = require('./Icon').default; const icon = require('./Icon').default;
const iconGroup = require('./IconGroup').default; const iconGroup = require('./IconGroup').default;
const imageIcon = require('./ImageIcon').default; const imageIcon = require('./ImageIcon').default;
const keyboard = require('./Keyboard').default; const keyboard = require('./Keyboard').default;
const linkIcon = require('./LinkIcon').default; const linkIcon = require('./LinkIcon').default;
const localStorageManager = require('./LocalStorageManager').default; const localSorageManager = require('./LocalStorageManager').default;
const mainTopic = require('./MainTopic').default; const mainTopic = require('./MainTopic').default;
const messages = require('./Messages').default; const messages = require('./Messages').default;
const messageBundle_ca = require('./MessageBundle_ca').default;
const messageBundle_de = require('./MessageBundle_de').default;
const messageBundle_en = require('./MessageBundle_en').default;
const messageBundle_es = require('./MessageBundle_es').default;
const messageBundle_fr = require('./MessageBundle_fr').default;
const messageBundle_pt_BR = require('./MessageBundle_pt_BR').default;
const messageBundle_zh_CN = require('./MessageBundle_zh_CN').default;
const messageBundle_zh_TW = require('./MessageBundle_zh_TW').default;
const multilineTextEditor = require('./MultilineTextEditor').default; const multilineTextEditor = require('./MultilineTextEditor').default;
const nodeGraph = require('./NodeGraph').default; const nodeGraph = require('./NodeGraph').default;
const noteIcon = require('./NoteIcon').default; const noteIcon = require('./NoteIcon').default;
const options = require('./Options').default; const options = require('./Options').default;
const persistenceManger = require('./PersistenceManager').default; const persistenceManager = require('./PersistenceManager').default;
const relationship = require('./Relationship').default; const relationship = require('./Relationship').default;
const relationshipPivot = require('./RelationshipPivot').default; const relationshipPivot = require('./RelationshipPivot').default;
const restPersistenceManager = require('./RestPersistenceManager').default; const resetPersistenceManager = require('./RestPersistenceManager').default;
const screenManager = require('./ScreenManager').default; const screenManager = require('./ScreenManager').default;
const shrinkConnector = require('./ShrinkConnector').default; const shrinkConnector = require('./ShrinkConnector').default;
const standaloneActionDispatcher = require('./StandaloneActionDispatcher').default; const standaloneActionDispatcher = require('./StandaloneActionDispatcher').default;
const textEditor = require('./TextEditor').default; const textEditor = require('./TextEditor').default;
//const textEditorFacotry = require('./TextEditorFactory').default; const textEditorFactory = require('./TextEditorFactory').default;
const topic = require('./Topic').default; const topic = require('./Topic').default;
const topicEventDispatcher = require('./TopicEventDispatcher').default; const topicEventDispatcher = require('./TopicEventDispatcher').default;
const topicFeature = require('./TopicFeature').default; const topicFeature = require('./TopicFeature').default;
@ -54,17 +48,17 @@ const topicStyle = require('./TopicStyle').default;
const workspace = require('./Workspace').default; const workspace = require('./Workspace').default;
export const Components = { export const Components = {
ActionDispatcher: acitonDispatcher, ActionDispatcher: actionDispatcher,
ActionIcon: actionIcon, ActionIcon: actionIcon,
CentralTopic: centralTopic, CentralTopic: centralTopic,
Command: command, Command: command,
ConnectionLine: connectionLine, ConnectionLine: connectionLine,
ControlPoint: controlPoint, ControlPoint: controlPoint,
Designer: designer, Designer: designer,
DesignerActionRunner: designerAcitonRun, DesignerActionRunner: designerActionRunner,
DesignerKeyboard: designerKeyboard, DesignerKeyboard: designerKeyboard,
DesignerModel: desginerModel, DesignerModel: designerModal,
DesignerUndoManager: desginerUndoManager, DesignerUndoManager: designerUndoManager,
DragConnector: dragConnector, DragConnector: dragConnector,
DragManager: dragManager, DragManager: dragManager,
DragPivot: dragPivot, DragPivot: dragPivot,
@ -72,34 +66,30 @@ export const Components = {
EditorOptions: editorOptions, EditorOptions: editorOptions,
EditorProperties: editorProperties, EditorProperties: editorProperties,
Events: events, Events: events,
footer: footer,
header: header,
Icon: icon, Icon: icon,
IconGroup: iconGroup, IconGroup: iconGroup,
ImageIcon: imageIcon, ImageIcon: imageIcon,
Keyboard: keyboard, Keyboard: keyboard,
LinkIcon: linkIcon, LinkIcon: linkIcon,
LocalStorageManager: localStorageManager,
localSorageManager: localSorageManager,
MainTopic: mainTopic, MainTopic: mainTopic,
MessageBundle_ca: messageBundle_ca,
MessageBundle_de: messageBundle_de,
MessageBundle_en: messageBundle_en,
MessageBundle_es: messageBundle_es,
MesasgeBundle_fr: messageBundle_fr,
MessageBundle_pt_BR: messageBundle_pt_BR,
MessageBundle_zh_CN: messageBundle_zh_CN,
MessageBundle_zh_TW: messageBundle_zh_TW,
Messages: messages, Messages: messages,
MultilineTextEditor: multilineTextEditor, MultilineTextEditor: multilineTextEditor,
NodeGraph: nodeGraph, NodeGraph: nodeGraph,
NoteIcon: noteIcon, NoteIcon: noteIcon,
Options: options, Options: options,
PersistenceManager: persistenceManger, PersistenceManager: persistenceManager,
Relationship: relationship, Relationship: relationship,
RelationshipPivot: relationshipPivot, RelationshipPivot: relationshipPivot,
RestPersistenceManager: restPersistenceManager, RestPersistenceManager: resetPersistenceManager,
ScreenManager: screenManager, ScreenManager: screenManager,
ShrinkConnector: shrinkConnector,
StandaloneActionDispatcher: standaloneActionDispatcher, StandaloneActionDispatcher: standaloneActionDispatcher,
TextEditor: textEditor, TextEditor: textEditor,
//TextEditorFactory: textEditorFacotry, TextEditorFactory: textEditorFactory,
Topic: topic, Topic: topic,
TopicEventDispatcher: topicEventDispatcher, TopicEventDispatcher: topicEventDispatcher,
TopicFeature: topicFeature, TopicFeature: topicFeature,

View File

@ -15,13 +15,14 @@
* 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.
*/ */
const ChildrenSorterStrategy = require('./ChildrenSorterStrategy').default const ChildrenSorterStrategy = require('./ChildrenSorterStrategy').default;
/** /**
* @class * @class
* @extends mindplot.layout.ChildrenSorterStrategy * @extends mindplot.layout.ChildrenSorterStrategy
*/ */
const AbstractBasicSorter = new Class(/** @lends AbstractBasicSorter */{ const AbstractBasicSorter = new Class(
/** @lends AbstractBasicSorter */ {
Extends: ChildrenSorterStrategy, Extends: ChildrenSorterStrategy,
/** /**
@ -29,18 +30,18 @@ const AbstractBasicSorter = new Class(/** @lends AbstractBasicSorter */{
* @param {} node * @param {} node
* @return the height of a node and its children if existing and not shrunken * @return the height of a node and its children if existing and not shrunken
*/ */
computeChildrenIdByHeights: function(treeSet, node) { computeChildrenIdByHeights: function (treeSet, node) {
var result = {}; var result = {};
this._computeChildrenHeight(treeSet, node, result); this._computeChildrenHeight(treeSet, node, result);
return result; return result;
}, },
_getVerticalPadding: function() { _getVerticalPadding: function () {
return AbstractBasicSorter.INTERNODE_VERTICAL_PADDING; return AbstractBasicSorter.INTERNODE_VERTICAL_PADDING;
}, },
_computeChildrenHeight : function(treeSet, node, heightCache) { _computeChildrenHeight: function (treeSet, node, heightCache) {
var height = node.getSize().height + (this._getVerticalPadding() * 2); // 2* Top and down padding; var height = node.getSize().height + this._getVerticalPadding() * 2; // 2* Top and down padding;
var result; var result;
var children = treeSet.getChildren(node); var children = treeSet.getChildren(node);
@ -48,9 +49,13 @@ const AbstractBasicSorter = new Class(/** @lends AbstractBasicSorter */{
result = height; result = height;
} else { } else {
var childrenHeight = 0; var childrenHeight = 0;
_.each(children, function(child) { _.each(
children,
function (child) {
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache); childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
}, this); },
this
);
result = Math.max(height, childrenHeight); result = Math.max(height, childrenHeight);
} }
@ -62,20 +67,20 @@ const AbstractBasicSorter = new Class(/** @lends AbstractBasicSorter */{
return result; return result;
}, },
_getSortedChildren:function(treeSet, node) { _getSortedChildren: function (treeSet, node) {
var result = treeSet.getChildren(node); var result = treeSet.getChildren(node);
result.sort(function(a, b) { result.sort(function (a, b) {
return a.getOrder() - b.getOrder() return a.getOrder() - b.getOrder();
}); });
return result; return result;
}, },
_getRelativeDirection: function(reference, position) { _getRelativeDirection: function (reference, position) {
var offset = position.x - reference.x; var offset = position.x - reference.x;
return offset >= 0 ? 1 : -1; return offset >= 0 ? 1 : -1;
},
} }
);
});
/** /**
* @constant * @constant

View File

@ -17,15 +17,14 @@
*/ */
const AbstractBasicSorter = require('./AbstractBasicSorter').default; const AbstractBasicSorter = require('./AbstractBasicSorter').default;
const BalancedSorter = new Class(/** @lends BalancedSorter */{ const BalancedSorter = new Class(
Extends:AbstractBasicSorter, /** @lends BalancedSorter */ {
Extends: AbstractBasicSorter,
/** /**
* @constructs * @constructs
* @extends mindplot.layout.AbstractBasicSorter * @extends mindplot.layout.AbstractBasicSorter
*/ */
initialize:function () { initialize: function () {},
},
/** /**
* @param {} graph * @param {} graph
@ -35,31 +34,53 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {Boolean} free * @param {Boolean} free
* @return an array with order and position * @return an array with order and position
*/ */
predict:function (graph, parent, node, position, free) { predict: function (graph, parent, node, position, free) {
// If its a free node... // If its a free node...
if (free) { if (free) {
$assert($defined(position), "position cannot be null for predict in free positioning"); $assert(
$assert($defined(node), "node cannot be null for predict in free positioning"); $defined(position),
'position cannot be null for predict in free positioning'
);
$assert($defined(node), 'node cannot be null for predict in free positioning');
var rootNode = graph.getRootNode(parent); var rootNode = graph.getRootNode(parent);
var direction = this._getRelativeDirection(rootNode.getPosition(), node.getPosition()); var direction = this._getRelativeDirection(
rootNode.getPosition(),
node.getPosition()
);
var limitXPos = parent.getPosition().x + direction * (parent.getSize().width / 2 + node.getSize().width / 2 + BalancedSorter.INTERNODE_HORIZONTAL_PADDING); var limitXPos =
parent.getPosition().x +
direction *
(parent.getSize().width / 2 +
node.getSize().width / 2 +
BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
var xPos = direction > 0 ? var xPos =
(position.x >= limitXPos ? position.x : limitXPos) : direction > 0
(position.x <= limitXPos ? position.x : limitXPos); ? position.x >= limitXPos
? position.x
: limitXPos
: position.x <= limitXPos
? position.x
: limitXPos;
return [0, {x:xPos, y:position.y}]; return [0, { x: xPos, y: position.y }];
} }
var rootNode = graph.getRootNode(parent); var rootNode = graph.getRootNode(parent);
// If it is a dragged node... // If it is a dragged node...
if (node) { if (node) {
$assert($defined(position), "position cannot be null for predict in dragging"); $assert($defined(position), 'position cannot be null for predict in dragging');
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition()); var nodeDirection = this._getRelativeDirection(
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position); rootNode.getPosition(),
node.getPosition()
);
var positionDirection = this._getRelativeDirection(
rootNode.getPosition(),
position
);
var siblings = graph.getSiblings(node); var siblings = graph.getSiblings(node);
var sameParent = parent == graph.getParent(node); var sameParent = parent == graph.getParent(node);
@ -73,7 +94,13 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
var left = this._getChildrenForOrder(parent, graph, 1); var left = this._getChildrenForOrder(parent, graph, 1);
} }
// Filter nodes on one side.. // Filter nodes on one side..
var order = position ? (position.x > rootNode.getPosition().x ? 0 : 1) : ((right.length - left.length) > 0 ? 1 : 0); var order = position
? position.x > rootNode.getPosition().x
? 0
: 1
: right.length - left.length > 0
? 1
: 0;
var direction = order % 2 == 0 ? 1 : -1; var direction = order % 2 == 0 ? 1 : -1;
// Exclude the dragged node (if set) // Exclude the dragged node (if set)
@ -83,30 +110,47 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
// No children? // No children?
if (children.length == 0) { if (children.length == 0) {
return [order, {x:parent.getPosition().x + direction * (parent.getSize().width / 2 + BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2), y:parent.getPosition().y}]; return [
order,
{
x:
parent.getPosition().x +
direction *
(parent.getSize().width / 2 +
BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2),
y: parent.getPosition().y,
},
];
} }
// Try to fit within ... // Try to fit within ...
var result = null; var result = null;
var last = children.getLast(); var last = children.getLast();
position = position || {x:last.getPosition().x, y:last.getPosition().y + 1}; position = position || { x: last.getPosition().x, y: last.getPosition().y + 1 };
_.each(children, function (child, index) { _.each(children, function (child, index) {
var cpos = child.getPosition(); var cpos = child.getPosition();
if (position.y > cpos.y) { if (position.y > cpos.y) {
yOffset = child == last ? let yOffset =
child.getSize().height + BalancedSorter.INTERNODE_VERTICAL_PADDING * 2 : child == last
(children[index + 1].getPosition().y - child.getPosition().y) / 2; ? child.getSize().height + BalancedSorter.INTERNODE_VERTICAL_PADDING * 2
result = [child.getOrder() + 2, {x:cpos.x, y:cpos.y + yOffset}]; : (children[index + 1].getPosition().y - child.getPosition().y) / 2;
result = [child.getOrder() + 2, { x: cpos.x, y: cpos.y + yOffset }];
} }
}); });
// Position wasn't below any node, so it must be inserted above // Position wasn't below any node, so it must be inserted above
if (!result) { if (!result) {
var first = children[0]; var first = children[0];
result = [position.x > 0 ? 0 : 1, { result = [
x:first.getPosition().x, position.x > 0 ? 0 : 1,
y:first.getPosition().y - first.getSize().height - BalancedSorter.INTERNODE_VERTICAL_PADDING * 2 {
}]; x: first.getPosition().x,
y:
first.getPosition().y -
first.getSize().height -
BalancedSorter.INTERNODE_VERTICAL_PADDING * 2,
},
];
} }
return result; return result;
@ -118,7 +162,7 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {} child * @param {} child
* @param {} order * @param {} order
*/ */
insert:function (treeSet, parent, child, order) { insert: function (treeSet, parent, child, order) {
var children = this._getChildrenForOrder(parent, treeSet, order); var children = this._getChildrenForOrder(parent, treeSet, order);
// If no children, return 0 or 1 depending on the side // If no children, return 0 or 1 depending on the side
@ -139,7 +183,7 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
} }
} }
var newOrder = order > (max + 1) ? (max + 2) : order; var newOrder = order > max + 1 ? max + 2 : order;
child.setOrder(newOrder); child.setOrder(newOrder);
}, },
@ -147,7 +191,7 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {} treeSet * @param {} treeSet
* @param {} node * @param {} node
*/ */
detach:function (treeSet, node) { detach: function (treeSet, node) {
var parent = treeSet.getParent(node); var parent = treeSet.getParent(node);
// Filter nodes on one side.. // Filter nodes on one side..
var children = this._getChildrenForOrder(parent, treeSet, node.getOrder()); var children = this._getChildrenForOrder(parent, treeSet, node.getOrder());
@ -165,18 +209,23 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {} node * @param {} node
* @return offsets * @return offsets
*/ */
computeOffsets:function (treeSet, node) { computeOffsets: function (treeSet, node) {
$assert(treeSet, "treeSet can no be null."); $assert(treeSet, 'treeSet can no be null.');
$assert(node, "node can no be null."); $assert(node, 'node can no be null.');
var children = this._getSortedChildren(treeSet, node); var children = this._getSortedChildren(treeSet, node);
// Compute heights ... // Compute heights ...
var heights = children.map( var heights = children
function (child) { .map(function (child) {
return {id:child.getId(), order:child.getOrder(), width:child.getSize().width, height:this._computeChildrenHeight(treeSet, child)}; return {
}, this).reverse(); id: child.getId(),
order: child.getOrder(),
width: child.getSize().width,
height: this._computeChildrenHeight(treeSet, child),
};
}, this)
.reverse();
// Compute the center of the branch ... // Compute the center of the branch ...
var totalPHeight = 0; var totalPHeight = 0;
@ -207,12 +256,16 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
} }
var yOffset = ysum + heights[i].height / 2; var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (node.getSize().width / 2 + heights[i].width / 2 + +BalancedSorter.INTERNODE_HORIZONTAL_PADDING); var xOffset =
direction *
(node.getSize().width / 2 +
heights[i].width / 2 +
+BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null"); $assert(!isNaN(xOffset), 'xOffset can not be null');
$assert(!isNaN(yOffset), "yOffset can not be null"); $assert(!isNaN(yOffset), 'yOffset can not be null');
result[heights[i].id] = {x:xOffset, y:yOffset}; result[heights[i].id] = { x: xOffset, y: yOffset };
} }
return result; return result;
}, },
@ -222,7 +275,7 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {} node * @param {} node
* @throw will throw an error if order elements are missing * @throw will throw an error if order elements are missing
*/ */
verify:function (treeSet, node) { verify: function (treeSet, node) {
// Check that all is consistent ... // Check that all is consistent ...
var children = this._getChildrenForOrder(node, treeSet, node.getOrder()); var children = this._getChildrenForOrder(node, treeSet, node.getOrder());
@ -230,8 +283,16 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
// All even numbered nodes should be "continuous" by themselves // All even numbered nodes should be "continuous" by themselves
var factor = node.getOrder() % 2 == 0 ? 2 : 1; var factor = node.getOrder() % 2 == 0 ? 2 : 1;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var order = i == 0 && factor == 1 ? 1 : (factor * i); var order = i == 0 && factor == 1 ? 1 : factor * i;
$assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i * factor) + ". Parent:" + node.getId() + ",Node:" + children[i].getId()); $assert(
children[i].getOrder() == order,
'Missing order elements. Missing order: ' +
i * factor +
'. Parent:' +
node.getId() +
',Node:' +
children[i].getId()
);
} }
}, },
@ -240,27 +301,28 @@ const BalancedSorter = new Class(/** @lends BalancedSorter */{
* @param {} child * @param {} child
* @return the direction of the child within the treeSet * @return the direction of the child within the treeSet
*/ */
getChildDirection:function (treeSet, child) { getChildDirection: function (treeSet, child) {
return child.getOrder() % 2 == 0 ? 1 : -1; return child.getOrder() % 2 == 0 ? 1 : -1;
}, },
/** /**
* @return {String} the print name of this class * @return {String} the print name of this class
*/ */
toString:function () { toString: function () {
return "Balanced Sorter"; return 'Balanced Sorter';
}, },
_getChildrenForOrder:function (parent, graph, order) { _getChildrenForOrder: function (parent, graph, order) {
return this._getSortedChildren(graph, parent).filter(function (child) { return this._getSortedChildren(graph, parent).filter(function (child) {
return child.getOrder() % 2 == order % 2; return child.getOrder() % 2 == order % 2;
}); });
}, },
_getVerticalPadding:function () { _getVerticalPadding: function () {
return BalancedSorter.INTERNODE_VERTICAL_PADDING; return BalancedSorter.INTERNODE_VERTICAL_PADDING;
},
} }
}); );
/** /**
* @constant * @constant

View File

@ -15,12 +15,13 @@
* 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.
*/ */
const Events = require('../Events').default const Events = require('../Events').default;
const RootedTreeSet = require('./RootedTreeSet').default const RootedTreeSet = require('./RootedTreeSet').default;
const OriginalLayout = require('./OriginalLayout').default const OriginalLayout = require('./OriginalLayout').default;
const ChangeEvent = require('./ChangeEvent').default; const ChangeEvent = require('./ChangeEvent').default;
const LayoutManager = new Class(/** @lends LayoutManager */{ const LayoutManager = new Class(
/** @lends LayoutManager */ {
Extends: Events, Extends: Events,
/** /**
* @constructs * @constructs
@ -30,10 +31,10 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if the root node id is null or undefined * @throws will throw an error if the root node id is null or undefined
* @throws will throw an error if the root size is null * @throws will throw an error if the root size is null
*/ */
initialize: function(rootNodeId, rootSize) { initialize: function (rootNodeId, rootSize) {
$assert($defined(rootNodeId), "rootNodeId can not be null"); $assert($defined(rootNodeId), 'rootNodeId can not be null');
$assert(rootSize, "rootSize can not be null"); $assert(rootSize, 'rootSize can not be null');
var position = position || {x:0, y:0}; var position = position || { x: 0, y: 0 };
this._treeSet = new RootedTreeSet(); this._treeSet = new RootedTreeSet();
this._layout = new OriginalLayout(this._treeSet); this._layout = new OriginalLayout(this._treeSet);
@ -48,8 +49,8 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @param size * @param size
* @throws will throw an error if id is null or undefined * @throws will throw an error if id is null or undefined
*/ */
updateNodeSize: function(id, size) { updateNodeSize: function (id, size) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
var node = this._treeSet.find(id); var node = this._treeSet.find(id);
node.setSize(size); node.setSize(size);
@ -62,9 +63,9 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if value is null or undefined * @throws will throw an error if value is null or undefined
* @return this * @return this
*/ */
updateShrinkState: function(id, value) { updateShrinkState: function (id, value) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
$assert($defined(value), "value can not be null"); $assert($defined(value), 'value can not be null');
var node = this._treeSet.find(id); var node = this._treeSet.find(id);
node.setShrunken(value); node.setShrunken(value);
@ -76,7 +77,7 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @param id * @param id
* @return {@link RootedTreeSet}.find(id) * @return {@link RootedTreeSet}.find(id)
*/ */
find: function(id) { find: function (id) {
return this._treeSet.find(id); return this._treeSet.find(id);
}, },
@ -88,16 +89,16 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if the position's x property is null or undefined * @throws will throw an error if the position's x property is null or undefined
* @throws will throw an error if the position's y property is null or undefined * @throws will throw an error if the position's y property is null or undefined
*/ */
moveNode: function(id, position) { moveNode: function (id, position) {
$assert($defined(id), "id cannot be null"); $assert($defined(id), 'id cannot be null');
$assert($defined(position), "position cannot be null"); $assert($defined(position), 'position cannot be null');
$assert($defined(position.x), "x can not be null"); $assert($defined(position.x), 'x can not be null');
$assert($defined(position.y), "y can not be null"); $assert($defined(position.y), 'y can not be null');
var node = this._treeSet.find(id); var node = this._treeSet.find(id);
// @Todo: this should not be here. This is broking the isolated node support... // @Todo: this should not be here. This is broking the isolated node support...
// node.setFree(true); // node.setFree(true);
// node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y - node.getPosition().y}); // node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y - node.getPosition().y});
node.setPosition(position); node.setPosition(position);
}, },
@ -110,10 +111,10 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if order is null or undefined * @throws will throw an error if order is null or undefined
* @return this * @return this
*/ */
connectNode: function(parentId, childId, order) { connectNode: function (parentId, childId, order) {
$assert($defined(parentId), "parentId cannot be null"); $assert($defined(parentId), 'parentId cannot be null');
$assert($defined(childId), "childId cannot be null"); $assert($defined(childId), 'childId cannot be null');
$assert($defined(order), "order cannot be null"); $assert($defined(order), 'order cannot be null');
this._layout.connectNode(parentId, childId, order); this._layout.connectNode(parentId, childId, order);
@ -125,8 +126,8 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if id is null or undefined * @throws will throw an error if id is null or undefined
* @return this * @return this
*/ */
disconnectNode: function(id) { disconnectNode: function (id) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
this._layout.disconnectNode(id); this._layout.disconnectNode(id);
return this; return this;
@ -139,8 +140,8 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if id is null or undefined * @throws will throw an error if id is null or undefined
* @return this * @return this
*/ */
addNode:function(id, size, position) { addNode: function (id, size, position) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
var result = this._layout.createNode(id, size, position, 'topic'); var result = this._layout.createNode(id, size, position, 'topic');
this._treeSet.add(result); this._treeSet.add(result);
@ -153,8 +154,8 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if id is null or undefined * @throws will throw an error if id is null or undefined
* @return this * @return this
*/ */
removeNode: function(id) { removeNode: function (id) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
var node = this._treeSet.find(id); var node = this._treeSet.find(id);
// Is It connected ? // Is It connected ?
@ -176,21 +177,21 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @param {Boolean=} free true specifies free node positioning * @param {Boolean=} free true specifies free node positioning
* @throws will throw an error if parentId is null or undefined * @throws will throw an error if parentId is null or undefined
*/ */
predict: function(parentId, nodeId, position, free) { predict: function (parentId, nodeId, position, free) {
$assert($defined(parentId), "parentId can not be null"); $assert($defined(parentId), 'parentId can not be null');
var parent = this._treeSet.find(parentId); var parent = this._treeSet.find(parentId);
var node = nodeId ? this._treeSet.find(nodeId) : null; var node = nodeId ? this._treeSet.find(nodeId) : null;
var sorter = parent.getSorter(); var sorter = parent.getSorter();
var result = sorter.predict(this._treeSet, parent, node, position, free); var result = sorter.predict(this._treeSet, parent, node, position, free);
return {order:result[0],position:result[1]}; return { order: result[0], position: result[1] };
}, },
/** /**
* logs dump to console * logs dump to console
*/ */
dump: function() { dump: function () {
console.log(this._treeSet.dump()); console.log(this._treeSet.dump());
}, },
@ -200,12 +201,19 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @throws will throw an error if containerId is null or undefined * @throws will throw an error if containerId is null or undefined
* @return canvas * @return canvas
*/ */
plot: function(containerId, size) { plot: function (containerId, size) {
$assert(containerId, "containerId cannot be null"); $assert(containerId, 'containerId cannot be null');
size = size || {width:200,height:200}; size = size || { width: 200, height: 200 };
var squaresize = 10; var squaresize = 10;
var canvas = Raphael(containerId, size.width, size.height); var canvas = Raphael(containerId, size.width, size.height);
canvas.drawGrid(0, 0, size.width, size.height, size.width / squaresize, size.height / squaresize); canvas.drawGrid(
0,
0,
size.width,
size.height,
size.width / squaresize,
size.height / squaresize
);
this._treeSet.plot(canvas); this._treeSet.plot(canvas);
return canvas; return canvas;
@ -216,37 +224,41 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
* @param fireEvents * @param fireEvents
* @return this * @return this
*/ */
layout: function(fireEvents) { layout: function (fireEvents) {
// File repositioning ... // File repositioning ...
this._layout.layout(); this._layout.layout();
// Collect changes ... // Collect changes ...
this._collectChanges(); this._collectChanges();
if ($(fireEvents).length>0 || fireEvents) { if ($(fireEvents).length > 0 || fireEvents) {
this._flushEvents(); this._flushEvents();
} }
return this; return this;
}, },
_flushEvents: function() { _flushEvents: function () {
_.each(this._events, function(event) { _.each(
this._events,
function (event) {
this.fireEvent('change', event); this.fireEvent('change', event);
}, this); },
this
);
this._events = []; this._events = [];
}, },
_collectChanges: function(nodes) { _collectChanges: function (nodes) {
if (!nodes) if (!nodes) nodes = this._treeSet.getTreeRoots();
nodes = this._treeSet.getTreeRoots();
_.each(nodes, function(node) { _.each(
nodes,
function (node) {
if (node.hasOrderChanged() || node.hasPositionChanged()) { if (node.hasOrderChanged() || node.hasPositionChanged()) {
// Find or create a event ... // Find or create a event ...
var id = node.getId(); var id = node.getId();
var event = this._events.some(function(event) { var event = this._events.some(function (event) {
return event.id == id; return event.id == id;
}); });
if (!event) { if (!event) {
@ -263,9 +275,11 @@ const LayoutManager = new Class(/** @lends LayoutManager */{
this._events.push(event); this._events.push(event);
} }
this._collectChanges(this._treeSet.getChildren(node)); this._collectChanges(this._treeSet.getChildren(node));
}, this); },
this
);
},
} }
);
});
export default LayoutManager; export default LayoutManager;

View File

@ -16,7 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
const Node = new Class(/** @lends Node */{ const Node = new Class(
/** @lends Node */ {
/** /**
* @constructs * @constructs
* @param id * @param id
@ -28,11 +29,11 @@ const Node = new Class(/** @lends Node */{
* @throws will throw an error if position is null or undefined * @throws will throw an error if position is null or undefined
* @throws will throw an error if sorter is null or undefined * @throws will throw an error if sorter is null or undefined
*/ */
initialize:function (id, size, position, sorter) { initialize: function (id, size, position, sorter) {
$assert(typeof id === 'number' && isFinite(id), "id can not be null"); $assert(typeof id === 'number' && isFinite(id), 'id can not be null');
$assert(size, "size can not be null"); $assert(size, 'size can not be null');
$assert(position, "position can not be null"); $assert(position, 'position can not be null');
$assert(sorter, "sorter can not be null"); $assert(sorter, 'sorter can not be null');
this._id = id; this._id = id;
this._sorter = sorter; this._sorter = sorter;
@ -44,48 +45,51 @@ const Node = new Class(/** @lends Node */{
}, },
/** */ /** */
getId:function () { getId: function () {
return this._id; return this._id;
}, },
/** */ /** */
setFree:function (value) { setFree: function (value) {
this._setProperty('free', value); this._setProperty('free', value);
}, },
/** */ /** */
isFree:function () { isFree: function () {
return this._getProperty('free'); return this._getProperty('free');
}, },
/** */ /** */
hasFreeChanged:function () { hasFreeChanged: function () {
return this._isPropertyChanged('free'); return this._isPropertyChanged('free');
}, },
/** */ /** */
hasFreeDisplacementChanged:function () { hasFreeDisplacementChanged: function () {
return this._isPropertyChanged('freeDisplacement'); return this._isPropertyChanged('freeDisplacement');
}, },
/** */ /** */
setShrunken:function (value) { setShrunken: function (value) {
this._setProperty('shrink', value); this._setProperty('shrink', value);
}, },
/** */ /** */
areChildrenShrunken:function () { areChildrenShrunken: function () {
return this._getProperty('shrink'); return this._getProperty('shrink');
}, },
/** */ /** */
setOrder:function (order) { setOrder: function (order) {
$assert(typeof order === 'number' && isFinite(order), "Order can not be null. Value:" + order); $assert(
typeof order === 'number' && isFinite(order),
'Order can not be null. Value:' + order
);
this._setProperty('order', order); this._setProperty('order', order);
}, },
/** */ /** */
resetPositionState:function () { resetPositionState: function () {
var prop = this._properties['position']; var prop = this._properties['position'];
if (prop) { if (prop) {
prop.hasChanged = false; prop.hasChanged = false;
@ -93,7 +97,7 @@ const Node = new Class(/** @lends Node */{
}, },
/** */ /** */
resetOrderState:function () { resetOrderState: function () {
var prop = this._properties['order']; var prop = this._properties['order'];
if (prop) { if (prop) {
prop.hasChanged = false; prop.hasChanged = false;
@ -101,7 +105,7 @@ const Node = new Class(/** @lends Node */{
}, },
/** */ /** */
resetFreeState:function () { resetFreeState: function () {
var prop = this._properties['freeDisplacement']; var prop = this._properties['freeDisplacement'];
if (prop) { if (prop) {
prop.hasChanged = false; prop.hasChanged = false;
@ -109,82 +113,89 @@ const Node = new Class(/** @lends Node */{
}, },
/** */ /** */
getOrder:function () { getOrder: function () {
return this._getProperty('order'); return this._getProperty('order');
}, },
/** */ /** */
hasOrderChanged:function () { hasOrderChanged: function () {
return this._isPropertyChanged('order'); return this._isPropertyChanged('order');
}, },
/** */ /** */
hasPositionChanged:function () { hasPositionChanged: function () {
return this._isPropertyChanged('position'); return this._isPropertyChanged('position');
}, },
/** */ /** */
hasSizeChanged:function () { hasSizeChanged: function () {
return this._isPropertyChanged('size'); return this._isPropertyChanged('size');
}, },
/** */ /** */
getPosition:function () { getPosition: function () {
return this._getProperty('position'); return this._getProperty('position');
}, },
/** */ /** */
setSize:function (size) { setSize: function (size) {
$assert($defined(size), "Size can not be null"); $assert($defined(size), 'Size can not be null');
this._setProperty('size', Object.clone(size)); this._setProperty('size', Object.clone(size));
}, },
/** */ /** */
getSize:function () { getSize: function () {
return this._getProperty('size'); return this._getProperty('size');
}, },
/** */ /** */
setFreeDisplacement:function (displacement) { setFreeDisplacement: function (displacement) {
$assert($defined(displacement), "Position can not be null"); $assert($defined(displacement), 'Position can not be null');
$assert($defined(displacement.x), "x can not be null"); $assert($defined(displacement.x), 'x can not be null');
$assert($defined(displacement.y), "y can not be null"); $assert($defined(displacement.y), 'y can not be null');
var oldDisplacement = this.getFreeDisplacement(); var oldDisplacement = this.getFreeDisplacement();
var newDisplacement = {x:oldDisplacement.x + displacement.x, y:oldDisplacement.y + displacement.y}; var newDisplacement = {
x: oldDisplacement.x + displacement.x,
y: oldDisplacement.y + displacement.y,
};
this._setProperty('freeDisplacement', Object.clone(newDisplacement)); this._setProperty('freeDisplacement', Object.clone(newDisplacement));
}, },
/** */ /** */
resetFreeDisplacement:function () { resetFreeDisplacement: function () {
this._setProperty('freeDisplacement', {x:0, y:0}); this._setProperty('freeDisplacement', { x: 0, y: 0 });
}, },
/** */ /** */
getFreeDisplacement:function () { getFreeDisplacement: function () {
var freeDisplacement = this._getProperty('freeDisplacement'); var freeDisplacement = this._getProperty('freeDisplacement');
return (freeDisplacement || {x:0, y:0}); return freeDisplacement || { x: 0, y: 0 };
}, },
/** */ /** */
setPosition:function (position) { setPosition: function (position) {
$assert($defined(position), "Position can not be null"); $assert($defined(position), 'Position can not be null');
$assert($defined(position.x), "x can not be null"); $assert($defined(position.x), 'x can not be null');
$assert($defined(position.y), "y can not be null"); $assert($defined(position.y), 'y can not be null');
// This is a performance improvement to avoid movements that really could be avoided. // This is a performance improvement to avoid movements that really could be avoided.
var currentPos = this.getPosition(); var currentPos = this.getPosition();
if (currentPos == null || Math.abs(currentPos.x - position.x) > 2 || Math.abs(currentPos.y - position.y) > 2) if (
currentPos == null ||
Math.abs(currentPos.x - position.x) > 2 ||
Math.abs(currentPos.y - position.y) > 2
)
this._setProperty('position', position); this._setProperty('position', position);
}, },
_setProperty:function (key, value) { _setProperty: function (key, value) {
var prop = this._properties[key]; var prop = this._properties[key];
if (!prop) { if (!prop) {
prop = { prop = {
hasChanged:false, hasChanged: false,
value:null, value: null,
oldValue:null oldValue: null,
}; };
} }
@ -197,26 +208,42 @@ const Node = new Class(/** @lends Node */{
this._properties[key] = prop; this._properties[key] = prop;
}, },
_getProperty:function (key) { _getProperty: function (key) {
var prop = this._properties[key]; var prop = this._properties[key];
return $defined(prop) ? prop.value : null; return $defined(prop) ? prop.value : null;
}, },
_isPropertyChanged:function (key) { _isPropertyChanged: function (key) {
var prop = this._properties[key]; var prop = this._properties[key];
return prop ? prop.hasChanged : false; return prop ? prop.hasChanged : false;
}, },
/** */ /** */
getSorter:function () { getSorter: function () {
return this._sorter; return this._sorter;
}, },
/** @return {String} returns id, order, position, size and shrink information*/ /** @return {String} returns id, order, position, size and shrink information*/
toString:function () { toString: function () {
return "[id:" + this.getId() + ", order:" + this.getOrder() + ", position: {" + this.getPosition().x + "," + this.getPosition().y + "}, size: {" + this.getSize().width + "," + this.getSize().height + "}, shrink:" + this.areChildrenShrunken() + "]"; return (
'[id:' +
this.getId() +
', order:' +
this.getOrder() +
', position: {' +
this.getPosition().x +
',' +
this.getPosition().y +
'}, size: {' +
this.getSize().width +
',' +
this.getSize().height +
'}, shrink:' +
this.areChildrenShrunken() +
']'
);
},
} }
);
});
export default Node; export default Node;

View File

@ -15,35 +15,35 @@
* 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.
*/ */
const Node = require('./Node').default; const Node = require('./Node').default;
const SymmetricSorter = require('./SymmetricSorter').default const SymmetricSorter = require('./SymmetricSorter').default;
const BalancedSorter = require('./BalancedSorter').default; const BalancedSorter = require('./BalancedSorter').default;
const OriginalLayout = new Class(/** @lends OriginalLayout */{ const OriginalLayout = new Class(
/** @lends OriginalLayout */ {
/** /**
* @constructs * @constructs
* @param treeSet * @param treeSet
*/ */
initialize:function (treeSet) { initialize: function (treeSet) {
this._treeSet = treeSet; this._treeSet = treeSet;
}, },
/** */ /** */
createNode:function (id, size, position, type) { createNode: function (id, size, position, type) {
$assert($defined(id), "id can not be null"); $assert($defined(id), 'id can not be null');
$assert(size, "size can not be null"); $assert(size, 'size can not be null');
$assert(position, "position can not be null"); $assert(position, 'position can not be null');
$assert(type, "type can not be null"); $assert(type, 'type can not be null');
var strategy = type === 'root' ? var strategy =
OriginalLayout.BALANCED_SORTER : type === 'root' ? OriginalLayout.BALANCED_SORTER : OriginalLayout.SYMMETRIC_SORTER;
OriginalLayout.SYMMETRIC_SORTER;
return new Node(id, size, position, strategy); return new Node(id, size, position, strategy);
}, },
/** */ /** */
connectNode:function (parentId, childId, order) { connectNode: function (parentId, childId, order) {
var parent = this._treeSet.find(parentId); var parent = this._treeSet.find(parentId);
var child = this._treeSet.find(childId); var child = this._treeSet.find(childId);
@ -59,10 +59,10 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
}, },
/** */ /** */
disconnectNode:function (nodeId) { disconnectNode: function (nodeId) {
var node = this._treeSet.find(nodeId); var node = this._treeSet.find(nodeId);
var parent = this._treeSet.getParent(node); var parent = this._treeSet.getParent(node);
$assert(parent, "Node already disconnected"); $assert(parent, 'Node already disconnected');
// Make it fixed // Make it fixed
node.setFree(false); node.setFree(false);
@ -80,10 +80,11 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
}, },
/** */ /** */
layout:function () { layout: function () {
var roots = this._treeSet.getTreeRoots(); var roots = this._treeSet.getTreeRoots();
_.each(roots, function (node) { _.each(
roots,
function (node) {
// Calculate all node heights ... // Calculate all node heights ...
var sorter = node.getSorter(); var sorter = node.getSorter();
@ -92,11 +93,12 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
this._layoutChildren(node, heightById); this._layoutChildren(node, heightById);
this._fixOverlapping(node, heightById); this._fixOverlapping(node, heightById);
}, this); },
this
);
}, },
_layoutChildren:function (node, heightById) { _layoutChildren: function (node, heightById) {
var nodeId = node.getId(); var nodeId = node.getId();
var children = this._treeSet.getChildren(node); var children = this._treeSet.getChildren(node);
var parent = this._treeSet.getParent(node); var parent = this._treeSet.getParent(node);
@ -126,9 +128,15 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
var childFreeDisplacement = child.getFreeDisplacement(); var childFreeDisplacement = child.getFreeDisplacement();
var direction = node.getSorter().getChildDirection(me._treeSet, child); var direction = node.getSorter().getChildDirection(me._treeSet, child);
if ((direction > 0 && childFreeDisplacement.x < 0) || (direction < 0 && childFreeDisplacement.x > 0)) { if (
(direction > 0 && childFreeDisplacement.x < 0) ||
(direction < 0 && childFreeDisplacement.x > 0)
) {
child.resetFreeDisplacement(); child.resetFreeDisplacement();
child.setFreeDisplacement({x:-childFreeDisplacement.x, y:childFreeDisplacement.y}); child.setFreeDisplacement({
x: -childFreeDisplacement.x,
y: childFreeDisplacement.y,
});
} }
offset.x += child.getFreeDisplacement().x; offset.x += child.getFreeDisplacement().x;
@ -137,7 +145,10 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
var parentX = parentPosition.x; var parentX = parentPosition.x;
var parentY = parentPosition.y; var parentY = parentPosition.y;
var newPos = {x:parentX + offset.x, y:parentY + offset.y + me._calculateAlignOffset(node, child, heightById)}; var newPos = {
x: parentX + offset.x,
y: parentY + offset.y + me._calculateAlignOffset(node, child, heightById),
};
me._treeSet.updateBranchPosition(child, newPos); me._treeSet.updateBranchPosition(child, newPos);
}); });
@ -145,12 +156,16 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
} }
// Continue reordering the children nodes ... // Continue reordering the children nodes ...
_.each(children, function (child) { _.each(
children,
function (child) {
this._layoutChildren(child, heightById); this._layoutChildren(child, heightById);
}, this); },
this
);
}, },
_calculateAlignOffset:function (node, child, heightById) { _calculateAlignOffset: function (node, child, heightById) {
if (child.isFree()) { if (child.isFree()) {
return 0; return 0;
} }
@ -160,9 +175,14 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
var nodeHeight = node.getSize().height; var nodeHeight = node.getSize().height;
var childHeight = child.getSize().height; var childHeight = child.getSize().height;
if (this._treeSet.isStartOfSubBranch(child) && this._branchIsTaller(child, heightById)) { if (
this._treeSet.isStartOfSubBranch(child) &&
this._branchIsTaller(child, heightById)
) {
if (this._treeSet.hasSinglePathToSingleLeaf(child)) { if (this._treeSet.hasSinglePathToSingleLeaf(child)) {
offset = heightById[child.getId()] / 2 - (childHeight + child.getSorter()._getVerticalPadding() * 2) / 2; offset =
heightById[child.getId()] / 2 -
(childHeight + child.getSorter()._getVerticalPadding() * 2) / 2;
} else { } else {
offset = this._treeSet.isLeaf(child) ? 0 : -(childHeight - nodeHeight) / 2; offset = this._treeSet.isLeaf(child) ? 0 : -(childHeight - nodeHeight) / 2;
} }
@ -172,8 +192,7 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
} else { } else {
offset = nodeHeight / 2 - childHeight / 2; offset = nodeHeight / 2 - childHeight / 2;
} }
} } else if (childHeight > nodeHeight) {
else if (childHeight > nodeHeight) {
if (this._treeSet.getSiblings(child).length > 0) { if (this._treeSet.getSiblings(child).length > 0) {
offset = 0; offset = 0;
} else { } else {
@ -184,28 +203,40 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
return offset; return offset;
}, },
_branchIsTaller:function (node, heightById) { _branchIsTaller: function (node, heightById) {
return heightById[node.getId()] > (node.getSize().height + node.getSorter()._getVerticalPadding() * 2); return (
heightById[node.getId()] >
node.getSize().height + node.getSorter()._getVerticalPadding() * 2
);
}, },
_fixOverlapping:function (node, heightById) { _fixOverlapping: function (node, heightById) {
var children = this._treeSet.getChildren(node); var children = this._treeSet.getChildren(node);
if (node.isFree()) { if (node.isFree()) {
this._shiftBranches(node, heightById); this._shiftBranches(node, heightById);
} }
_.each(children, function (child) { _.each(
children,
function (child) {
this._fixOverlapping(child, heightById); this._fixOverlapping(child, heightById);
}, this); },
this
);
}, },
_shiftBranches:function (node, heightById) { _shiftBranches: function (node, heightById) {
var shiftedBranches = [node]; var shiftedBranches = [node];
var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(node, node.getFreeDisplacement().y); var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(
node,
node.getFreeDisplacement().y
);
var last = node; var last = node;
_.each(siblingsToShift, function (sibling) { _.each(
siblingsToShift,
function (sibling) {
var overlappingOccurs = shiftedBranches.some(function (shiftedBranch) { var overlappingOccurs = shiftedBranches.some(function (shiftedBranch) {
return this._branchesOverlap(shiftedBranch, sibling, heightById); return this._branchesOverlap(shiftedBranch, sibling, heightById);
}, this); }, this);
@ -215,21 +246,29 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
this._treeSet.shiftBranchPosition(sibling, 0, sAmount); this._treeSet.shiftBranchPosition(sibling, 0, sAmount);
shiftedBranches.push(sibling); shiftedBranches.push(sibling);
} }
}, this); },
this
);
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y).filter(function (branch) { var branchesToShift = this._treeSet
.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y)
.filter(function (branch) {
return !shiftedBranches.contains(branch); return !shiftedBranches.contains(branch);
}); });
_.each(branchesToShift, function (branch) { _.each(
branchesToShift,
function (branch) {
var bAmount = node.getFreeDisplacement().y; var bAmount = node.getFreeDisplacement().y;
this._treeSet.shiftBranchPosition(branch, 0, bAmount); this._treeSet.shiftBranchPosition(branch, 0, bAmount);
shiftedBranches.push(branch); shiftedBranches.push(branch);
last = branch; last = branch;
}, this); },
this
);
}, },
_branchesOverlap:function (branchA, branchB, heightById) { _branchesOverlap: function (branchA, branchB, heightById) {
// a branch doesn't really overlap with itself // a branch doesn't really overlap with itself
if (branchA == branchB) { if (branchA == branchB) {
return false; return false;
@ -241,10 +280,9 @@ const OriginalLayout = new Class(/** @lends OriginalLayout */{
var bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2; var bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2;
return !(topA >= bottomB || bottomA <= topB); return !(topA >= bottomB || bottomA <= topB);
},
} }
);
});
/** /**
* @type {mindplot.layout.SymmetricSorter} * @type {mindplot.layout.SymmetricSorter}

View File

@ -16,9 +16,10 @@
* limitations under the License. * limitations under the License.
*/ */
const RootedTreeSet = new Class(/** @lends RootedTreeSet */{ const RootedTreeSet = new Class(
/** @lends RootedTreeSet */ {
/** @constructs */ /** @constructs */
initialize:function () { initialize: function () {
this._rootNodes = []; this._rootNodes = [];
}, },
@ -26,17 +27,17 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @param root * @param root
* @throws will throw an error if root is null or undefined * @throws will throw an error if root is null or undefined
*/ */
setRoot:function (root) { setRoot: function (root) {
$assert(root, 'root can not be null'); $assert(root, 'root can not be null');
this._rootNodes.push(this._decodate(root)); this._rootNodes.push(this._decodate(root));
}, },
/** getter */ /** getter */
getTreeRoots:function () { getTreeRoots: function () {
return this._rootNodes; return this._rootNodes;
}, },
_decodate:function (node) { _decodate: function (node) {
node._children = []; node._children = [];
return node; return node;
}, },
@ -47,19 +48,21 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node with id already exists * @throws will throw an error if node with id already exists
* @throws will throw an error if node has been added already * @throws will throw an error if node has been added already
*/ */
add:function (node) { add: function (node) {
$assert(node, 'node can not be null'); $assert(node, 'node can not be null');
$assert(!this.find(node.getId(), false), 'node already exits with this id. Id:' + node.getId()); $assert(
!this.find(node.getId(), false),
'node already exits with this id. Id:' + node.getId()
);
$assert(!node._children, 'node already added'); $assert(!node._children, 'node already added');
this._rootNodes.push(this._decodate(node)); this._rootNodes.push(this._decodate(node));
}, },
/** /**
* @param nodeId * @param nodeId
* @throws will throw an error if nodeId is null or undefined * @throws will throw an error if nodeId is null or undefined
*/ */
remove:function (nodeId) { remove: function (nodeId) {
$assert($defined(nodeId), 'nodeId can not be null'); $assert($defined(nodeId), 'nodeId can not be null');
var node = this.find(nodeId); var node = this.find(nodeId);
this._rootNodes.erase(node); this._rootNodes.erase(node);
@ -72,13 +75,16 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if childId is null or undefined * @throws will throw an error if childId is null or undefined
* @throws will throw an error if node with id childId is already a child of parent * @throws will throw an error if node with id childId is already a child of parent
*/ */
connect:function (parentId, childId) { connect: function (parentId, childId) {
$assert($defined(parentId), 'parent can not be null'); $assert($defined(parentId), 'parent can not be null');
$assert($defined(childId), 'child can not be null'); $assert($defined(childId), 'child can not be null');
var parent = this.find(parentId); var parent = this.find(parentId);
var child = this.find(childId, true); var child = this.find(childId, true);
$assert(!child._parent, 'node already connected. Id:' + child.getId() + ",previous:" + child._parent); $assert(
!child._parent,
'node already connected. Id:' + child.getId() + ',previous:' + child._parent
);
parent._children.push(child); parent._children.push(child);
child._parent = parent; child._parent = parent;
@ -90,10 +96,10 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if nodeId is null or undefined * @throws will throw an error if nodeId is null or undefined
* @throws will throw an error if node is not connected * @throws will throw an error if node is not connected
*/ */
disconnect:function (nodeId) { disconnect: function (nodeId) {
$assert($defined(nodeId), 'nodeId can not be null'); $assert($defined(nodeId), 'nodeId can not be null');
var node = this.find(nodeId); var node = this.find(nodeId);
$assert(node._parent, "Node is not connected"); $assert(node._parent, 'Node is not connected');
node._parent._children.erase(node); node._parent._children.erase(node);
this._rootNodes.push(node); this._rootNodes.push(node);
@ -107,7 +113,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node cannot be found * @throws will throw an error if node cannot be found
* @return node * @return node
*/ */
find:function (id, validate) { find: function (id, validate) {
$assert($defined(id), 'id can not be null'); $assert($defined(id), 'id can not be null');
var graphs = this._rootNodes; var graphs = this._rootNodes;
@ -120,15 +126,16 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
} }
} }
validate = !$defined(validate) ? true : validate; validate = !$defined(validate) ? true : validate;
$assert(validate ? result : true, 'node could not be found id:' + id + "\n,RootedTreeSet" + this.dump()); $assert(
validate ? result : true,
'node could not be found id:' + id + '\n,RootedTreeSet' + this.dump()
);
return result; return result;
}, },
_find:function (id, parent) { _find: function (id, parent) {
if (parent.getId() == id) { if (parent.getId() == id) {
return parent; return parent;
} }
var result = null; var result = null;
@ -136,8 +143,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var child = children[i]; var child = children[i];
result = this._find(id, child); result = this._find(id, child);
if (result) if (result) break;
break;
} }
return result; return result;
@ -148,7 +154,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if nodeId is null or undefined * @throws will throw an error if nodeId is null or undefined
* @return children * @return children
*/ */
getChildren:function (node) { getChildren: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return node._children; return node._children;
}, },
@ -158,8 +164,8 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return root node or the provided node, if it has no parent * @return root node or the provided node, if it has no parent
*/ */
getRootNode:function (node) { getRootNode: function (node) {
$assert(node, "node cannot be null"); $assert(node, 'node cannot be null');
var parent = this.getParent(node); var parent = this.getParent(node);
if ($defined(parent)) { if ($defined(parent)) {
return this.getRootNode(parent); return this.getRootNode(parent);
@ -172,12 +178,12 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @param node * @param node
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return {Array} ancestors*/ * @return {Array} ancestors*/
getAncestors:function (node) { getAncestors: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return this._getAncestors(this.getParent(node), []); return this._getAncestors(this.getParent(node), []);
}, },
_getAncestors:function (node, ancestors) { _getAncestors: function (node, ancestors) {
var result = ancestors; var result = ancestors;
if (node) { if (node) {
result.push(node); result.push(node);
@ -191,7 +197,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return {Array} siblings * @return {Array} siblings
*/ */
getSiblings:function (node) { getSiblings: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
if (!$defined(node._parent)) { if (!$defined(node._parent)) {
return []; return [];
@ -207,12 +213,12 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return {Boolean} whether the node has a single path to a single leaf (no branching) * @return {Boolean} whether the node has a single path to a single leaf (no branching)
*/ */
hasSinglePathToSingleLeaf:function (node) { hasSinglePathToSingleLeaf: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return this._hasSinglePathToSingleLeaf(node); return this._hasSinglePathToSingleLeaf(node);
}, },
_hasSinglePathToSingleLeaf:function (node) { _hasSinglePathToSingleLeaf: function (node) {
var children = this.getChildren(node); var children = this.getChildren(node);
if (children.length == 1) { if (children.length == 1) {
@ -225,7 +231,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
/** /**
* @param node * @param node
* @return {Boolean} whether the node is the start of a subbranch*/ * @return {Boolean} whether the node is the start of a subbranch*/
isStartOfSubBranch:function (node) { isStartOfSubBranch: function (node) {
return this.getSiblings(node).length > 0 && this.getChildren(node).length == 1; return this.getSiblings(node).length > 0 && this.getChildren(node).length == 1;
}, },
@ -234,7 +240,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return {Boolean} whether the node is a leaf * @return {Boolean} whether the node is a leaf
*/ */
isLeaf:function (node) { isLeaf: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return this.getChildren(node).length == 0; return this.getChildren(node).length == 0;
}, },
@ -244,7 +250,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return parent * @return parent
*/ */
getParent:function (node) { getParent: function (node) {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return node._parent; return node._parent;
}, },
@ -252,22 +258,22 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
/** /**
* @return result * @return result
*/ */
dump:function () { dump: function () {
var branches = this._rootNodes; var branches = this._rootNodes;
var result = ""; var result = '';
for (var i = 0; i < branches.length; i++) { for (var i = 0; i < branches.length; i++) {
var branch = branches[i]; var branch = branches[i];
result += this._dump(branch, ""); result += this._dump(branch, '');
} }
return result; return result;
}, },
_dump:function (node, indent) { _dump: function (node, indent) {
var result = indent + node + "\n"; var result = indent + node + '\n';
var children = this.getChildren(node); var children = this.getChildren(node);
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var child = children[i]; var child = children[i];
result += this._dump(child, indent + " "); result += this._dump(child, indent + ' ');
} }
return result; return result;
@ -276,7 +282,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
/** /**
* @param canvas * @param canvas
*/ */
plot:function (canvas) { plot: function (canvas) {
var branches = this._rootNodes; var branches = this._rootNodes;
for (var i = 0; i < branches.length; i++) { for (var i = 0; i < branches.length; i++) {
var branch = branches[i]; var branch = branches[i];
@ -284,24 +290,71 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
} }
}, },
_plot:function (canvas, node, root) { _plot: function (canvas, node, root) {
var children = this.getChildren(node); var children = this.getChildren(node);
var cx = node.getPosition().x + canvas.width / 2 - node.getSize().width / 2; var cx = node.getPosition().x + canvas.width / 2 - node.getSize().width / 2;
var cy = node.getPosition().y + canvas.height / 2 - node.getSize().height / 2; var cy = node.getPosition().y + canvas.height / 2 - node.getSize().height / 2;
var rect = canvas.rect(cx, cy, node.getSize().width, node.getSize().height); var rect = canvas.rect(cx, cy, node.getSize().width, node.getSize().height);
var order = node.getOrder() == null ? "r" : node.getOrder(); var order = node.getOrder() == null ? 'r' : node.getOrder();
var text = canvas.text(node.getPosition().x + canvas.width / 2, node.getPosition().y + canvas.height / 2, node.getId() + "[" + order + "]"); var text = canvas.text(
node.getPosition().x + canvas.width / 2,
node.getPosition().y + canvas.height / 2,
node.getId() + '[' + order + ']'
);
text.attr('fill', '#FFF'); text.attr('fill', '#FFF');
var fillColor = this._rootNodes.contains(node) ? "#000" : (node.isFree() ? "#abc" : "#c00"); var fillColor = this._rootNodes.contains(node)
? '#000'
: node.isFree()
? '#abc'
: '#c00';
rect.attr('fill', fillColor); rect.attr('fill', fillColor);
var rectPosition = {x:rect.attr("x") - canvas.width / 2 + rect.attr("width") / 2, y:rect.attr("y") - canvas.height / 2 + rect.attr("height") / 2}; var rectPosition = {
var rectSize = {width:rect.attr("width"), height:rect.attr("height")}; x: rect.attr('x') - canvas.width / 2 + rect.attr('width') / 2,
y: rect.attr('y') - canvas.height / 2 + rect.attr('height') / 2,
};
var rectSize = { width: rect.attr('width'), height: rect.attr('height') };
rect.click(function () { rect.click(function () {
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", freeDisplacement:(" + node.getFreeDisplacement().x + "," + node.getFreeDisplacement().y + ")]"); console.log(
'[id:' +
node.getId() +
', order:' +
node.getOrder() +
', position:(' +
rectPosition.x +
',' +
rectPosition.y +
'), size:' +
rectSize.width +
'x' +
rectSize.height +
', freeDisplacement:(' +
node.getFreeDisplacement().x +
',' +
node.getFreeDisplacement().y +
')]'
);
}); });
text.click(function () { text.click(function () {
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", freeDisplacement:(" + node.getFreeDisplacement().x + "," + node.getFreeDisplacement().y + ")]"); console.log(
'[id:' +
node.getId() +
', order:' +
node.getOrder() +
', position:(' +
rectPosition.x +
',' +
rectPosition.y +
'), size:' +
rectSize.width +
'x' +
rectSize.height +
', freeDisplacement:(' +
node.getFreeDisplacement().x +
',' +
node.getFreeDisplacement().y +
')]'
);
}); });
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
@ -314,8 +367,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @param node * @param node
* @param position * @param position
*/ */
updateBranchPosition:function (node, position) { updateBranchPosition: function (node, position) {
var oldPos = node.getPosition(); var oldPos = node.getPosition();
node.setPosition(position); node.setPosition(position);
@ -327,7 +379,6 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
_.each(children, function (child) { _.each(children, function (child) {
me.shiftBranchPosition(child, xOffset, yOffset); me.shiftBranchPosition(child, xOffset, yOffset);
}); });
}, },
/** /**
@ -335,9 +386,9 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @param xOffset * @param xOffset
* @param yOffset * @param yOffset
*/ */
shiftBranchPosition:function (node, xOffset, yOffset) { shiftBranchPosition: function (node, xOffset, yOffset) {
var position = node.getPosition(); var position = node.getPosition();
node.setPosition({x:position.x + xOffset, y:position.y + yOffset}); node.setPosition({ x: position.x + xOffset, y: position.y + yOffset });
var children = this.getChildren(node); var children = this.getChildren(node);
var me = this; var me = this;
@ -351,12 +402,18 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @param yOffset * @param yOffset
* @return siblings in the offset (vertical) direction, i.e. with lower or higher order, respectively * @return siblings in the offset (vertical) direction, i.e. with lower or higher order, respectively
*/ */
getSiblingsInVerticalDirection:function (node, yOffset) { getSiblingsInVerticalDirection: function (node, yOffset) {
// siblings with lower or higher order, depending on the direction of the offset and on the same side as their parent // siblings with lower or higher order, depending on the direction of the offset and on the same side as their parent
var parent = this.getParent(node); var parent = this.getParent(node);
var siblings = this.getSiblings(node).filter(function (sibling) { var siblings = this.getSiblings(node).filter(function (sibling) {
var sameSide = node.getPosition().x > parent.getPosition().x ? sibling.getPosition().x > parent.getPosition().x : sibling.getPosition().x < parent.getPosition().x; var sameSide =
var orderOK = yOffset < 0 ? sibling.getOrder() < node.getOrder() : sibling.getOrder() > node.getOrder(); node.getPosition().x > parent.getPosition().x
? sibling.getPosition().x > parent.getPosition().x
: sibling.getPosition().x < parent.getPosition().x;
var orderOK =
yOffset < 0
? sibling.getOrder() < node.getOrder()
: sibling.getOrder() > node.getOrder();
return orderOK && sameSide; return orderOK && sameSide;
}); });
@ -373,7 +430,7 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
* @return branches of the root node on the same side as the given node's, in the given * @return branches of the root node on the same side as the given node's, in the given
* vertical direction * vertical direction
*/ */
getBranchesInVerticalDirection:function (node, yOffset) { getBranchesInVerticalDirection: function (node, yOffset) {
// direct descendants of the root that do not contain the node and are on the same side // direct descendants of the root that do not contain the node and are on the same side
// and on the direction of the offset // and on the direction of the offset
var rootNode = this.getRootNode(node); var rootNode = this.getRootNode(node);
@ -383,14 +440,20 @@ const RootedTreeSet = new Class(/** @lends RootedTreeSet */{
var branch = branches[0]; var branch = branches[0];
var rootDescendants = this.getSiblings(branch).filter(function (sibling) { var rootDescendants = this.getSiblings(branch).filter(function (sibling) {
var sameSide = node.getPosition().x > rootNode.getPosition().x ? sibling.getPosition().x > rootNode.getPosition().x : sibling.getPosition().x < rootNode.getPosition().x; var sameSide =
var sameDirection = yOffset < 0 ? sibling.getOrder() < branch.getOrder() : sibling.getOrder() > branch.getOrder(); node.getPosition().x > rootNode.getPosition().x
? sibling.getPosition().x > rootNode.getPosition().x
: sibling.getPosition().x < rootNode.getPosition().x;
var sameDirection =
yOffset < 0
? sibling.getOrder() < branch.getOrder()
: sibling.getOrder() > branch.getOrder();
return sameSide && sameDirection; return sameSide && sameDirection;
}, this); }, this);
return rootDescendants; return rootDescendants;
},
} }
);
});
export default RootedTreeSet; export default RootedTreeSet;

View File

@ -17,15 +17,14 @@
*/ */
const AbstractBasicSorter = require('./AbstractBasicSorter').default; const AbstractBasicSorter = require('./AbstractBasicSorter').default;
const SymmetricSorter = new Class(/** @lends SymmetricSorter */{ const SymmetricSorter = new Class(
/** @lends SymmetricSorter */ {
Extends: AbstractBasicSorter, Extends: AbstractBasicSorter,
/** /**
* @constructs * @constructs
* @extends mindplot.layout.AbstractBasicSorter * @extends mindplot.layout.AbstractBasicSorter
*/ */
initialize:function () { initialize: function () {},
},
/** /**
* Predict the order and position of a dragged node. * Predict the order and position of a dragged node.
@ -37,39 +36,64 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* @param free Free drag or not * @param free Free drag or not
* @return {*} * @return {*}
*/ */
predict:function (graph, parent, node, position, free) { predict: function (graph, parent, node, position, free) {
var self = this; var self = this;
var rootNode = graph.getRootNode(parent); var rootNode = graph.getRootNode(parent);
// If its a free node... // If its a free node...
if (free) { if (free) {
$assert($defined(position), "position cannot be null for predict in free positioning"); $assert(
$assert($defined(node), "node cannot be null for predict in free positioning"); $defined(position),
'position cannot be null for predict in free positioning'
);
$assert($defined(node), 'node cannot be null for predict in free positioning');
var direction = this._getRelativeDirection(rootNode.getPosition(), parent.getPosition()); var direction = this._getRelativeDirection(
var limitXPos = parent.getPosition().x + direction * (parent.getSize().width / 2 + node.getSize().width / 2 + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING); rootNode.getPosition(),
parent.getPosition()
);
var limitXPos =
parent.getPosition().x +
direction *
(parent.getSize().width / 2 +
node.getSize().width / 2 +
SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
var xPos = direction > 0 ? var xPos =
(position.x >= limitXPos ? position.x : limitXPos) : direction > 0
(position.x <= limitXPos ? position.x : limitXPos); ? position.x >= limitXPos
? position.x
: limitXPos
: position.x <= limitXPos
? position.x
: limitXPos;
return [0, {x:xPos, y:position.y}]; return [0, { x: xPos, y: position.y }];
} }
// Its not a dragged node (it is being added) // Its not a dragged node (it is being added)
if (!node) { if (!node) {
var parentDirection = self._getRelativeDirection(rootNode.getPosition(), parent.getPosition()); var parentDirection = self._getRelativeDirection(
rootNode.getPosition(),
parent.getPosition()
);
var position = { var position = {
x:parent.getPosition().x + parentDirection * (parent.getSize().width + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING), x:
y:parent.getPosition().y parent.getPosition().x +
parentDirection *
(parent.getSize().width + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
y: parent.getPosition().y,
}; };
return [graph.getChildren(parent).length, position]; return [graph.getChildren(parent).length, position];
} }
// If it is a dragged node... // If it is a dragged node...
$assert($defined(position), "position cannot be null for predict in dragging"); $assert($defined(position), 'position cannot be null for predict in dragging');
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition()); var nodeDirection = this._getRelativeDirection(
rootNode.getPosition(),
node.getPosition()
);
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position); var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position);
var siblings = graph.getSiblings(node); var siblings = graph.getSiblings(node);
@ -84,8 +108,11 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
if (parentChildren.length == 0) { if (parentChildren.length == 0) {
// Fit as a child of the parent node... // Fit as a child of the parent node...
var position = { var position = {
x:parent.getPosition().x + positionDirection * (parent.getSize().width + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING), x:
y:parent.getPosition().y parent.getPosition().x +
positionDirection *
(parent.getSize().width + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
y: parent.getPosition().y,
}; };
return [0, position]; return [0, position];
} else { } else {
@ -94,31 +121,46 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
var last = parentChildren.getLast(); var last = parentChildren.getLast();
for (var i = 0; i < parentChildren.length; i++) { for (var i = 0; i < parentChildren.length; i++) {
var parentChild = parentChildren[i]; var parentChild = parentChildren[i];
var nodeAfter = (i + 1) == parentChild.length ? null : parentChildren[i + 1]; var nodeAfter = i + 1 == parentChild.length ? null : parentChildren[i + 1];
// Fit at the bottom // Fit at the bottom
if (!nodeAfter && position.y > parentChild.getPosition().y) { if (!nodeAfter && position.y > parentChild.getPosition().y) {
var order = (graph.getParent(node) && graph.getParent(node).getId() == parent.getId()) ? var order =
last.getOrder() : last.getOrder() + 1; graph.getParent(node) && graph.getParent(node).getId() == parent.getId()
? last.getOrder()
: last.getOrder() + 1;
var position = { var position = {
x:parentChild.getPosition().x, x: parentChild.getPosition().x,
y:parentChild.getPosition().y + parentChild.getSize().height + SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 y:
parentChild.getPosition().y +
parentChild.getSize().height +
SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2,
}; };
return [order, position]; return [order, position];
} }
// Fit after this node // Fit after this node
if (nodeAfter && position.y > parentChild.getPosition().y && position.y < nodeAfter.getPosition().y) { if (
if (nodeAfter.getId() == node.getId() || parentChild.getId() == node.getId()) { nodeAfter &&
position.y > parentChild.getPosition().y &&
position.y < nodeAfter.getPosition().y
) {
if (
nodeAfter.getId() == node.getId() ||
parentChild.getId() == node.getId()
) {
return [node.getOrder(), node.getPosition()]; return [node.getOrder(), node.getPosition()];
} else { } else {
var order = position.y > node.getPosition().y ? var order =
nodeAfter.getOrder() - 1 : parentChild.getOrder() + 1; position.y > node.getPosition().y
? nodeAfter.getOrder() - 1
: parentChild.getOrder() + 1;
var position = { var position = {
x:parentChild.getPosition().x, x: parentChild.getPosition().x,
y:parentChild.getPosition().y + (nodeAfter.getPosition().y - parentChild.getPosition().y) / 2 y:
parentChild.getPosition().y +
(nodeAfter.getPosition().y - parentChild.getPosition().y) / 2,
}; };
return [order, position]; return [order, position];
} }
} }
@ -128,8 +170,11 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
// Position wasn't below any node, so it must be fitted above the first // Position wasn't below any node, so it must be fitted above the first
var first = parentChildren[0]; var first = parentChildren[0];
var position = { var position = {
x:first.getPosition().x, x: first.getPosition().x,
y:first.getPosition().y - first.getSize().height - SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 y:
first.getPosition().y -
first.getSize().height -
SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2,
}; };
return [0, position]; return [0, position];
}, },
@ -141,9 +186,12 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* @param order * @param order
* @throws will throw an error if the order is not strictly continuous * @throws will throw an error if the order is not strictly continuous
*/ */
insert:function (treeSet, parent, child, order) { insert: function (treeSet, parent, child, order) {
var children = this._getSortedChildren(treeSet, parent); var children = this._getSortedChildren(treeSet, parent);
$assert(order <= children.length, "Order must be continues and can not have holes. Order:" + order); $assert(
order <= children.length,
'Order must be continues and can not have holes. Order:' + order
);
// Shift all the elements in one . // Shift all the elements in one .
for (var i = order; i < children.length; i++) { for (var i = order; i < children.length; i++) {
@ -157,11 +205,11 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* @param treeSet * @param treeSet
* @param node * @param node
* @throws will throw an error if the node is in the wrong position*/ * @throws will throw an error if the node is in the wrong position*/
detach:function (treeSet, node) { detach: function (treeSet, node) {
var parent = treeSet.getParent(node); var parent = treeSet.getParent(node);
var children = this._getSortedChildren(treeSet, parent); var children = this._getSortedChildren(treeSet, parent);
var order = node.getOrder(); var order = node.getOrder();
$assert(children[order] === node, "Node seems not to be in the right position"); $assert(children[order] === node, 'Node seems not to be in the right position');
// Shift all the nodes ... // Shift all the nodes ...
for (var i = node.getOrder() + 1; i < children.length; i++) { for (var i = node.getOrder() + 1; i < children.length; i++) {
@ -182,17 +230,24 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* value, is null or undefined * value, is null or undefined
* @return offsets * @return offsets
*/ */
computeOffsets:function (treeSet, node) { computeOffsets: function (treeSet, node) {
$assert(treeSet, "treeSet can no be null."); $assert(treeSet, 'treeSet can no be null.');
$assert(node, "node can no be null."); $assert(node, 'node can no be null.');
var children = this._getSortedChildren(treeSet, node); var children = this._getSortedChildren(treeSet, node);
// Compute heights ... // Compute heights ...
var heights = children.map( var heights = children
function (child) { .map(function (child) {
return {id:child.getId(), order:child.getOrder(), position:child.getPosition(), width:child.getSize().width, height:this._computeChildrenHeight(treeSet, child)}; return {
}, this).reverse(); id: child.getId(),
order: child.getOrder(),
position: child.getPosition(),
width: child.getSize().width,
height: this._computeChildrenHeight(treeSet, child),
};
}, this)
.reverse();
// Compute the center of the branch ... // Compute the center of the branch ...
var totalHeight = 0; var totalHeight = 0;
@ -209,12 +264,16 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
var direction = this.getChildDirection(treeSet, childNode); var direction = this.getChildDirection(treeSet, childNode);
var yOffset = ysum + heights[i].height / 2; var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (heights[i].width / 2 + node.getSize().width / 2 + SymmetricSorter.INTERNODE_HORIZONTAL_PADDING); var xOffset =
direction *
(heights[i].width / 2 +
node.getSize().width / 2 +
SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null"); $assert(!isNaN(xOffset), 'xOffset can not be null');
$assert(!isNaN(yOffset), "yOffset can not be null"); $assert(!isNaN(yOffset), 'yOffset can not be null');
result[heights[i].id] = {x:xOffset, y:yOffset}; result[heights[i].id] = { x: xOffset, y: yOffset };
} }
return result; return result;
}, },
@ -224,12 +283,12 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* @param node * @param node
* @throws will throw an error if order elements are missing * @throws will throw an error if order elements are missing
*/ */
verify:function (treeSet, node) { verify: function (treeSet, node) {
// Check that all is consistent ... // Check that all is consistent ...
var children = this._getSortedChildren(treeSet, node); var children = this._getSortedChildren(treeSet, node);
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
$assert(children[i].getOrder() == i, "missing order elements"); $assert(children[i].getOrder() == i, 'missing order elements');
} }
}, },
@ -237,9 +296,9 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
* @param treeSet * @param treeSet
* @param child * @param child
* @return direction of the given child from its parent or from the root node, if isolated*/ * @return direction of the given child from its parent or from the root node, if isolated*/
getChildDirection:function (treeSet, child) { getChildDirection: function (treeSet, child) {
$assert(treeSet, "treeSet can no be null."); $assert(treeSet, 'treeSet can no be null.');
$assert(treeSet.getParent(child), "This should not happen"); $assert(treeSet.getParent(child), 'This should not happen');
var result; var result;
var rootNode = treeSet.getRootNode(child); var rootNode = treeSet.getRootNode(child);
@ -252,20 +311,20 @@ const SymmetricSorter = new Class(/** @lends SymmetricSorter */{
var grandParent = treeSet.getParent(parent); var grandParent = treeSet.getParent(parent);
var sorter = grandParent.getSorter(); var sorter = grandParent.getSorter();
result = sorter.getChildDirection(treeSet, parent); result = sorter.getChildDirection(treeSet, parent);
} }
return result; return result;
}, },
/** @return {String} the print name of this class */ /** @return {String} the print name of this class */
toString:function () { toString: function () {
return "Symmetric Sorter"; return 'Symmetric Sorter';
}, },
_getVerticalPadding:function () { _getVerticalPadding: function () {
return SymmetricSorter.INTERNODE_VERTICAL_PADDING; return SymmetricSorter.INTERNODE_VERTICAL_PADDING;
},
} }
}); );
/** /**
* @constant * @constant
@ -280,4 +339,4 @@ SymmetricSorter.INTERNODE_VERTICAL_PADDING = 5;
*/ */
SymmetricSorter.INTERNODE_HORIZONTAL_PADDING = 30; SymmetricSorter.INTERNODE_HORIZONTAL_PADDING = 30;
export default SymmetricSorter export default SymmetricSorter;

View File

@ -0,0 +1,76 @@
/*
---
MooTools: the javascript framework
web build:
- http://mootools.net/core/b28139f033891d55fabb70ffafd6813b
packager build:
- packager build Core/Core Core/Array Core/Class Core/Class.Extras
copyrights:
- [MooTools](http://mootools.net)
licenses:
- [MIT License](http://mootools.net/license.txt)
...
*/
(function(){this.MooTools={version:"1.4.5",build:"ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0"};var o=this.typeOf=function(i){if(i==null){return"null";}if(i.$family!=null){return i.$family();
}if(i.nodeName){if(i.nodeType==1){return"element";}if(i.nodeType==3){return(/\S/).test(i.nodeValue)?"textnode":"whitespace";}}else{if(typeof i.length=="number"){if(i.callee){return"arguments";
}if("item" in i){return"collection";}}}return typeof i;};var j=this.instanceOf=function(t,i){if(t==null){return false;}var s=t.$constructor||t.constructor;
while(s){if(s===i){return true;}s=s.parent;}if(!t.hasOwnProperty){return false;}return t instanceof i;};var f=this.Function;var p=true;for(var k in {toString:1}){p=null;
}if(p){p=["hasOwnProperty","valueOf","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","constructor"];}f.prototype.overloadSetter=function(s){var i=this;
return function(u,t){if(u==null){return this;}if(s||typeof u!="string"){for(var v in u){i.call(this,v,u[v]);}if(p){for(var w=p.length;w--;){v=p[w];if(u.hasOwnProperty(v)){i.call(this,v,u[v]);
}}}}else{i.call(this,u,t);}return this;};};f.prototype.overloadGetter=function(s){var i=this;return function(u){var v,t;if(typeof u!="string"){v=u;}else{if(arguments.length>1){v=arguments;
}else{if(s){v=[u];}}}if(v){t={};for(var w=0;w<v.length;w++){t[v[w]]=i.call(this,v[w]);}}else{t=i.call(this,u);}return t;};};f.prototype.extend=function(i,s){this[i]=s;
}.overloadSetter();f.prototype.implement=function(i,s){this.prototype[i]=s;}.overloadSetter();var n=Array.prototype.slice;f.from=function(i){return(o(i)=="function")?i:function(){return i;
};};Array.from=function(i){if(i==null){return[];}return(a.isEnumerable(i)&&typeof i!="string")?(o(i)=="array")?i:n.call(i):[i];};Number.from=function(s){var i=parseFloat(s);
return isFinite(i)?i:null;};String.from=function(i){return i+"";};f.implement({hide:function(){this.$hidden=true;return this;},protect:function(){this.$protected=true;
return this;}});var a=this.Type=function(u,t){if(u){var s=u.toLowerCase();var i=function(v){return(o(v)==s);};a["is"+u]=i;if(t!=null){t.prototype.$family=(function(){return s;
}).hide();}}if(t==null){return null;}t.extend(this);t.$constructor=a;t.prototype.$constructor=t;return t;};var e=Object.prototype.toString;a.isEnumerable=function(i){return(i!=null&&typeof i.length=="number"&&e.call(i)!="[object Function]");
};var q={};var r=function(i){var s=o(i.prototype);return q[s]||(q[s]=[]);};var b=function(t,x){if(x&&x.$hidden){return;}var s=r(this);for(var u=0;u<s.length;
u++){var w=s[u];if(o(w)=="type"){b.call(w,t,x);}else{w.call(this,t,x);}}var v=this.prototype[t];if(v==null||!v.$protected){this.prototype[t]=x;}if(this[t]==null&&o(x)=="function"){m.call(this,t,function(i){return x.apply(i,n.call(arguments,1));
});}};var m=function(i,t){if(t&&t.$hidden){return;}var s=this[i];if(s==null||!s.$protected){this[i]=t;}};a.implement({implement:b.overloadSetter(),extend:m.overloadSetter(),alias:function(i,s){b.call(this,i,this.prototype[s]);
}.overloadSetter(),mirror:function(i){r(this).push(i);return this;}});new a("Type",a);var d=function(s,x,v){var u=(x!=Object),B=x.prototype;if(u){x=new a(s,x);
}for(var y=0,w=v.length;y<w;y++){var C=v[y],A=x[C],z=B[C];if(A){A.protect();}if(u&&z){x.implement(C,z.protect());}}if(u){var t=B.propertyIsEnumerable(v[0]);
x.forEachMethod=function(G){if(!t){for(var F=0,D=v.length;F<D;F++){G.call(B,B[v[F]],v[F]);}}for(var E in B){G.call(B,B[E],E);}};}return d;};d("String",String,["charAt","charCodeAt","concat","indexOf","lastIndexOf","match","quote","replace","search","slice","split","substr","substring","trim","toLowerCase","toUpperCase"])("Array",Array,["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice","indexOf","lastIndexOf","filter","forEach","every","map","some","reduce","reduceRight"])("Number",Number,["toExponential","toFixed","toLocaleString","toPrecision"])("Function",f,["apply","call","bind"])("RegExp",RegExp,["exec","test"])("Object",Object,["create","defineProperty","defineProperties","keys","getPrototypeOf","getOwnPropertyDescriptor","getOwnPropertyNames","preventExtensions","isExtensible","seal","isSealed","freeze","isFrozen"])("Date",Date,["now"]);
Object.extend=m.overloadSetter();Date.extend("now",function(){return +(new Date);});new a("Boolean",Boolean);Number.prototype.$family=function(){return isFinite(this)?"number":"null";
}.hide();Number.extend("random",function(s,i){return Math.floor(Math.random()*(i-s+1)+s);});var g=Object.prototype.hasOwnProperty;Object.extend("forEach",function(i,t,u){for(var s in i){if(g.call(i,s)){t.call(u,i[s],s,i);
}}});Object.each=Object.forEach;Array.implement({forEach:function(u,v){for(var t=0,s=this.length;t<s;t++){if(t in this){u.call(v,this[t],t,this);}}},each:function(i,s){Array.forEach(this,i,s);
return this;}});var l=function(i){switch(o(i)){case"array":return i.clone();case"object":return Object.clone(i);default:return i;}};Array.implement("clone",function(){var s=this.length,t=new Array(s);
while(s--){t[s]=l(this[s]);}return t;});var h=function(s,i,t){switch(o(t)){case"object":if(o(s[i])=="object"){Object.merge(s[i],t);}else{s[i]=Object.clone(t);
}break;case"array":s[i]=t.clone();break;default:s[i]=t;}return s;};Object.extend({merge:function(z,u,t){if(o(u)=="string"){return h(z,u,t);}for(var y=1,s=arguments.length;
y<s;y++){var w=arguments[y];for(var x in w){h(z,x,w[x]);}}return z;},clone:function(i){var t={};for(var s in i){t[s]=l(i[s]);}return t;},append:function(w){for(var v=1,t=arguments.length;
v<t;v++){var s=arguments[v]||{};for(var u in s){w[u]=s[u];}}return w;}});["Object","WhiteSpace","TextNode","Collection","Arguments"].each(function(i){new a(i);
});var c=Date.now();String.extend("uniqueID",function(){return(c++).toString(36);});})();Array.implement({every:function(c,d){for(var b=0,a=this.length>>>0;
b<a;b++){if((b in this)&&!c.call(d,this[b],b,this)){return false;}}return true;},filter:function(d,f){var c=[];for(var e,b=0,a=this.length>>>0;b<a;b++){if(b in this){e=this[b];
if(d.call(f,e,b,this)){c.push(e);}}}return c;},indexOf:function(c,d){var b=this.length>>>0;for(var a=(d<0)?Math.max(0,b+d):d||0;a<b;a++){if(this[a]===c){return a;
}}return -1;},map:function(c,e){var d=this.length>>>0,b=Array(d);for(var a=0;a<d;a++){if(a in this){b[a]=c.call(e,this[a],a,this);}}return b;},some:function(c,d){for(var b=0,a=this.length>>>0;
b<a;b++){if((b in this)&&c.call(d,this[b],b,this)){return true;}}return false;},clean:function(){return this.filter(function(a){return a!=null;});},invoke:function(a){var b=Array.slice(arguments,1);
return this.map(function(c){return c[a].apply(c,b);});},associate:function(c){var d={},b=Math.min(this.length,c.length);for(var a=0;a<b;a++){d[c[a]]=this[a];
}return d;},link:function(c){var a={};for(var e=0,b=this.length;e<b;e++){for(var d in c){if(c[d](this[e])){a[d]=this[e];delete c[d];break;}}}return a;},contains:function(a,b){return this.indexOf(a,b)!=-1;
},append:function(a){this.push.apply(this,a);return this;},getLast:function(){return(this.length)?this[this.length-1]:null;},getRandom:function(){return(this.length)?this[Number.random(0,this.length-1)]:null;
},include:function(a){if(!this.contains(a)){this.push(a);}return this;},combine:function(c){for(var b=0,a=c.length;b<a;b++){this.include(c[b]);}return this;
},erase:function(b){for(var a=this.length;a--;){if(this[a]===b){this.splice(a,1);}}return this;},empty:function(){this.length=0;return this;},flatten:function(){var d=[];
for(var b=0,a=this.length;b<a;b++){var c=typeOf(this[b]);if(c=="null"){continue;}d=d.concat((c=="array"||c=="collection"||c=="arguments"||instanceOf(this[b],Array))?Array.flatten(this[b]):this[b]);
}return d;},pick:function(){for(var b=0,a=this.length;b<a;b++){if(this[b]!=null){return this[b];}}return null;},rgbToHex:function(d){if(this.length<3){return null;}if(this.length==4&&this[3]==0&&!d){return"transparent";
}var b=[];for(var a=0;a<3;a++){var c=(this[a]-0).toString(16);b.push((c.length==1)?"0"+c:c);}return(d)?b:"#"+b.join("");}});String.implement({test:function(a,b){return((typeOf(a)=="regexp")?a:new RegExp(""+a,b)).test(this);
},contains:function(a,b){return(b)?(b+this+b).indexOf(b+a+b)>-1:String(this).indexOf(a)>-1;},trim:function(){return String(this).replace(/^\s+|\s+$/g,"");
},clean:function(){return String(this).replace(/\s+/g," ").trim();},camelCase:function(){return String(this).replace(/-\D/g,function(a){return a.charAt(1).toUpperCase();
});},hyphenate:function(){return String(this).replace(/[A-Z]/g,function(a){return("-"+a.charAt(0).toLowerCase());});},capitalize:function(){return String(this).replace(/\b[a-z]/g,function(a){return a.toUpperCase();
});},escapeRegExp:function(){return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1");},rgbToHex:function(b){var a=String(this).match(/\d{1,3}/g);
return(a)?a.rgbToHex(b):null;},substitute:function(a,b){return String(this).replace(b||(/\\?\{([^{}]+)\}/g),function(d,c){if(d.charAt(0)=="\\"){return d.slice(1);
}return(a[c]!=null)?a[c]:"";});}});
Function.implement({bind:function(e){var a=this,b=arguments.length>1?Array.slice(arguments,1):null,d=function(){};var c=function(){var g=e,h=arguments.length;if(this instanceof c){d.prototype=a.prototype;g=new d;}var f=(!b&&!h)?a.call(g):a.apply(g,b&&h?b.concat(Array.slice(arguments)):b||arguments);return g==e?f:g;};return c;},pass:function(b,c){var a=this;if(b!=null){b=Array.from(b);}return function(){return a.apply(c,b||arguments);};},delay:function(b,c,a){return setTimeout(this.pass((a==null?[]:a),c),b);},});
Number.alias("each","times");(function(b){var a={};b.each(function(c){if(!Number[c]){a[c]=function(){return Math[c].apply(null,[this].concat(Array.from(arguments)));
};}});Number.implement(a);})(["abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","sin","sqrt","tan"]);(function(){var a=this.Class=new Type("Class",function(h){if(instanceOf(h,Function)){h={initialize:h};
}var g=function(){e(this);if(g.$prototyping){return this;}this.$caller=null;var i=(this.initialize)?this.initialize.apply(this,arguments):this;this.$caller=this.caller=null;
return i;}.extend(this).implement(h);g.$constructor=a;g.prototype.$constructor=g;g.prototype.parent=c;return g;});var c=function(){if(!this.$caller){throw new Error('The method "parent" cannot be called.');
}var g=this.$caller.$name,h=this.$caller.$owner.parent,i=(h)?h.prototype[g]:null;if(!i){throw new Error('The method "'+g+'" has no parent.');}return i.apply(this,arguments);
};var e=function(g){for(var h in g){var j=g[h];switch(typeOf(j)){case"object":var i=function(){};i.prototype=j;g[h]=e(new i);break;case"array":g[h]=j.clone();
break;}}return g;};var b=function(g,h,j){if(j.$origin){j=j.$origin;}var i=function(){if(j.$protected&&this.$caller==null){throw new Error('The method "'+h+'" cannot be called.');
}var l=this.caller,m=this.$caller;this.caller=m;this.$caller=i;var k=j.apply(this,arguments);this.$caller=m;this.caller=l;return k;}.extend({$owner:g,$origin:j,$name:h});
return i;};var f=function(h,i,g){if(a.Mutators.hasOwnProperty(h)){i=a.Mutators[h].call(this,i);if(i==null){return this;}}if(typeOf(i)=="function"){if(i.$hidden){return this;
}this.prototype[h]=(g)?i:b(this,h,i);}else{Object.merge(this.prototype,h,i);}return this;};var d=function(g){g.$prototyping=true;var h=new g;delete g.$prototyping;
return h;};a.implement("implement",f.overloadSetter());a.Mutators={Extends:function(g){this.parent=g;this.prototype=d(g);},Implements:function(g){Array.from(g).each(function(j){var h=new j;for(var i in h){f.call(this,i,h[i],true);}},this);}};})();

File diff suppressed because it is too large Load Diff

View File

@ -421,5 +421,5 @@ INodeModel._nextUUID = function () {
}; };
INodeModel._uuid = 0; INodeModel._uuid = 0;
export default INodeModel;
export { TopicShape }; export { TopicShape };
export default INodeModel;

View File

@ -1,21 +1,21 @@
const featureModel = require('./FeatureModel').default; const featureModel = require('./FeatureModel').default;
const iconModel = require('./IconModel').default; const iconModel = require('./IconModel').default;
const imindmap = require('./IMindmap').default; const iMindmap = require('./IMindmap').default;
const inodeModel = require('./INodeModel').default; const iNodeModel = require('./INodeModel').default;
const linkModel = require('./LinkModel').default; const linkModel = require('./LinkModel').default;
const noteModel = require('./NoteModel').default;
const mindmap = require('./Mindmap').default; const mindmap = require('./Mindmap').default;
const nodeModel = require('./NodeModel').default; const nodeModel = require('./NodeModel').default;
const noteModel = require('./NoteModel').default;
const relationshipModel = require('./RelationshipModel').default; const relationshipModel = require('./RelationshipModel').default;
export const Models = { export const Model = {
FeatureModel: featureModel, FeatureModel: featureModel,
IconModel: iconModel, IconModel: iconModel,
IMindmap: imindmap, IMindmap: iMindmap,
INodeModel: inodeModel, INodeModel: iNodeModel,
LinkModel: linkModel, LinkModel: linkModel,
NoteModel: noteModel,
Mindmap: mindmap, Mindmap: mindmap,
NodeModel: nodeModel, NodeModel: nodeModel,
NoteModel: noteModel,
RelationshipModel: relationshipModel, RelationshipModel: relationshipModel,
}; };

View File

@ -0,0 +1,7 @@
const fadeEffect = require('./FadeEffect').default;
const shape = require('./Shape').default;
export const Utils = {
FadeEffect: fadeEffect,
Shape: shape,
};

View File

@ -18,47 +18,46 @@
const ToolbarPaneItem = require('./ToolbarPaneItem').default; const ToolbarPaneItem = require('./ToolbarPaneItem').default;
const ColorPalettePanel = new Class({ const ColorPalettePanel = new Class({
Extends:ToolbarPaneItem, Extends: ToolbarPaneItem,
initialize:function (buttonId, model, baseUrl) { initialize: function (buttonId, model, baseUrl) {
this._baseUrl = baseUrl; this._baseUrl = baseUrl;
this.parent(buttonId, model); this.parent(buttonId, model);
$assert($defined(baseUrl), "baseUrl can not be null"); $assert($defined(baseUrl), 'baseUrl can not be null');
}, },
_load:function () { _load: function () {
if (!ColorPalettePanel._panelContent) { if (!ColorPalettePanel._panelContent) {
// Load all the CSS styles ... // Load all the CSS styles ...
$('<link>') $('<link>')
.appendTo($('head')) .appendTo($('head'))
.attr({type : 'text/css', rel : 'stylesheet'}) .attr({ type: 'text/css', rel: 'stylesheet' })
.attr('href', this._baseUrl + '/colorPalette.css'); .attr('href', this._baseUrl + '/colorPalette.css');
// Load panel html fragment ... // Load panel html fragment ...
var result; var result;
$.ajax({ $.ajax({
url:this._baseUrl + '/colorPalette.html', url: `${this._baseUrl}/colorPalette.html`,
method:'get', method: 'GET',
async:false, async: false,
success:function (responseText) { success: function (responseText) {
result = responseText; result = responseText;
}, },
error:function () { error: function () {
result = '<div>Sorry, your request failed :(</div>'; result = '<div>Sorry, your request failed :(</div>';
} },
}); });
ColorPalettePanel._panelContent = result; ColorPalettePanel._panelContent = result;
} }
return ColorPalettePanel._panelContent; return ColorPalettePanel._panelContent;
}, },
buildPanel: function () {
buildPanel:function () { var content = $('<div class="toolbarPanel"></div>').attr(
var content = $('<div class="toolbarPanel"></div>').attr('id', this._buttonId + 'colorPalette'); 'id',
this._buttonId + 'colorPalette'
);
content.html(this._load()); content.html(this._load());
// Register on toolbar elements ... // Register on toolbar elements ...
@ -67,7 +66,7 @@ const ColorPalettePanel = new Class({
var me = this; var me = this;
_.each(colorCells, function (elem) { _.each(colorCells, function (elem) {
$(elem).on('click', function () { $(elem).on('click', function () {
var color = $(elem).css("background-color"); var color = $(elem).css('background-color');
model.setValue(color); model.setValue(color);
me.hide(); me.hide();
}); });
@ -76,18 +75,20 @@ const ColorPalettePanel = new Class({
return content; return content;
}, },
_updateSelectedItem:function () { _updateSelectedItem: function () {
var panelElem = this.getPanelElem(); var panelElem = this.getPanelElem();
// Clear selected cell based on the color ... // Clear selected cell based on the color ...
panelElem.find("td[class='palette-cell palette-cell-selected']").attr('class', 'palette-cell'); panelElem
.find("td[class='palette-cell palette-cell-selected']")
.attr('class', 'palette-cell');
// Mark the cell as selected ... // Mark the cell as selected ...
var colorCells = panelElem.find('div[class=palette-colorswatch]'); var colorCells = panelElem.find('div[class=palette-colorswatch]');
var model = this.getModel(); var model = this.getModel();
var modelValue = model.getValue(); var modelValue = model.getValue();
_.each(colorCells, function (elem) { _.each(colorCells, function (elem) {
var color = $(elem).css("background-color").rgbToHex(); var color = $(elem).css('background-color').rgbToHex();
if (modelValue != null && modelValue[0] == 'r') { if (modelValue != null && modelValue[0] == 'r') {
modelValue = modelValue.rgbToHex(); modelValue = modelValue.rgbToHex();
} }
@ -97,8 +98,7 @@ const ColorPalettePanel = new Class({
} }
}); });
return panelElem; return panelElem;
} },
}); });
export default ColorPalettePanel; export default ColorPalettePanel;

View File

@ -6,7 +6,6 @@
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
*
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
@ -50,5 +49,7 @@ const ModalDialogNotifier = new Class({
var dialogNotifier = new ModalDialogNotifier(); var dialogNotifier = new ModalDialogNotifier();
const $notifyModal = dialogNotifier.show.bind(dialogNotifier); const $notifyModal = dialogNotifier.show.bind(dialogNotifier);
$notifyModal;
export { $notifyModal };
export default ModalDialogNotifier; export default ModalDialogNotifier;

View File

@ -46,4 +46,5 @@ const $notify = function (msg) {
toolbarNotifier.logMessage(msg); toolbarNotifier.logMessage(msg);
}; };
export { $notify };
export default ToolbarNotifier; export default ToolbarNotifier;

View File

@ -3,7 +3,7 @@ const floatingTip = require('./FloatingTip').default;
const fontFamilyPanel = require('./FontFamilyPanel').default; const fontFamilyPanel = require('./FontFamilyPanel').default;
const fontSizePanel = require('./FontSizePanel').default; const fontSizePanel = require('./FontSizePanel').default;
const iconPanel = require('./IconPanel').default; const iconPanel = require('./IconPanel').default;
const imenu = require('./IMenu').default; const iMenu = require('./IMenu').default;
const keyboardShortcutTooltip = require('./KeyboardShortcutTooltip').default; const keyboardShortcutTooltip = require('./KeyboardShortcutTooltip').default;
const linkEditor = require('./LinkEditor').default; const linkEditor = require('./LinkEditor').default;
const linkIconTooltip = require('./LinkIconTooltip').default; const linkIconTooltip = require('./LinkIconTooltip').default;
@ -22,7 +22,7 @@ export const Widgets = {
FontFamilyPanel: fontFamilyPanel, FontFamilyPanel: fontFamilyPanel,
FontSizePanel: fontSizePanel, FontSizePanel: fontSizePanel,
IconPanel: iconPanel, IconPanel: iconPanel,
Imenu: imenu, IMenu: iMenu,
KeyboardShortcutTooltip: keyboardShortcutTooltip, KeyboardShortcutTooltip: keyboardShortcutTooltip,
LinkEditor: linkEditor, LinkEditor: linkEditor,
LinkIconTooltip: linkIconTooltip, LinkIconTooltip: linkIconTooltip,

View File

@ -9,23 +9,27 @@ function mindplot() {
const { Layout } = require('./components/layout'); const { Layout } = require('./components/layout');
// Model // Model
const { Models } = require('./components/model'); const { Model } = require('./components/model');
// Persistence // Persistence
const { Persistence } = require('./components/persistence'); const { Persistence } = require('./components/persistence');
// Utils
const { Utils } = require('./components/util');
// Widgets // Widgets
const { Widgets } = require('./components/widget'); const { Widgets } = require('./components/widget');
// Commponents // Components
const { Components } = require('./components'); const { Components } = require('./components');
return { return {
commands: Commands, commands: Commands,
layout: Layout, layouts: Layout,
models: Models, models: Model,
persistence: Persistence, persistence: Persistence,
widget: Widgets, utils: Utils,
component: Components, widgets: Widgets,
components: Components,
}; };
} }

View File

@ -20,9 +20,9 @@
"url": "git+https://ezequielVega@bitbucket.org/lilabyus/wisemapping-frontend.git" "url": "git+https://ezequielVega@bitbucket.org/lilabyus/wisemapping-frontend.git"
}, },
"scripts": { "scripts": {
"build": "yarn build:dev && yarn build:test", "build": "yarn mindplot:build && yarn test:build",
"build:dev": "webpack --config webpack.prod.js", "test:build": "webpack --config webpack.test.js",
"build:test": "webpack --config webpack.test.js", "mindplot:build": "webpack --config webpack.prod.js",
"start": "webpack serve --config webpack.dev.js" "start": "webpack serve --config webpack.dev.js"
}, },
"dependencies": { "dependencies": {
@ -31,7 +31,6 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.14.6", "@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"clean-webpack-plugin": "^4.0.0-alpha.0", "clean-webpack-plugin": "^4.0.0-alpha.0",
"webpack": "^5.44.0", "webpack": "^5.44.0",

View File

@ -1,28 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
<script
type="text/javascript"
src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"
></script>
<script
type="text/javascript"
src="../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js"
></script>
<script
type="text/javascript"
src="../../../lib/components/libraries/underscorejs/underscore-min.js"
></script>
<script type="text/javascript" src="../../../../core-js/dist/core.js"></script> <head>
<script type="text/javascript" src="../../../lib/components/header.js"></script> <script src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../../../dist/main.js"></script> <script type='text/javascript' src='../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js'></script>
<script src="../../../lib/components/libraries/underscorejs/underscore-min.js"></script>
<script type='text/javascript' src='../../../../core-js/dist/core.js'></script>
<script src="../../../dist/main.js"></script>
<script type="text/javascript" src="test/raphael-min.js"></script> <script type="text/javascript" src="test/raphael-min.js"></script>
<script type="text/javascript" src="test/raphael-plugins.js"></script> <script type="text/javascript" src="test/raphael-plugins.js"></script>
<script type="text/javascript" src="../../../dist/test/layout.test.js"></script> <script src="../../../dist/test/layout.test.js"></script>
<style type="text/css"> <style type="text/css">
div.col { div.col {
@ -33,9 +23,12 @@
float: none; float: none;
} }
</style> </style>
</head>
<body> </head>
<div id="basicTest" style="display: none"> <body>
<div id="basicTest" style="display: none;">
<h1>Basic Tests</h1> <h1>Basic Tests</h1>
<h3>testAligned:</h3> <h3>testAligned:</h3>
@ -79,9 +72,9 @@
<h3>testReconnectSingleNode:</h3> <h3>testReconnectSingleNode:</h3>
<div id="testReconnectSingleNode1" class="col"></div> <div id="testReconnectSingleNode1" class="col"></div>
<div id="testReconnectSingleNode2" class="col"></div> <div id="testReconnectSingleNode2" class="col"></div>
</div> </div>
<div id="balancedTest" style="display: none"> <div id="balancedTest" style="display: none;">
<h1>Balanced Sorter Tests</h1> <h1>Balanced Sorter Tests</h1>
<h3>testBalanced:</h3> <h3>testBalanced:</h3>
@ -110,9 +103,9 @@
<div id="testBalancedNodeDragPredict1"></div> <div id="testBalancedNodeDragPredict1"></div>
<div id="testBalancedNodeDragPredict2"></div> <div id="testBalancedNodeDragPredict2"></div>
<div id="testBalancedNodeDragPredict3"></div> <div id="testBalancedNodeDragPredict3"></div>
</div> </div>
<div id="symmetricTest" style="display: none"> <div id="symmetricTest" style="display: none;">
<h1>Symmetric Sorter Tests</h1> <h1>Symmetric Sorter Tests</h1>
<h3>testSymmetry:</h3> <h3>testSymmetry:</h3>
<div id="testSymmetry"></div> <div id="testSymmetry"></div>
@ -126,9 +119,9 @@
<h3>testSymmetricDragPredict:</h3> <h3>testSymmetricDragPredict:</h3>
<div id="testSymmetricDragPredict1"></div> <div id="testSymmetricDragPredict1"></div>
</div> </div>
<div id="freeTest" style="display: none"> <div id="freeTest" style="display: none;">
<h1>Free Positioning Tests</h1> <h1>Free Positioning Tests</h1>
<h3>testFreePosition:</h3> <h3>testFreePosition:</h3>
@ -175,6 +168,7 @@
<h3>testFreeOverlap:</h3> <h3>testFreeOverlap:</h3>
<div id="testFreeOverlap1" class="col"></div> <div id="testFreeOverlap1" class="col"></div>
<div id="testFreeOverlap2" class="col"></div> <div id="testFreeOverlap2" class="col"></div>
</div> </div>
</body>
</body>
</html> </html>

View File

@ -1,16 +1,33 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en">
<html>
<head> <head>
<script src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"></script> <meta charset="UTF-8" />
<script src="../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="../../../lib/components/libraries/underscorejs/underscore-min.js"></script> <title>Document</title>
<script src="../../../lib/components/libraries/bootstrap/js/bootstrap.min.js"></script> <script
type="text/javascript"
src="../../../lib/components/libraries/jquery/jquery-2.1.0.js"
></script>
<script type="text/javascript" src="../../../../core-js/dist/core.js"></script> <script type="text/javascript" src="../../../../core-js/dist/core.js"></script>
<script
type="text/javascript"
src="../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js"
></script>
<script
type="text/javascript"
src="../../../lib/components/libraries/underscorejs/underscore-min.js"
></script>
<script
type="text/javascript"
src="../../../lib/components/libraries/bootstrap/js/bootstrap.min.js"
></script>
<script type="text/javascript" src="../../../dist/main.js"></script>
<script type="text/javascript" src="../../../dist/test/palette.test.js"></script> <script type="text/javascript" src="../../../dist/test/palette.test.js"></script>
</head> </head>
<body>
<body> <body>
<div id="myButton" style="border: 1px red solid">The button</div> <div id="myButton" style="border: 1px red solid">The button</div>
</body> </body>
</body>
</html> </html>

View File

@ -17,6 +17,9 @@
*/ */
const TestSuite = require('./TestSuite').default; const TestSuite = require('./TestSuite').default;
const Mindplot = require('../../../../lib/mindplot');
const mindplot = Mindplot();
const BalancedTestSuite = new Class({ const BalancedTestSuite = new Class({
Extends: TestSuite, Extends: TestSuite,

View File

@ -16,6 +16,9 @@
* limitations under the License. * limitations under the License.
*/ */
const TestSuite = require('./TestSuite').default; const TestSuite = require('./TestSuite').default;
const Mindplot = require('../../../../lib/mindplot');
const mindplot = Mindplot();
const FreeTestSuite = new Class({ const FreeTestSuite = new Class({
Extends: TestSuite, Extends: TestSuite,

View File

@ -16,6 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
const TestSuite = require('./TestSuite').default; const TestSuite = require('./TestSuite').default;
const Mindplot = require('../../../../lib/mindplot');
const mindplot = Mindplot();
const SymmetricTestSuite = new Class({ const SymmetricTestSuite = new Class({
Extends: TestSuite, Extends: TestSuite,
@ -154,6 +156,8 @@ const SymmetricTestSuite = new Class({
console.log('\tAdded as child of node 5 and dropped at (380, -30):'); console.log('\tAdded as child of node 5 and dropped at (380, -30):');
var prediction2d = manager.predict(5, null, { x: 380, y: -30 }); var prediction2d = manager.predict(5, null, { x: 380, y: -30 });
this._plotPrediction(graph2, prediction2d); this._plotPrediction(graph2, prediction2d);
// Prediction calculator error
$assert( $assert(
prediction2d.position.y < manager.find(7).getPosition().y && prediction2d.position.y < manager.find(7).getPosition().y &&
prediction2d.position.x == manager.find(7).getPosition().x, prediction2d.position.x == manager.find(7).getPosition().x,
@ -164,6 +168,7 @@ const SymmetricTestSuite = new Class({
console.log('\tAdded as child of node 5 and dropped at (375, 15):'); console.log('\tAdded as child of node 5 and dropped at (375, 15):');
var prediction2a = manager.predict(5, null, { x: 375, y: 15 }); var prediction2a = manager.predict(5, null, { x: 375, y: 15 });
this._plotPrediction(graph2, prediction2a); this._plotPrediction(graph2, prediction2a);
$assert( $assert(
prediction2a.position.y > manager.find(7).getPosition().y && prediction2a.position.y > manager.find(7).getPosition().y &&
prediction2a.position.y < manager.find(8).getPosition().y && prediction2a.position.y < manager.find(8).getPosition().y &&
@ -278,6 +283,7 @@ const SymmetricTestSuite = new Class({
console.log('testSymmetricDragPredict:'); console.log('testSymmetricDragPredict:');
var position = { x: 0, y: 0 }; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1); manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.layout(); manager.layout();

View File

@ -15,12 +15,14 @@
* 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.
*/ */
const Mindplot = require('../../../../lib/mindplot');
const mindplot = Mindplot();
const TestSuite = new Class({ const TestSuite = new Class({
Extends: mindplot.layout.ChildrenSorterStrategy, Extends: mindplot.layout.ChildrenSorterStrategy,
initialize: function () { initialize: function () {
$('#basicTest').css('display', 'block'); $('#basicTest').css('display', 'block');
// this.testAligned(); // this.testAligned();
this.testBaselineAligned1(); this.testBaselineAligned1();
this.testBaselineAligned2(); this.testBaselineAligned2();
@ -230,6 +232,9 @@ const TestSuite = new Class({
manager.plot('testEventsComplex2', { width: 800, height: 200 }); manager.plot('testEventsComplex2', { width: 800, height: 200 });
// Check only 4 nodes were repositioned // Check only 4 nodes were repositioned
console.log(events.length);
$assert(events.length == 4, 'Only 4 nodes should be repositioned.'); $assert(events.length == 4, 'Only 4 nodes should be repositioned.');
console.log('OK!\n\n'); console.log('OK!\n\n');

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"></script>
<script src="../../../lib/components/libraries/mootools/mootools-core-1.6.0.js"></script>
<script src="../../../../core-js/dist/core.js"></script>
<script src="../../../dist/main.js"></script>
<script src="../../../dist/24.js"></script>
</head>
<body></body>
</html>

View File

@ -4,15 +4,21 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
/** @type {import('webpack').Configuration} */ /** @type {import('webpack').Configuration} */
module.exports = { module.exports = {
entry: { entry: {
palette: path.resolve(__dirname, './test/javascript/static/test/testPalette'), testingLayout: './test/javascript/static/test/testingLayout',
layout: path.resolve(__dirname, './test/javascript/static/test/testLayout'), testingPallete: './test/javascript/static/test/testingPalette',
}, },
output: { output: {
path: path.resolve(__dirname, 'dist', 'test'), path: path.resolve(__dirname, 'dist', 'tests'),
filename: '[name].test.js', filename: '[name].js',
publicPath: '', publicPath: '',
}, },
mode: 'production', optimization: {
splitChunks: {
chunks: 'all',
minSize: 2000000,
},
},
devtool: 'source-map',
module: { module: {
rules: [ rules: [
{ {

View File

@ -35,7 +35,7 @@ function web2D() {
const verdanaFont = require('./components/peer/svg/VerdanaFont').default; //eslint-disable-line const verdanaFont = require('./components/peer/svg/VerdanaFont').default; //eslint-disable-line
const point = require('./components/Point').default; //eslint-disable-line const point = require('./components/Point').default; //eslint-disable-line
global.web2d = { const web2d = {
ElementPeer: elementPeer, ElementPeer: elementPeer,
Element: element, Element: element,
Workspace: workspace, Workspace: workspace,
@ -68,7 +68,7 @@ function web2D() {
Point: point, Point: point,
}; };
return global.web2d; //eslint-disable-line return web2d; //eslint-disable-line
} }
module.exports = web2D; //eslint-disable-line module.exports = web2D; //eslint-disable-line

4859
yarn.lock

File diff suppressed because it is too large Load Diff