Fix chage to type

This commit is contained in:
Paulo Gustavo Veiga 2022-01-02 14:16:18 -08:00
parent 5695c2ab6a
commit 90f1906788
12 changed files with 29 additions and 35 deletions

View File

@ -59,7 +59,7 @@ class CommandContext {
/** */ /** */
createModel() { createModel() {
const mindmap = this._designer.getMindmap(); const mindmap = this._designer.getMindmap();
return mindmap.createNode(NodeModel.MAIN_TOPIC_TYPE); return mindmap.createNode('MainTopic');
} }
/** */ /** */

View File

@ -34,7 +34,7 @@ class ConnectionLine {
let line; let line;
const ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); const ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
if (targetNode.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (targetNode.getType() === 'CentralTopic') {
line = this._createLine(lineType, ConnectionLine.CURVED); line = this._createLine(lineType, ConnectionLine.CURVED);
line.setSrcControlPoint(ctrlPoints[0]); line.setSrcControlPoint(ctrlPoints[0]);
line.setDestControlPoint(ctrlPoints[1]); line.setDestControlPoint(ctrlPoints[1]);

View File

@ -243,7 +243,7 @@ class Designer extends Events {
}); });
// Register node listeners ... // Register node listeners ...
if (topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.getType() !== 'CentralTopic') {
// Central Topic doesn't support to be dragged // Central Topic doesn't support to be dragged
this._dragManager.add(topic); this._dragManager.add(topic);
} }
@ -443,7 +443,7 @@ class Designer extends Events {
} }
// Execute event ... // Execute event ...
const topic = nodes[0]; const topic = nodes[0];
if (topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.getType() !== 'CentralTopic') {
this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken()); this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken());
} }
} }
@ -476,7 +476,7 @@ class Designer extends Events {
*/ */
_copyNodeProps(sourceModel, targetModel) { _copyNodeProps(sourceModel, targetModel) {
// I don't copy the font size if the target is the source is the central topic. // I don't copy the font size if the target is the source is the central topic.
if (sourceModel.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { if (sourceModel.getType() !== 'CentralTopic') {
const fontSize = sourceModel.getFontSize(); const fontSize = sourceModel.getFontSize();
if (fontSize) { if (fontSize) {
targetModel.setFontSize(fontSize); targetModel.setFontSize(fontSize);
@ -586,7 +586,7 @@ class Designer extends Events {
// Hack: if parent is central topic, add node below not on opposite side. // Hack: if parent is central topic, add node below not on opposite side.
// This should be done in the layout // This should be done in the layout
if (parentTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (parentTopic.getType() === 'CentralTopic') {
siblingModel.setOrder(topic.getOrder() + 2); siblingModel.setOrder(topic.getOrder() + 2);
} }
@ -954,7 +954,7 @@ class Designer extends Events {
/** */ /** */
changeTopicShape(shape) { changeTopicShape(shape) {
const validateFunc = (topic) => !( const validateFunc = (topic) => !(
topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE && shape === TopicShape.LINE topic.getType() === 'CentralTopic' && shape === TopicShape.LINE
); );
const validateError = 'Central Topic shape can not be changed to line figure.'; const validateError = 'Central Topic shape can not be changed to line figure.';

View File

@ -145,7 +145,7 @@ class DragPivot {
let result = null; let result = null;
const parentTopic = this._targetTopic; const parentTopic = this._targetTopic;
if (parentTopic) { if (parentTopic) {
if (parentTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (parentTopic.getType() === 'CentralTopic') {
result = this._straightLine; result = this._straightLine;
} else { } else {
result = this._curvedLine; result = this._curvedLine;

View File

@ -25,15 +25,12 @@ import {
} from '@wisemapping/web2d'; } from '@wisemapping/web2d';
import IconGroupRemoveTip from './IconGroupRemoveTip'; import IconGroupRemoveTip from './IconGroupRemoveTip';
import NoteModel from './model/NoteModel';
import LinkModel from './model/LinkModel';
import IconModel from './model/IconModel';
import Icon from './Icon'; import Icon from './Icon';
const ORDER_BY_TYPE = new Map(); const ORDER_BY_TYPE = new Map();
ORDER_BY_TYPE.set(IconModel.FEATURE_TYPE, 0); ORDER_BY_TYPE.set('icon', 0);
ORDER_BY_TYPE.set(NoteModel.FEATURE_TYPE, 1); ORDER_BY_TYPE.set('note', 1);
ORDER_BY_TYPE.set(LinkModel.FEATURE_TYPE, 2); ORDER_BY_TYPE.set('link', 2);
class IconGroup { class IconGroup {
constructor(topicId, iconSize) { constructor(topicId, iconSize) {
@ -191,4 +188,4 @@ class IconGroup {
} }
IconGroup.ICON_PADDING = 5; IconGroup.ICON_PADDING = 5;
export default IconGroup; export default IconGroup;

View File

@ -22,9 +22,9 @@ export const create = (nodeModel, options) => {
$assert(type, 'Node model type can not be null'); $assert(type, 'Node model type can not be null');
let result; let result;
if (type === INodeModel.CENTRAL_TOPIC_TYPE) { if (type === 'CentralTopic') {
result = new CentralTopic(nodeModel, options); result = new CentralTopic(nodeModel, options);
} else if (type === INodeModel.MAIN_TOPIC_TYPE) { } else if (type === 'MainTopic') {
result = new MainTopic(nodeModel, options); result = new MainTopic(nodeModel, options);
} else { } else {
$assert(false, `unsupported node type:${type}`); $assert(false, `unsupported node type:${type}`);

View File

@ -86,7 +86,7 @@ class Relationship extends ConnectionLine {
const targetTopic = this._targetTopic; const targetTopic = this._targetTopic;
let targetPosition = targetTopic.getPosition(); let targetPosition = targetTopic.getPosition();
if (targetTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (targetTopic.getType() === 'CentralTopic') {
targetPosition = Shape.workoutIncomingConnectionPoint(targetTopic, sourcePosition); targetPosition = Shape.workoutIncomingConnectionPoint(targetTopic, sourcePosition);
} }

View File

@ -131,7 +131,7 @@ class RelationshipPivot {
_calculateFromPosition(toPosition) { _calculateFromPosition(toPosition) {
// Calculate origin position ... // Calculate origin position ...
let sourcePosition = this._sourceTopic.getPosition(); let sourcePosition = this._sourceTopic.getPosition();
if (this._sourceTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (this._sourceTopic.getType() === 'CentralTopic') {
sourcePosition = Shape.workoutIncomingConnectionPoint(this._sourceTopic, toPosition); sourcePosition = Shape.workoutIncomingConnectionPoint(this._sourceTopic, toPosition);
} }
const controlPoint = Shape.calculateDefaultControlPoints(sourcePosition, toPosition); const controlPoint = Shape.calculateDefaultControlPoints(sourcePosition, toPosition);

View File

@ -1337,7 +1337,7 @@ class Topic extends NodeGraph {
/** @return {Boolean} true if the topic is the central topic of the map */ /** @return {Boolean} true if the topic is the central topic of the map */
isCentralTopic() { isCentralTopic() {
return this.getModel().getType() === INodeModel.CENTRAL_TOPIC_TYPE; return this.getModel().getType() === 'CentralTopic';
} }
} }

View File

@ -17,29 +17,26 @@
*/ */
import { $assert } from '@wisemapping/core-js'; import { $assert } from '@wisemapping/core-js';
import IconModel from './model/IconModel';
import ImageIcon from './ImageIcon'; import ImageIcon from './ImageIcon';
import LinkModel from './model/LinkModel';
import LinkIcon from './LinkIcon'; import LinkIcon from './LinkIcon';
import NoteModel from './model/NoteModel';
import NoteIcon from './NoteIcon'; import NoteIcon from './NoteIcon';
const TopicFeatureFactory = { const TopicFeatureFactory = {
/** the icon object */ /** the icon object */
Icon: { Icon: {
id: IconModel.FEATURE_TYPE, id: 'icon',
icon: ImageIcon, icon: ImageIcon,
}, },
/** the link object */ /** the link object */
Link: { Link: {
id: LinkModel.FEATURE_TYPE, id: 'link',
icon: LinkIcon, icon: LinkIcon,
}, },
/** the note object */ /** the note object */
Note: { Note: {
id: NoteModel.FEATURE_TYPE, id: 'note',
icon: NoteIcon, icon: NoteIcon,
}, },

View File

@ -51,11 +51,11 @@ class XMLSerializerBeta {
const parentTopic = document.createElement('topic'); const parentTopic = document.createElement('topic');
// Set topic attributes... // Set topic attributes...
if (topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.getType() === 'CentralTopic') {
parentTopic.setAttribute('central', true); parentTopic.setAttribute('central', true);
} else { } else {
const parent = topic.getParent(); const parent = topic.getParent();
if (parent == null || parent.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (parent == null || parent.getType() === 'CentralTopic') {
const pos = topic.getPosition(); const pos = topic.getPosition();
parentTopic.setAttribute('position', `${pos.x},${pos.y}`); parentTopic.setAttribute('position', `${pos.x},${pos.y}`);
} else { } else {
@ -206,8 +206,8 @@ class XMLSerializerBeta {
_deserializeNode(domElem, mindmap) { _deserializeNode(domElem, mindmap) {
const type = domElem.getAttribute('central') != null const type = domElem.getAttribute('central') != null
? INodeModel.CENTRAL_TOPIC_TYPE ? 'CentralTopic'
: INodeModel.MAIN_TOPIC_TYPE; : 'MainTopic';
const topic = mindmap.createNode(type); const topic = mindmap.createNode(type);
// Load attributes... // Load attributes...

View File

@ -68,7 +68,7 @@ class XMLSerializerPela {
const parentTopic = document.createElement('topic'); const parentTopic = document.createElement('topic');
// Set topic attributes... // Set topic attributes...
if (topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.getType() === 'CentralTopic') {
parentTopic.setAttribute('central', 'true'); parentTopic.setAttribute('central', 'true');
} else { } else {
const pos = topic.getPosition(); const pos = topic.getPosition();
@ -96,7 +96,7 @@ class XMLSerializerPela {
} }
} }
if (topic.areChildrenShrunken() && topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.areChildrenShrunken() && topic.getType() !== 'CentralTopic') {
parentTopic.setAttribute('shrink', 'true'); parentTopic.setAttribute('shrink', 'true');
} }
@ -268,8 +268,8 @@ class XMLSerializerPela {
_deserializeNode(domElem, mindmap) { _deserializeNode(domElem, mindmap) {
const type = domElem.getAttribute('central') != null const type = domElem.getAttribute('central') != null
? INodeModel.CENTRAL_TOPIC_TYPE ? 'CentralTopic'
: INodeModel.MAIN_TOPIC_TYPE; : 'MainTopic';
// Load attributes... // Load attributes...
let id = domElem.getAttribute('id'); let id = domElem.getAttribute('id');
@ -349,7 +349,7 @@ class XMLSerializerPela {
const isShrink = domElem.getAttribute('shrink'); const isShrink = domElem.getAttribute('shrink');
// Hack: Some production maps has been stored with the central topic collapsed. This is a bug. // Hack: Some production maps has been stored with the central topic collapsed. This is a bug.
if ($defined(isShrink) && type !== INodeModel.CENTRAL_TOPIC_TYPE) { if ($defined(isShrink) && type !== 'CentralTopic') {
topic.setChildrenShrunken(isShrink); topic.setChildrenShrunken(isShrink);
} }