Added tests palette and layout

This commit is contained in:
Ezequiel-Vega 2021-09-08 17:45:26 -03:00
parent cbc461e760
commit d515e0bb57
26 changed files with 2271 additions and 1279 deletions

View File

@ -977,8 +977,7 @@ const Designer = new Class(
changeTopicShape: function (shape) {
var validateFunc = function (topic) {
return !(
topic.getType() == INodeModel.CENTRAL_TOPIC_TYPE &&
shape == TopicShape.LINE
topic.getType() == INodeModel.CENTRAL_TOPIC_TYPE && shape == TopicShape.LINE
);
};
@ -1001,11 +1000,9 @@ const Designer = new Class(
addIconType: function (iconType) {
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.addFeatureToTopic(
topicsIds[0],
TopicFeature.Icon.id,
{ id: iconType }
);
this._actionDispatcher.addFeatureToTopic(topicsIds[0], TopicFeature.Icon.id, {
id: iconType,
});
}
},

View File

@ -21,17 +21,17 @@ const Messages = new Class({
init: function (locale) {
locale = $defined(locale) ? locale : 'en';
var bundle = Messages.BUNDLES[locale];
if (bundle == null && locale.indexOf("_") != -1) {
if (bundle == null && locale.indexOf('_') != -1) {
// Try to locate without the specialization ...
locale = locale.substring(0, locale.indexOf("_"));
locale = locale.substring(0, locale.indexOf('_'));
bundle = Messages.BUNDLES[locale];
}
Messages.__bundle = bundle;
}
}
},
},
});
$msg = function (key) {
global.$msg = function (key) {
if (!Messages.__bundle) {
Messages.init('en');
}

View File

@ -15,31 +15,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const Core = require('@wismapping/core-js')
const Core = require('@wismapping/core-js');
const core = Core();
const XMLSerializerFactory = require('./persistence/XMLSerializerFactory');
const PersistenceManager = new Class({
Static: {
loadFromDom: function (mapId, mapDom) {
$assert(mapId, "mapId can not be null");
$assert(mapDom, "mapDom can not be null");
$assert(mapId, 'mapId can not be null');
$assert(mapDom, 'mapDom can not be null');
var serializer = XMLSerializerFactory.getSerializerFromDocument(mapDom);
return serializer.loadFromDom(mapDom, mapId);
}
},
},
initialize: function () {
},
initialize: function () {},
save: function (mindmap, editorProperties, saveHistory, events, sync) {
$assert(mindmap, "mindmap can not be null");
$assert(editorProperties, "editorProperties can not be null");
$assert(mindmap, 'mindmap can not be null');
$assert(editorProperties, 'editorProperties can not be null');
var mapId = mindmap.getId();
$assert(mapId, "mapId can not be null");
$assert(mapId, 'mapId can not be null');
var serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap);
var domMap = serializer.toXML(mindmap);
@ -55,26 +53,26 @@ const PersistenceManager = new Class({
},
load: function (mapId) {
$assert(mapId, "mapId can not be null");
$assert(mapId, 'mapId can not be null');
var domDocument = this.loadMapDom(mapId);
return PersistenceManager.loadFromDom(mapId, domDocument);
},
discardChanges: function (mapId) {
throw new Error("Method must be implemented");
throw new Error('Method must be implemented');
},
loadMapDom: function (mapId) {
throw new Error("Method must be implemented");
throw new Error('Method must be implemented');
},
saveMapXml: function (mapId, mapXml, pref, saveHistory, events, sync) {
throw new Error("Method must be implemented");
throw new Error('Method must be implemented');
},
unlockMap: function (mindmap) {
throw new Error("Method must be implemented");
}
throw new Error('Method must be implemented');
},
});
PersistenceManager.init = function (instance) {

View File

@ -378,4 +378,4 @@ const CommandContext = new Class(
}
);
export {StandaloneActionDispatcher, CommandContext}
export { StandaloneActionDispatcher, CommandContext };

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const web2D = require('@wismapping/web2d')
const web2d = web2D()
const web2D = require('@wismapping/web2d');
const web2d = web2D();
const NodeGraph = require('./NodeGraph').default;
const { TopicShape } = require('./model/INodeModel');
const TopicStyle = require('./TopicStyle').default;
@ -240,10 +240,7 @@ const Topic = new Class(
/** @return outer shape */
getOuterShape: function () {
if (!$defined(this._outerShape)) {
var rect = this._buildShape(
Topic.OUTER_SHAPE_ATTRIBUTES,
TopicShape.ROUNDED_RECT
);
var rect = this._buildShape(Topic.OUTER_SHAPE_ATTRIBUTES, TopicShape.ROUNDED_RECT);
rect.setPosition(-2, -3);
rect.setOpacity(0);
this._outerShape = rect;
@ -991,9 +988,7 @@ const Topic = new Class(
}
var textShape = this.getTextShape();
textShape.setVisibility(
this.getShapeType() != TopicShape.IMAGE ? value : false
);
textShape.setVisibility(this.getShapeType() != TopicShape.IMAGE ? value : false);
},
/** */
@ -1091,10 +1086,7 @@ const Topic = new Class(
outgoingLine.removeFromWorkspace(workspace);
// Remove from workspace.
EventBus.instance.fireEvent(
EventBus.events.NodeDisconnectEvent,
this.getModel()
);
EventBus.instance.fireEvent(EventBus.events.NodeDisconnectEvent, this.getModel());
// Change text based on the current connection ...
var model = this.getModel();
@ -1216,10 +1208,7 @@ const Topic = new Class(
workspace.removeChild(line);
}
this._isInWorkspace = false;
EventBus.instance.fireEvent(
EventBus.events.NodeRemoved,
this.getModel()
);
EventBus.instance.fireEvent(EventBus.events.NodeRemoved, this.getModel());
},
/** */
@ -1228,20 +1217,14 @@ const Topic = new Class(
workspace.append(elem);
if (!this.isInWorkspace()) {
if (!this.isCentralTopic()) {
EventBus.instance.fireEvent(
EventBus.events.NodeAdded,
this.getModel()
);
EventBus.instance.fireEvent(EventBus.events.NodeAdded, this.getModel());
}
if (this.getModel().isConnected())
EventBus.instance.fireEvent(
EventBus.events.NodeConnectEvent,
{
EventBus.instance.fireEvent(EventBus.events.NodeConnectEvent, {
parentNode: this.getOutgoingConnectedTopic().getModel(),
childNode: this.getModel(),
}
);
});
}
this._isInWorkspace = true;
this._adjustShapes();

View File

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

View File

@ -17,7 +17,7 @@
*/
const ConnectionLine = require('../ConnectionLine').default;
RelationshipModel = new Class(
const RelationshipModel = new Class(
/** @lends RelationshipModel */ {
Static: {
_nextUUID: function () {

View File

@ -31,7 +31,7 @@ const FloatingTip = new Class({
content: '',
delay: 0,
container: false,
destroyOnExit: false
destroyOnExit: false,
},
initialize: function (element, options) {
@ -41,11 +41,11 @@ const FloatingTip = new Class({
},
//FIXME: find a better way to do that...
_createPopover: function() {
_createPopover: function () {
this.element.popover(this.options);
var me = this;
if (this.options.destroyOnExit) {
this.element.one('hidden.bs.popover', function() {
this.element.one('hidden.bs.popover', function () {
me.element.popover('destroy');
me._createPopover();
});
@ -62,7 +62,7 @@ const FloatingTip = new Class({
this.element.popover('hide');
this.fireEvent('hide');
return this;
}
},
});
export default FloatingTip;

View File

@ -17,14 +17,14 @@
*/
const ModalDialogNotifier = new Class({
initialize: function () {},
//FIXME: replace by alert()
show: function (message, title) {
$assert(message, "message can not be null");
$assert(message, 'message can not be null');
var modalDialog = $('<div class="modal fade">' +
var modalDialog = $(
'<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-body"></div>' +
@ -37,18 +37,18 @@ const ModalDialogNotifier = new Class({
'</div>' +
'</div>' +
'</div>' +
'</div>');
'</div>'
);
var p = '<p>' + message + '</p>'
var h4 = title ? '<h4>' + title + '</h4>' : "";
var p = '<p>' + message + '</p>';
var h4 = title ? '<h4>' + title + '</h4>' : '';
modalDialog.find('.alert-content').append(h4 + p);
modalDialog.modal();
}
},
});
var dialogNotifier = new ModalDialogNotifier();
$notifyModal = dialogNotifier.show.bind(dialogNotifier);
const $notifyModal = dialogNotifier.show.bind(dialogNotifier);
export default ModalDialogNotifier;

View File

@ -17,31 +17,32 @@
*/
const ToolbarNotifier = new Class({
initialize:function () {
initialize: function () {
this.container = $('#headerNotifier');
},
hide:function () {
hide: function () {
this.container.hide();
},
logMessage:function (msg, fade) {
logMessage: function (msg, fade) {
$assert(msg, 'msg can not be null');
// In case of print,embedded no message is displayed ....
if (this.container && !this.container.data('transitioning')) {
this.container.data('transitioning', true);
this.container.text(msg);
this.container.css({top: "5px", left: ($(window).width() - this.container.width()) / 2 - 9});
this.container.css({
top: '5px',
left: ($(window).width() - this.container.width()) / 2 - 9,
});
this.container.show().fadeOut(5000);
}
this.container.data('transitioning', false);
}
},
});
var toolbarNotifier = new ToolbarNotifier();
$notify = function(msg) {
const $notify = function (msg) {
toolbarNotifier.logMessage(msg);
};

View File

@ -19,22 +19,22 @@ const ToolbarItem = require('./ToolbarItem').default;
const FloatingTip = require('./FloatingTip').default;
const ToolbarPaneItem = new Class({
Extends:ToolbarItem,
initialize : function(buttonId, model) {
$assert(buttonId, "buttonId can not be null");
$assert(model, "model can not be null");
Extends: ToolbarItem,
initialize: function (buttonId, model) {
$assert(buttonId, 'buttonId can not be null');
$assert(model, 'model can not be null');
this._model = model;
var me = this;
var fn = function() {
var fn = function () {
// Is the panel being displayed ?
me.isVisible() ? me.hide() : me.show();
};
this.parent(buttonId, fn, {topicAction:true,relAction:false});
this.parent(buttonId, fn, { topicAction: true, relAction: false });
this._panelElem = this._init();
this._visible = false;
},
_init:function () {
_init: function () {
// Load the context of the panel ...
var panelElem = this.buildPanel();
panelElem.css('cursor', 'default');
@ -44,34 +44,35 @@ const ToolbarPaneItem = new Class({
this._tip = new FloatingTip(buttonElem, {
html: true,
placement: 'bottom',
content: function() {
content: function () {
return me._updateSelectedItem();
},
className: 'toolbarPaneTip',
trigger: 'manual',
template: '<div class="popover popoverGray" role="tooltip"><div class="arrow arrowGray"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
template:
'<div class="popover popoverGray" role="tooltip"><div class="arrow arrowGray"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
});
this._tip.addEvent('hide', function() {
me._visible = false
this._tip.addEvent('hide', function () {
me._visible = false;
});
this._tip.addEvent('show', function() {
me._visible = true
this._tip.addEvent('show', function () {
me._visible = true;
});
return panelElem;
},
getModel : function() {
getModel: function () {
return this._model;
},
getPanelElem : function() {
getPanelElem: function () {
return this._panelElem;
}.protect(),
show : function() {
show: function () {
if (!this.isVisible()) {
this.parent();
this._tip.show();
@ -79,7 +80,7 @@ const ToolbarPaneItem = new Class({
}
},
hide : function() {
hide: function () {
if (this.isVisible()) {
this.parent();
this._tip.hide();
@ -87,11 +88,11 @@ const ToolbarPaneItem = new Class({
}
},
isVisible : function() {
isVisible: function () {
return this._visible;
},
disable : function() {
disable: function () {
this.hide();
var elem = this.getButtonElem();
if (this._enable) {
@ -106,7 +107,7 @@ const ToolbarPaneItem = new Class({
}
},
enable : function() {
enable: function () {
var elem = this.getButtonElem();
if (!this._enable) {
elem.bind('click', this._fn);
@ -116,11 +117,9 @@ const ToolbarPaneItem = new Class({
}
},
buildPanel : function() {
throw "Method must be implemented";
}.protect()
buildPanel: function () {
throw 'Method must be implemented';
}.protect(),
});
export default ToolbarPaneItem;

View File

@ -9,12 +9,12 @@ const linkEditor = require('./LinkEditor').default;
const linkIconTooltip = require('./LinkIconTooltip').default;
const listToolbarPanel = require('./ListToolbarPanel').default;
const menu = require('./Menu').default;
const modalDialogNotifier = require('./ModalDialogNotifier');
const noteEditor = require('./NoteEditor');
const toolbarItem = require('./ToolbarItem');
const toolbarNotifier = require('./ToolbarNotifier');
const toolbarPanelItem = require('./ToolbarPaneItem');
const topicShapePanel = require('./TopicShapePanel');
const modalDialogNotifier = require('./ModalDialogNotifier').default;
const noteEditor = require('./NoteEditor').default;
const toolbarItem = require('./ToolbarItem').default;
const toolbarNotifier = require('./ToolbarNotifier').default;
const toolbarPanelItem = require('./ToolbarPaneItem').default;
const topicShapePanel = require('./TopicShapePanel').default;
export const Widgets = {
ColorPalettePanel: colorPalettePanel,

View File

@ -21,11 +21,11 @@ function mindplot() {
const { Components } = require('./components');
return {
Commands,
Layout,
Models,
Persistence,
Widgets,
Components,
commands: Commands,
layout: Layout,
models: Models,
persistence: Persistence,
widget: Widgets,
component: Components,
};
}

View File

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

View File

@ -1,39 +1,28 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js'></script>
<script type='text/javascript' src='../../../../core-js/target/core.js'></script>
<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='../../../lib/components/header.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/Node.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/RootedTreeSet.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/LayoutManager.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/ChildrenSorterStrategy.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/AbstractBasicSorter.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/SymmetricSorter.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/GridSorter.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/BalancedSorter.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/OriginalLayout.js'></script>
<script type='text/javascript' src='../../../lib/components/layout/ChangeEvent.js'></script>
<script type="text/javascript" src="../../../../core-js/dist/core.js"></script>
<script type="text/javascript" src="../../../lib/components/header.js"></script>
<script type="text/javascript" src="../../../dist/main.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/TestSuite.js'></script>
<script type='text/javascript' src='test/BalancedTestSuite.js'></script>
<script type='text/javascript' src='test/SymmetricTestSuite.js'></script>
<script type='text/javascript' src='test/FreeTestSuite.js'></script>
<script type='text/javascript'>
window.addEvent('domready', function() {
var basicTest = new mindplot.layout.TestSuite();
var balancedTest = new mindplot.layout.BalancedTestSuite();
var symmetricTest = new mindplot.layout.SymmetricTestSuite();
var freeTest = new mindplot.layout.FreeTestSuite();
})
</script>
<script type="text/javascript" src="../../../dist/test/layout.test.js"></script>
<style type="text/css">
div.col {
@ -44,12 +33,9 @@
float: none;
}
</style>
</head>
<body>
<div id="basicTest" style="display: none;">
</head>
<body>
<div id="basicTest" style="display: none">
<h1>Basic Tests</h1>
<h3>testAligned:</h3>
@ -93,9 +79,9 @@
<h3>testReconnectSingleNode:</h3>
<div id="testReconnectSingleNode1" 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>
<h3>testBalanced:</h3>
@ -124,9 +110,9 @@
<div id="testBalancedNodeDragPredict1"></div>
<div id="testBalancedNodeDragPredict2"></div>
<div id="testBalancedNodeDragPredict3"></div>
</div>
</div>
<div id="symmetricTest" style="display: none;">
<div id="symmetricTest" style="display: none">
<h1>Symmetric Sorter Tests</h1>
<h3>testSymmetry:</h3>
<div id="testSymmetry"></div>
@ -140,9 +126,9 @@
<h3>testSymmetricDragPredict:</h3>
<div id="testSymmetricDragPredict1"></div>
</div>
</div>
<div id="freeTest" style="display: none;">
<div id="freeTest" style="display: none">
<h1>Free Positioning Tests</h1>
<h3>testFreePosition:</h3>
@ -189,7 +175,6 @@
<h3>testFreeOverlap:</h3>
<div id="testFreeOverlap1" class="col"></div>
<div id="testFreeOverlap2" class="col"></div>
</div>
</body>
</div>
</body>
</html>

View File

@ -1,41 +1,16 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='../../../../../wise-doc/src/main/webapp/js/mootools-core-1.3.2-full-compat.js'></script>
<script type='text/javascript'
src='../../../../../wise-doc/src/main/webapp/js/mootools-more-1.3.2.1-yui.js'></script>
<head>
<script src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"></script>
<script 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 src="../../../lib/components/libraries/bootstrap/js/bootstrap.min.js"></script>
<script type='text/javascript' src='../../../main/javascript/header.js'></script>
<script type='text/javascript' src='../../../../../core-js/target/classes/core.js'></script>
<script type='text/javascript' src='../../../main/javascript/widget/ToolbarItem.js'></script>
<script type='text/javascript' src='../../../main/javascript/widget/ColorPalettePanel.js'></script>
<script type='text/javascript'>
window.addEvent("load", function(e) {
var model = {
getValue: function() {
},
setValue : function(value) {
console.log("value:" + value);
}
};
var palette = new mindplot.widget.ColorPalettePanel('myButton', model,"/mindplot/src/main/javascript/widget");
});
</script>
</head>
<body>
<div id="myButton" style="border: 1px red solid">
The button
</div>
</body>
<script type="text/javascript" src="../../../../core-js/dist/core.js"></script>
<script type="text/javascript" src="../../../dist/test/palette.test.js"></script>
</head>
<body>
<div id="myButton" style="border: 1px red solid">The button</div>
</body>
</html>

View File

@ -15,374 +15,483 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.layout.BalancedTestSuite = new Class({
Extends: mindplot.layout.TestSuite,
const TestSuite = require('./TestSuite').default;
initialize:function() {
$('#balancedTest').setStyle("display","block");
const BalancedTestSuite = new Class({
Extends: TestSuite,
initialize: function () {
$('#balancedTest').css('display', 'block');
this.testBalanced();
this.testBalancedPredict();
this.testBalancedNodeDragPredict();
},
testBalanced: function() {
console.log("testBalanced:");
var position = {x:0, y:0};
var plotsize = {width:1000, height:200};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testBalanced: function () {
console.log('testBalanced:');
var position = { x: 0, y: 0 };
var plotsize = { width: 1000, height: 200 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.layout();
manager.plot("testBalanced1", plotsize);
manager.plot('testBalanced1', plotsize);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 2, 1);
manager.layout();
manager.plot("testBalanced2", plotsize);
manager.plot('testBalanced2', plotsize);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 3, 2);
manager.layout();
manager.plot("testBalanced3", plotsize);
manager.plot('testBalanced3', plotsize);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 4, 3);
manager.layout();
manager.plot("testBalanced4", plotsize);
manager.plot('testBalanced4', plotsize);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 5, 4);
manager.layout();
manager.plot("testBalanced5", plotsize);
manager.plot('testBalanced5', plotsize);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 6, 5);
manager.layout();
manager.plot("testBalanced6", plotsize);
manager.plot('testBalanced6', plotsize);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.connectNode(3, 7, 0)
manager.connectNode(7, 8, 0)
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.connectNode(3, 7, 0);
manager.connectNode(7, 8, 0);
manager.connectNode(7, 9, 1);
manager.layout();
manager.plot("testBalanced7", plotsize);
manager.plot('testBalanced7', plotsize);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.connectNode(6, 10, 0)
manager.connectNode(10, 11, 0)
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.connectNode(6, 10, 0);
manager.connectNode(10, 11, 0);
manager.connectNode(10, 12, 1);
manager.layout();
manager.plot("testBalanced8", plotsize);
manager.plot('testBalanced8', plotsize);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 13, 4);
manager.layout();
manager.plot("testBalanced9", {width:1000, height:400});
manager.plot('testBalanced9', { width: 1000, height: 400 });
// Check orders have shifted accordingly
$assert(manager.find(5).getOrder() == 6, "Node 5 should have order 6");
$assert(manager.find(5).getOrder() == 6, 'Node 5 should have order 6');
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 14, 5);
manager.layout();
manager.plot("testBalanced10", {width:1000, height:400});
manager.plot('testBalanced10', { width: 1000, height: 400 });
// Check orders have shifted accordingly
$assert(manager.find(6).getOrder() == 7, "Node 6 should have order 7");
$assert(manager.find(6).getOrder() == 7, 'Node 6 should have order 7');
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(15, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 15, 4);
manager.layout();
manager.plot("testBalanced11", {width:1000, height:400});
manager.plot('testBalanced11', { width: 1000, height: 400 });
// Check orders have shifted accordingly
$assert(manager.find(13).getOrder() == 6, "Node 13 should have order 6");
$assert(manager.find(5).getOrder() == 8, "Node 5 should have order 8");
$assert(manager.find(13).getOrder() == 6, 'Node 13 should have order 6');
$assert(manager.find(5).getOrder() == 8, 'Node 5 should have order 8');
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(16, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 16, 25);
manager.layout();
manager.plot("testBalanced12", {width:1000, height:400});
manager.plot('testBalanced12', { width: 1000, height: 400 });
// Check orders have shifted accordingly
$assert(manager.find(16).getOrder() == 9, "Node 16 should have order 9");
$assert(manager.find(16).getOrder() == 9, 'Node 16 should have order 9');
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(17, TestSuite.NODE_SIZE, position);
manager.addNode(18, TestSuite.NODE_SIZE, position);
manager.addNode(19, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 17, 11);
manager.connectNode(0, 18, 13);
manager.connectNode(0, 19, 10);
manager.layout();
manager.plot("testBalanced13", {width:1000, height:400});
manager.plot('testBalanced13', { width: 1000, height: 400 });
// Check that everything is ok
$assert(manager.find(1).getPosition().x > manager.find(0).getPosition().x,
"even order nodes must be at right of central topic");
$assert(manager.find(3).getPosition().x > manager.find(0).getPosition().x,
"even order nodes must be at right of central topic");
$assert(manager.find(5).getPosition().x > manager.find(0).getPosition().x,
"even order nodes must be at right of central topic");
$assert(manager.find(2).getPosition().x < manager.find(0).getPosition().x,
"odd order nodes must be at right of central topic");
$assert(manager.find(4).getPosition().x < manager.find(0).getPosition().x,
"odd order nodes must be at right of central topic");
$assert(manager.find(6).getPosition().x < manager.find(0).getPosition().x,
"odd order nodes must be at right of central topic");
$assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x,
"children of 1st level even order nodes must be to the right");
$assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x,
"children of 1st level even order nodes must be to the right");
$assert(manager.find(9).getPosition().x > manager.find(7).getPosition().x,
"children of 1st level even order nodes must be to the right");
$assert(manager.find(10).getPosition().x < manager.find(6).getPosition().x,
"children of 1st level odd order nodes must be to the left");
$assert(manager.find(11).getPosition().x < manager.find(10).getPosition().x,
"children of 1st level odd order nodes must be to the left");
$assert(manager.find(12).getPosition().x < manager.find(10).getPosition().x,
"children of 1st level odd order nodes must be to the left");
$assert(
manager.find(1).getPosition().x > manager.find(0).getPosition().x,
'even order nodes must be at right of central topic'
);
$assert(
manager.find(3).getPosition().x > manager.find(0).getPosition().x,
'even order nodes must be at right of central topic'
);
$assert(
manager.find(5).getPosition().x > manager.find(0).getPosition().x,
'even order nodes must be at right of central topic'
);
$assert(
manager.find(2).getPosition().x < manager.find(0).getPosition().x,
'odd order nodes must be at right of central topic'
);
$assert(
manager.find(4).getPosition().x < manager.find(0).getPosition().x,
'odd order nodes must be at right of central topic'
);
$assert(
manager.find(6).getPosition().x < manager.find(0).getPosition().x,
'odd order nodes must be at right of central topic'
);
$assert(
manager.find(7).getPosition().x > manager.find(3).getPosition().x,
'children of 1st level even order nodes must be to the right'
);
$assert(
manager.find(8).getPosition().x > manager.find(7).getPosition().x,
'children of 1st level even order nodes must be to the right'
);
$assert(
manager.find(9).getPosition().x > manager.find(7).getPosition().x,
'children of 1st level even order nodes must be to the right'
);
$assert(
manager.find(10).getPosition().x < manager.find(6).getPosition().x,
'children of 1st level odd order nodes must be to the left'
);
$assert(
manager.find(11).getPosition().x < manager.find(10).getPosition().x,
'children of 1st level odd order nodes must be to the left'
);
$assert(
manager.find(12).getPosition().x < manager.find(10).getPosition().x,
'children of 1st level odd order nodes must be to the left'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testBalancedPredict: function() {
console.log("testBalancedPredict:");
var position = {x:0, y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testBalancedPredict: function () {
console.log('testBalancedPredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0,1,0);
manager.connectNode(0,2,1);
manager.connectNode(0,3,2);
manager.connectNode(0,4,3);
manager.connectNode(0,5,4);
manager.connectNode(4,7,0);
manager.connectNode(4,8,1);
manager.connectNode(8,9,0);
manager.connectNode(3,10,0);
manager.connectNode(3,11,1);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(0, 3, 2);
manager.connectNode(0, 4, 3);
manager.connectNode(0, 5, 4);
manager.connectNode(4, 7, 0);
manager.connectNode(4, 8, 1);
manager.connectNode(8, 9, 0);
manager.connectNode(3, 10, 0);
manager.connectNode(3, 11, 1);
manager.layout();
// Graph 1
var graph1 = manager.plot("testBalancedPredict1", {width:1000, height:400});
var graph1 = manager.plot('testBalancedPredict1', { width: 1000, height: 400 });
console.log("\tAdded as child of node 0 and dropped at (165, -70):");
var prediction1a = manager.predict(0, null, {x:165, y:-70});
console.log('\tAdded as child of node 0 and dropped at (165, -70):');
var prediction1a = manager.predict(0, null, { x: 165, y: -70 });
this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.y < manager.find(1).getPosition().y &&
prediction1a.position.x == manager.find(1).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction1a.order == 0, "Prediction order should be 0");
$assert(
prediction1a.position.y < manager.find(1).getPosition().y &&
prediction1a.position.x == manager.find(1).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction1a.order == 0, 'Prediction order should be 0');
console.log("\tAdded as child of node 0 and dropped at (165, -10):");
var prediction1b = manager.predict(0, null, {x:165, y:-10});
console.log('\tAdded as child of node 0 and dropped at (165, -10):');
var prediction1b = manager.predict(0, null, { x: 165, y: -10 });
this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.y > manager.find(1).getPosition().y &&
$assert(
prediction1b.position.y > manager.find(1).getPosition().y &&
prediction1b.position.y < manager.find(3).getPosition().y &&
prediction1b.position.x == manager.find(1).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction1b.order == 2, "Prediction order should be 2");
prediction1b.position.x == manager.find(1).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction1b.order == 2, 'Prediction order should be 2');
console.log("\tAdded as child of node 0 and dropped at (145, 15):");
var prediction1c = manager.predict(0, null, {x:145, y:15});
console.log('\tAdded as child of node 0 and dropped at (145, 15):');
var prediction1c = manager.predict(0, null, { x: 145, y: 15 });
this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.y > manager.find(3).getPosition().y &&
$assert(
prediction1c.position.y > manager.find(3).getPosition().y &&
prediction1c.position.y < manager.find(5).getPosition().y &&
prediction1c.position.x == manager.find(3).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction1c.order == 4, "Prediction order should be 4");
prediction1c.position.x == manager.find(3).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction1c.order == 4, 'Prediction order should be 4');
console.log("\tAdded as child of node 0 and dropped at (145, 70):");
var prediction1d = manager.predict(0, null, {x:145, y:70});
console.log('\tAdded as child of node 0 and dropped at (145, 70):');
var prediction1d = manager.predict(0, null, { x: 145, y: 70 });
this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.y > manager.find(5).getPosition().y &&
prediction1d.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction1d.order == 6, "Prediction order should be 6");
$assert(
prediction1d.position.y > manager.find(5).getPosition().y &&
prediction1d.position.x == manager.find(5).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction1d.order == 6, 'Prediction order should be 6');
// Graph 2
var graph2 = manager.plot("testBalancedPredict2", {width:1000, height:400});
var graph2 = manager.plot('testBalancedPredict2', { width: 1000, height: 400 });
console.log("\tAdded as child of node 0 and dropped at (-145, -50):");
var prediction2a = manager.predict(0, null, {x:-145, y:-50});
console.log('\tAdded as child of node 0 and dropped at (-145, -50):');
var prediction2a = manager.predict(0, null, { x: -145, y: -50 });
this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.y < manager.find(2).getPosition().y &&
prediction2a.position.x == manager.find(2).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2a.order == 1, "Prediction order should be 1");
$assert(
prediction2a.position.y < manager.find(2).getPosition().y &&
prediction2a.position.x == manager.find(2).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2a.order == 1, 'Prediction order should be 1');
console.log("\tAdded as child of node 0 and dropped at (-145, -10):");
var prediction2b = manager.predict(0, null, {x:-145, y:-10});
console.log('\tAdded as child of node 0 and dropped at (-145, -10):');
var prediction2b = manager.predict(0, null, { x: -145, y: -10 });
this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.y > manager.find(2).getPosition().y &&
$assert(
prediction2b.position.y > manager.find(2).getPosition().y &&
prediction2b.position.y < manager.find(4).getPosition().y &&
prediction2b.position.x == manager.find(2).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2b.order == 3, "Prediction order should be 3");
prediction2b.position.x == manager.find(2).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2b.order == 3, 'Prediction order should be 3');
console.log("\tAdded as child of node 0 and dropped at (-145, 40):");
var prediction2c = manager.predict(0, null, {x:-145, y:400});
console.log('\tAdded as child of node 0 and dropped at (-145, 40):');
var prediction2c = manager.predict(0, null, { x: -145, y: 400 });
this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.y > manager.find(4).getPosition().y &&
prediction2c.position.x == manager.find(4).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2c.order == 5, "Prediction order should be 5");
$assert(
prediction2c.position.y > manager.find(4).getPosition().y &&
prediction2c.position.x == manager.find(4).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2c.order == 5, 'Prediction order should be 5');
// Graph 3
console.log("\tPredict nodes added with no position:");
var graph3 = manager.plot("testBalancedPredict3", {width:1000, height:400});
console.log('\tPredict nodes added with no position:');
var graph3 = manager.plot('testBalancedPredict3', { width: 1000, height: 400 });
var prediction3 = manager.predict(0, null, null);
this._plotPrediction(graph3, prediction3);
$assert(prediction3.position.y > manager.find(4).getPosition().y &&
prediction3.position.x == manager.find(4).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction3.order == 5, "Prediction order should be 5");
$assert(
prediction3.position.y > manager.find(4).getPosition().y &&
prediction3.position.x == manager.find(4).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction3.order == 5, 'Prediction order should be 5');
console.log("\tPredict nodes added with no position:");
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, prediction3.position);
manager.connectNode(0,6,prediction3.order);
console.log('\tPredict nodes added with no position:');
manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position);
manager.connectNode(0, 6, prediction3.order);
manager.layout();
var graph4 = manager.plot("testBalancedPredict4", {width:1000, height:400});
var graph4 = manager.plot('testBalancedPredict4', { width: 1000, height: 400 });
var prediction4 = manager.predict(0, null, null);
this._plotPrediction(graph4, prediction4);
$assert(prediction4.position.y > manager.find(5).getPosition().y &&
prediction4.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction4.order == 6, "Prediction order should be 6");
$assert(
prediction4.position.y > manager.find(5).getPosition().y &&
prediction4.position.x == manager.find(5).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction4.order == 6, 'Prediction order should be 6');
console.log("\tPredict nodes added only a root node:");
console.log('\tPredict nodes added only a root node:');
manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4).removeNode(5);
manager.layout();
var graph5 = manager.plot("testBalancedPredict5", {width:1000, height:400});
var graph5 = manager.plot('testBalancedPredict5', { width: 1000, height: 400 });
var prediction5a = manager.predict(0, null, null);
var prediction5b = manager.predict(0, null, {x:40, y:100});
var prediction5b = manager.predict(0, null, { x: 40, y: 100 });
this._plotPrediction(graph5, prediction5a);
this._plotPrediction(graph5, prediction5b);
$assert(prediction5a.position.x > manager.find(0).getPosition().x &&
prediction5a.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction5a.order == 0, "Prediction order should be 0");
$assert(prediction5a.position.x == prediction5b.position.x &&
prediction5a.position.y == prediction5b.position.y, "Both predictions should be the same");
$assert(prediction5a.order == prediction5b.order, "Both predictions should be the same");
$assert(
prediction5a.position.x > manager.find(0).getPosition().x &&
prediction5a.position.y == manager.find(0).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction5a.order == 0, 'Prediction order should be 0');
$assert(
prediction5a.position.x == prediction5b.position.x &&
prediction5a.position.y == prediction5b.position.y,
'Both predictions should be the same'
);
$assert(prediction5a.order == prediction5b.order, 'Both predictions should be the same');
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testBalancedNodeDragPredict: function() {
console.log("testBalancedNodeDragPredict:");
var position = {x:0, y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testBalancedNodeDragPredict: function () {
console.log('testBalancedNodeDragPredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Graph 1
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.layout();
var graph1 = manager.plot("testBalancedNodeDragPredict1", {width:800, height:400});
var graph1 = manager.plot('testBalancedNodeDragPredict1', { width: 800, height: 400 });
var prediction1a = manager.predict(0, 1, {x:50, y:50});
var prediction1a = manager.predict(0, 1, { x: 50, y: 50 });
this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x == manager.find(1).getPosition().x &&
$assert(
prediction1a.position.x == manager.find(1).getPosition().x &&
prediction1a.position.y == manager.find(1).getPosition().y,
"Prediction position should be the same as node 1");
$assert(prediction1a.order == manager.find(1).getOrder(), "Prediction order should be the same as node 1");
'Prediction position should be the same as node 1'
);
$assert(
prediction1a.order == manager.find(1).getOrder(),
'Prediction order should be the same as node 1'
);
var prediction1b = manager.predict(0, 1, {x:50, y:-50});
var prediction1b = manager.predict(0, 1, { x: 50, y: -50 });
this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x == manager.find(1).getPosition().x &&
$assert(
prediction1b.position.x == manager.find(1).getPosition().x &&
prediction1b.position.y == manager.find(1).getPosition().y,
"Prediction position should be the same as node 1");
$assert(prediction1b.order == manager.find(1).getOrder(), "Prediction order should be the same as node 1");
'Prediction position should be the same as node 1'
);
$assert(
prediction1b.order == manager.find(1).getOrder(),
'Prediction order should be the same as node 1'
);
var prediction1c = manager.predict(0, 1, {x:-50, y:50});
var prediction1c = manager.predict(0, 1, { x: -50, y: 50 });
this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.x < manager.find(0).getPosition().x &&
prediction1c.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction1c.order == 1, "Prediction order should be the same as node 1");
$assert(
prediction1c.position.x < manager.find(0).getPosition().x &&
prediction1c.position.y == manager.find(0).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1c.order == 1, 'Prediction order should be the same as node 1');
var prediction1d = manager.predict(0, 1, {x:-50, y:-50});
var prediction1d = manager.predict(0, 1, { x: -50, y: -50 });
this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.x < manager.find(0).getPosition().x &&
prediction1d.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction1d.order == 1, "Prediction order should be the same as node 1");
$assert(
prediction1d.position.x < manager.find(0).getPosition().x &&
prediction1d.position.y == manager.find(0).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1d.order == 1, 'Prediction order should be the same as node 1');
// Graph 2
manager.disconnectNode(1);
manager.connectNode(0, 1, 1);
manager.layout();
var graph2 = manager.plot("testBalancedNodeDragPredict2", {width:800, height:400});
var graph2 = manager.plot('testBalancedNodeDragPredict2', { width: 800, height: 400 });
var prediction2a = manager.predict(0, 1, {x:50, y:50});
var prediction2a = manager.predict(0, 1, { x: 50, y: 50 });
this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.x > manager.find(0).getPosition().x &&
prediction2a.position.y == manager.find(0).getPosition().y, "Prediction is positioned incorrectly");
$assert(prediction2a.order == 0, "Prediction order should be 0");
$assert(
prediction2a.position.x > manager.find(0).getPosition().x &&
prediction2a.position.y == manager.find(0).getPosition().y,
'Prediction is positioned incorrectly'
);
$assert(prediction2a.order == 0, 'Prediction order should be 0');
var prediction2b = manager.predict(0, 1, {x:50, y:-50});
var prediction2b = manager.predict(0, 1, { x: 50, y: -50 });
this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.x > manager.find(0).getPosition().x &&
prediction2b.position.y == manager.find(0).getPosition().y, "Prediction is positioned incorrectly");
$assert(prediction2b.order == 0, "Prediction order should be 0");
$assert(
prediction2b.position.x > manager.find(0).getPosition().x &&
prediction2b.position.y == manager.find(0).getPosition().y,
'Prediction is positioned incorrectly'
);
$assert(prediction2b.order == 0, 'Prediction order should be 0');
var prediction2c = manager.predict(0, 1, {x:-50, y:50});
var prediction2c = manager.predict(0, 1, { x: -50, y: 50 });
this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.x == manager.find(1).getPosition().x &&
$assert(
prediction2c.position.x == manager.find(1).getPosition().x &&
prediction2c.position.y == manager.find(1).getPosition().y,
"Prediction position should be the same as node 1");
$assert(prediction2c.order == manager.find(1).getOrder(), "Prediction order should be the same as node 1");
'Prediction position should be the same as node 1'
);
$assert(
prediction2c.order == manager.find(1).getOrder(),
'Prediction order should be the same as node 1'
);
var prediction2d = manager.predict(0, 1, {x:-50, y:-50});
var prediction2d = manager.predict(0, 1, { x: -50, y: -50 });
this._plotPrediction(graph2, prediction2d);
$assert(prediction2d.position.x == manager.find(1).getPosition().x &&
$assert(
prediction2d.position.x == manager.find(1).getPosition().x &&
prediction2d.position.y == manager.find(1).getPosition().y,
"Prediction position should be the same as node 1");
$assert(prediction2d.order == manager.find(1).getOrder(), "Prediction order should be the same as node 1");
'Prediction position should be the same as node 1'
);
$assert(
prediction2d.order == manager.find(1).getOrder(),
'Prediction order should be the same as node 1'
);
// Graph 3
manager.disconnectNode(1);
manager.connectNode(0, 1, 0);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,2,2);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
manager.layout();
var graph3 = manager.plot("testBalancedNodeDragPredict3", {width:800, height:400});
var graph3 = manager.plot('testBalancedNodeDragPredict3', { width: 800, height: 400 });
var prediction3a = manager.predict(0, 1, {x:50, y:50});
var prediction3a = manager.predict(0, 1, { x: 50, y: 50 });
this._plotPrediction(graph3, prediction3a);
$assert(prediction3a.position.x == manager.find(2).getPosition().x &&
prediction3a.position.y > manager.find(2).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction3a.order == 4, "Prediction order should be 4");
$assert(
prediction3a.position.x == manager.find(2).getPosition().x &&
prediction3a.position.y > manager.find(2).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction3a.order == 4, 'Prediction order should be 4');
var prediction3b = manager.predict(0, 1, {x:50, y:-50});
var prediction3b = manager.predict(0, 1, { x: 50, y: -50 });
this._plotPrediction(graph3, prediction3b);
$assert(prediction3b.position.x == manager.find(1).getPosition().x &&
$assert(
prediction3b.position.x == manager.find(1).getPosition().x &&
prediction3b.position.y == manager.find(1).getPosition().y &&
prediction3b.order == manager.find(1).getOrder(), "Prediction should be the exact same as dragged node");
prediction3b.order == manager.find(1).getOrder(),
'Prediction should be the exact same as dragged node'
);
var prediction3c = manager.predict(0, 1, {x:-50, y:50});
var prediction3c = manager.predict(0, 1, { x: -50, y: 50 });
this._plotPrediction(graph3, prediction3c);
$assert(prediction3c.position.x < manager.find(0).getPosition().x &&
prediction3c.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction3c.order == 1, "Prediction order should be 1");
$assert(
prediction3c.position.x < manager.find(0).getPosition().x &&
prediction3c.position.y == manager.find(0).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction3c.order == 1, 'Prediction order should be 1');
var prediction3d = manager.predict(0, 1, {x:-50, y:-50});
var prediction3d = manager.predict(0, 1, { x: -50, y: -50 });
this._plotPrediction(graph3, prediction3d);
$assert(prediction3d.position.x < manager.find(0).getPosition().x &&
prediction3d.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction3d.order == 1, "Prediction order should be 1");
$assert(
prediction3d.position.x < manager.find(0).getPosition().x &&
prediction3d.position.y == manager.find(0).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction3d.order == 1, 'Prediction order should be 1');
var prediction3e = manager.predict(0, 1, {x:50, y:0});
var prediction3e = manager.predict(0, 1, { x: 50, y: 0 });
this._plotPrediction(graph3, prediction3e);
$assert(prediction3e.position.x == manager.find(1).getPosition().x &&
$assert(
prediction3e.position.x == manager.find(1).getPosition().x &&
prediction3e.position.y == manager.find(1).getPosition().y,
"Prediction position should be the same as node 1");
$assert(prediction3e.order == manager.find(1).getOrder(), "Prediction order should be the same as node 1");
'Prediction position should be the same as node 1'
);
$assert(
prediction3e.order == manager.find(1).getOrder(),
'Prediction order should be the same as node 1'
);
console.log("OK!\n\n");
}
console.log('OK!\n\n');
},
});
export default BalancedTestSuite;

View File

@ -15,11 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.layout.FreeTestSuite = new Class({
Extends: mindplot.layout.TestSuite,
const TestSuite = require('./TestSuite').default;
const FreeTestSuite = new Class({
Extends: TestSuite,
initialize:function() {
$('#freeTest').setStyle("display","block");
initialize: function () {
$('#freeTest').css('display', 'block');
this.testFreePosition();
this.testFreePredict();
@ -31,121 +32,133 @@ mindplot.layout.FreeTestSuite = new Class({
this.testFreeOverlap();
},
testFreePosition: function() {
console.log("testFreePosition:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testFreePosition: function () {
console.log('testFreePosition:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(20, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(21, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(22, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.addNode(15, TestSuite.NODE_SIZE, position);
manager.addNode(16, TestSuite.NODE_SIZE, position);
manager.addNode(17, TestSuite.NODE_SIZE, position);
manager.addNode(18, TestSuite.NODE_SIZE, position);
manager.addNode(19, TestSuite.NODE_SIZE, position);
manager.addNode(20, TestSuite.NODE_SIZE, position);
manager.addNode(21, TestSuite.NODE_SIZE, position);
manager.addNode(22, TestSuite.NODE_SIZE, position);
manager.connectNode(0,1,0).connectNode(0,2,1).connectNode(0,3,2).connectNode(0,4,3);
manager.connectNode(4,21,0).connectNode(4,22,0);
manager.connectNode(1,5,0);
manager.connectNode(5,6,0).connectNode(6,8,0).connectNode(8,9,0);
manager.connectNode(5,7,1).connectNode(7,10,0);
manager.connectNode(3,11,0).connectNode(11,14,0).connectNode(14,18,0).connectNode(14,19,1).connectNode(14,20,2);
manager.connectNode(3,12,1).connectNode(12,15,0).connectNode(12,16,1).connectNode(12,17,2);
manager.connectNode(3,13,2);
manager.connectNode(0, 1, 0).connectNode(0, 2, 1).connectNode(0, 3, 2).connectNode(0, 4, 3);
manager.connectNode(4, 21, 0).connectNode(4, 22, 0);
manager.connectNode(1, 5, 0);
manager.connectNode(5, 6, 0).connectNode(6, 8, 0).connectNode(8, 9, 0);
manager.connectNode(5, 7, 1).connectNode(7, 10, 0);
manager
.connectNode(3, 11, 0)
.connectNode(11, 14, 0)
.connectNode(14, 18, 0)
.connectNode(14, 19, 1)
.connectNode(14, 20, 2);
manager
.connectNode(3, 12, 1)
.connectNode(12, 15, 0)
.connectNode(12, 16, 1)
.connectNode(12, 17, 2);
manager.connectNode(3, 13, 2);
manager.layout();
manager.plot("testFreePosition1", {width:1400, height:600});
manager.plot('testFreePosition1', { width: 1400, height: 600 });
console.log("\tmove node 12 to (300,30):");
manager.moveNode(12, {x:300, y:30});
console.log('\tmove node 12 to (300,30):');
manager.moveNode(12, { x: 300, y: 30 });
manager.layout(true);
manager.plot("testFreePosition2", {width:1400, height:600});
this._assertFreePosition(manager, 12, {x:300, y:30})
manager.plot('testFreePosition2', { width: 1400, height: 600 });
this._assertFreePosition(manager, 12, { x: 300, y: 30 });
console.log("\tmove node 13 to (340,180):");
var node13Pos = {x:340, y:180};
console.log('\tmove node 13 to (340,180):');
var node13Pos = { x: 340, y: 180 };
manager.moveNode(13, node13Pos);
manager.layout(true);
manager.plot("testFreePosition3", {width:1400, height:600});
manager.plot('testFreePosition3', { width: 1400, height: 600 });
this._assertFreePosition(manager, 13, node13Pos);
console.log("\tmove node 11 to (250,-50):");
manager.moveNode(11, {x:250, y:-50});
console.log('\tmove node 11 to (250,-50):');
manager.moveNode(11, { x: 250, y: -50 });
manager.layout(true);
manager.plot("testFreePosition4", {width:1400, height:600});
this._assertFreePosition(manager, 11, {x:250, y:-50});
$assert(manager.find(13).getPosition().x == node13Pos.x && manager.find(13).getPosition().y == node13Pos.y,
"Node 13 shouldn't have moved");
manager.plot('testFreePosition4', { width: 1400, height: 600 });
this._assertFreePosition(manager, 11, { x: 250, y: -50 });
$assert(
manager.find(13).getPosition().x == node13Pos.x &&
manager.find(13).getPosition().y == node13Pos.y,
"Node 13 shouldn't have moved"
);
console.log("\tmove node 7 to (350,-190):");
manager.moveNode(7, {x:350, y:-190});
console.log('\tmove node 7 to (350,-190):');
manager.moveNode(7, { x: 350, y: -190 });
manager.layout(true);
manager.plot("testFreePosition5", {width:1400, height:600});
this._assertFreePosition(manager, 7, {x:350, y:-190});
manager.plot('testFreePosition5', { width: 1400, height: 600 });
this._assertFreePosition(manager, 7, { x: 350, y: -190 });
console.log("\tadd node 23 to 12:");
manager.addNode(23, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.connectNode(12,23,3);
console.log('\tadd node 23 to 12:');
manager.addNode(23, TestSuite.NODE_SIZE, position);
manager.connectNode(12, 23, 3);
manager.layout(true);
manager.plot("testFreePosition6", {width:1400, height:600});
manager.plot('testFreePosition6', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null);
console.log("\tmove node 4 to (-300, 190):");
manager.moveNode(4, {x:-300, y:190});
console.log('\tmove node 4 to (-300, 190):');
manager.moveNode(4, { x: -300, y: 190 });
manager.layout(true);
manager.plot("testFreePosition7", {width:1400, height:600});
this._assertFreePosition(manager, 4, {x:-300, y:190});
manager.plot('testFreePosition7', { width: 1400, height: 600 });
this._assertFreePosition(manager, 4, { x: -300, y: 190 });
console.log("\tadd node 24 to 3:");
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.connectNode(3,24,3);
console.log('\tadd node 24 to 3:');
manager.addNode(24, TestSuite.NODE_SIZE, position);
manager.connectNode(3, 24, 3);
manager.layout(true);
manager.plot("testFreePosition8", {width:1400, height:600});
manager.plot('testFreePosition8', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null);
console.log("\tadd node 25 to 17:");
manager.addNode(25, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.connectNode(17,25,0);
console.log('\tadd node 25 to 17:');
manager.addNode(25, TestSuite.NODE_SIZE, position);
manager.connectNode(17, 25, 0);
manager.layout(true);
manager.plot("testFreePosition9", {width:1400, height:600});
manager.plot('testFreePosition9', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testFreePredict: function() {
console.log("testFreePredict:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testFreePredict: function () {
console.log('testFreePredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
@ -160,50 +173,62 @@ mindplot.layout.FreeTestSuite = new Class({
manager.connectNode(2, 10, 1);
manager.layout();
var graph = manager.plot("testFreePredict1", {width:1000, height:400});
var graph = manager.plot('testFreePredict1', { width: 1000, height: 400 });
var pos1 = {x: 370, y:80};
var pos1 = { x: 370, y: 80 };
var predict1 = manager.predict(5, 11, pos1, true);
this._plotPrediction(graph, predict1);
$assert(predict1.position.x == pos1.x && predict1.position.y == pos1.y, "free predict should return the same position");
$assert(
predict1.position.x == pos1.x && predict1.position.y == pos1.y,
'free predict should return the same position'
);
var pos2 = {x: -200, y:80};
var pos2 = { x: -200, y: 80 };
var predict2 = manager.predict(0, 2, pos2, true);
this._plotPrediction(graph, predict2);
$assert(predict2.position.x == pos2.x && predict2.position.y == pos2.y, "free predict should return the same position");
$assert(
predict2.position.x == pos2.x && predict2.position.y == pos2.y,
'free predict should return the same position'
);
var pos3 = {x: 200, y:30};
var pos3 = { x: 200, y: 30 };
var node5 = manager.find(5);
var predict3 = manager.predict(3, 5, pos3, true);
this._plotPrediction(graph, predict3);
$assert(predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, "free predict should return the x-coordinate of the node");
$assert(
predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y,
'free predict should return the x-coordinate of the node'
);
var pos4 = {x: -100, y:45};
var pos4 = { x: -100, y: 45 };
var node10 = manager.find(10);
var predict4 = manager.predict(2, 10, pos4, true);
this._plotPrediction(graph, predict4);
$assert(predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, "free predict should return the x-coordinate of the node");
$assert(
predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y,
'free predict should return the x-coordinate of the node'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testReconnectFreeNode: function() {
console.log("testReconnectFreeNode:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testReconnectFreeNode: function () {
console.log('testReconnectFreeNode:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
@ -218,265 +243,313 @@ mindplot.layout.FreeTestSuite = new Class({
manager.connectNode(2, 10, 1);
manager.layout();
manager.plot("testReconnectFreeNode1", {width:1000, height:400});
manager.plot('testReconnectFreeNode1', { width: 1000, height: 400 });
console.log("\tmove node 5");
manager.moveNode(5, {x:250, y:30});
console.log('\tmove node 5');
manager.moveNode(5, { x: 250, y: 30 });
manager.layout();
manager.plot("testReconnectFreeNode2", {width:1000, height:400});
this._assertFreePosition(manager, 5, {x:250, y:30});
manager.plot('testReconnectFreeNode2', { width: 1000, height: 400 });
this._assertFreePosition(manager, 5, { x: 250, y: 30 });
console.log("\treconnect node 5 to node 2");
console.log('\treconnect node 5 to node 2');
manager.disconnectNode(5);
manager.connectNode(2,5,2);
manager.connectNode(2, 5, 2);
manager.layout();
manager.plot("testReconnectFreeNode3", {width:1000, height:400});
$assert(manager.find(5).getPosition().y > manager.find(10).getPosition().y &&
manager.find(5).getPosition().x == manager.find(10).getPosition().x, "Node 5 is incorrectly positioned"
manager.plot('testReconnectFreeNode3', { width: 1000, height: 400 });
$assert(
manager.find(5).getPosition().y > manager.find(10).getPosition().y &&
manager.find(5).getPosition().x == manager.find(10).getPosition().x,
'Node 5 is incorrectly positioned'
);
$assert(manager.find(5).getOrder() == 2, "Node 5 should have order 2");
$assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2');
console.log("\tmove node 8");
manager.moveNode(8, {x:-370, y:60});
console.log('\tmove node 8');
manager.moveNode(8, { x: -370, y: 60 });
manager.layout();
manager.plot("testReconnectFreeNode4", {width:1000, height:400});
this._assertFreePosition(manager, 8, {x:-370, y:60});
manager.plot('testReconnectFreeNode4', { width: 1000, height: 400 });
this._assertFreePosition(manager, 8, { x: -370, y: 60 });
console.log("\treconnect node 5 to node 10");
console.log('\treconnect node 5 to node 10');
manager.disconnectNode(5);
manager.connectNode(10,5,0);
manager.connectNode(10, 5, 0);
manager.layout();
manager.plot("testReconnectFreeNode5", {width:1000, height:400});
$assert(manager.find(5).getPosition().y == manager.find(10).getPosition().y &&
manager.find(5).getPosition().x < manager.find(10).getPosition().x, "Node 5 is incorrectly positioned"
manager.plot('testReconnectFreeNode5', { width: 1000, height: 400 });
$assert(
manager.find(5).getPosition().y == manager.find(10).getPosition().y &&
manager.find(5).getPosition().x < manager.find(10).getPosition().x,
'Node 5 is incorrectly positioned'
);
$assert(manager.find(5).getOrder() == 0, "Node 5 should have order 0");
$assert(manager.find(5).getOrder() == 0, 'Node 5 should have order 0');
console.log("reconnect node 5 to node 3");
console.log('reconnect node 5 to node 3');
manager.disconnectNode(5);
manager.connectNode(3,5,2);
manager.connectNode(3, 5, 2);
manager.layout();
manager.plot("testReconnectFreeNode6", {width:1000, height:400});
$assert(manager.find(5).getPosition().y > manager.find(6).getPosition().y &&
manager.find(5).getPosition().x == manager.find(6).getPosition().x, "Node 5 is incorrectly positioned"
manager.plot('testReconnectFreeNode6', { width: 1000, height: 400 });
$assert(
manager.find(5).getPosition().y > manager.find(6).getPosition().y &&
manager.find(5).getPosition().x == manager.find(6).getPosition().x,
'Node 5 is incorrectly positioned'
);
$assert(manager.find(5).getOrder() == 2, "Node 5 should have order 2");
$assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2');
console.log("\tmove node 8");
manager.moveNode(8, {x:370, y:30});
console.log('\tmove node 8');
manager.moveNode(8, { x: 370, y: 30 });
manager.layout();
manager.plot("testReconnectFreeNode7", {width:1000, height:400});
this._assertFreePosition(manager, 8, {x:370, y:30});
manager.plot('testReconnectFreeNode7', { width: 1000, height: 400 });
this._assertFreePosition(manager, 8, { x: 370, y: 30 });
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testSiblingOverlapping: function() {
console.log("testSiblingOverlapping:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testSiblingOverlapping: function () {
console.log('testSiblingOverlapping:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,2,0);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,3,1);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,2);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,3);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,4);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,7,5);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,8,6);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,9,4);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 1);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 2);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 3);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 4);
manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(1, 7, 5);
manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(1, 8, 6);
manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(0, 9, 4);
manager.layout();
manager.plot("testSiblingOverlapping1", {width:800, height:600});
manager.plot('testSiblingOverlapping1', { width: 800, height: 600 });
console.log("\tmove node 2");
manager.moveNode(2, {x:250, y: -30});
console.log('\tmove node 2');
manager.moveNode(2, { x: 250, y: -30 });
manager.layout();
manager.plot("testSiblingOverlapping2", {width:800, height:600});
this._assertFreePosition(manager, 2, {x:250, y: -30});
manager.plot('testSiblingOverlapping2', { width: 800, height: 600 });
this._assertFreePosition(manager, 2, { x: 250, y: -30 });
console.log("\tmove node 7");
manager.moveNode(7, {x:250, y: 100});
console.log('\tmove node 7');
manager.moveNode(7, { x: 250, y: 100 });
manager.layout();
manager.plot("testSiblingOverlapping3", {width:800, height:600});
this._assertFreePosition(manager, 7, {x:250, y: 100});
manager.plot('testSiblingOverlapping3', { width: 800, height: 600 });
this._assertFreePosition(manager, 7, { x: 250, y: 100 });
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testRootNodeChildrenPositioning: function() {
console.log("testRootNodeChildrenPositioning:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testRootNodeChildrenPositioning: function () {
console.log('testRootNodeChildrenPositioning:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,2,1);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,3,2);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,4,3);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,5,4);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,6,5);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 2);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(0, 4, 3);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 4);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 5);
manager.layout();
manager.plot("testRootNodeChildrenPositioning1", {width:800, height:600});
manager.plot('testRootNodeChildrenPositioning1', { width: 800, height: 600 });
console.log("\tmove node 1");
manager.moveNode(1, {x:150, y:0});
console.log('\tmove node 1');
manager.moveNode(1, { x: 150, y: 0 });
manager.layout();
manager.plot("testRootNodeChildrenPositioning2", {width:800, height:600});
this._assertFreePosition(manager, 1, {x:150, y:0});
manager.plot('testRootNodeChildrenPositioning2', { width: 800, height: 600 });
this._assertFreePosition(manager, 1, { x: 150, y: 0 });
console.log("\tmove node 4");
manager.moveNode(4, {x:-140, y:30});
console.log('\tmove node 4');
manager.moveNode(4, { x: -140, y: 30 });
manager.layout();
manager.plot("testRootNodeChildrenPositioning3", {width:800, height:600});
this._assertFreePosition(manager, 4, {x:-140, y:30});
manager.plot('testRootNodeChildrenPositioning3', { width: 800, height: 600 });
this._assertFreePosition(manager, 4, { x: -140, y: 30 });
console.log("\tmove node 2");
manager.moveNode(2, {x:-150, y:-50});
console.log('\tmove node 2');
manager.moveNode(2, { x: -150, y: -50 });
manager.layout();
manager.plot("testRootNodeChildrenPositioning4", {width:800, height:600});
this._assertFreePosition(manager, 2, {x:-150, y:-50});
manager.plot('testRootNodeChildrenPositioning4', { width: 800, height: 600 });
this._assertFreePosition(manager, 2, { x: -150, y: -50 });
//TODO(gb): fix this. It's not working
// console.log("\tmove node 6");
// manager.moveNode(6, {x:-150, y:-50});
// manager.layout();
// manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600});
// this._assertFreePosition(manager, 6, {x:-150, y:-50});
// console.log("\tmove node 6");
// manager.moveNode(6, {x:-150, y:-50});
// manager.layout();
// manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600});
// this._assertFreePosition(manager, 6, {x:-150, y:-50});
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testBalancedFreePredict: function() {
console.log("testBalancedFreePredict:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testBalancedFreePredict: function () {
console.log('testBalancedFreePredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.layout();
var graph1 = manager.plot("testBalancedFreePredict1", {width:800, height:400});
var graph1 = manager.plot('testBalancedFreePredict1', { width: 800, height: 400 });
var predict1 = manager.predict(0, 1, {x:70, y:0}, true);
var predict1 = manager.predict(0, 1, { x: 70, y: 0 }, true);
this._plotPrediction(graph1, predict1);
$assert(predict1.position.x == manager.find(1).getPosition().x, "Prediction x pos should be the same as node 1");
$assert(
predict1.position.x == manager.find(1).getPosition().x,
'Prediction x pos should be the same as node 1'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testFreeReorder: function() {
console.log("testFreeReorder:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testFreeReorder: function () {
console.log('testFreeReorder:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,1);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,2);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,2,2);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,7,0);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,8,1);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,9,2);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,10,3);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0);
manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1);
manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2);
manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,3,4);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,11,0);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,12,1);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,13,2);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,14,3);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,15,4);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,16,5);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4);
manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0);
manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1);
manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2);
manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3);
manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4);
manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5);
manager.layout();
manager.moveNode(14, {x:270, y:-160});
manager.moveNode(14, { x: 270, y: -160 });
manager.layout();
manager.plot("testFreeReorder1", {width:800, height:1200});
$assert(manager.find(14).getPosition().y > manager.find(10).getPosition().y, "Node 14 should be below branch 2");
manager.plot('testFreeReorder1', { width: 800, height: 1200 });
$assert(
manager.find(14).getPosition().y > manager.find(10).getPosition().y,
'Node 14 should be below branch 2'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testFreeOverlap: function() {
console.log("testFreeOverlap:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testFreeOverlap: function () {
console.log('testFreeOverlap:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,1,0);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,1);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,2);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,2,2);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,7,0);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,8,1);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,9,2);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,10,3);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0);
manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1);
manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2);
manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,3,4);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,11,0);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,12,1);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,13,2);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,14,3);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,15,4);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,16,5);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4);
manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0);
manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1);
manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2);
manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3);
manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4);
manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5);
manager.layout();
manager.plot("testFreeOverlap1", {width:800, height:1200});
manager.plot('testFreeOverlap1', { width: 800, height: 1200 });
manager.moveNode(14, {x:270, y:7});
manager.moveNode(14, { x: 270, y: 7 });
manager.layout();
manager.plot("testFreeOverlap2", {width:800, height:1200});
$assert(manager.find(2).getPosition().y > manager.find(1).getPosition().y, "Branches 1 and 2 are overlapping");
manager.plot('testFreeOverlap2', { width: 800, height: 1200 });
$assert(
manager.find(2).getPosition().y > manager.find(1).getPosition().y,
'Branches 1 and 2 are overlapping'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
_assertFreePosition: function(manager, id, position) {
_assertFreePosition: function (manager, id, position) {
if (id != null && position.x != null && position.y != null) {
var node = manager.find(id);
$assert(node.getPosition().x == position.x && node.getPosition().y == position.y,
"Freely moved node " + id + " is not left at free position (" + position.x + "," + position.y + "). " +
"Actual position: (" + node.getPosition().x + "," + node.getPosition().y + ")");
$assert(
node.getPosition().x == position.x && node.getPosition().y == position.y,
'Freely moved node ' +
id +
' is not left at free position (' +
position.x +
',' +
position.y +
'). ' +
'Actual position: (' +
node.getPosition().x +
',' +
node.getPosition().y +
')'
);
}
var treeSet = manager._treeSet;
_.each(treeSet._rootNodes, function(rootNode) {
_.each(
treeSet._rootNodes,
function (rootNode) {
var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
this._assertBranchCollision(treeSet, rootNode, heightById);
}, this);
},
this
);
},
_assertBranchCollision: function(treeSet, node, heightById) {
_assertBranchCollision: function (treeSet, node, heightById) {
var children = treeSet.getChildren(node);
var childOfRootNode = treeSet._rootNodes.contains(node);
_.each(children, function(child) {
_.each(
children,
function (child) {
var height = heightById[child.getId()];
var siblings = treeSet.getSiblings(child);
if (childOfRootNode) {
siblings = siblings.filter(function(sibling) {
return (child.getOrder() % 2) == (sibling.getOrder() % 2);
})
siblings = siblings.filter(function (sibling) {
return child.getOrder() % 2 == sibling.getOrder() % 2;
});
}
_.each(siblings, function(sibling) {
_.each(
siblings,
function (sibling) {
this._branchesOverlap(child, sibling, heightById);
}, this);
}, this);
},
this
);
},
this
);
_.each(children, function(child) {
_.each(
children,
function (child) {
this._assertBranchCollision(treeSet, child, heightById);
}, this)
},
this
);
},
_branchesOverlap: function(branchA, branchB, heightById) {
var topA = branchA.getPosition().y - heightById[branchA.getId()]/2;
var bottomA = branchA.getPosition().y + heightById[branchA.getId()]/2;
var topB = branchB.getPosition().y - heightById[branchB.getId()]/2;
var bottomB = branchB.getPosition().y + heightById[branchB.getId()]/2;
_branchesOverlap: function (branchA, branchB, heightById) {
var topA = branchA.getPosition().y - heightById[branchA.getId()] / 2;
var bottomA = branchA.getPosition().y + heightById[branchA.getId()] / 2;
var topB = branchB.getPosition().y - heightById[branchB.getId()] / 2;
var bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2;
$assert(topA >= bottomB || bottomA <= topB, "Branches " + branchA.getId() + " and " + branchB.getId() + " overlap");
}
$assert(
topA >= bottomB || bottomA <= topB,
'Branches ' + branchA.getId() + ' and ' + branchB.getId() + ' overlap'
);
},
});
export default FreeTestSuite;

View File

@ -15,36 +15,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.layout.SymmetricTestSuite = new Class({
Extends: mindplot.layout.TestSuite,
const TestSuite = require('./TestSuite').default;
initialize:function() {
$('#symmetricTest').setStyle("display","block");
const SymmetricTestSuite = new Class({
Extends: TestSuite,
initialize: function () {
$('#symmetricTest').css('display', 'block');
this.testSymmetry();
this.testSymmetricPredict();
this.testSymmetricDragPredict();
},
testSymmetry: function() {
console.log("testSymmetry:")
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testSymmetry: function () {
console.log('testSymmetry:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 14, 0);
manager.connectNode(14, 13, 0);
manager.connectNode(13, 1, 0);
@ -61,38 +63,53 @@ mindplot.layout.SymmetricTestSuite = new Class({
manager.connectNode(6, 12, 1);
manager.layout();
manager.plot("testSymmetry",{width:1600, height:400});
manager.plot('testSymmetry', { width: 1600, height: 400 });
// All nodes should be positioned symmetrically with respect to their common ancestors
$assert(manager.find(14).getPosition().y == manager.find(13).getPosition().y, "Symmetry is not respected");
$assert(manager.find(5).getPosition().y == manager.find(10).getPosition().y, "Symmetry is not respected");
$assert(manager.find(11).getPosition().y - manager.find(6).getPosition().y ==
-(manager.find(12).getPosition().y - manager.find(6).getPosition().y), "Symmetry is not respected");
$assert(manager.find(8).getPosition().y - manager.find(1).getPosition().y ==
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
$assert(manager.find(9).getPosition().y - manager.find(1).getPosition().y ==
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
$assert(
manager.find(14).getPosition().y == manager.find(13).getPosition().y,
'Symmetry is not respected'
);
$assert(
manager.find(5).getPosition().y == manager.find(10).getPosition().y,
'Symmetry is not respected'
);
$assert(
manager.find(11).getPosition().y - manager.find(6).getPosition().y ==
-(manager.find(12).getPosition().y - manager.find(6).getPosition().y),
'Symmetry is not respected'
);
$assert(
manager.find(8).getPosition().y - manager.find(1).getPosition().y ==
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y),
'Symmetry is not respected'
);
$assert(
manager.find(9).getPosition().y - manager.find(1).getPosition().y ==
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y),
'Symmetry is not respected'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testSymmetricPredict: function() {
console.log("testSymmetricPredict:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testSymmetricPredict: function () {
console.log('testSymmetricPredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
@ -109,158 +126,221 @@ mindplot.layout.SymmetricTestSuite = new Class({
manager.layout();
// Graph
var graph1 = manager.plot("testSymmetricPredict1", {width:1000, height:400});
var graph1 = manager.plot('testSymmetricPredict1', { width: 1000, height: 400 });
console.log("\tAdded as child of node 9 and dropped at (-280, 45):");
var prediction1a = manager.predict(9, null, {x:-280, y:45});
console.log('\tAdded as child of node 9 and dropped at (-280, 45):');
var prediction1a = manager.predict(9, null, { x: -280, y: 45 });
this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x < manager.find(9).getPosition().x &&
prediction1a.position.y == manager.find(9).getPosition().y, "Prediction incorrectly positioned");
$assert(prediction1a.order == 0, "Prediction order should be 0");
$assert(
prediction1a.position.x < manager.find(9).getPosition().x &&
prediction1a.position.y == manager.find(9).getPosition().y,
'Prediction incorrectly positioned'
);
$assert(prediction1a.order == 0, 'Prediction order should be 0');
console.log("\tAdded as child of node 1 and dropped at (155, -90):");
var prediction1b = manager.predict(1, null, {x:-155, y:-90});
console.log('\tAdded as child of node 1 and dropped at (155, -90):');
var prediction1b = manager.predict(1, null, { x: -155, y: -90 });
this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x > manager.find(1).getPosition().x &&
prediction1b.position.y == manager.find(1).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction1b.order == 0, "Prediction order should be 0");
$assert(
prediction1b.position.x > manager.find(1).getPosition().x &&
prediction1b.position.y == manager.find(1).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1b.order == 0, 'Prediction order should be 0');
// Graph 2
var graph2 = manager.plot("testSymmetricPredict2", {width:1000, height:400});
var graph2 = manager.plot('testSymmetricPredict2', { width: 1000, height: 400 });
console.log("\tAdded as child of node 5 and dropped at (380, -30):");
var prediction2d = manager.predict(5, null, {x:380, y:-30});
console.log('\tAdded as child of node 5 and dropped at (380, -30):');
var prediction2d = manager.predict(5, null, { x: 380, y: -30 });
this._plotPrediction(graph2, prediction2d);
$assert(prediction2d.position.y < manager.find(7).getPosition().y &&
prediction2d.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned" );
$assert(prediction2d.order == 0, "Prediction order should be 0");
$assert(
prediction2d.position.y < manager.find(7).getPosition().y &&
prediction2d.position.x == manager.find(7).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2d.order == 0, 'Prediction order should be 0');
console.log("\tAdded as child of node 5 and dropped at (375, 15):");
var prediction2a = manager.predict(5, null, {x:375, y:15});
console.log('\tAdded as child of node 5 and dropped at (375, 15):');
var prediction2a = manager.predict(5, null, { x: 375, y: 15 });
this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.y > manager.find(7).getPosition().y &&
$assert(
prediction2a.position.y > manager.find(7).getPosition().y &&
prediction2a.position.y < manager.find(8).getPosition().y &&
prediction2a.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2a.order == 1, "Prediction order should be 1");
prediction2a.position.x == manager.find(7).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2a.order == 1, 'Prediction order should be 1');
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
var prediction2b = manager.predict(5, null, {x:375, y:45});
console.log('\tAdded as child of node 5 and dropped at (375, 45):');
var prediction2b = manager.predict(5, null, { x: 375, y: 45 });
this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.y > manager.find(8).getPosition().y &&
$assert(
prediction2b.position.y > manager.find(8).getPosition().y &&
prediction2b.position.y < manager.find(11).getPosition().y &&
prediction2b.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2b.order == 2, "Prediction order should be 2");
prediction2b.position.x == manager.find(7).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2b.order == 2, 'Prediction order should be 2');
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
var prediction2c = manager.predict(5, null, {x:375, y:65});
console.log('\tAdded as child of node 5 and dropped at (375, 45):');
var prediction2c = manager.predict(5, null, { x: 375, y: 65 });
this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.y > manager.find(11).getPosition().y &&
prediction2c.position.x == manager.find(11).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction2c.order == 3, "Prediction order should be 3");
$assert(
prediction2c.position.y > manager.find(11).getPosition().y &&
prediction2c.position.x == manager.find(11).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2c.order == 3, 'Prediction order should be 3');
// Graph 3
var graph3 = manager.plot("testSymmetricPredict3", {width:1000, height:400});
var graph3 = manager.plot('testSymmetricPredict3', { width: 1000, height: 400 });
console.log("\tAdded as child of node 3 and dropped at (280, 45):");
var prediction3a = manager.predict(3, null, {x:280, y:45});
console.log('\tAdded as child of node 3 and dropped at (280, 45):');
var prediction3a = manager.predict(3, null, { x: 280, y: 45 });
this._plotPrediction(graph3, prediction3a);
$assert(prediction3a.position.y > manager.find(5).getPosition().y &&
$assert(
prediction3a.position.y > manager.find(5).getPosition().y &&
prediction3a.position.y < manager.find(6).getPosition().y &&
prediction3a.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction3a.order == 2, "Prediction order should be 2");
prediction3a.position.x == manager.find(5).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction3a.order == 2, 'Prediction order should be 2');
console.log("\tAdded as child of node 3 and dropped at (255, 110):");
var prediction3b = manager.predict(3, null, {x:255, y:110});
console.log('\tAdded as child of node 3 and dropped at (255, 110):');
var prediction3b = manager.predict(3, null, { x: 255, y: 110 });
this._plotPrediction(graph3, prediction3b);
$assert(prediction3b.position.y > manager.find(6).getPosition().y &&
prediction3b.position.x == manager.find(6).getPosition().x, "Prediction incorrectly positioned");
$assert(prediction3b.order == 3, "Prediction order should be 3");
$assert(
prediction3b.position.y > manager.find(6).getPosition().y &&
prediction3b.position.x == manager.find(6).getPosition().x,
'Prediction incorrectly positioned'
);
$assert(prediction3b.order == 3, 'Prediction order should be 3');
// Graph 4
console.log("\tAdded as child of node 2 and dropped at (-260, 0):");
var graph4 = manager.plot("testSymmetricPredict4", {width:1000, height:400});
var prediction4 = manager.predict(2, null, {x:-260, y:0});
console.log('\tAdded as child of node 2 and dropped at (-260, 0):');
var graph4 = manager.plot('testSymmetricPredict4', { width: 1000, height: 400 });
var prediction4 = manager.predict(2, null, { x: -260, y: 0 });
this._plotPrediction(graph4, prediction4);
$assert(prediction4.position.y > manager.find(9).getPosition().y &&
$assert(
prediction4.position.y > manager.find(9).getPosition().y &&
prediction4.position.y < manager.find(10).getPosition().y &&
prediction4.position.x == manager.find(9).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction4.order == 1, "Prediction order should be 1");
prediction4.position.x == manager.find(9).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction4.order == 1, 'Prediction order should be 1');
// Graph 5
console.log("\tPredict nodes added with no position:");
var graph5 = manager.plot("testSymmetricPredict5", {width:1000, height:400});
console.log('\tPredict nodes added with no position:');
var graph5 = manager.plot('testSymmetricPredict5', { width: 1000, height: 400 });
var prediction5a = manager.predict(1, null, null);
this._plotPrediction(graph5, prediction5a);
$assert(prediction5a.position.y == manager.find(1).getPosition().y &&
prediction5a.position.x > manager.find(1).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction5a.order == 0, "Prediction order should be 0");
$assert(
prediction5a.position.y == manager.find(1).getPosition().y &&
prediction5a.position.x > manager.find(1).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction5a.order == 0, 'Prediction order should be 0');
var prediction5b = manager.predict(2, null, null);
this._plotPrediction(graph5, prediction5b);
$assert(prediction5b.position.y > manager.find(10).getPosition().y &&
$assert(
prediction5b.position.y > manager.find(10).getPosition().y &&
prediction5b.position.x < manager.find(2).getPosition().x &&
prediction5b.position.x == manager.find(10).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction5b.order == 2, "Prediction order should be 2");
prediction5b.position.x == manager.find(10).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction5b.order == 2, 'Prediction order should be 2');
var prediction5c = manager.predict(3, null, null);
this._plotPrediction(graph5, prediction5c);
$assert(prediction5c.position.y > manager.find(6).getPosition().y &&
$assert(
prediction5c.position.y > manager.find(6).getPosition().y &&
prediction5c.position.x > manager.find(3).getPosition().x &&
prediction5c.position.x == manager.find(6).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction5c.order == 3, "Prediction order should be 3");
prediction5c.position.x == manager.find(6).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction5c.order == 3, 'Prediction order should be 3');
var prediction5d = manager.predict(10, null, null);
this._plotPrediction(graph5, prediction5d);
$assert(prediction5d.position.y == manager.find(10).getPosition().y &&
prediction5d.position.x < manager.find(10).getPosition().x, "Prediction is incorrectly positioned");
$assert(prediction5d.order == 0, "Prediction order should be 0");
$assert(
prediction5d.position.y == manager.find(10).getPosition().y &&
prediction5d.position.x < manager.find(10).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction5d.order == 0, 'Prediction order should be 0');
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testSymmetricDragPredict: function() {
console.log("testSymmetricDragPredict:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
testSymmetricDragPredict: function () {
console.log('testSymmetricDragPredict:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.layout();
// Graph 1
var graph1 = manager.plot("testSymmetricDragPredict1", {width:1000, height:400});
var graph1 = manager.plot('testSymmetricDragPredict1', { width: 1000, height: 400 });
var prediction1a = manager.predict(1, 2, {x:-250, y:-20});
var prediction1a = manager.predict(1, 2, { x: -250, y: -20 });
this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x == manager.find(2).getPosition().x &&
prediction1a.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
$assert(prediction1a.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
$assert(
prediction1a.position.x == manager.find(2).getPosition().x &&
prediction1a.position.y == manager.find(2).getPosition().y,
'Prediction position should be the same as node 2'
);
$assert(
prediction1a.order == manager.find(2).getOrder(),
'Predicition order should be the same as node 2'
);
var prediction1b = manager.predict(1, 2, {x:-250, y:20});
var prediction1b = manager.predict(1, 2, { x: -250, y: 20 });
this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x == manager.find(2).getPosition().x &&
prediction1b.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
$assert(prediction1b.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
$assert(
prediction1b.position.x == manager.find(2).getPosition().x &&
prediction1b.position.y == manager.find(2).getPosition().y,
'Prediction position should be the same as node 2'
);
$assert(
prediction1b.order == manager.find(2).getOrder(),
'Predicition order should be the same as node 2'
);
var prediction1c = manager.predict(0, 2, {x:-100, y:-20});
var prediction1c = manager.predict(0, 2, { x: -100, y: -20 });
this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.x == manager.find(1).getPosition().x &&
prediction1c.position.y < manager.find(1).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction1c.order == 1, "Prediction order should be 1");
$assert(
prediction1c.position.x == manager.find(1).getPosition().x &&
prediction1c.position.y < manager.find(1).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1c.order == 1, 'Prediction order should be 1');
var prediction1d = manager.predict(0, 2, {x:-100, y:20});
var prediction1d = manager.predict(0, 2, { x: -100, y: 20 });
this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.x == manager.find(1).getPosition().x &&
prediction1d.position.y > manager.find(1).getPosition().y, "Prediction is incorrectly positioned");
$assert(prediction1d.order == 3, "Prediction order should be 3");
$assert(
prediction1d.position.x == manager.find(1).getPosition().x &&
prediction1d.position.y > manager.find(1).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1d.order == 3, 'Prediction order should be 3');
var prediction1e = manager.predict(1, 2, {x:-250, y:0});
var prediction1e = manager.predict(1, 2, { x: -250, y: 0 });
this._plotPrediction(graph1, prediction1e);
$assert(prediction1e.position.x == manager.find(2).getPosition().x &&
prediction1e.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
$assert(prediction1e.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
console.log("OK!\n\n");
}
$assert(
prediction1e.position.x == manager.find(2).getPosition().x &&
prediction1e.position.y == manager.find(2).getPosition().y,
'Prediction position should be the same as node 2'
);
$assert(
prediction1e.order == manager.find(2).getOrder(),
'Predicition order should be the same as node 2'
);
console.log('OK!\n\n');
},
});
export default SymmetricTestSuite;

View File

@ -15,13 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.layout.TestSuite = new Class({
const TestSuite = new Class({
Extends: mindplot.layout.ChildrenSorterStrategy,
initialize:function() {
$('#basicTest').setStyle("display","block");
initialize: function () {
$('#basicTest').css('display', 'block');
// this.testAligned();
// this.testAligned();
this.testBaselineAligned1();
this.testBaselineAligned2();
this.testEvents();
@ -33,143 +33,170 @@ mindplot.layout.TestSuite = new Class({
this.testReconnectSingleNode();
},
testAligned: function() {
console.log("testAligned:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testAligned: function () {
console.log('testAligned:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 3, 0);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3, 4, 0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,5,2);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,6,4);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,7,6);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(3, 4, 0);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 2);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 4);
manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(0, 7, 6);
manager.layout();
manager.plot("testAligned", {width:1200,height:200});
manager.plot('testAligned', { width: 1200, height: 200 });
// Child nodes should be vertically aligned
$assert(manager.find(1).getPosition().y == manager.find(2).getPosition().y, "Child nodes are not vertically aligned");
$assert(manager.find(1).getPosition().y == manager.find(3).getPosition().y, "Child nodes are not vertically aligned");
$assert(manager.find(1).getPosition().y == manager.find(4).getPosition().y, "Child nodes are not vertically aligned");
$assert(
manager.find(1).getPosition().y == manager.find(2).getPosition().y,
'Child nodes are not vertically aligned'
);
$assert(
manager.find(1).getPosition().y == manager.find(3).getPosition().y,
'Child nodes are not vertically aligned'
);
$assert(
manager.find(1).getPosition().y == manager.find(4).getPosition().y,
'Child nodes are not vertically aligned'
);
// Siblings should be horizontally aligned
$assert(manager.find(1).getPosition().x == manager.find(5).getPosition().x, "Sibling nodes are not horizontally aligned");
$assert(manager.find(1).getPosition().x == manager.find(6).getPosition().x, "Sibling nodes are not horizontally aligned");
$assert(manager.find(1).getPosition().x == manager.find(7).getPosition().x, "Sibling nodes are not horizontally aligned");
$assert(
manager.find(1).getPosition().x == manager.find(5).getPosition().x,
'Sibling nodes are not horizontally aligned'
);
$assert(
manager.find(1).getPosition().x == manager.find(6).getPosition().x,
'Sibling nodes are not horizontally aligned'
);
$assert(
manager.find(1).getPosition().x == manager.find(7).getPosition().x,
'Sibling nodes are not horizontally aligned'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testBaselineAligned1: function() {
console.log("testBaselineAligned1:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testBaselineAligned1: function () {
console.log('testBaselineAligned1:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 3, 0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3, 5, 0);
manager.addNode(6, {width:140, height:130}, position).connectNode(3, 6, 1);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(6, 7, 0);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 8, 0);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 9, 1);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 10, 2);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 11, 3);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 12, 4);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 13, 5);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 14, 6);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 15, 7);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 16, 8);
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(7, 17, 9);
manager.addNode(29, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(6, 29, 1);
manager.addNode(30, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(6, 30, 2);
manager.addNode(31, {width:100, height:50}, position).connectNode(6, 31, 3);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 0);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(3, 5, 0);
manager.addNode(6, { width: 140, height: 130 }, position).connectNode(3, 6, 1);
manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(6, 7, 0);
manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(7, 8, 0);
manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(7, 9, 1);
manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(7, 10, 2);
manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(7, 11, 3);
manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(7, 12, 4);
manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(7, 13, 5);
manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(7, 14, 6);
manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(7, 15, 7);
manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(7, 16, 8);
manager.addNode(17, TestSuite.NODE_SIZE, position).connectNode(7, 17, 9);
manager.addNode(29, TestSuite.NODE_SIZE, position).connectNode(6, 29, 1);
manager.addNode(30, TestSuite.NODE_SIZE, position).connectNode(6, 30, 2);
manager.addNode(31, { width: 100, height: 50 }, position).connectNode(6, 31, 3);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 4, 1);
manager.addNode(18, {width:80, height:70}, position).connectNode(4, 18, 0);
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(18, 19, 0);
manager.addNode(20, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(19, 20, 0);
manager.addNode(21, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(20, 21, 0);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 1);
manager.addNode(18, { width: 80, height: 70 }, position).connectNode(4, 18, 0);
manager.addNode(19, TestSuite.NODE_SIZE, position).connectNode(18, 19, 0);
manager.addNode(20, TestSuite.NODE_SIZE, position).connectNode(19, 20, 0);
manager.addNode(21, TestSuite.NODE_SIZE, position).connectNode(20, 21, 0);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 2, 1);
manager.addNode(22, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 22, 0);
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(22, 24, 0);
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1);
manager.addNode(22, TestSuite.NODE_SIZE, position).connectNode(2, 22, 0);
manager.addNode(24, TestSuite.NODE_SIZE, position).connectNode(22, 24, 0);
manager.addNode(23, {width:80, height:50}, position).connectNode(2, 23, 1);
manager.addNode(25, {width:80, height:40}, position).connectNode(23, 25, 0);
manager.addNode(26, {width:80, height:80}, position).connectNode(25, 26, 0);
manager.addNode(27, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(26, 27, 0);
manager.addNode(28, {width:80, height:80}, position).connectNode(27, 28, 0);
manager.addNode(23, { width: 80, height: 50 }, position).connectNode(2, 23, 1);
manager.addNode(25, { width: 80, height: 40 }, position).connectNode(23, 25, 0);
manager.addNode(26, { width: 80, height: 80 }, position).connectNode(25, 26, 0);
manager.addNode(27, TestSuite.NODE_SIZE, position).connectNode(26, 27, 0);
manager.addNode(28, { width: 80, height: 80 }, position).connectNode(27, 28, 0);
// manager.layout();
// manager.plot("testBaselineAligned1", {width:1600,height:800});
// manager.layout();
// manager.plot("testBaselineAligned1", {width:1600,height:800});
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testBaselineAligned2: function() {
console.log("testBaselineAligned2:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, {width: 130, height:200}, position).connectNode(1, 2, 0);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 3, 0);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 4, 1);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 5, 2);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2, 6, 3);
testBaselineAligned2: function () {
console.log('testBaselineAligned2:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
manager.addNode(2, { width: 130, height: 200 }, position).connectNode(1, 2, 0);
manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0);
manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(2, 4, 1);
manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(2, 5, 2);
manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(2, 6, 3);
manager.layout();
manager.plot("testBaselineAligned2", {width:1600,height:800});
manager.plot('testBaselineAligned2', { width: 1600, height: 800 });
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testEvents: function() {
console.log("testEvents:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testEvents: function () {
console.log('testEvents:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y: 60});
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, { x: 0, y: 60 });
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(1, 3, 0);
var events = [];
manager.addEvent('change', function(event) {
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
manager.addEvent('change', function (event) {
console.log(
'\tUpdated nodes: {id:' +
event.getId() +
', order: ' +
event.getOrder() +
',position: {' +
event.getPosition().x +
',' +
event.getPosition().y +
'}'
);
events.push(event);
});
manager.layout(true);
manager.plot("testEvents1", {width:800, height:200});
manager.plot('testEvents1', { width: 800, height: 200 });
console.log("\t--- Layout without changes should not affect the tree ---");
console.log('\t--- Layout without changes should not affect the tree ---');
events.empty();
manager.layout(true);
manager.plot("testEvents2", {width:800, height:200});
manager.plot('testEvents2', { width: 800, height: 200 });
// Check no events where fired
$assert(events.length == 0, "Unnecessary tree updated.");
$assert(events.length == 0, 'Unnecessary tree updated.');
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testEventsComplex: function() {
console.log("testEventsComplex:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testEventsComplex: function () {
console.log('testEventsComplex:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y:60});
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, { x: 0, y: 60 });
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(0, 3, 2);
@ -177,39 +204,49 @@ mindplot.layout.TestSuite = new Class({
manager.connectNode(3, 5, 1);
var events = [];
manager.addEvent('change', function(event) {
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
manager.addEvent('change', function (event) {
console.log(
'\tUpdated nodes: {id:' +
event.getId() +
', order: ' +
event.getOrder() +
',position: {' +
event.getPosition().x +
',' +
event.getPosition().y +
'}'
);
events.push(event);
});
manager.layout(true);
manager.plot("testEventsComplex1", {width:800, height:200});
manager.plot('testEventsComplex1', { width: 800, height: 200 });
console.log("\t--- Connect a new node ---");
console.log('\t--- Connect a new node ---');
events.empty();
manager.connectNode(3, 6, 2);
manager.layout(true);
manager.plot("testEventsComplex2", {width:800, height:200});
manager.plot('testEventsComplex2', { width: 800, height: 200 });
// Check only 4 nodes were repositioned
$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');
},
testDisconnect: function() {
console.log("testDisconnect:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testDisconnect: function () {
console.log('testDisconnect:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(1, 2, 0);
manager.connectNode(1, 3, 1);
@ -219,55 +256,65 @@ mindplot.layout.TestSuite = new Class({
manager.connectNode(5, 7, 1);
var events = [];
manager.addEvent('change', function(event) {
manager.addEvent('change', function (event) {
var pos = event.getPosition();
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
var posStr = pos ? ',position: {' + pos.x + ',' + pos.y : '';
var node = manager.find(event.getId());
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
console.log(
'\tUpdated nodes: {id:' +
event.getId() +
', order: ' +
event.getOrder() +
posStr +
'}'
);
events.push(event);
});
manager.layout(true);
manager.plot("testDisconnect1", {width:1200, height:400});
manager.plot('testDisconnect1', { width: 1200, height: 400 });
console.log("--- Disconnect node 2 ---");
console.log('--- Disconnect node 2 ---');
events.empty();
manager.disconnectNode(2);
manager.layout(true);
manager.plot("testDisconnect2", {width:1200, height:400});
manager.plot('testDisconnect2', { width: 1200, height: 400 });
// Check that orders have been shifted accordingly
$assert(manager.find(2).getOrder() == 0, "Node 2 should have order 0");
$assert(manager.find(3).getOrder() == 0, "Node 3 should now have order 0");
$assert(manager.find(4).getOrder() == 1, "Node 4 should have order 1");
$assert(manager.find(2).getOrder() == 0, 'Node 2 should have order 0');
$assert(manager.find(3).getOrder() == 0, 'Node 3 should now have order 0');
$assert(manager.find(4).getOrder() == 1, 'Node 4 should have order 1');
console.log("--- Disconnect node 4 ---");
console.log('--- Disconnect node 4 ---');
manager.disconnectNode(4);
manager.layout(true);
manager.plot("testDisconnect3", {width:1200, height:400});
manager.plot('testDisconnect3', { width: 1200, height: 400 });
// Check that nodes 1 and 3 are now vertically aligned
$assert(manager.find(1).getPosition().y == manager.find(3).getPosition().y, "Nodes 1 and 3 should now be vertically aligned");
$assert(
manager.find(1).getPosition().y == manager.find(3).getPosition().y,
'Nodes 1 and 3 should now be vertically aligned'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testReconnect: function() {
console.log("testReconnect:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testReconnect: function () {
console.log('testReconnect:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(0, 3, 2);
@ -282,39 +329,52 @@ mindplot.layout.TestSuite = new Class({
manager.connectNode(6, 12, 1);
manager.layout();
manager.plot("testReconnect1",{width:1200, height:400});
manager.plot('testReconnect1', { width: 1200, height: 400 });
// Reconnect node 6 to node 4
console.log("\tReconnect node 6 to node 4");
console.log('\tReconnect node 6 to node 4');
manager.disconnectNode(6);
manager.connectNode(4,6,0);
manager.connectNode(4, 6, 0);
manager.layout();
manager.plot("testReconnect2",{width:1200, height:400});
manager.plot('testReconnect2', { width: 1200, height: 400 });
// Check nodes are left aligned correctly
$assert(manager.find(1).getPosition().y == manager.find(7).getPosition().y, "Nodes 1 and 7 should be vertically aligned");
$assert(manager.find(4).getPosition().y == manager.find(6).getPosition().y, "Nodes 4 and 6 should be vertically aligned");
$assert(manager.find(4).getPosition().x > manager.find(6).getPosition().x, "Node 6 and their children should be to the left of node 4");
$assert(manager.find(6).getPosition().x > manager.find(11).getPosition().x && manager.find(11).getPosition().x == manager.find(12).getPosition().x, "Nodes 11 and 12 should be to the left of node 6 and horizontally aligned");
$assert(
manager.find(1).getPosition().y == manager.find(7).getPosition().y,
'Nodes 1 and 7 should be vertically aligned'
);
$assert(
manager.find(4).getPosition().y == manager.find(6).getPosition().y,
'Nodes 4 and 6 should be vertically aligned'
);
$assert(
manager.find(4).getPosition().x > manager.find(6).getPosition().x,
'Node 6 and their children should be to the left of node 4'
);
$assert(
manager.find(6).getPosition().x > manager.find(11).getPosition().x &&
manager.find(11).getPosition().x == manager.find(12).getPosition().x,
'Nodes 11 and 12 should be to the left of node 6 and horizontally aligned'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testRemoveNode: function() {
console.log("testRemoveNode:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testRemoveNode: function () {
console.log('testRemoveNode:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.connectNode(0, 5, 1);
@ -327,107 +387,126 @@ mindplot.layout.TestSuite = new Class({
manager.connectNode(3, 4, 0);
var events = [];
manager.addEvent('change', function(event) {
manager.addEvent('change', function (event) {
var pos = event.getPosition();
var posStr = pos ? ",position: {" + pos.x + "," + event.getPosition().y : "";
var posStr = pos ? ',position: {' + pos.x + ',' + event.getPosition().y : '';
events.push(event);
});
manager.layout(true);
manager.plot("testRemoveNode1", {width:1000, height:200});
manager.plot('testRemoveNode1', { width: 1000, height: 200 });
console.log("\t--- Remove node 3 ---");
console.log('\t--- Remove node 3 ---');
manager.removeNode(3);
manager.layout(true);
manager.plot("testRemoveNode2", {width:1000, height:200});
manager.plot('testRemoveNode2', { width: 1000, height: 200 });
// Check nodes are correctly aligned and node 6 is aligned with the root node
$assert(manager.find(1).getPosition().y == manager.find(2).getPosition().y, "Nodes 1 and 2 should be vertically algined");
$assert(manager.find(6).getPosition().y == manager.find(0).getPosition().y, "Node 6 should be aligned to the root node");
$assert(
manager.find(1).getPosition().y == manager.find(2).getPosition().y,
'Nodes 1 and 2 should be vertically algined'
);
$assert(
manager.find(6).getPosition().y == manager.find(0).getPosition().y,
'Node 6 should be aligned to the root node'
);
console.log("\t--- Remove node 6 ---");
console.log('\t--- Remove node 6 ---');
manager.removeNode(6);
manager.layout(true);
manager.plot("testRemoveNode3", {width:1000, height:200});
manager.plot('testRemoveNode3', { width: 1000, height: 200 });
// Check orders were shifted accordingly
$assert(manager.find(8).getOrder() == 2, "Node 8 should have order 2");
$assert(manager.find(8).getOrder() == 2, 'Node 8 should have order 2');
console.log("\t--- Remove node 5 ---");
console.log('\t--- Remove node 5 ---');
manager.removeNode(5);
manager.layout(true);
manager.plot("testRemoveNode4", {width:1000, height:200});
manager.plot('testRemoveNode4', { width: 1000, height: 200 });
// Check orders were shifted accordingly
$assert(manager.find(7).getOrder() == 1, "Node 7 should have order 1");
$assert(manager.find(9).getOrder() == 3, "Node 9 should have order 3");
$assert(manager.find(7).getOrder() == 1, 'Node 7 should have order 1');
$assert(manager.find(9).getOrder() == 3, 'Node 9 should have order 3');
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testSize: function() {
console.log("testSize:");
var position = {x:0, y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testSize: function () {
console.log('testSize:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, {width: 60, height: 60}, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(3, {width: 260, height: 30}, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(7, {width: 80, height: 80}, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(9, {width: 30, height: 30}, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(12, {width: 100, height: 70}, position);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, { width: 60, height: 60 }, position);
manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, { width: 260, height: 30 }, position);
manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(7, { width: 80, height: 80 }, position);
manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, { width: 30, height: 30 }, position);
manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, { width: 100, height: 70 }, position);
manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.addNode(15, TestSuite.NODE_SIZE, position);
manager.addNode(16, TestSuite.NODE_SIZE, position);
manager.addNode(17, TestSuite.NODE_SIZE, position);
manager.connectNode(0,1,0);
manager.connectNode(1,16,0);
manager.connectNode(0,2,1);
manager.connectNode(0,3,2);
manager.connectNode(0,4,3);
manager.connectNode(0,5,4);
manager.connectNode(4,7,0);
manager.connectNode(7,15,0);
manager.connectNode(7,17,1);
manager.connectNode(4,8,1);
manager.connectNode(8,9,0);
manager.connectNode(3,10,0);
manager.connectNode(3,11,1);
manager.connectNode(9,12,0);
manager.connectNode(9,13,1);
manager.connectNode(13,14,0);
manager.connectNode(0, 1, 0);
manager.connectNode(1, 16, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(0, 3, 2);
manager.connectNode(0, 4, 3);
manager.connectNode(0, 5, 4);
manager.connectNode(4, 7, 0);
manager.connectNode(7, 15, 0);
manager.connectNode(7, 17, 1);
manager.connectNode(4, 8, 1);
manager.connectNode(8, 9, 0);
manager.connectNode(3, 10, 0);
manager.connectNode(3, 11, 1);
manager.connectNode(9, 12, 0);
manager.connectNode(9, 13, 1);
manager.connectNode(13, 14, 0);
manager.layout();
manager.plot("testSize1", {width: 1400, height: 400});
manager.plot('testSize1', { width: 1400, height: 400 });
// Check that all enlarged nodes shift children accordingly
$assert(manager.find(10).getPosition().x > manager.find(3).getPosition().x && manager.find(10).getPosition().x == manager.find(11).getPosition().x, "Nodes 10 and 11 should be horizontally algined and to the right of enlarged node 3");
$assert(
manager.find(10).getPosition().x > manager.find(3).getPosition().x &&
manager.find(10).getPosition().x == manager.find(11).getPosition().x,
'Nodes 10 and 11 should be horizontally algined and to the right of enlarged node 3'
);
var xPosNode7 = manager.find(7).getPosition().x;
var xPosNode8 = manager.find(8).getPosition().x;
manager.updateNodeSize(4, {width:100, height:30});
manager.updateNodeSize(4, { width: 100, height: 30 });
manager.layout();
manager.plot("testSize2", {width: 1400, height: 400});
manager.plot('testSize2', { width: 1400, height: 400 });
// Check that all enlarged nodes shift children accordingly
$assert(manager.find(2).getPosition().x - manager.find(4).getPosition().x == 10, "Node 4 should have been shifted by 10");
$assert(xPosNode7 - manager.find(7).getPosition().x == 20, "Node 7 should have been shifted by 20");
$assert(xPosNode8 - manager.find(8).getPosition().x == 20, "Node 8 should have been shifted by 20");
$assert(
manager.find(2).getPosition().x - manager.find(4).getPosition().x == 10,
'Node 4 should have been shifted by 10'
);
$assert(
xPosNode7 - manager.find(7).getPosition().x == 20,
'Node 7 should have been shifted by 20'
);
$assert(
xPosNode8 - manager.find(8).getPosition().x == 20,
'Node 8 should have been shifted by 20'
);
var graph2 = manager.plot("testSize3", {width: 1400, height: 400});
this._plotPrediction(graph2, manager.predict(0, null, {x:-145, y:400}));
this._plotPrediction(graph2, manager.predict(9, null, {x:-330, y:70}));
this._plotPrediction(graph2, manager.predict(9, null, {x:-330, y:120}));
this._plotPrediction(graph2, manager.predict(0, null, {x:15, y:20}));
var graph2 = manager.plot('testSize3', { width: 1400, height: 400 });
this._plotPrediction(graph2, manager.predict(0, null, { x: -145, y: 400 }));
this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 70 }));
this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 120 }));
this._plotPrediction(graph2, manager.predict(0, null, { x: 15, y: 20 }));
//TODO(gb): make asserts
var graph3 = manager.plot("testSize4", {width: 1400, height: 400});
var graph3 = manager.plot('testSize4', { width: 1400, height: 400 });
this._plotPrediction(graph3, manager.predict(0, null, null));
this._plotPrediction(graph3, manager.predict(9, null, null));
this._plotPrediction(graph3, manager.predict(3, null, null));
@ -435,52 +514,71 @@ mindplot.layout.TestSuite = new Class({
//TODO(gb): make asserts
var yPosNode2 = manager.find(2).getPosition().y;
manager.updateNodeSize(7, {width:80, height:120});
manager.updateNodeSize(7, { width: 80, height: 120 });
manager.layout();
manager.plot("testSize5", {width: 1400, height: 400});
manager.plot('testSize5', { width: 1400, height: 400 });
// Check that all enlarged nodes shift children accordingly
$assert(yPosNode2 - manager.find(2).getPosition().y == 20, "Node 2 should have been shifted by 20");
$assert(
yPosNode2 - manager.find(2).getPosition().y == 20,
'Node 2 should have been shifted by 20'
);
console.log("OK!\n\n");
console.log('OK!\n\n');
},
testReconnectSingleNode: function() {
console.log("testReconnectSingleNode:");
var position = {x:0,y:0};
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
testReconnectSingleNode: function () {
console.log('testReconnectSingleNode:');
var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0);
manager.layout();
var graph = manager.plot("testReconnectSingleNode1", {width:1000, height:400});
var prediction = manager.predict(0, null, {x:-50, y:0});
var graph = manager.plot('testReconnectSingleNode1', { width: 1000, height: 400 });
var prediction = manager.predict(0, null, { x: -50, y: 0 });
this._plotPrediction(graph, prediction);
// Check prediction is to the left of the root node
$assert(prediction.position.x < manager.find(0).getPosition().x, "Prediction should be to the left of the root node");
$assert(prediction.order == 1, "Prediction should have order 1");
$assert(
prediction.position.x < manager.find(0).getPosition().x,
'Prediction should be to the left of the root node'
);
$assert(prediction.order == 1, 'Prediction should have order 1');
manager.disconnectNode(1);
manager.connectNode(0,1,1);
manager.connectNode(0, 1, 1);
manager.layout();
manager.plot("testReconnectSingleNode2", {width:1000, height:400});
manager.plot('testReconnectSingleNode2', { width: 1000, height: 400 });
// Check reconnected node is to the left of the root node
$assert(manager.find(1).getPosition().x < manager.find(0).getPosition().x, "Node 1 should now be to the left of the root node");
$assert(manager.find(1).getOrder() == 1, "Node 1 should now have order 0");
$assert(
manager.find(1).getPosition().x < manager.find(0).getPosition().x,
'Node 1 should now be to the left of the root node'
);
$assert(manager.find(1).getOrder() == 1, 'Node 1 should now have order 0');
},
_plotPrediction: function(canvas, prediction) {
_plotPrediction: function (canvas, prediction) {
var position = prediction.position;
var order = prediction.order;
console.log("\t\tprediction {order:" + order + ", position: (" + position.x + "," + position.y + ")}");
var cx = position.x + canvas.width / 2 - mindplot.layout.TestSuite.NODE_SIZE.width / 2;
var cy = position.y + canvas.height / 2 - mindplot.layout.TestSuite.NODE_SIZE.height / 2;
canvas.rect(cx, cy, mindplot.layout.TestSuite.NODE_SIZE.width, mindplot.layout.TestSuite.NODE_SIZE.height);
}
console.log(
'\t\tprediction {order:' +
order +
', position: (' +
position.x +
',' +
position.y +
')}'
);
var cx = position.x + canvas.width / 2 - TestSuite.NODE_SIZE.width / 2;
var cy = position.y + canvas.height / 2 - TestSuite.NODE_SIZE.height / 2;
canvas.rect(cx, cy, TestSuite.NODE_SIZE.width, TestSuite.NODE_SIZE.height);
},
});
mindplot.layout.TestSuite.NODE_SIZE = {width:80, height:30},
mindplot.layout.TestSuite.ROOT_NODE_SIZE = {width:120, height:40}
(TestSuite.NODE_SIZE = { width: 80, height: 30 }),
(TestSuite.ROOT_NODE_SIZE = { width: 120, height: 40 });
export default TestSuite;

View File

@ -0,0 +1,14 @@
const Mindplot = require('../../../../lib/mindplot');
global.mindplot = Mindplot();
const TestSuite = require('./TestSuite').default;
const BalancedTestSuite = require('./BalancedTestSuite').default;
const SymmetricTestSuite = require('./SymmetricTestSuite').default;
const FreeTestSuite = require('./FreeTestSuite').default;
window.addEventListener('DOMContentLoaded', function () {
var basicTest = new TestSuite();
var balancedTest = new BalancedTestSuite();
var symmetricTest = new SymmetricTestSuite();
var freeTest = new FreeTestSuite();
});

View File

@ -11,6 +11,6 @@ window.addEventListener('load', function (e) {
var palette = new mindplot.widget.ColorPalettePanel(
'myButton',
model,
'/mindplot/src/main/javascript/widget'
'../../../lib/components/widget'
);
});

View File

@ -8,6 +8,7 @@ const prodConfig = {
optimization: {
splitChunks: {
chunks: 'all',
minSize: 2000000,
},
},
};

View File

@ -3,12 +3,16 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
/** @type {import('webpack').Configuration} */
module.exports = {
entry: './lib/mindplot',
entry: {
palette: path.resolve(__dirname, './test/javascript/static/test/testPalette'),
layout: path.resolve(__dirname, './test/javascript/static/test/testLayout'),
},
output: {
path: path.resolve(__dirname, 'dist', 'test'),
filename: '[name].js',
filename: '[name].test.js',
publicPath: '',
},
mode: 'production',
module: {
rules: [
{

View File

@ -5,7 +5,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: './test/javascript/render/testing.js',
output: {
path: path.resolve(__dirname, 'target', 'tests'),
path: path.resolve(__dirname, 'dist', 'tests'),
filename: '[name].js',
publicPath: '',
},

710
yarn.lock

File diff suppressed because it is too large Load Diff