FORder icons based type

This commit is contained in:
Paulo Gustavo Veiga 2021-12-27 09:01:01 -08:00
parent 5496d66a90
commit c9018c7b86
3 changed files with 69 additions and 52 deletions

View File

@ -16,12 +16,25 @@
* limitations under the License. * limitations under the License.
*/ */
// eslint-disable-next-line max-classes-per-file // eslint-disable-next-line max-classes-per-file
import { $assert, $defined } from '@wisemapping/core-js'; import {
import { Group } from '@wisemapping/web2d'; $assert,
$defined
} from '@wisemapping/core-js';
import {
Group
} 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();
ORDER_BY_TYPE.set(IconModel.FEATURE_TYPE, 0);
ORDER_BY_TYPE.set(NoteModel.FEATURE_TYPE, 1);
ORDER_BY_TYPE.set(LinkModel.FEATURE_TYPE, 2);
class IconGroup { class IconGroup {
constructor(topicId, iconSize) { constructor(topicId, iconSize) {
$assert($defined(topicId), 'topicId can not be null'); $assert($defined(topicId), 'topicId can not be null');
@ -64,7 +77,10 @@ class IconGroup {
/** */ /** */
seIconSize(width, height) { seIconSize(width, height) {
this._iconSize = { width, height }; this._iconSize = {
width,
height,
};
this._resize(this._icons.length); this._resize(this._icons.length);
} }
@ -76,15 +92,23 @@ class IconGroup {
addIcon(icon, remove) { addIcon(icon, remove) {
$defined(icon, 'icon is not defined'); $defined(icon, 'icon is not defined');
// Order could have change, need to re-add all.
const icons = this._icons.slice();
this._icons.forEach((i) => {
this._removeIcon(i);
});
icon.setGroup(this); icon.setGroup(this);
this._icons.push(icon); icons.push(icon);
this._icons = icons.sort((a, b) => ORDER_BY_TYPE.get(a.getModel().getType()) - ORDER_BY_TYPE.get(b.getModel().getType()));
// Adjust group and position ... // Add all the nodes back ...
this._resize(this._icons.length); this._resize(this._icons.length);
this._positionIcon(icon, this._icons.length - 1); this._icons.forEach((i, index) => {
this._positionIcon(i, index);
const imageShape = icon.getImage(); const imageShape = i.getImage();
this._group.append(imageShape); this._group.append(imageShape);
});
// Register event for the group .. // Register event for the group ..
if (remove) { if (remove) {
@ -166,11 +190,5 @@ class IconGroup {
} }
} }
/**
* @constant
* @type {Number}
* @default
*/
IconGroup.ICON_PADDING = 5; IconGroup.ICON_PADDING = 5;
export default IconGroup; export default IconGroup;

View File

@ -48,7 +48,7 @@ import INodeModel, {
TopicShape, TopicShape,
} from './model/INodeModel'; } from './model/INodeModel';
const ICON_SCALING_FACTOR = 1; const ICON_SCALING_FACTOR = 1.8;
class Topic extends NodeGraph { class Topic extends NodeGraph {
/** /**
@ -1263,37 +1263,31 @@ class Topic extends NodeGraph {
if (this._isInWorkspace) { if (this._isInWorkspace) {
const textShape = this.getTextShape(); const textShape = this.getTextShape();
if (this.getShapeType() !== TopicShape.IMAGE) { if (this.getShapeType() !== TopicShape.IMAGE) {
// Calculate topic size and adjust elements ...
const textWidth = textShape.getWidth(); const textWidth = textShape.getWidth();
const textHeight = textShape.getHeight();
const padding = TopicStyle.getInnerPadding(this);
let textHeight = textShape.getHeight(); // Adjust icons group based on the font size ...
textHeight = textHeight !== 0 ? textHeight : 20;
const topicPadding = TopicStyle.getInnerPadding(this);
// Adjust the icon size to the size of the text ...
const iconGroup = this.getOrBuildIconGroup(); const iconGroup = this.getOrBuildIconGroup();
const fontHeight = this.getTextShape().getFontHeight(); const fontHeight = this.getTextShape().getFontHeight();
const iconHeight = ICON_SCALING_FACTOR * fontHeight;
iconGroup.seIconSize(iconHeight, iconHeight);
const iconSize = ICON_SCALING_FACTOR * fontHeight; // Calculate size and adjust ...
iconGroup.setPosition(topicPadding, topicPadding); const topicHeight = Math.max(iconHeight, textHeight) + padding * 2;
iconGroup.seIconSize(iconSize, iconSize); const textIconSpacing = Math.round(fontHeight / 4);
const iconGroupWith = iconGroup.getSize().width;
// Add a extra padding between the text and the icons const topicWith = iconGroupWith + textIconSpacing + textWidth + padding * 2;
let iconsWidth = iconGroup.getSize().width;
if (iconsWidth !== 0) {
iconsWidth += textHeight / 4;
}
const height = textHeight + topicPadding * 2;
const width = textWidth + iconsWidth + topicPadding * 2;
this.setSize({ this.setSize({
width, width: topicWith,
height, height: topicHeight,
}); });
// Position node ... // Adjust all topic elements positions ...
textShape.setPosition(topicPadding + iconsWidth, topicPadding); iconGroup.setPosition(padding, (topicHeight - iconHeight) / 2);
textShape.setPosition(padding + iconGroupWith + textIconSpacing, (topicHeight - textHeight) / 2);
} else { } else {
// In case of images, the size is fixed ... // In case of images, the size is fixed ...
const size = this.getModel().getImageSize(); const size = this.getModel().getImageSize();

View File

@ -15,9 +15,16 @@
* 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.
*/ */
import { $assert, $defined } from '@wisemapping/core-js'; import {
import { $msg } from './Messages'; $assert,
import { TopicShape } from './model/INodeModel'; $defined,
} from '@wisemapping/core-js';
import {
$msg,
} from './Messages';
import {
TopicShape,
} from './model/INodeModel';
class TopicStyle { class TopicStyle {
static _getStyles(topic) { static _getStyles(topic) {
@ -42,7 +49,9 @@ class TopicStyle {
} }
static defaultText(topic) { static defaultText(topic) {
const { msgKey } = this._getStyles(topic); const {
msgKey,
} = this._getStyles(topic);
return $msg(msgKey); return $msg(msgKey);
} }
@ -59,7 +68,7 @@ class TopicStyle {
} }
static getInnerPadding(topic) { static getInnerPadding(topic) {
return this._getStyles(topic).innerPadding; return Math.round(topic.getTextShape().getFontHeight() * 0.5);
} }
static defaultShapeType(topic) { static defaultShapeType(topic) {
@ -79,7 +88,6 @@ TopicStyle.STYLES = {
color: '#ffffff', color: '#ffffff',
}, },
msgKey: 'CENTRAL_TOPIC', msgKey: 'CENTRAL_TOPIC',
innerPadding: 11,
shapeType: TopicShape.ROUNDED_RECT, shapeType: TopicShape.ROUNDED_RECT,
}, },
@ -94,7 +102,6 @@ TopicStyle.STYLES = {
color: 'rgb(82,92,97)', color: 'rgb(82,92,97)',
}, },
msgKey: 'MAIN_TOPIC', msgKey: 'MAIN_TOPIC',
innerPadding: 3,
shapeType: TopicShape.LINE, shapeType: TopicShape.LINE,
}, },
@ -109,7 +116,6 @@ TopicStyle.STYLES = {
color: 'rgb(82,92,97)', color: 'rgb(82,92,97)',
}, },
msgKey: 'SUB_TOPIC', msgKey: 'SUB_TOPIC',
innerPadding: 3,
shapeType: TopicShape.LINE, shapeType: TopicShape.LINE,
}, },
@ -124,7 +130,6 @@ TopicStyle.STYLES = {
color: 'rgb(82,92,97)', color: 'rgb(82,92,97)',
}, },
msgKey: 'ISOLATED_TOPIC', msgKey: 'ISOLATED_TOPIC',
innerPadding: 4,
shapeType: TopicShape.LINE, shapeType: TopicShape.LINE,
}, },
}; };