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

View File

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

View File

@ -15,31 +15,29 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const Core = require('@wismapping/core-js') const Core = require('@wismapping/core-js');
const core = Core(); const core = Core();
const XMLSerializerFactory = require('./persistence/XMLSerializerFactory'); const XMLSerializerFactory = require('./persistence/XMLSerializerFactory');
const PersistenceManager = new Class({ const PersistenceManager = new Class({
Static: { Static: {
loadFromDom: function (mapId, mapDom) { loadFromDom: function (mapId, mapDom) {
$assert(mapId, "mapId can not be null"); $assert(mapId, 'mapId can not be null');
$assert(mapDom, "mapDom can not be null"); $assert(mapDom, 'mapDom can not be null');
var serializer = XMLSerializerFactory.getSerializerFromDocument(mapDom); var serializer = XMLSerializerFactory.getSerializerFromDocument(mapDom);
return serializer.loadFromDom(mapDom, mapId); return serializer.loadFromDom(mapDom, mapId);
} },
}, },
initialize: function () { initialize: function () {},
},
save: function (mindmap, editorProperties, saveHistory, events, sync) { save: function (mindmap, editorProperties, saveHistory, events, sync) {
$assert(mindmap, "mindmap can not be null"); $assert(mindmap, 'mindmap can not be null');
$assert(editorProperties, "editorProperties can not be null"); $assert(editorProperties, 'editorProperties can not be null');
var mapId = mindmap.getId(); var mapId = mindmap.getId();
$assert(mapId, "mapId can not be null"); $assert(mapId, 'mapId can not be null');
var serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap); var serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap);
var domMap = serializer.toXML(mindmap); var domMap = serializer.toXML(mindmap);
@ -55,26 +53,26 @@ const PersistenceManager = new Class({
}, },
load: function (mapId) { load: function (mapId) {
$assert(mapId, "mapId can not be null"); $assert(mapId, 'mapId can not be null');
var domDocument = this.loadMapDom(mapId); var domDocument = this.loadMapDom(mapId);
return PersistenceManager.loadFromDom(mapId, domDocument); return PersistenceManager.loadFromDom(mapId, domDocument);
}, },
discardChanges: function (mapId) { discardChanges: function (mapId) {
throw new Error("Method must be implemented"); throw new Error('Method must be implemented');
}, },
loadMapDom: function (mapId) { 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) { 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) { unlockMap: function (mindmap) {
throw new Error("Method must be implemented"); throw new Error('Method must be implemented');
} },
}); });
PersistenceManager.init = function (instance) { 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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const web2D = require('@wismapping/web2d') const web2D = require('@wismapping/web2d');
const web2d = web2D() const web2d = web2D();
const NodeGraph = require('./NodeGraph').default; const NodeGraph = require('./NodeGraph').default;
const { TopicShape } = require('./model/INodeModel'); const { TopicShape } = require('./model/INodeModel');
const TopicStyle = require('./TopicStyle').default; const TopicStyle = require('./TopicStyle').default;
@ -240,10 +240,7 @@ const Topic = new Class(
/** @return outer shape */ /** @return outer shape */
getOuterShape: function () { getOuterShape: function () {
if (!$defined(this._outerShape)) { if (!$defined(this._outerShape)) {
var rect = this._buildShape( var rect = this._buildShape(Topic.OUTER_SHAPE_ATTRIBUTES, TopicShape.ROUNDED_RECT);
Topic.OUTER_SHAPE_ATTRIBUTES,
TopicShape.ROUNDED_RECT
);
rect.setPosition(-2, -3); rect.setPosition(-2, -3);
rect.setOpacity(0); rect.setOpacity(0);
this._outerShape = rect; this._outerShape = rect;
@ -991,9 +988,7 @@ const Topic = new Class(
} }
var textShape = this.getTextShape(); var textShape = this.getTextShape();
textShape.setVisibility( textShape.setVisibility(this.getShapeType() != TopicShape.IMAGE ? value : false);
this.getShapeType() != TopicShape.IMAGE ? value : false
);
}, },
/** */ /** */
@ -1091,10 +1086,7 @@ const Topic = new Class(
outgoingLine.removeFromWorkspace(workspace); outgoingLine.removeFromWorkspace(workspace);
// Remove from workspace. // Remove from workspace.
EventBus.instance.fireEvent( EventBus.instance.fireEvent(EventBus.events.NodeDisconnectEvent, this.getModel());
EventBus.events.NodeDisconnectEvent,
this.getModel()
);
// Change text based on the current connection ... // Change text based on the current connection ...
var model = this.getModel(); var model = this.getModel();
@ -1216,10 +1208,7 @@ const Topic = new Class(
workspace.removeChild(line); workspace.removeChild(line);
} }
this._isInWorkspace = false; this._isInWorkspace = false;
EventBus.instance.fireEvent( EventBus.instance.fireEvent(EventBus.events.NodeRemoved, this.getModel());
EventBus.events.NodeRemoved,
this.getModel()
);
}, },
/** */ /** */
@ -1228,20 +1217,14 @@ const Topic = new Class(
workspace.append(elem); workspace.append(elem);
if (!this.isInWorkspace()) { if (!this.isInWorkspace()) {
if (!this.isCentralTopic()) { if (!this.isCentralTopic()) {
EventBus.instance.fireEvent( EventBus.instance.fireEvent(EventBus.events.NodeAdded, this.getModel());
EventBus.events.NodeAdded,
this.getModel()
);
} }
if (this.getModel().isConnected()) if (this.getModel().isConnected())
EventBus.instance.fireEvent( EventBus.instance.fireEvent(EventBus.events.NodeConnectEvent, {
EventBus.events.NodeConnectEvent, parentNode: this.getOutgoingConnectedTopic().getModel(),
{ childNode: this.getModel(),
parentNode: this.getOutgoingConnectedTopic().getModel(), });
childNode: this.getModel(),
}
);
} }
this._isInWorkspace = true; this._isInWorkspace = true;
this._adjustShapes(); this._adjustShapes();

View File

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

View File

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

View File

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

View File

@ -17,38 +17,38 @@
*/ */
const ModalDialogNotifier = new Class({ const ModalDialogNotifier = new Class({
initialize: function () {}, initialize: function () {},
//FIXME: replace by alert() //FIXME: replace by alert()
show: function (message, title) { 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-dialog">' + '<div class="modal fade">' +
'<div class="modal-content">' + '<div class="modal-dialog">' +
'<div class="modal-body"></div>' + '<div class="modal-content">' +
'<div class="alert alert-block alert-warning">' + '<div class="modal-body"></div>' +
'<img src="images/alert-sign.png">' + '<div class="alert alert-block alert-warning">' +
'<div style="display: inline-block" class="alert-content"></div>' + '<img src="images/alert-sign.png">' +
'</div>' + '<div style="display: inline-block" class="alert-content"></div>' +
'<div class="modal-footer">' + '</div>' +
'<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' + '<div class="modal-footer">' +
'</div>' + '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' +
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'); '</div>' +
'</div>'
);
var p = '<p>' + message + '</p>' var p = '<p>' + message + '</p>';
var h4 = title ? '<h4>' + title + '</h4>' : ""; var h4 = title ? '<h4>' + title + '</h4>' : '';
modalDialog.find('.alert-content').append(h4 + p); modalDialog.find('.alert-content').append(h4 + p);
modalDialog.modal(); modalDialog.modal();
} },
}); });
var dialogNotifier = new ModalDialogNotifier(); var dialogNotifier = new ModalDialogNotifier();
$notifyModal = dialogNotifier.show.bind(dialogNotifier); const $notifyModal = dialogNotifier.show.bind(dialogNotifier);
export default ModalDialogNotifier; export default ModalDialogNotifier;

View File

@ -17,31 +17,32 @@
*/ */
const ToolbarNotifier = new Class({ const ToolbarNotifier = new Class({
initialize: function () {
initialize:function () {
this.container = $('#headerNotifier'); this.container = $('#headerNotifier');
}, },
hide:function () { hide: function () {
this.container.hide(); this.container.hide();
}, },
logMessage:function (msg, fade) { logMessage: function (msg, fade) {
$assert(msg, 'msg can not be null'); $assert(msg, 'msg can not be null');
// In case of print,embedded no message is displayed .... // In case of print,embedded no message is displayed ....
if (this.container && !this.container.data('transitioning')) { if (this.container && !this.container.data('transitioning')) {
this.container.data('transitioning', true); this.container.data('transitioning', true);
this.container.text(msg); 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.show().fadeOut(5000);
} }
this.container.data('transitioning', false); this.container.data('transitioning', false);
} },
}); });
var toolbarNotifier = new ToolbarNotifier(); var toolbarNotifier = new ToolbarNotifier();
$notify = function(msg) { const $notify = function (msg) {
toolbarNotifier.logMessage(msg); toolbarNotifier.logMessage(msg);
}; };

View File

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

View File

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

View File

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

View File

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

View File

