2021-07-16 16:41:58 +02:00
|
|
|
/*
|
2021-12-25 23:39:34 +01:00
|
|
|
* Copyright [2021] [wisemapping]
|
2021-07-16 16:41:58 +02: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-19 17:31:29 +01:00
|
|
|
import { Elipse } from '@wisemapping/web2d';
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
import TopicConfig from './TopicConfig';
|
|
|
|
import ActionDispatcher from './ActionDispatcher';
|
2022-02-06 06:28:35 +01:00
|
|
|
import Topic from './Topic';
|
|
|
|
import IconGroup from './IconGroup';
|
2021-07-16 16:41:58 +02:00
|
|
|
|
2021-12-05 00:39:20 +01:00
|
|
|
class ShirinkConnector {
|
2022-02-06 06:28:35 +01:00
|
|
|
private _isShrink: boolean;
|
|
|
|
private _ellipse: any;
|
|
|
|
constructor(topic: Topic) {
|
2022-01-04 02:27:54 +01:00
|
|
|
this._isShrink = false;
|
2021-12-19 17:31:29 +01:00
|
|
|
const ellipse = new Elipse(TopicConfig.INNER_RECT_ATTRIBUTES);
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse = ellipse;
|
2022-02-06 06:28:35 +01:00
|
|
|
|
2021-10-05 02:05:34 +02:00
|
|
|
ellipse.setFill('rgb(62,118,179)');
|
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
ellipse.setSize(TopicConfig.CONNECTOR_WIDTH, TopicConfig.CONNECTOR_WIDTH);
|
2021-10-05 02:05:34 +02:00
|
|
|
ellipse.addEvent('click', (event) => {
|
|
|
|
const model = topic.getModel();
|
|
|
|
const collapse = !model.areChildrenShrunken();
|
|
|
|
|
|
|
|
const topicId = topic.getId();
|
|
|
|
const actionDispatcher = ActionDispatcher.getInstance();
|
|
|
|
actionDispatcher.shrinkBranch([topicId], collapse);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
ellipse.addEvent('mousedown', (event: Event) => {
|
2021-10-05 02:05:34 +02:00
|
|
|
// Avoid node creation ...
|
|
|
|
event.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
ellipse.addEvent('dblclick', (event: Event) => {
|
2021-10-05 02:05:34 +02:00
|
|
|
// Avoid node creation ...
|
|
|
|
event.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
ellipse.addEvent('mouseover', () => {
|
2022-01-04 02:27:54 +01:00
|
|
|
ellipse.setStroke(this._isShrink ? 1 : 2, 'solid');
|
2021-10-05 02:05:34 +02:00
|
|
|
});
|
2022-01-04 02:27:54 +01:00
|
|
|
|
2021-12-02 01:41:56 +01:00
|
|
|
ellipse.addEvent('mouseout', () => {
|
2022-01-04 02:27:54 +01:00
|
|
|
ellipse.setStroke(this._isShrink ? 2 : 1, 'solid');
|
2021-10-05 02:05:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ellipse.setCursor('default');
|
|
|
|
const model = topic.getModel();
|
|
|
|
this.changeRender(model.areChildrenShrunken());
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
changeRender(isShrink: boolean) {
|
2021-10-05 02:05:34 +02:00
|
|
|
const elipse = this._ellipse;
|
|
|
|
if (isShrink) {
|
|
|
|
elipse.setStroke('2', 'solid');
|
|
|
|
} else {
|
|
|
|
elipse.setStroke('1', 'solid');
|
2021-07-16 16:41:58 +02:00
|
|
|
}
|
2022-01-04 02:27:54 +01:00
|
|
|
this._isShrink = isShrink;
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
setVisibility(value: boolean): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.setVisibility(value);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
setOpacity(opacity: number): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.setOpacity(opacity);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
setFill(color: string): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.setFill(color);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
setAttribute(name: string, value) {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.setAttribute(name, value);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
addToWorkspace(group): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
group.append(this._ellipse);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
setPosition(x: number, y: number): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.setPosition(x, y);
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
moveToBack(): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.moveToBack();
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
2021-10-05 02:05:34 +02:00
|
|
|
|
2022-02-06 06:28:35 +01:00
|
|
|
moveToFront(): void {
|
2021-10-05 02:05:34 +02:00
|
|
|
this._ellipse.moveToFront();
|
2021-12-05 00:39:20 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 16:41:58 +02:00
|
|
|
|
|
|
|
export default ShirinkConnector;
|