mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 14:47:56 +01:00
Enable nullable check.
This commit is contained in:
parent
4ae3e07537
commit
d80260ae8b
@ -31,7 +31,7 @@ ORDER_BY_TYPE.set('link', 2);
|
|||||||
class IconGroup {
|
class IconGroup {
|
||||||
private _icons: ImageIcon[];
|
private _icons: ImageIcon[];
|
||||||
|
|
||||||
private _group;
|
private _group: Group;
|
||||||
|
|
||||||
private _removeTip: IconGroupRemoveTip;
|
private _removeTip: IconGroupRemoveTip;
|
||||||
|
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert } from '@wisemapping/core-js';
|
||||||
import { Group, Rect, Line } from '@wisemapping/web2d';
|
import { Group, Rect, Line } from '@wisemapping/web2d';
|
||||||
|
import ImageIcon from './ImageIcon';
|
||||||
|
|
||||||
export default class RemoveTip {
|
class IconGroupRemoveTip {
|
||||||
/** @lends IconGroup.RemoveTip */
|
private _group: Group;
|
||||||
/**
|
|
||||||
* @classdesc inner class of IconGroup
|
private _activeIcon: ImageIcon | null;
|
||||||
* @constructs
|
|
||||||
* @param container
|
private _widget: Group;
|
||||||
*/
|
|
||||||
constructor(container) {
|
private _closeTimeoutId;
|
||||||
$assert(container, 'group can not be null');
|
|
||||||
this._fadeElem = container;
|
constructor(group: Group) {
|
||||||
|
$assert(group, 'group can not be null');
|
||||||
|
this._group = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
show(topicId: number, icon: ImageIcon) {
|
||||||
* @param topicId
|
|
||||||
* @param icon
|
|
||||||
* @throws will throw an error if icon is null or undefined
|
|
||||||
*/
|
|
||||||
show(topicId, icon) {
|
|
||||||
$assert(icon, 'icon can not be null');
|
$assert(icon, 'icon can not be null');
|
||||||
|
|
||||||
// Nothing to do ...
|
// Nothing to do ...
|
||||||
@ -48,50 +46,43 @@ export default class RemoveTip {
|
|||||||
});
|
});
|
||||||
|
|
||||||
widget.setPosition(pos.x + 80, pos.y - 50);
|
widget.setPosition(pos.x + 80, pos.y - 50);
|
||||||
this._fadeElem.append(widget);
|
this._group.append(widget);
|
||||||
|
|
||||||
// Setup current element ...
|
// Setup current element ...
|
||||||
this._activeIcon = icon;
|
this._activeIcon = icon;
|
||||||
this._widget = widget;
|
this._widget = widget;
|
||||||
} else {
|
} else if (this._closeTimeoutId) {
|
||||||
clearTimeout(this._closeTimeoutId);
|
clearTimeout(this._closeTimeoutId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
|
||||||
hide() {
|
hide() {
|
||||||
this.close(200);
|
this.close(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
close(delay: number) {
|
||||||
* @param delay
|
|
||||||
*/
|
|
||||||
close(delay) {
|
|
||||||
// This is not ok, trying to close the same dialog twice ?
|
|
||||||
if (this._closeTimeoutId) {
|
if (this._closeTimeoutId) {
|
||||||
clearTimeout(this._closeTimeoutId);
|
clearTimeout(this._closeTimeoutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const me = this;
|
|
||||||
if (this._activeIcon) {
|
if (this._activeIcon) {
|
||||||
const widget = this._widget;
|
const widget = this._widget;
|
||||||
const close = function close() {
|
const close = () => {
|
||||||
me._activeIcon = null;
|
this._activeIcon = null;
|
||||||
me._fadeElem.removeChild(widget);
|
this._group.removeChild(widget);
|
||||||
me._widget = null;
|
this._widget = null;
|
||||||
me._closeTimeoutId = null;
|
this._closeTimeoutId = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!$defined(delay) || delay === 0) {
|
if (delay > 0) {
|
||||||
close();
|
|
||||||
} else {
|
|
||||||
this._closeTimeoutId = setTimeout(close, delay);
|
this._closeTimeoutId = setTimeout(close, delay);
|
||||||
|
} else {
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
private _buildWeb2d(): Group {
|
||||||
_buildWeb2d() {
|
|
||||||
const result = new Group({
|
const result = new Group({
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
@ -144,23 +135,19 @@ export default class RemoveTip {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
decorate(topicId: number, icon) {
|
||||||
* @param topicId
|
|
||||||
* @param icon
|
|
||||||
*/
|
|
||||||
decorate(topicId, icon) {
|
|
||||||
const me = this;
|
|
||||||
|
|
||||||
if (!icon.__remove) {
|
if (!icon.__remove) {
|
||||||
icon.addEvent('mouseover', () => {
|
icon.addEvent('mouseover', () => {
|
||||||
me.show(topicId, icon);
|
this.show(topicId, icon);
|
||||||
});
|
});
|
||||||
|
|
||||||
icon.addEvent('mouseout', () => {
|
icon.addEvent('mouseout', () => {
|
||||||
me.hide();
|
this.hide();
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
icon.__remove = true;
|
icon.__remove = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default IconGroupRemoveTip;
|
@ -145,16 +145,17 @@ class RelationshipPivot {
|
|||||||
|
|
||||||
private _calculateFromPosition(toPosition: Point): Point {
|
private _calculateFromPosition(toPosition: Point): Point {
|
||||||
// Calculate origin position ...
|
// Calculate origin position ...
|
||||||
|
const sourceTopic = this._sourceTopic!;
|
||||||
let sourcePosition = this._sourceTopic!.getPosition();
|
let sourcePosition = this._sourceTopic!.getPosition();
|
||||||
if (this._sourceTopic!.getType() === 'CentralTopic') {
|
if (sourceTopic!.getType() === 'CentralTopic') {
|
||||||
sourcePosition = Shape.workoutIncomingConnectionPoint(this._sourceTopic, toPosition);
|
sourcePosition = Shape.workoutIncomingConnectionPoint(sourceTopic, toPosition);
|
||||||
}
|
}
|
||||||
const controlPoint = Shape.calculateDefaultControlPoints(sourcePosition, toPosition);
|
const controlPoint = Shape.calculateDefaultControlPoints(sourcePosition, toPosition);
|
||||||
const point = new Point(
|
const point = {
|
||||||
parseInt(controlPoint[0].x, 10) + sourcePosition.x,
|
x: controlPoint[0].x + sourcePosition.x,
|
||||||
parseInt(controlPoint[0].y, 10) + sourcePosition.y,
|
y: controlPoint[0].y + sourcePosition.y,
|
||||||
);
|
};
|
||||||
return Shape.calculateRelationShipPointCoordinates(this._sourceTopic, point);
|
return Shape.calculateRelationShipPointCoordinates(sourceTopic, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _connectOnFocus(event: string, targetTopic: Topic): void {
|
private _connectOnFocus(event: string, targetTopic: Topic): void {
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2021] [wisemapping]
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// FIXME: this Class should be reimplemented
|
|
||||||
import Events from '../Events';
|
|
||||||
|
|
||||||
class FadeEffect extends Events {
|
|
||||||
constructor(elements, isVisible) {
|
|
||||||
super();
|
|
||||||
this._isVisible = isVisible;
|
|
||||||
this._element = elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
start() {
|
|
||||||
const visible = this._isVisible;
|
|
||||||
this._element.forEach((elem) => {
|
|
||||||
if (elem) {
|
|
||||||
elem.setVisibility(visible);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this._isVisible = !visible;
|
|
||||||
this.fireEvent('complete');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default FadeEffect;
|
|
@ -19,46 +19,56 @@ import { Point } from '@wisemapping/web2d';
|
|||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import { TopicShape } from '../model/INodeModel';
|
import { TopicShape } from '../model/INodeModel';
|
||||||
import TopicConfig from '../TopicConfig';
|
import TopicConfig from '../TopicConfig';
|
||||||
|
import PositionType from '../PositionType';
|
||||||
|
import SizeType from '../SizeType';
|
||||||
|
import Topic from '../Topic';
|
||||||
|
|
||||||
const Shape = {
|
class Shape {
|
||||||
isAtRight(sourcePoint, targetPoint) {
|
static isAtRight(sourcePoint: PositionType, targetPoint: PositionType): boolean {
|
||||||
$assert(sourcePoint, 'Source can not be null');
|
$assert(sourcePoint, 'Source can not be null');
|
||||||
$assert(targetPoint, 'Target can not be null');
|
$assert(targetPoint, 'Target can not be null');
|
||||||
return sourcePoint.x < targetPoint.x;
|
return sourcePoint.x < targetPoint.x;
|
||||||
},
|
}
|
||||||
|
|
||||||
calculateRectConnectionPoint(rectCenterPoint, rectSize, isAtRight) {
|
static calculateRectConnectionPoint(
|
||||||
|
rectCenterPoint: PositionType,
|
||||||
|
rectSize: SizeType,
|
||||||
|
isAtRight: boolean,
|
||||||
|
): PositionType {
|
||||||
$assert(rectCenterPoint, 'rectCenterPoint can not be null');
|
$assert(rectCenterPoint, 'rectCenterPoint can not be null');
|
||||||
$assert(rectSize, 'rectSize can not be null');
|
$assert(rectSize, 'rectSize can not be null');
|
||||||
$assert($defined(isAtRight), 'isRight can not be null');
|
$assert($defined(isAtRight), 'isRight can not be null');
|
||||||
|
|
||||||
// This is used fix a minor difference ...z
|
// This is used fix a minor difference ...z
|
||||||
const correctionHardcode = 2;
|
const correctionHardcode = 2;
|
||||||
let result;
|
let result: PositionType;
|
||||||
if (isAtRight) {
|
if (isAtRight) {
|
||||||
result = new Point(
|
result = {
|
||||||
rectCenterPoint.x - rectSize.width / 2 + correctionHardcode,
|
x: rectCenterPoint.x - rectSize.width / 2 + correctionHardcode,
|
||||||
rectCenterPoint.y,
|
y: rectCenterPoint.y,
|
||||||
);
|
};
|
||||||
} else {
|
} else {
|
||||||
result = new Point(
|
result = {
|
||||||
parseFloat(rectCenterPoint.x) + rectSize.width / 2 - correctionHardcode,
|
x: rectCenterPoint.x + rectSize.width / 2 - correctionHardcode,
|
||||||
rectCenterPoint.y,
|
y: rectCenterPoint.y,
|
||||||
);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
}
|
||||||
|
|
||||||
calculateRelationShipPointCoordinates(topic, controlPoint) {
|
static calculateRelationShipPointCoordinates(
|
||||||
|
topic: Topic,
|
||||||
|
controlPoint: PositionType,
|
||||||
|
): PositionType {
|
||||||
const size = topic.getSize();
|
const size = topic.getSize();
|
||||||
const position = topic.getPosition();
|
const position = topic.getPosition();
|
||||||
const yGap = position.y - controlPoint.y;
|
const yGap = position.y - controlPoint.y;
|
||||||
const xGap = position.x - controlPoint.x;
|
const xGap = position.x - controlPoint.x;
|
||||||
const disable = Math.abs(yGap) < 5 || Math.abs(xGap) < 5 || Math.abs(yGap - xGap) < 5;
|
const disable = Math.abs(yGap) < 5 || Math.abs(xGap) < 5 || Math.abs(yGap - xGap) < 5;
|
||||||
|
|
||||||
let y;
|
let y: number;
|
||||||
let x;
|
let x: number;
|
||||||
const gap = 5;
|
const gap = 5;
|
||||||
if (controlPoint.y > position.y + size.height / 2) {
|
if (controlPoint.y > position.y + size.height / 2) {
|
||||||
y = position.y + size.height / 2 + gap;
|
y = position.y + size.height / 2 + gap;
|
||||||
@ -84,10 +94,13 @@ const Shape = {
|
|||||||
y = !disable ? position.y - (yGap / xGap) * (position.x - x) : position.y;
|
y = !disable ? position.y - (yGap / xGap) * (position.x - x) : position.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Point(x, y);
|
return { x, y };
|
||||||
},
|
}
|
||||||
|
|
||||||
calculateDefaultControlPoints(srcPos, tarPos) {
|
static calculateDefaultControlPoints(
|
||||||
|
srcPos: PositionType,
|
||||||
|
tarPos: PositionType,
|
||||||
|
): [PositionType, PositionType] {
|
||||||
const y = srcPos.y - tarPos.y;
|
const y = srcPos.y - tarPos.y;
|
||||||
const x = srcPos.x - tarPos.x;
|
const x = srcPos.x - tarPos.x;
|
||||||
const div = Math.abs(x) > 0.1 ? x : 0.1; // Prevent division by 0.
|
const div = Math.abs(x) > 0.1 ? x : 0.1; // Prevent division by 0.
|
||||||
@ -105,9 +118,9 @@ const Shape = {
|
|||||||
const y2 = m * (x2 - tarPos.x) + tarPos.y;
|
const y2 = m * (x2 - tarPos.x) + tarPos.y;
|
||||||
|
|
||||||
return [new Point(-srcPos.x + x1, -srcPos.y + y1), new Point(-tarPos.x + x2, -tarPos.y + y2)];
|
return [new Point(-srcPos.x + x1, -srcPos.y + y1), new Point(-tarPos.x + x2, -tarPos.y + y2)];
|
||||||
},
|
}
|
||||||
|
|
||||||
workoutIncomingConnectionPoint(targetNode, sourcePosition) {
|
static workoutIncomingConnectionPoint(targetNode: Topic, sourcePosition: PositionType) {
|
||||||
$assert(sourcePosition, 'sourcePoint can not be null');
|
$assert(sourcePosition, 'sourcePoint can not be null');
|
||||||
const pos = targetNode.getPosition();
|
const pos = targetNode.getPosition();
|
||||||
const size = targetNode.getSize();
|
const size = targetNode.getSize();
|
||||||
@ -129,7 +142,7 @@ const Shape = {
|
|||||||
result.x = Math.ceil(result.x);
|
result.x = Math.ceil(result.x);
|
||||||
result.y = Math.ceil(result.y);
|
result.y = Math.ceil(result.y);
|
||||||
return result;
|
return result;
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default Shape;
|
export default Shape;
|
Loading…
Reference in New Issue
Block a user