@ -1,195 +1,180 @@
<!DOCTYPE HTML> <!DOCTYPE html>
<html> <html>
<head> <head>
<script type='text/javascript' src='../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js'></script> <script
<script type='text/javascript' src='../../../../core-js/target/core.js'></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="../../../../core-js/dist/core.js"></script>
<script type='text/javascript' src='../../../lib/components/layout/Node.js'></script> <script type="text/javascript" src="../../../lib/components/header.js"></script>
<script type='text/javascript' src='../../../lib/components/layout/RootedTreeSet.js'></script> <script type="text/javascript" src="../../../dist/main.js"></script>
<script type='text/javascript' src='../../../lib/components/layout/LayoutManager.js'></script> <script type="text/javascript" src="test/raphael-min.js"></script>
<script type='text/javascript' src='../../../lib/components/layout/ChildrenSorterStrategy.js'></script> <script type="text/javascript" src="test/raphael-plugins.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="test/raphael-min.js"></script> <script type="text/javascript" src="../../../dist/test/layout.test.js"></script>
<script type="text/javascript" src="test/raphael-plugins.js"></script>
<script type='text/javascript' src='test/TestSuite.js'></script> <style type="text/css">
<script type='text/javascript' src='test/BalancedTestSuite.js'></script> div.col {
<script type='text/javascript' src='test/SymmetricTestSuite.js'></script> float: left;
<script type='text/javascript' src='test/FreeTestSuite.js'></script> margin-right: 20px;
}
div.col.last {
float: none;
}
</style>
</head>
<body>
<div id="basicTest" style="display: none">
<h1>Basic Tests</h1>
<script type='text/javascript'> <h3>testAligned:</h3>
window.addEvent('domready', function() { <div id="testAligned"></div>
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>
<style type="text/css"> <h3>testBaselineAligned:</h3>
div.col { <div id="testBaselineAligned1"></div>
float: left; <div id="testBaselineAligned2"></div>
margin-right: 20px;
}
div.col.last {
float: none;
}
</style>
</head> <h3>testEvents:</h3>
<body> <div id="testEvents1" class="col"></div>
<div id="testEvents2" class="col last"></div>
<h3>testEventsComplex:</h3>
<div id="testEventsComplex1" class="col"></div>
<div id="testEventsComplex2" class="col last"></div>
<div id="basicTest" style="display: none;"> <h3>testDisconnect:</h3>
<h1>Basic Tests</h1> <div id="testDisconnect1" class="col"></div>
<div id="testDisconnect2" class="col"></div>
<div id="testDisconnect3" class="col last"></div>
<h3>testAligned:</h3> <h3>testReconnect:</h3>
<div id="testAligned"></div> <div id="testReconnect1" class="col"></div>
<div id="testReconnect2" class="col last"></div>
<h3>testBaselineAligned:</h3> <h3>testRemoveNode:</h3>
<div id="testBaselineAligned1"></div> <div id="testRemoveNode1" class="col"></div>
<div id="testBaselineAligned2"></div> <div id="testRemoveNode2" class="col last"></div>
<div id="testRemoveNode3" class="col last"></div>
<div id="testRemoveNode4" class="col last"></div>
<h3>testEvents:</h3> <h3>testSize:</h3>
<div id="testEvents1" class="col"></div> <div id="testSize1" class="col"></div>
<div id="testEvents2" class="col last"></div> <div id="testSize2" class="col last"></div>
<div id="testSize3" class="col last"></div>
<div id="testSize4" class="col last"></div>
<div id="testSize5" class="col last"></div>
<div id="testSize6" class="col last"></div>
<h3>testEventsComplex:</h3> <h3>testReconnectSingleNode:</h3>
<div id="testEventsComplex1" class="col"></div> <div id="testReconnectSingleNode1" class="col"></div>
<div id="testEventsComplex2" class="col last"></div> <div id="testReconnectSingleNode2" class="col"></div>
</div>
<h3>testDisconnect:</h3> <div id="balancedTest" style="display: none">
<div id="testDisconnect1" class="col"></div> <h1>Balanced Sorter Tests</h1>
<div id="testDisconnect2" class="col"></div>
<div id="testDisconnect3" class="col last"></div>
<h3>testReconnect:</h3> <h3>testBalanced:</h3>
<div id="testReconnect1" class="col"></div> <div id="testBalanced1" class="col"></div>
<div id="testReconnect2" class="col last"></div> <div id="testBalanced2" class="col"></div>
<div id="testBalanced3" class="col last"></div>
<div id="testBalanced4" class="col"></div>
<div id="testBalanced5" class="col"></div>
<div id="testBalanced6" class="col last"></div>
<div id="testBalanced7" class="col"></div>
<div id="testBalanced8" class="col last"></div>
<div id="testBalanced9" class="col last"></div>
<div id="testBalanced10" class="col last"></div>
<div id="testBalanced11" class="col last"></div>
<div id="testBalanced12" class="col last"></div>
<div id="testBalanced13" class="col last"></div>
<h3>testRemoveNode:</h3> <h3>testBalancedPredict:</h3>
<div id="testRemoveNode1" class="col"></div> <div id="testBalancedPredict1"></div>
<div id="testRemoveNode2" class="col last"></div> <div id="testBalancedPredict2"></div>
<div id="testRemoveNode3" class="col last"></div> <div id="testBalancedPredict3"></div>
<div id="testRemoveNode4" class="col last"></div> <div id="testBalancedPredict4"></div>
<div id="testBalancedPredict5"></div>
<h3>testSize:</h3> <h3>testBalancedNodeDragPredict</h3>
<div id="testSize1" class="col"></div> <div id="testBalancedNodeDragPredict1"></div>
<div id="testSize2" class="col last"></div> <div id="testBalancedNodeDragPredict2"></div>
<div id="testSize3" class="col last"></div> <div id="testBalancedNodeDragPredict3"></div>
<div id="testSize4" class="col last"></div> </div>
<div id="testSize5" class="col last"></div>
<div id="testSize6" class="col last"></div>
<h3>testReconnectSingleNode:</h3> <div id="symmetricTest" style="display: none">
<div id="testReconnectSingleNode1" class="col"></div> <h1>Symmetric Sorter Tests</h1>
<div id="testReconnectSingleNode2" class="col"></div> <h3>testSymmetry:</h3>
</div> <div id="testSymmetry"></div>
<div id="balancedTest" style="display: none;"> <h3>testSymmetricPredict:</h3>
<h1>Balanced Sorter Tests</h1> <div id="testSymmetricPredict1"></div>
<div id="testSymmetricPredict2"></div>
<div id="testSymmetricPredict3"></div>
<div id="testSymmetricPredict4"></div>
<div id="testSymmetricPredict5"></div>
<h3>testBalanced:</h3> <h3>testSymmetricDragPredict:</h3>
<div id="testBalanced1" class="col"></div> <div id="testSymmetricDragPredict1"></div>
<div id="testBalanced2" class="col"></div> </div>
<div id="testBalanced3" class="col last"></div>
<div id="testBalanced4" class="col"></div>
<div id="testBalanced5" class="col"></div>
<div id="testBalanced6" class="col last"></div>
<div id="testBalanced7" class="col"></div>
<div id="testBalanced8" class="col last"></div>
<div id="testBalanced9" class="col last"></div>
<div id="testBalanced10" class="col last"></div>
<div id="testBalanced11" class="col last"></div>
<div id="testBalanced12" class="col last"></div>
<div id="testBalanced13" class="col last"></div>
<h3>testBalancedPredict:</h3> <div id="freeTest" style="display: none">
<div id="testBalancedPredict1"></div> <h1>Free Positioning Tests</h1>
<div id="testBalancedPredict2"></div>
<div id="testBalancedPredict3"></div>
<div id="testBalancedPredict4"></div>
<div id="testBalancedPredict5"></div>
<h3>testBalancedNodeDragPredict</h3>
<div id="testBalancedNodeDragPredict1"></div>
<div id="testBalancedNodeDragPredict2"></div>
<div id="testBalancedNodeDragPredict3"></div>
</div>
<div id="symmetricTest" style="display: none;"> <h3>testFreePosition:</h3>
<h1>Symmetric Sorter Tests</h1> <div id="testFreePosition1" class="col"></div>
<h3>testSymmetry:</h3> <div id="testFreePosition2" class="col last"></div>
<div id="testSymmetry"></div> <div id="testFreePosition3" class="col last"></div>
<div id="testFreePosition4" class="col last"></div>
<div id="testFreePosition5" class="col last"></div>
<div id="testFreePosition6" class="col last"></div>
<div id="testFreePosition7" class="col last"></div>
<div id="testFreePosition8" class="col last"></div>
<div id="testFreePosition9" class="col last"></div>
<h3>testSymmetricPredict:</h3> <h3>testFreePredict:</h3>
<div id="testSymmetricPredict1"></div> <div id="testFreePredict1" class="col"></div>
<div id="testSymmetricPredict2"></div>
<div id="testSymmetricPredict3"></div>
<div id="testSymmetricPredict4"></div>
<div id="testSymmetricPredict5"></div>
<h3>testSymmetricDragPredict:</h3>
<div id="testSymmetricDragPredict1"></div>
</div>
<div id="freeTest" style="display: none;"> <h3>testReconnectFreeNode:</h3>
<h1>Free Positioning Tests</h1> <div id="testReconnectFreeNode1" class="col"></div>
<div id="testReconnectFreeNode2" class="col"></div>
<div id="testReconnectFreeNode3" class="col"></div>
<div id="testReconnectFreeNode4" class="col"></div>
<div id="testReconnectFreeNode5" class="col"></div>
<div id="testReconnectFreeNode6" class="col"></div>
<div id="testReconnectFreeNode7" class="col"></div>
<h3>testFreePosition:</h3> <h3>testSiblingOverlapping:</h3>
<div id="testFreePosition1" class="col"></div> <div id="testSiblingOverlapping1" class="col"></div>
<div id="testFreePosition2" class="col last"></div> <div id="testSiblingOverlapping2" class="col"></div>
<div id="testFreePosition3" class="col last"></div> <div id="testSiblingOverlapping3" class="col"></div>
<div id="testFreePosition4" class="col last"></div>
<div id="testFreePosition5" class="col last"></div>
<div id="testFreePosition6" class="col last"></div>
<div id="testFreePosition7" class="col last"></div>
<div id="testFreePosition8" class="col last"></div>
<div id="testFreePosition9" class="col last"></div>
<h3>testFreePredict:</h3> <h3>testRootNodeChildrenPositioning:</h3>
<div id="testFreePredict1" class="col"></div> <div id="testRootNodeChildrenPositioning1" class="col"></div>
<div id="testRootNodeChildrenPositioning2" class="col"></div>
<div id="testRootNodeChildrenPositioning3" class="col"></div>
<div id="testRootNodeChildrenPositioning4" class="col"></div>
<div id="testRootNodeChildrenPositioning5" class="col"></div>
<h3>testReconnectFreeNode:</h3> <h3>testBalancedFreePredict:</h3>
<div id="testReconnectFreeNode1" class="col"></div> <div id="testBalancedFreePredict1" class="col"></div>
<div id="testReconnectFreeNode2" class="col"></div>
<div id="testReconnectFreeNode3" class="col"></div>
<div id="testReconnectFreeNode4" class="col"></div>
<div id="testReconnectFreeNode5" class="col"></div>
<div id="testReconnectFreeNode6" class="col"></div>
<div id="testReconnectFreeNode7" class="col"></div>
<h3>testSiblingOverlapping:</h3> <h3>testFreeReorder:</h3>
<div id="testSiblingOverlapping1" class="col"></div> <div id="testFreeReorder1" class="col"></div>
<div id="testSiblingOverlapping2" class="col"></div>
<div id="testSiblingOverlapping3" class="col"></div>
<h3>testRootNodeChildrenPositioning:</h3>
<div id="testRootNodeChildrenPositioning1" class="col"></div>
<div id="testRootNodeChildrenPositioning2" class="col"></div>
<div id="testRootNodeChildrenPositioning3" class="col"></div>
<div id="testRootNodeChildrenPositioning4" class="col"></div>
<div id="testRootNodeChildrenPositioning5" class="col"></div>
<h3>testBalancedFreePredict:</h3>
<div id="testBalancedFreePredict1" class="col"></div>
<h3>testFreeReorder:</h3> <h3>testFreeOverlap:</h3>
<div id="testFreeReorder1" class="col"></div> <div id="testFreeOverlap1" class="col"></div>
<div id="testFreeOverlap2" class="col"></div>
<h3>testFreeOverlap:</h3> </div>
<div id="testFreeOverlap1" class="col"></div> </body>
<div id="testFreeOverlap2" class="col"></div>
</div>
</body>
</html> </html>

View File

@ -1,41 +1,16 @@
<!DOCTYPE HTML> <!DOCTYPE html>
<html> <html>
<head> <head>
<script type='text/javascript' <script src="../../../lib/components/libraries/jquery/jquery-2.1.0.min.js"></script>
src='../../../../../wise-doc/src/main/webapp/js/mootools-core-1.3.2-full-compat.js'></script> <script src="../../../lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js"></script>
<script type='text/javascript' <script src="../../../lib/components/libraries/underscorejs/underscore-min.js"></script>
src='../../../../../wise-doc/src/main/webapp/js/mootools-more-1.3.2.1-yui.js'></script> <script src="../../../lib/components/libraries/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../../../core-js/dist/core.js"></script>
<script type='text/javascript' src='../../../main/javascript/header.js'></script> <script type="text/javascript" src="../../../dist/test/palette.test.js"></script>
<script type='text/javascript' src='../../../../../core-js/target/classes/core.js'></script> </head>
<body>
<script type='text/javascript' src='../../../main/javascript/widget/ToolbarItem.js'></script> <div id="myButton" style="border: 1px red solid">The button</div>
<script type='text/javascript' src='../../../main/javascript/widget/ColorPalettePanel.js'></script> </body>
</html>
<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>
</html>

View File

@ -15,374 +15,483 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.layout.BalancedTestSuite = new Class({ const TestSuite = require('./TestSuite').default;
Extends: mindplot.layout.TestSuite,
initialize:function() { const BalancedTestSuite = new Class({
$('#balancedTest').setStyle("display","block"); Extends: TestSuite,
initialize: function () {
$('#balancedTest').css('display', 'block');
this.testBalanced(); this.testBalanced();
this.testBalancedPredict(); this.testBalancedPredict();
this.testBalancedNodeDragPredict(); this.testBalancedNodeDragPredict();
}, },
testBalanced: function() { testBalanced: function () {
console.log("testBalanced:"); console.log('testBalanced:');
var position = {x:0, y:0}; var position = { x: 0, y: 0 };
var plotsize = {width:1000, height:200}; var plotsize = { width: 1000, height: 200 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); 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.connectNode(0, 1, 0);
manager.layout(); 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.connectNode(0, 2, 1);
manager.layout(); 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.connectNode(0, 3, 2);
manager.layout(); 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.connectNode(0, 4, 3);
manager.layout(); 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.connectNode(0, 5, 4);
manager.layout(); 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.connectNode(0, 6, 5);
manager.layout(); manager.layout();
manager.plot("testBalanced6", plotsize); manager.plot('testBalanced6', plotsize);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.connectNode(3, 7, 0) manager.connectNode(3, 7, 0);
manager.connectNode(7, 8, 0) manager.connectNode(7, 8, 0);
manager.connectNode(7, 9, 1); manager.connectNode(7, 9, 1);
manager.layout(); manager.layout();
manager.plot("testBalanced7", plotsize); manager.plot('testBalanced7', plotsize);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.connectNode(6, 10, 0) manager.connectNode(6, 10, 0);
manager.connectNode(10, 11, 0) manager.connectNode(10, 11, 0);
manager.connectNode(10, 12, 1); manager.connectNode(10, 12, 1);
manager.layout(); 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.connectNode(0, 13, 4);
manager.layout(); manager.layout();
manager.plot("testBalanced9", {width:1000, height:400}); manager.plot('testBalanced9', { width: 1000, height: 400 });
// Check orders have shifted accordingly // 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.connectNode(0, 14, 5);
manager.layout(); manager.layout();
manager.plot("testBalanced10", {width:1000, height:400}); manager.plot('testBalanced10', { width: 1000, height: 400 });
// Check orders have shifted accordingly // 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.connectNode(0, 15, 4);
manager.layout(); manager.layout();
manager.plot("testBalanced11", {width:1000, height:400}); manager.plot('testBalanced11', { width: 1000, height: 400 });
// Check orders have shifted accordingly // Check orders have shifted accordingly
$assert(manager.find(13).getOrder() == 6, "Node 13 should have order 6"); $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(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.connectNode(0, 16, 25);
manager.layout(); manager.layout();
manager.plot("testBalanced12", {width:1000, height:400}); manager.plot('testBalanced12', { width: 1000, height: 400 });
// Check orders have shifted accordingly // 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(17, TestSuite.NODE_SIZE, position);
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(18, TestSuite.NODE_SIZE, position);
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(19, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 17, 11); manager.connectNode(0, 17, 11);
manager.connectNode(0, 18, 13); manager.connectNode(0, 18, 13);
manager.connectNode(0, 19, 10); manager.connectNode(0, 19, 10);
manager.layout(); manager.layout();
manager.plot("testBalanced13", {width:1000, height:400}); manager.plot('testBalanced13', { width: 1000, height: 400 });
// Check that everything is ok // Check that everything is ok
$assert(manager.find(1).getPosition().x > manager.find(0).getPosition().x, $assert(
"even order nodes must be at right of central topic"); manager.find(1).getPosition().x > manager.find(0).getPosition().x,
$assert(manager.find(3).getPosition().x > manager.find(0).getPosition().x, 'even order nodes must be at right of central topic'
"even order nodes must be at right of central topic"); );
$assert(manager.find(5).getPosition().x > manager.find(0).getPosition().x, $assert(
"even order nodes must be at right of central topic"); manager.find(3).getPosition().x > manager.find(0).getPosition().x,
$assert(manager.find(2).getPosition().x < manager.find(0).getPosition().x, 'even order nodes must be at right of central topic'
"odd order nodes must be at right of central topic"); );
$assert(manager.find(4).getPosition().x < manager.find(0).getPosition().x, $assert(
"odd order nodes must be at right of central topic"); manager.find(5).getPosition().x > manager.find(0).getPosition().x,
$assert(manager.find(6).getPosition().x < manager.find(0).getPosition().x, 'even order nodes must be at right of central topic'
"odd order nodes must be at right of central topic"); );
$assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x, $assert(
"children of 1st level even order nodes must be to the right"); manager.find(2).getPosition().x < manager.find(0).getPosition().x,
$assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x, 'odd order nodes must be at right of central topic'
"children of 1st level even order nodes must be to the right"); );
$assert(manager.find(9).getPosition().x > manager.find(7).getPosition().x, $assert(
"children of 1st level even order nodes must be to the right"); manager.find(4).getPosition().x < manager.find(0).getPosition().x,
$assert(manager.find(10).getPosition().x < manager.find(6).getPosition().x, 'odd order nodes must be at right of central topic'
"children of 1st level odd order nodes must be to the left"); );
$assert(manager.find(11).getPosition().x < manager.find(10).getPosition().x, $assert(
"children of 1st level odd order nodes must be to the left"); manager.find(6).getPosition().x < manager.find(0).getPosition().x,
$assert(manager.find(12).getPosition().x < manager.find(10).getPosition().x, 'odd order nodes must be at right of central topic'
"children of 1st level odd order nodes must be to the left"); );
$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() { testBalancedPredict: function () {
console.log("testBalancedPredict:"); console.log('testBalancedPredict:');
var position = {x:0, y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); 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.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0,1,0); manager.connectNode(0, 1, 0);
manager.connectNode(0,2,1); manager.connectNode(0, 2, 1);
manager.connectNode(0,3,2); manager.connectNode(0, 3, 2);
manager.connectNode(0,4,3); manager.connectNode(0, 4, 3);
manager.connectNode(0,5,4); manager.connectNode(0, 5, 4);
manager.connectNode(4,7,0); manager.connectNode(4, 7, 0);
manager.connectNode(4,8,1); manager.connectNode(4, 8, 1);
manager.connectNode(8,9,0); manager.connectNode(8, 9, 0);
manager.connectNode(3,10,0); manager.connectNode(3, 10, 0);
manager.connectNode(3,11,1); manager.connectNode(3, 11, 1);
manager.layout(); manager.layout();
// Graph 1 // 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):"); console.log('\tAdded as child of node 0 and dropped at (165, -70):');
var prediction1a = manager.predict(0, null, {x:165, y:-70}); var prediction1a = manager.predict(0, null, { x: 165, y: -70 });
this._plotPrediction(graph1, prediction1a); this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.y < manager.find(1).getPosition().y && $assert(
prediction1a.position.x == manager.find(1).getPosition().x, "Prediction is incorrectly positioned"); prediction1a.position.y < manager.find(1).getPosition().y &&
$assert(prediction1a.order == 0, "Prediction order should be 0"); 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):"); console.log('\tAdded as child of node 0 and dropped at (165, -10):');
var prediction1b = manager.predict(0, null, {x:165, y:-10}); var prediction1b = manager.predict(0, null, { x: 165, y: -10 });
this._plotPrediction(graph1, prediction1b); this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.y > manager.find(1).getPosition().y && $assert(
prediction1b.position.y < manager.find(3).getPosition().y && prediction1b.position.y > manager.find(1).getPosition().y &&
prediction1b.position.x == manager.find(1).getPosition().x, "Prediction is incorrectly positioned"); prediction1b.position.y < manager.find(3).getPosition().y &&
$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):"); console.log('\tAdded as child of node 0 and dropped at (145, 15):');
var prediction1c = manager.predict(0, null, {x:145, y:15}); var prediction1c = manager.predict(0, null, { x: 145, y: 15 });
this._plotPrediction(graph1, prediction1c); this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.y > manager.find(3).getPosition().y && $assert(
prediction1c.position.y < manager.find(5).getPosition().y && prediction1c.position.y > manager.find(3).getPosition().y &&
prediction1c.position.x == manager.find(3).getPosition().x, "Prediction is incorrectly positioned"); prediction1c.position.y < manager.find(5).getPosition().y &&
$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):"); console.log('\tAdded as child of node 0 and dropped at (145, 70):');
var prediction1d = manager.predict(0, null, {x:145, y:70}); var prediction1d = manager.predict(0, null, { x: 145, y: 70 });
this._plotPrediction(graph1, prediction1d); this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.y > manager.find(5).getPosition().y && $assert(
prediction1d.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned"); prediction1d.position.y > manager.find(5).getPosition().y &&
$assert(prediction1d.order == 6, "Prediction order should be 6"); prediction1d.position.x == manager.find(5).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction1d.order == 6, 'Prediction order should be 6');
// Graph 2 // 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):"); console.log('\tAdded as child of node 0 and dropped at (-145, -50):');
var prediction2a = manager.predict(0, null, {x:-145, y:-50}); var prediction2a = manager.predict(0, null, { x: -145, y: -50 });
this._plotPrediction(graph2, prediction2a); this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.y < manager.find(2).getPosition().y && $assert(
prediction2a.position.x == manager.find(2).getPosition().x, "Prediction is incorrectly positioned"); prediction2a.position.y < manager.find(2).getPosition().y &&
$assert(prediction2a.order == 1, "Prediction order should be 1"); 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):"); console.log('\tAdded as child of node 0 and dropped at (-145, -10):');
var prediction2b = manager.predict(0, null, {x:-145, y:-10}); var prediction2b = manager.predict(0, null, { x: -145, y: -10 });
this._plotPrediction(graph2, prediction2b); this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.y > manager.find(2).getPosition().y && $assert(
prediction2b.position.y < manager.find(4).getPosition().y && prediction2b.position.y > manager.find(2).getPosition().y &&
prediction2b.position.x == manager.find(2).getPosition().x, "Prediction is incorrectly positioned"); prediction2b.position.y < manager.find(4).getPosition().y &&
$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):"); console.log('\tAdded as child of node 0 and dropped at (-145, 40):');
var prediction2c = manager.predict(0, null, {x:-145, y:400}); var prediction2c = manager.predict(0, null, { x: -145, y: 400 });
this._plotPrediction(graph2, prediction2c); this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.y > manager.find(4).getPosition().y && $assert(
prediction2c.position.x == manager.find(4).getPosition().x, "Prediction is incorrectly positioned"); prediction2c.position.y > manager.find(4).getPosition().y &&
$assert(prediction2c.order == 5, "Prediction order should be 5"); prediction2c.position.x == manager.find(4).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2c.order == 5, 'Prediction order should be 5');
// Graph 3 // Graph 3
console.log("\tPredict nodes added with no position:"); console.log('\tPredict nodes added with no position:');
var graph3 = manager.plot("testBalancedPredict3", {width:1000, height:400}); var graph3 = manager.plot('testBalancedPredict3', { width: 1000, height: 400 });
var prediction3 = manager.predict(0, null, null); var prediction3 = manager.predict(0, null, null);
this._plotPrediction(graph3, prediction3); this._plotPrediction(graph3, prediction3);
$assert(prediction3.position.y > manager.find(4).getPosition().y && $assert(
prediction3.position.x == manager.find(4).getPosition().x, "Prediction is incorrectly positioned"); prediction3.position.y > manager.find(4).getPosition().y &&
$assert(prediction3.order == 5, "Prediction order should be 5"); 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:"); console.log('\tPredict nodes added with no position:');
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, prediction3.position); manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position);
manager.connectNode(0,6,prediction3.order); manager.connectNode(0, 6, prediction3.order);
manager.layout(); 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); var prediction4 = manager.predict(0, null, null);
this._plotPrediction(graph4, prediction4); this._plotPrediction(graph4, prediction4);
$assert(prediction4.position.y > manager.find(5).getPosition().y && $assert(
prediction4.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned"); prediction4.position.y > manager.find(5).getPosition().y &&
$assert(prediction4.order == 6, "Prediction order should be 6"); 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.removeNode(1).removeNode(2).removeNode(3).removeNode(4).removeNode(5);
manager.layout(); 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 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, prediction5a);
this._plotPrediction(graph5, prediction5b); this._plotPrediction(graph5, prediction5b);
$assert(prediction5a.position.x > manager.find(0).getPosition().x && $assert(
prediction5a.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned"); prediction5a.position.x > manager.find(0).getPosition().x &&
$assert(prediction5a.order == 0, "Prediction order should be 0"); prediction5a.position.y == manager.find(0).getPosition().y,
$assert(prediction5a.position.x == prediction5b.position.x && 'Prediction is incorrectly positioned'
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.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() { testBalancedNodeDragPredict: function () {
console.log("testBalancedNodeDragPredict:"); console.log('testBalancedNodeDragPredict:');
var position = {x:0, y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Graph 1 // 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(); 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); this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x == manager.find(1).getPosition().x && $assert(
prediction1a.position.y == manager.find(1).getPosition().y, prediction1a.position.x == manager.find(1).getPosition().x &&
"Prediction position should be the same as node 1"); prediction1a.position.y == manager.find(1).getPosition().y,
$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); this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x == manager.find(1).getPosition().x && $assert(
prediction1b.position.y == manager.find(1).getPosition().y, prediction1b.position.x == manager.find(1).getPosition().x &&
"Prediction position should be the same as node 1"); prediction1b.position.y == manager.find(1).getPosition().y,
$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); this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.x < manager.find(0).getPosition().x && $assert(
prediction1c.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned"); prediction1c.position.x < manager.find(0).getPosition().x &&
$assert(prediction1c.order == 1, "Prediction order should be the same as node 1"); 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); this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.x < manager.find(0).getPosition().x && $assert(
prediction1d.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned"); prediction1d.position.x < manager.find(0).getPosition().x &&
$assert(prediction1d.order == 1, "Prediction order should be the same as node 1"); 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 // Graph 2
manager.disconnectNode(1); manager.disconnectNode(1);
manager.connectNode(0, 1, 1); manager.connectNode(0, 1, 1);
manager.layout(); 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); this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.x > manager.find(0).getPosition().x && $assert(
prediction2a.position.y == manager.find(0).getPosition().y, "Prediction is positioned incorrectly"); prediction2a.position.x > manager.find(0).getPosition().x &&
$assert(prediction2a.order == 0, "Prediction order should be 0"); 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); this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.x > manager.find(0).getPosition().x && $assert(
prediction2b.position.y == manager.find(0).getPosition().y, "Prediction is positioned incorrectly"); prediction2b.position.x > manager.find(0).getPosition().x &&
$assert(prediction2b.order == 0, "Prediction order should be 0"); 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); this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.x == manager.find(1).getPosition().x && $assert(
prediction2c.position.y == manager.find(1).getPosition().y, prediction2c.position.x == manager.find(1).getPosition().x &&
"Prediction position should be the same as node 1"); prediction2c.position.y == manager.find(1).getPosition().y,
$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); this._plotPrediction(graph2, prediction2d);
$assert(prediction2d.position.x == manager.find(1).getPosition().x && $assert(
prediction2d.position.y == manager.find(1).getPosition().y, prediction2d.position.x == manager.find(1).getPosition().x &&
"Prediction position should be the same as node 1"); prediction2d.position.y == manager.find(1).getPosition().y,
$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 // Graph 3
manager.disconnectNode(1); manager.disconnectNode(1);
manager.connectNode(0, 1, 0); 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(); 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); this._plotPrediction(graph3, prediction3a);
$assert(prediction3a.position.x == manager.find(2).getPosition().x && $assert(
prediction3a.position.y > manager.find(2).getPosition().y, "Prediction is incorrectly positioned"); prediction3a.position.x == manager.find(2).getPosition().x &&
$assert(prediction3a.order == 4, "Prediction order should be 4"); 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); this._plotPrediction(graph3, prediction3b);
$assert(prediction3b.position.x == manager.find(1).getPosition().x && $assert(
prediction3b.position.y == manager.find(1).getPosition().y && prediction3b.position.x == manager.find(1).getPosition().x &&
prediction3b.order == manager.find(1).getOrder(), "Prediction should be the exact same as dragged node"); prediction3b.position.y == manager.find(1).getPosition().y &&
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); this._plotPrediction(graph3, prediction3c);
$assert(prediction3c.position.x < manager.find(0).getPosition().x && $assert(
prediction3c.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned"); prediction3c.position.x < manager.find(0).getPosition().x &&
$assert(prediction3c.order == 1, "Prediction order should be 1"); 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); this._plotPrediction(graph3, prediction3d);
$assert(prediction3d.position.x < manager.find(0).getPosition().x && $assert(
prediction3d.position.y == manager.find(0).getPosition().y, "Prediction is incorrectly positioned"); prediction3d.position.x < manager.find(0).getPosition().x &&
$assert(prediction3d.order == 1, "Prediction order should be 1"); 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); this._plotPrediction(graph3, prediction3e);
$assert(prediction3e.position.x == manager.find(1).getPosition().x && $assert(
prediction3e.position.y == manager.find(1).getPosition().y, prediction3e.position.x == manager.find(1).getPosition().x &&
"Prediction position should be the same as node 1"); prediction3e.position.y == manager.find(1).getPosition().y,
$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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.layout.FreeTestSuite = new Class({ const TestSuite = require('./TestSuite').default;
Extends: mindplot.layout.TestSuite, const FreeTestSuite = new Class({
Extends: TestSuite,
initialize:function() { initialize: function () {
$('#freeTest').setStyle("display","block"); $('#freeTest').css('display', 'block');
this.testFreePosition(); this.testFreePosition();
this.testFreePredict(); this.testFreePredict();
@ -31,121 +32,133 @@ mindplot.layout.FreeTestSuite = new Class({
this.testFreeOverlap(); this.testFreeOverlap();
}, },
testFreePosition: function() { testFreePosition: function () {
console.log("testFreePosition:"); console.log('testFreePosition:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(15, TestSuite.NODE_SIZE, position);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(16, TestSuite.NODE_SIZE, position);
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(17, TestSuite.NODE_SIZE, position);
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(18, TestSuite.NODE_SIZE, position);
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(19, TestSuite.NODE_SIZE, position);
manager.addNode(20, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(20, TestSuite.NODE_SIZE, position);
manager.addNode(21, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(21, TestSuite.NODE_SIZE, position);
manager.addNode(22, mindplot.layout.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(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(4, 21, 0).connectNode(4, 22, 0);
manager.connectNode(1,5,0); manager.connectNode(1, 5, 0);
manager.connectNode(5,6,0).connectNode(6,8,0).connectNode(8,9,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(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
manager.connectNode(3,12,1).connectNode(12,15,0).connectNode(12,16,1).connectNode(12,17,2); .connectNode(3, 11, 0)
manager.connectNode(3,13,2); .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.layout();
manager.plot("testFreePosition1", {width:1400, height:600}); manager.plot('testFreePosition1', { width: 1400, height: 600 });
console.log("\tmove node 12 to (300,30):"); console.log('\tmove node 12 to (300,30):');
manager.moveNode(12, {x:300, y:30}); manager.moveNode(12, { x: 300, y: 30 });
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition2", {width:1400, height:600}); manager.plot('testFreePosition2', { width: 1400, height: 600 });
this._assertFreePosition(manager, 12, {x:300, y:30}) this._assertFreePosition(manager, 12, { x: 300, y: 30 });
console.log("\tmove node 13 to (340,180):"); console.log('\tmove node 13 to (340,180):');
var node13Pos = {x:340, y:180}; var node13Pos = { x: 340, y: 180 };
manager.moveNode(13, node13Pos); manager.moveNode(13, node13Pos);
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition3", {width:1400, height:600}); manager.plot('testFreePosition3', { width: 1400, height: 600 });
this._assertFreePosition(manager, 13, node13Pos); this._assertFreePosition(manager, 13, node13Pos);
console.log("\tmove node 11 to (250,-50):"); console.log('\tmove node 11 to (250,-50):');
manager.moveNode(11, {x:250, y:-50}); manager.moveNode(11, { x: 250, y: -50 });
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition4", {width:1400, height:600}); manager.plot('testFreePosition4', { width: 1400, height: 600 });
this._assertFreePosition(manager, 11, {x:250, y:-50}); this._assertFreePosition(manager, 11, { x: 250, y: -50 });
$assert(manager.find(13).getPosition().x == node13Pos.x && manager.find(13).getPosition().y == node13Pos.y, $assert(
"Node 13 shouldn't have moved"); 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):"); console.log('\tmove node 7 to (350,-190):');
manager.moveNode(7, {x:350, y:-190}); manager.moveNode(7, { x: 350, y: -190 });
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition5", {width:1400, height:600}); manager.plot('testFreePosition5', { width: 1400, height: 600 });
this._assertFreePosition(manager, 7, {x:350, y:-190}); this._assertFreePosition(manager, 7, { x: 350, y: -190 });
console.log("\tadd node 23 to 12:"); console.log('\tadd node 23 to 12:');
manager.addNode(23, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(23, TestSuite.NODE_SIZE, position);
manager.connectNode(12,23,3); manager.connectNode(12, 23, 3);
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition6", {width:1400, height:600}); manager.plot('testFreePosition6', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null); this._assertFreePosition(manager, null, null);
console.log("\tmove node 4 to (-300, 190):"); console.log('\tmove node 4 to (-300, 190):');
manager.moveNode(4, {x:-300, y:190}); manager.moveNode(4, { x: -300, y: 190 });
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition7", {width:1400, height:600}); manager.plot('testFreePosition7', { width: 1400, height: 600 });
this._assertFreePosition(manager, 4, {x:-300, y:190}); this._assertFreePosition(manager, 4, { x: -300, y: 190 });
console.log("\tadd node 24 to 3:"); console.log('\tadd node 24 to 3:');
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(24, TestSuite.NODE_SIZE, position);
manager.connectNode(3,24,3); manager.connectNode(3, 24, 3);
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition8", {width:1400, height:600}); manager.plot('testFreePosition8', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null); this._assertFreePosition(manager, null, null);
console.log("\tadd node 25 to 17:"); console.log('\tadd node 25 to 17:');
manager.addNode(25, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(25, TestSuite.NODE_SIZE, position);
manager.connectNode(17,25,0); manager.connectNode(17, 25, 0);
manager.layout(true); manager.layout(true);
manager.plot("testFreePosition9", {width:1400, height:600}); manager.plot('testFreePosition9', { width: 1400, height: 600 });
this._assertFreePosition(manager, null, null); this._assertFreePosition(manager, null, null);
console.log("OK!\n\n"); console.log('OK!\n\n');
}, },
testFreePredict: function() { testFreePredict: function () {
console.log("testFreePredict:"); console.log('testFreePredict:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0); manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1); manager.connectNode(0, 2, 1);
@ -160,50 +173,62 @@ mindplot.layout.FreeTestSuite = new Class({
manager.connectNode(2, 10, 1); manager.connectNode(2, 10, 1);
manager.layout(); 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); var predict1 = manager.predict(5, 11, pos1, true);
this._plotPrediction(graph, predict1); 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); var predict2 = manager.predict(0, 2, pos2, true);
this._plotPrediction(graph, predict2); 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 node5 = manager.find(5);
var predict3 = manager.predict(3, 5, pos3, true); var predict3 = manager.predict(3, 5, pos3, true);
this._plotPrediction(graph, predict3); 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 node10 = manager.find(10);
var predict4 = manager.predict(2, 10, pos4, true); var predict4 = manager.predict(2, 10, pos4, true);
this._plotPrediction(graph, predict4); 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() { testReconnectFreeNode: function () {
console.log("testReconnectFreeNode:"); console.log('testReconnectFreeNode:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0); manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1); manager.connectNode(0, 2, 1);
@ -218,265 +243,313 @@ mindplot.layout.FreeTestSuite = new Class({
manager.connectNode(2, 10, 1); manager.connectNode(2, 10, 1);
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode1", {width:1000, height:400}); manager.plot('testReconnectFreeNode1', { width: 1000, height: 400 });
console.log("\tmove node 5"); console.log('\tmove node 5');
manager.moveNode(5, {x:250, y:30}); manager.moveNode(5, { x: 250, y: 30 });
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode2", {width:1000, height:400}); manager.plot('testReconnectFreeNode2', { width: 1000, height: 400 });
this._assertFreePosition(manager, 5, {x:250, y:30}); 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.disconnectNode(5);
manager.connectNode(2,5,2); manager.connectNode(2, 5, 2);
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode3", {width:1000, height:400}); manager.plot('testReconnectFreeNode3', { width: 1000, height: 400 });
$assert(manager.find(5).getPosition().y > manager.find(10).getPosition().y && $assert(
manager.find(5).getPosition().x == manager.find(10).getPosition().x, "Node 5 is incorrectly positioned" 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"); console.log('\tmove node 8');
manager.moveNode(8, {x:-370, y:60}); manager.moveNode(8, { x: -370, y: 60 });
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode4", {width:1000, height:400}); manager.plot('testReconnectFreeNode4', { width: 1000, height: 400 });
this._assertFreePosition(manager, 8, {x:-370, y:60}); 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.disconnectNode(5);
manager.connectNode(10,5,0); manager.connectNode(10, 5, 0);
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode5", {width:1000, height:400}); manager.plot('testReconnectFreeNode5', { width: 1000, height: 400 });
$assert(manager.find(5).getPosition().y == manager.find(10).getPosition().y && $assert(
manager.find(5).getPosition().x < manager.find(10).getPosition().x, "Node 5 is incorrectly positioned" 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.disconnectNode(5);
manager.connectNode(3,5,2); manager.connectNode(3, 5, 2);
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode6", {width:1000, height:400}); manager.plot('testReconnectFreeNode6', { width: 1000, height: 400 });
$assert(manager.find(5).getPosition().y > manager.find(6).getPosition().y && $assert(
manager.find(5).getPosition().x == manager.find(6).getPosition().x, "Node 5 is incorrectly positioned" 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"); console.log('\tmove node 8');
manager.moveNode(8, {x:370, y:30}); manager.moveNode(8, { x: 370, y: 30 });
manager.layout(); manager.layout();
manager.plot("testReconnectFreeNode7", {width:1000, height:400}); manager.plot('testReconnectFreeNode7', { width: 1000, height: 400 });
this._assertFreePosition(manager, 8, {x:370, y:30}); this._assertFreePosition(manager, 8, { x: 370, y: 30 });
console.log("OK!\n\n"); console.log('OK!\n\n');
}, },
testSiblingOverlapping: function() { testSiblingOverlapping: function () {
console.log("testSiblingOverlapping:"); console.log('testSiblingOverlapping:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // 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.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,2,0); manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,3,1); manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 1);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,2); manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 2);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,3); manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 3);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,4); manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 4);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,7,5); manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(1, 7, 5);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,8,6); manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(1, 8, 6);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,9,4); manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(0, 9, 4);
manager.layout(); manager.layout();
manager.plot("testSiblingOverlapping1", {width:800, height:600}); manager.plot('testSiblingOverlapping1', { width: 800, height: 600 });
console.log("\tmove node 2"); console.log('\tmove node 2');
manager.moveNode(2, {x:250, y: -30}); manager.moveNode(2, { x: 250, y: -30 });
manager.layout(); manager.layout();
manager.plot("testSiblingOverlapping2", {width:800, height:600}); manager.plot('testSiblingOverlapping2', { width: 800, height: 600 });
this._assertFreePosition(manager, 2, {x:250, y: -30}); this._assertFreePosition(manager, 2, { x: 250, y: -30 });
console.log("\tmove node 7"); console.log('\tmove node 7');
manager.moveNode(7, {x:250, y: 100}); manager.moveNode(7, { x: 250, y: 100 });
manager.layout(); manager.layout();
manager.plot("testSiblingOverlapping3", {width:800, height:600}); manager.plot('testSiblingOverlapping3', { width: 800, height: 600 });
this._assertFreePosition(manager, 7, {x:250, y: 100}); this._assertFreePosition(manager, 7, { x: 250, y: 100 });
console.log("OK!\n\n"); console.log('OK!\n\n');
}, },
testRootNodeChildrenPositioning: function() { testRootNodeChildrenPositioning: function () {
console.log("testRootNodeChildrenPositioning:"); console.log('testRootNodeChildrenPositioning:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // 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.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,2,1); manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,3,2); manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 2);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,4,3); manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(0, 4, 3);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,5,4); manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 4);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0,6,5); manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 5);
manager.layout(); manager.layout();
manager.plot("testRootNodeChildrenPositioning1", {width:800, height:600}); manager.plot('testRootNodeChildrenPositioning1', { width: 800, height: 600 });
console.log("\tmove node 1"); console.log('\tmove node 1');
manager.moveNode(1, {x:150, y:0}); manager.moveNode(1, { x: 150, y: 0 });
manager.layout(); manager.layout();
manager.plot("testRootNodeChildrenPositioning2", {width:800, height:600}); manager.plot('testRootNodeChildrenPositioning2', { width: 800, height: 600 });
this._assertFreePosition(manager, 1, {x:150, y:0}); this._assertFreePosition(manager, 1, { x: 150, y: 0 });
console.log("\tmove node 4"); console.log('\tmove node 4');
manager.moveNode(4, {x:-140, y:30}); manager.moveNode(4, { x: -140, y: 30 });
manager.layout(); manager.layout();
manager.plot("testRootNodeChildrenPositioning3", {width:800, height:600}); manager.plot('testRootNodeChildrenPositioning3', { width: 800, height: 600 });
this._assertFreePosition(manager, 4, {x:-140, y:30}); this._assertFreePosition(manager, 4, { x: -140, y: 30 });
console.log("\tmove node 2"); console.log('\tmove node 2');
manager.moveNode(2, {x:-150, y:-50}); manager.moveNode(2, { x: -150, y: -50 });
manager.layout(); manager.layout();
manager.plot("testRootNodeChildrenPositioning4", {width:800, height:600}); manager.plot('testRootNodeChildrenPositioning4', { width: 800, height: 600 });
this._assertFreePosition(manager, 2, {x:-150, y:-50}); this._assertFreePosition(manager, 2, { x: -150, y: -50 });
//TODO(gb): fix this. It's not working //TODO(gb): fix this. It's not working
// console.log("\tmove node 6"); // console.log("\tmove node 6");
// manager.moveNode(6, {x:-150, y:-50}); // manager.moveNode(6, {x:-150, y:-50});
// manager.layout(); // manager.layout();
// manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600}); // manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600});
// this._assertFreePosition(manager, 6, {x:-150, y:-50}); // this._assertFreePosition(manager, 6, {x:-150, y:-50});
console.log("OK!\n\n"); console.log('OK!\n\n');
}, },
testBalancedFreePredict: function() { testBalancedFreePredict: function () {
console.log("testBalancedFreePredict:"); console.log('testBalancedFreePredict:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // 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(); 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); 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() { testFreeReorder: function () {
console.log("testFreeReorder:"); console.log('testFreeReorder:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // 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.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,0); manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,1); manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,2); 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(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,7,0); manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,8,1); manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,9,2); manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,10,3); 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(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,11,0); manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,12,1); manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,13,2); manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,14,3); manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,15,4); manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,16,5); manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5);
manager.layout(); manager.layout();
manager.moveNode(14, {x:270, y:-160}); manager.moveNode(14, { x: 270, y: -160 });
manager.layout(); manager.layout();
manager.plot("testFreeReorder1", {width:800, height:1200}); 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"); $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() { testFreeOverlap: function () {
console.log("testFreeOverlap:"); console.log('testFreeOverlap:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // 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.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,4,0); manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,5,1); manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1,6,2); 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(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,7,0); manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,8,1); manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,9,2); manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(2,10,3); 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(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,11,0); manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,12,1); manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,13,2); manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,14,3); manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3);
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,15,4); manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4);
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(3,16,5); manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5);
manager.layout(); 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.layout();
manager.plot("testFreeOverlap2", {width:800, height:1200}); manager.plot('testFreeOverlap2', { width: 800, height: 1200 });
$assert(manager.find(2).getPosition().y > manager.find(1).getPosition().y, "Branches 1 and 2 are overlapping"); $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) { if (id != null && position.x != null && position.y != null) {
var node = manager.find(id); var node = manager.find(id);
$assert(node.getPosition().x == position.x && node.getPosition().y == position.y, $assert(
"Freely moved node " + id + " is not left at free position (" + position.x + "," + position.y + "). " + node.getPosition().x == position.x && node.getPosition().y == position.y,
"Actual position: (" + node.getPosition().x + "," + node.getPosition().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; var treeSet = manager._treeSet;
_.each(treeSet._rootNodes, function(rootNode) { _.each(
var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode); treeSet._rootNodes,
this._assertBranchCollision(treeSet, rootNode, heightById); function (rootNode) {
}, this); var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
this._assertBranchCollision(treeSet, rootNode, heightById);
},
this
);
}, },
_assertBranchCollision: function(treeSet, node, heightById) { _assertBranchCollision: function (treeSet, node, heightById) {
var children = treeSet.getChildren(node); var children = treeSet.getChildren(node);
var childOfRootNode = treeSet._rootNodes.contains(node); var childOfRootNode = treeSet._rootNodes.contains(node);
_.each(children, function(child) { _.each(
var height = heightById[child.getId()]; children,
var siblings = treeSet.getSiblings(child); function (child) {
if (childOfRootNode) { var height = heightById[child.getId()];
siblings = siblings.filter(function(sibling) { var siblings = treeSet.getSiblings(child);
return (child.getOrder() % 2) == (sibling.getOrder() % 2); if (childOfRootNode) {
}) siblings = siblings.filter(function (sibling) {
} return child.getOrder() % 2 == sibling.getOrder() % 2;
_.each(siblings, function(sibling) { });
this._branchesOverlap(child, sibling, heightById); }
}, this); _.each(
}, this); siblings,
function (sibling) {
this._branchesOverlap(child, sibling, heightById);
},
this
);
},
this
);
_.each(children, function(child) { _.each(
this._assertBranchCollision(treeSet, child, heightById); children,
}, this) function (child) {
this._assertBranchCollision(treeSet, child, heightById);
},
this
);
}, },
_branchesOverlap: function(branchA, branchB, heightById) { _branchesOverlap: function (branchA, branchB, heightById) {
var topA = branchA.getPosition().y - heightById[branchA.getId()]/2; var topA = branchA.getPosition().y - heightById[branchA.getId()] / 2;
var bottomA = 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 topB = branchB.getPosition().y - heightById[branchB.getId()] / 2;
var bottomB = 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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.layout.SymmetricTestSuite = new Class({ const TestSuite = require('./TestSuite').default;
Extends: mindplot.layout.TestSuite,
initialize:function() { const SymmetricTestSuite = new Class({
$('#symmetricTest').setStyle("display","block"); Extends: TestSuite,
initialize: function () {
$('#symmetricTest').css('display', 'block');
this.testSymmetry(); this.testSymmetry();
this.testSymmetricPredict(); this.testSymmetricPredict();
this.testSymmetricDragPredict(); this.testSymmetricDragPredict();
}, },
testSymmetry: function() { testSymmetry: function () {
console.log("testSymmetry:") console.log('testSymmetry:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); 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.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(12, TestSuite.NODE_SIZE, position);
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(13, TestSuite.NODE_SIZE, position);
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(14, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 14, 0); manager.connectNode(0, 14, 0);
manager.connectNode(14, 13, 0); manager.connectNode(14, 13, 0);
manager.connectNode(13, 1, 0); manager.connectNode(13, 1, 0);
@ -61,38 +63,53 @@ mindplot.layout.SymmetricTestSuite = new Class({
manager.connectNode(6, 12, 1); manager.connectNode(6, 12, 1);
manager.layout(); 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 // 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(
$assert(manager.find(5).getPosition().y == manager.find(10).getPosition().y, "Symmetry is not respected"); manager.find(14).getPosition().y == manager.find(13).getPosition().y,
$assert(manager.find(11).getPosition().y - manager.find(6).getPosition().y == 'Symmetry is not respected'
-(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 == $assert(
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected"); manager.find(5).getPosition().y == manager.find(10).getPosition().y,
$assert(manager.find(9).getPosition().y - manager.find(1).getPosition().y == 'Symmetry is not respected'
-(manager.find(11).getPosition().y - manager.find(1).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() { testSymmetricPredict: function () {
console.log("testSymmetricPredict:"); console.log('testSymmetricPredict:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
// Prepare a sample graph ... // Prepare a sample graph ...
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(1, TestSuite.NODE_SIZE, position);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(2, TestSuite.NODE_SIZE, position);
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(3, TestSuite.NODE_SIZE, position);
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(4, TestSuite.NODE_SIZE, position);
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(5, TestSuite.NODE_SIZE, position);
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(6, TestSuite.NODE_SIZE, position);
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(7, TestSuite.NODE_SIZE, position);
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(8, TestSuite.NODE_SIZE, position);
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(9, TestSuite.NODE_SIZE, position);
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(10, TestSuite.NODE_SIZE, position);
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position); manager.addNode(11, TestSuite.NODE_SIZE, position);
manager.connectNode(0, 1, 0); manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 1); manager.connectNode(0, 2, 1);
@ -109,158 +126,221 @@ mindplot.layout.SymmetricTestSuite = new Class({
manager.layout(); manager.layout();
// Graph // 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):"); console.log('\tAdded as child of node 9 and dropped at (-280, 45):');
var prediction1a = manager.predict(9, null, {x:-280, y:45}); var prediction1a = manager.predict(9, null, { x: -280, y: 45 });
this._plotPrediction(graph1, prediction1a); this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x < manager.find(9).getPosition().x && $assert(
prediction1a.position.y == manager.find(9).getPosition().y, "Prediction incorrectly positioned"); prediction1a.position.x < manager.find(9).getPosition().x &&
$assert(prediction1a.order == 0, "Prediction order should be 0"); 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):"); console.log('\tAdded as child of node 1 and dropped at (155, -90):');
var prediction1b = manager.predict(1, null, {x:-155, y:-90}); var prediction1b = manager.predict(1, null, { x: -155, y: -90 });
this._plotPrediction(graph1, prediction1b); this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x > manager.find(1).getPosition().x && $assert(
prediction1b.position.y == manager.find(1).getPosition().y, "Prediction is incorrectly positioned"); prediction1b.position.x > manager.find(1).getPosition().x &&
$assert(prediction1b.order == 0, "Prediction order should be 0"); prediction1b.position.y == manager.find(1).getPosition().y,
'Prediction is incorrectly positioned'
);
$assert(prediction1b.order == 0, 'Prediction order should be 0');
// Graph 2 // 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):"); console.log('\tAdded as child of node 5 and dropped at (380, -30):');
var prediction2d = manager.predict(5, null, {x:380, y:-30}); var prediction2d = manager.predict(5, null, { x: 380, y: -30 });
this._plotPrediction(graph2, prediction2d); this._plotPrediction(graph2, prediction2d);
$assert(prediction2d.position.y < manager.find(7).getPosition().y && $assert(
prediction2d.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned" ); prediction2d.position.y < manager.find(7).getPosition().y &&
$assert(prediction2d.order == 0, "Prediction order should be 0"); 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):"); console.log('\tAdded as child of node 5 and dropped at (375, 15):');
var prediction2a = manager.predict(5, null, {x:375, y:15}); var prediction2a = manager.predict(5, null, { x: 375, y: 15 });
this._plotPrediction(graph2, prediction2a); this._plotPrediction(graph2, prediction2a);
$assert(prediction2a.position.y > manager.find(7).getPosition().y && $assert(
prediction2a.position.y < manager.find(8).getPosition().y && prediction2a.position.y > manager.find(7).getPosition().y &&
prediction2a.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned"); prediction2a.position.y < manager.find(8).getPosition().y &&
$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):"); console.log('\tAdded as child of node 5 and dropped at (375, 45):');
var prediction2b = manager.predict(5, null, {x:375, y:45}); var prediction2b = manager.predict(5, null, { x: 375, y: 45 });
this._plotPrediction(graph2, prediction2b); this._plotPrediction(graph2, prediction2b);
$assert(prediction2b.position.y > manager.find(8).getPosition().y && $assert(
prediction2b.position.y < manager.find(11).getPosition().y && prediction2b.position.y > manager.find(8).getPosition().y &&
prediction2b.position.x == manager.find(7).getPosition().x, "Prediction is incorrectly positioned"); prediction2b.position.y < manager.find(11).getPosition().y &&
$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):"); console.log('\tAdded as child of node 5 and dropped at (375, 45):');
var prediction2c = manager.predict(5, null, {x:375, y:65}); var prediction2c = manager.predict(5, null, { x: 375, y: 65 });
this._plotPrediction(graph2, prediction2c); this._plotPrediction(graph2, prediction2c);
$assert(prediction2c.position.y > manager.find(11).getPosition().y && $assert(
prediction2c.position.x == manager.find(11).getPosition().x, "Prediction is incorrectly positioned"); prediction2c.position.y > manager.find(11).getPosition().y &&
$assert(prediction2c.order == 3, "Prediction order should be 3"); prediction2c.position.x == manager.find(11).getPosition().x,
'Prediction is incorrectly positioned'
);
$assert(prediction2c.order == 3, 'Prediction order should be 3');
// Graph 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):"); console.log('\tAdded as child of node 3 and dropped at (280, 45):');
var prediction3a = manager.predict(3, null, {x:280, y:45}); var prediction3a = manager.predict(3, null, { x: 280, y: 45 });
this._plotPrediction(graph3, prediction3a); this._plotPrediction(graph3, prediction3a);
$assert(prediction3a.position.y > manager.find(5).getPosition().y && $assert(
prediction3a.position.y < manager.find(6).getPosition().y && prediction3a.position.y > manager.find(5).getPosition().y &&
prediction3a.position.x == manager.find(5).getPosition().x, "Prediction is incorrectly positioned"); prediction3a.position.y < manager.find(6).getPosition().y &&
$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):"); console.log('\tAdded as child of node 3 and dropped at (255, 110):');
var prediction3b = manager.predict(3, null, {x:255, y:110}); var prediction3b = manager.predict(3, null, { x: 255, y: 110 });
this._plotPrediction(graph3, prediction3b); this._plotPrediction(graph3, prediction3b);
$assert(prediction3b.position.y > manager.find(6).getPosition().y && $assert(
prediction3b.position.x == manager.find(6).getPosition().x, "Prediction incorrectly positioned"); prediction3b.position.y > manager.find(6).getPosition().y &&
$assert(prediction3b.order == 3, "Prediction order should be 3"); prediction3b.position.x == manager.find(6).getPosition().x,
'Prediction incorrectly positioned'
);
$assert(prediction3b.order == 3, 'Prediction order should be 3');
// Graph 4 // Graph 4
console.log("\tAdded as child of node 2 and dropped at (-260, 0):"); console.log('\tAdded as child of node 2 and dropped at (-260, 0):');
var graph4 = manager.plot("testSymmetricPredict4", {width:1000, height:400}); var graph4 = manager.plot('testSymmetricPredict4', { width: 1000, height: 400 });
var prediction4 = manager.predict(2, null, {x:-260, y:0}); var prediction4 = manager.predict(2, null, { x: -260, y: 0 });
this._plotPrediction(graph4, prediction4); this._plotPrediction(graph4, prediction4);
$assert(prediction4.position.y > manager.find(9).getPosition().y && $assert(
prediction4.position.y < manager.find(10).getPosition().y && prediction4.position.y > manager.find(9).getPosition().y &&
prediction4.position.x == manager.find(9).getPosition().x, "Prediction is incorrectly positioned"); prediction4.position.y < manager.find(10).getPosition().y &&
$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 // Graph 5
console.log("\tPredict nodes added with no position:"); console.log('\tPredict nodes added with no position:');
var graph5 = manager.plot("testSymmetricPredict5", {width:1000, height:400}); var graph5 = manager.plot('testSymmetricPredict5', { width: 1000, height: 400 });
var prediction5a = manager.predict(1, null, null); var prediction5a = manager.predict(1, null, null);
this._plotPrediction(graph5, prediction5a); this._plotPrediction(graph5, prediction5a);
$assert(prediction5a.position.y == manager.find(1).getPosition().y && $assert(
prediction5a.position.x > manager.find(1).getPosition().x, "Prediction is incorrectly positioned"); prediction5a.position.y == manager.find(1).getPosition().y &&
$assert(prediction5a.order == 0, "Prediction order should be 0"); 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); var prediction5b = manager.predict(2, null, null);
this._plotPrediction(graph5, prediction5b); this._plotPrediction(graph5, prediction5b);
$assert(prediction5b.position.y > manager.find(10).getPosition().y && $assert(
prediction5b.position.x < manager.find(2).getPosition().x && prediction5b.position.y > manager.find(10).getPosition().y &&
prediction5b.position.x == manager.find(10).getPosition().x, "Prediction is incorrectly positioned"); prediction5b.position.x < manager.find(2).getPosition().x &&
$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); var prediction5c = manager.predict(3, null, null);
this._plotPrediction(graph5, prediction5c); this._plotPrediction(graph5, prediction5c);
$assert(prediction5c.position.y > manager.find(6).getPosition().y && $assert(
prediction5c.position.x > manager.find(3).getPosition().x && prediction5c.position.y > manager.find(6).getPosition().y &&
prediction5c.position.x == manager.find(6).getPosition().x, "Prediction is incorrectly positioned"); prediction5c.position.x > manager.find(3).getPosition().x &&
$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); var prediction5d = manager.predict(10, null, null);
this._plotPrediction(graph5, prediction5d); this._plotPrediction(graph5, prediction5d);
$assert(prediction5d.position.y == manager.find(10).getPosition().y && $assert(
prediction5d.position.x < manager.find(10).getPosition().x, "Prediction is incorrectly positioned"); prediction5d.position.y == manager.find(10).getPosition().y &&
$assert(prediction5d.order == 0, "Prediction order should be 0"); 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() { testSymmetricDragPredict: function () {
console.log("testSymmetricDragPredict:"); console.log('testSymmetricDragPredict:');
var position = {x:0,y:0}; var position = { x: 0, y: 0 };
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE); var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 1); manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
manager.layout(); manager.layout();
// Graph 1 // 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); this._plotPrediction(graph1, prediction1a);
$assert(prediction1a.position.x == manager.find(2).getPosition().x && $assert(
prediction1a.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2"); prediction1a.position.x == manager.find(2).getPosition().x &&
$assert(prediction1a.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2"); 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); this._plotPrediction(graph1, prediction1b);
$assert(prediction1b.position.x == manager.find(2).getPosition().x && $assert(
prediction1b.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2"); prediction1b.position.x == manager.find(2).getPosition().x &&
$assert(prediction1b.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2"); 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); this._plotPrediction(graph1, prediction1c);
$assert(prediction1c.position.x == manager.find(1).getPosition().x && $assert(
prediction1c.position.y < manager.find(1).getPosition().y, "Prediction is incorrectly positioned"); prediction1c.position.x == manager.find(1).getPosition().x &&
$assert(prediction1c.order == 1, "Prediction order should be 1"); 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); this._plotPrediction(graph1, prediction1d);
$assert(prediction1d.position.x == manager.find(1).getPosition().x && $assert(
prediction1d.position.y > manager.find(1).getPosition().y, "Prediction is incorrectly positioned"); prediction1d.position.x == manager.find(1).getPosition().x &&
$assert(prediction1d.order == 3, "Prediction order should be 3"); 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); this._plotPrediction(graph1, prediction1e);
$assert(prediction1e.position.x == manager.find(2).getPosition().x && $assert(
prediction1e.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2"); prediction1e.position.x == manager.find(2).getPosition().x &&
$assert(prediction1e.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2"); 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"); console.log('OK!\n\n');
} },
});
export default SymmetricTestSuite;
});

View File

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

View File

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

View File

@ -3,12 +3,16 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
/** @type {import('webpack').Configuration} */ /** @type {import('webpack').Configuration} */
module.exports = { 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: { output: {
path: path.resolve(__dirname, 'dist', 'test'), path: path.resolve(__dirname, 'dist', 'test'),
filename: '[name].js', filename: '[name].test.js',
publicPath: '', publicPath: '',
}, },
mode: 'production',
module: { module: {
rules: [ rules: [
{ {

View File

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

710
yarn.lock

File diff suppressed because it is too large Load Diff