2021-12-13 22:30:37 +01:00
|
|
|
/* eslint-disable no-console */
|
2021-12-02 01:41:56 +01:00
|
|
|
/*
|
2021-12-25 23:39:34 +01:00
|
|
|
* Copyright [2021] [wisemapping]
|
2021-12-02 01:41:56 +01:00
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2021-12-13 22:30:37 +01:00
|
|
|
import $ from 'jquery';
|
|
|
|
import { $assert } from '@wisemapping/core-js';
|
2021-12-02 01:41:56 +01:00
|
|
|
import TestSuite from './TestSuite';
|
2021-12-04 01:11:17 +01:00
|
|
|
import LayoutManager from '../../../src/components/layout/LayoutManager';
|
2021-12-02 01:41:56 +01:00
|
|
|
|
2021-12-13 22:30:37 +01:00
|
|
|
class SymmetricTestSuite extends TestSuite {
|
|
|
|
constructor() {
|
2021-12-02 01:41:56 +01:00
|
|
|
$('#symmetricTest').css('display', 'block');
|
2021-12-13 22:30:37 +01:00
|
|
|
super();
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
this.testSymmetry();
|
|
|
|
this.testSymmetricPredict();
|
|
|
|
this.testSymmetricDragPredict();
|
2021-12-13 22:30:37 +01:00
|
|
|
}
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
testSymmetry() {
|
|
|
|
console.log('testSymmetry:');
|
|
|
|
const position = { x: 0, y: 0 };
|
2021-12-04 01:11:17 +01:00
|
|
|
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(12, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(13, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(14, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.connectNode(0, 14, 0);
|
|
|
|
manager.connectNode(14, 13, 0);
|
|
|
|
manager.connectNode(13, 1, 0);
|
|
|
|
manager.connectNode(13, 2, 1);
|
|
|
|
manager.connectNode(13, 3, 2);
|
|
|
|
manager.connectNode(13, 4, 3);
|
|
|
|
manager.connectNode(13, 5, 4);
|
|
|
|
manager.connectNode(1, 6, 0);
|
|
|
|
manager.connectNode(1, 7, 1);
|
|
|
|
manager.connectNode(7, 8, 0);
|
|
|
|
manager.connectNode(8, 9, 0);
|
|
|
|
manager.connectNode(5, 10, 0);
|
|
|
|
manager.connectNode(6, 11, 0);
|
|
|
|
manager.connectNode(6, 12, 1);
|
|
|
|
|
|
|
|
manager.layout();
|
|
|
|
manager.plot('testSymmetry', { width: 1600, height: 400 });
|
|
|
|
|
|
|
|
// All nodes should be positioned symmetrically with respect to their common ancestors
|
|
|
|
$assert(
|
2021-12-04 01:11:17 +01:00
|
|
|
manager.find(14).getPosition().y === manager.find(13).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Symmetry is not respected',
|
|
|
|
);
|
|
|
|
$assert(
|
2021-12-04 01:11:17 +01:00
|
|
|
manager.find(5).getPosition().y === manager.find(10).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Symmetry is not respected',
|
|
|
|
);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
manager.find(11).getPosition().y - manager.find(6).getPosition().y ===
|
|
|
|
-(manager.find(12).getPosition().y - manager.find(6).getPosition().y),
|
2021-12-02 01:41:56 +01:00
|
|
|
'Symmetry is not respected',
|
|
|
|
);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
manager.find(8).getPosition().y - manager.find(1).getPosition().y ==
|
|
|
|
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y),
|
2021-12-02 01:41:56 +01:00
|
|
|
'Symmetry is not respected',
|
|
|
|
);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
manager.find(9).getPosition().y - manager.find(1).getPosition().y ==
|
|
|
|
-(manager.find(11).getPosition().y - manager.find(1).getPosition().y),
|
2021-12-02 01:41:56 +01:00
|
|
|
'Symmetry is not respected',
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log('OK!\n\n');
|
2021-12-13 22:30:37 +01:00
|
|
|
}
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
testSymmetricPredict() {
|
|
|
|
console.log('testSymmetricPredict:');
|
|
|
|
const position = { x: 0, y: 0 };
|
2021-12-04 01:11:17 +01:00
|
|
|
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
// Prepare a sample graph ...
|
|
|
|
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
|
|
|
|
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
manager.connectNode(0, 2, 1);
|
|
|
|
manager.connectNode(0, 3, 2);
|
|
|
|
manager.connectNode(3, 4, 0);
|
|
|
|
manager.connectNode(3, 5, 1);
|
|
|
|
manager.connectNode(3, 6, 2);
|
|
|
|
manager.connectNode(5, 7, 0);
|
|
|
|
manager.connectNode(5, 8, 1);
|
|
|
|
manager.connectNode(5, 11, 2);
|
|
|
|
manager.connectNode(2, 9, 0);
|
|
|
|
manager.connectNode(2, 10, 1);
|
|
|
|
|
|
|
|
manager.layout();
|
|
|
|
|
|
|
|
// Graph
|
|
|
|
const graph1 = manager.plot('testSymmetricPredict1', { width: 1000, height: 400 });
|
|
|
|
|
|
|
|
console.log('\tAdded as child of node 9 and dropped at (-280, 45):');
|
|
|
|
const prediction1a = manager.predict(9, null, { x: -280, y: 45 });
|
|
|
|
this._plotPrediction(graph1, prediction1a);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1a.position.x < manager.find(9).getPosition().x &&
|
|
|
|
prediction1a.position.y == manager.find(9).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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):');
|
|
|
|
const prediction1b = manager.predict(1, null, { x: -155, y: -90 });
|
|
|
|
this._plotPrediction(graph1, prediction1b);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1b.position.x > manager.find(1).getPosition().x &&
|
|
|
|
prediction1b.position.y == manager.find(1).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction1b.order == 0, 'Prediction order should be 0');
|
|
|
|
|
|
|
|
// Graph 2
|
|
|
|
const graph2 = manager.plot('testSymmetricPredict2', { width: 1000, height: 400 });
|
|
|
|
|
|
|
|
console.log('\tAdded as child of node 5 and dropped at (380, -30):');
|
|
|
|
const prediction2d = manager.predict(5, null, { x: 380, y: -30 });
|
|
|
|
this._plotPrediction(graph2, prediction2d);
|
|
|
|
|
|
|
|
// Prediction calculator error
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction2d.position.y < manager.find(7).getPosition().y &&
|
|
|
|
prediction2d.position.x == manager.find(7).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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):');
|
|
|
|
const prediction2a = manager.predict(5, null, { x: 375, y: 15 });
|
|
|
|
this._plotPrediction(graph2, prediction2a);
|
|
|
|
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction2a.position.y > manager.find(7).getPosition().y &&
|
|
|
|
prediction2a.position.y < manager.find(8).getPosition().y &&
|
|
|
|
prediction2a.position.x == manager.find(7).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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):');
|
|
|
|
const prediction2b = manager.predict(5, null, { x: 375, y: 45 });
|
|
|
|
this._plotPrediction(graph2, prediction2b);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction2b.position.y > manager.find(8).getPosition().y &&
|
|
|
|
prediction2b.position.y < manager.find(11).getPosition().y &&
|
|
|
|
prediction2b.position.x == manager.find(7).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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):');
|
|
|
|
const prediction2c = manager.predict(5, null, { x: 375, y: 65 });
|
|
|
|
this._plotPrediction(graph2, prediction2c);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction2c.position.y > manager.find(11).getPosition().y &&
|
|
|
|
prediction2c.position.x == manager.find(11).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction2c.order == 3, 'Prediction order should be 3');
|
|
|
|
|
|
|
|
// Graph 3
|
|
|
|
const graph3 = manager.plot('testSymmetricPredict3', { width: 1000, height: 400 });
|
|
|
|
|
|
|
|
console.log('\tAdded as child of node 3 and dropped at (280, 45):');
|
|
|
|
const prediction3a = manager.predict(3, null, { x: 280, y: 45 });
|
|
|
|
this._plotPrediction(graph3, prediction3a);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction3a.position.y > manager.find(5).getPosition().y &&
|
|
|
|
prediction3a.position.y < manager.find(6).getPosition().y &&
|
|
|
|
prediction3a.position.x == manager.find(5).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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):');
|
|
|
|
const prediction3b = manager.predict(3, null, { x: 255, y: 110 });
|
|
|
|
this._plotPrediction(graph3, prediction3b);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction3b.position.y > manager.find(6).getPosition().y &&
|
|
|
|
prediction3b.position.x == manager.find(6).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction3b.order == 3, 'Prediction order should be 3');
|
|
|
|
|
|
|
|
// Graph 4
|
|
|
|
console.log('\tAdded as child of node 2 and dropped at (-260, 0):');
|
|
|
|
const graph4 = manager.plot('testSymmetricPredict4', { width: 1000, height: 400 });
|
|
|
|
const prediction4 = manager.predict(2, null, { x: -260, y: 0 });
|
|
|
|
this._plotPrediction(graph4, prediction4);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction4.position.y > manager.find(9).getPosition().y &&
|
|
|
|
prediction4.position.y < manager.find(10).getPosition().y &&
|
|
|
|
prediction4.position.x == manager.find(9).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction4.order == 1, 'Prediction order should be 1');
|
|
|
|
|
|
|
|
// Graph 5
|
|
|
|
console.log('\tPredict nodes added with no position:');
|
|
|
|
const graph5 = manager.plot('testSymmetricPredict5', { width: 1000, height: 400 });
|
|
|
|
const prediction5a = manager.predict(1, null, null);
|
|
|
|
this._plotPrediction(graph5, prediction5a);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction5a.position.y == manager.find(1).getPosition().y &&
|
|
|
|
prediction5a.position.x > manager.find(1).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction5a.order == 0, 'Prediction order should be 0');
|
|
|
|
|
|
|
|
const prediction5b = manager.predict(2, null, null);
|
|
|
|
this._plotPrediction(graph5, prediction5b);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction5b.position.y > manager.find(10).getPosition().y &&
|
|
|
|
prediction5b.position.x < manager.find(2).getPosition().x &&
|
|
|
|
prediction5b.position.x == manager.find(10).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction5b.order == 2, 'Prediction order should be 2');
|
|
|
|
|
|
|
|
const prediction5c = manager.predict(3, null, null);
|
|
|
|
this._plotPrediction(graph5, prediction5c);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction5c.position.y > manager.find(6).getPosition().y &&
|
|
|
|
prediction5c.position.x > manager.find(3).getPosition().x &&
|
|
|
|
prediction5c.position.x == manager.find(6).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction5c.order == 3, 'Prediction order should be 3');
|
|
|
|
|
|
|
|
const prediction5d = manager.predict(10, null, null);
|
|
|
|
this._plotPrediction(graph5, prediction5d);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction5d.position.y == manager.find(10).getPosition().y &&
|
|
|
|
prediction5d.position.x < manager.find(10).getPosition().x,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction5d.order == 0, 'Prediction order should be 0');
|
|
|
|
|
|
|
|
console.log('OK!\n\n');
|
2021-12-13 22:30:37 +01:00
|
|
|
}
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
testSymmetricDragPredict() {
|
|
|
|
console.log('testSymmetricDragPredict:');
|
|
|
|
const position = { x: 0, y: 0 };
|
2021-12-04 01:11:17 +01:00
|
|
|
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
|
|
|
|
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
|
|
|
|
manager.layout();
|
|
|
|
|
|
|
|
// Graph 1
|
|
|
|
const graph1 = manager.plot('testSymmetricDragPredict1', { width: 1000, height: 400 });
|
|
|
|
|
|
|
|
const prediction1a = manager.predict(1, 2, { x: -250, y: -20 });
|
|
|
|
this._plotPrediction(graph1, prediction1a);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1a.position.x == manager.find(2).getPosition().x &&
|
|
|
|
prediction1a.position.y == manager.find(2).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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',
|
|
|
|
);
|
|
|
|
|
|
|
|
const prediction1b = manager.predict(1, 2, { x: -250, y: 20 });
|
|
|
|
this._plotPrediction(graph1, prediction1b);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1b.position.x == manager.find(2).getPosition().x &&
|
|
|
|
prediction1b.position.y == manager.find(2).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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',
|
|
|
|
);
|
|
|
|
|
|
|
|
const prediction1c = manager.predict(0, 2, { x: -100, y: -20 });
|
|
|
|
this._plotPrediction(graph1, prediction1c);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1c.position.x == manager.find(1).getPosition().x &&
|
|
|
|
prediction1c.position.y < manager.find(1).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction1c.order == 1, 'Prediction order should be 1');
|
|
|
|
|
|
|
|
const prediction1d = manager.predict(0, 2, { x: -100, y: 20 });
|
|
|
|
this._plotPrediction(graph1, prediction1d);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1d.position.x == manager.find(1).getPosition().x &&
|
|
|
|
prediction1d.position.y > manager.find(1).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'Prediction is incorrectly positioned',
|
|
|
|
);
|
|
|
|
$assert(prediction1d.order == 3, 'Prediction order should be 3');
|
|
|
|
|
|
|
|
const prediction1e = manager.predict(1, 2, { x: -250, y: 0 });
|
|
|
|
this._plotPrediction(graph1, prediction1e);
|
|
|
|
$assert(
|
2022-07-13 03:58:11 +02:00
|
|
|
prediction1e.position.x == manager.find(2).getPosition().x &&
|
|
|
|
prediction1e.position.y == manager.find(2).getPosition().y,
|
2021-12-02 01:41:56 +01:00
|
|
|
'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');
|
2021-12-13 22:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-02 01:41:56 +01:00
|
|
|
|
|
|
|
export default SymmetricTestSuite;
|