wisemapping-frontend/packages/mindplot/src/components/TopicStyle.js

129 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-07-16 16:41:58 +02:00
/*
* Copyright [2011] [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.
*/
2022-07-13 03:58:11 +02:00
import { $assert, $defined } from '@wisemapping/core-js';
import { $msg } from './Messages';
import { TopicShape } from './model/INodeModel';
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
class TopicStyle {
static _getStyles(topic) {
$assert(topic, 'topic can not be null');
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
let result;
if (topic.isCentralTopic()) {
result = TopicStyle.STYLES.CENTRAL_TOPIC;
} else {
const targetTopic = topic.getOutgoingConnectedTopic();
if ($defined(targetTopic)) {
if (targetTopic.isCentralTopic()) {
result = TopicStyle.STYLES.MAIN_TOPIC;
} else {
result = TopicStyle.STYLES.SUB_TOPIC;
}
2021-10-05 02:05:34 +02:00
} else {
2021-12-05 00:39:20 +01:00
result = TopicStyle.STYLES.ISOLATED_TOPIC;
2021-10-05 02:05:34 +02:00
}
}
2021-12-05 00:39:20 +01:00
return result;
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static defaultText(topic) {
2022-07-13 03:58:11 +02:00
const { msgKey } = this._getStyles(topic);
2021-12-05 00:39:20 +01:00
return $msg(msgKey);
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static defaultFontStyle(topic) {
return this._getStyles(topic).fontStyle;
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static defaultBackgroundColor(topic) {
return this._getStyles(topic).backgroundColor;
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static defaultBorderColor(topic) {
return this._getStyles(topic).borderColor;
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static getInnerPadding(topic) {
2021-12-27 20:42:32 +01:00
return Math.round(topic.getTextShape().getFontHeight() * 0.5);
2021-12-05 00:39:20 +01:00
}
2021-07-16 16:41:58 +02:00
2021-12-05 00:39:20 +01:00
static defaultShapeType(topic) {
return this._getStyles(topic).shapeType;
}
}
2021-07-16 16:41:58 +02:00
TopicStyle.STYLES = {
2021-10-05 02:05:34 +02:00
CENTRAL_TOPIC: {
borderColor: 'rgb(57,113,177)',
backgroundColor: 'rgb(80,157,192)',
fontStyle: {
font: 'Verdana',
size: 10,
style: 'normal',
weight: 'bold',
color: '#ffffff',
2021-07-16 16:41:58 +02:00
},
2021-10-05 02:05:34 +02:00
msgKey: 'CENTRAL_TOPIC',
shapeType: TopicShape.ROUNDED_RECT,
},
2021-07-16 16:41:58 +02:00
2021-10-05 02:05:34 +02:00
MAIN_TOPIC: {
borderColor: 'rgb(2,59,185)',
backgroundColor: 'rgb(224,229,239)',
fontStyle: {
font: 'Arial',
size: 8,
style: 'normal',
weight: 'normal',
color: 'rgb(82,92,97)',
2021-07-16 16:41:58 +02:00
},
2021-10-05 02:05:34 +02:00
msgKey: 'MAIN_TOPIC',
shapeType: TopicShape.LINE,
},
2021-07-16 16:41:58 +02:00
2021-10-05 02:05:34 +02:00
SUB_TOPIC: {
borderColor: 'rgb(2,59,185)',
backgroundColor: 'rgb(224,229,239)',
fontStyle: {
font: 'Arial',
size: 6,
style: 'normal',
weight: 'normal',
color: 'rgb(82,92,97)',
2021-07-16 16:41:58 +02:00
},
2021-10-05 02:05:34 +02:00
msgKey: 'SUB_TOPIC',
shapeType: TopicShape.LINE,
},
2021-07-16 16:41:58 +02:00
2021-10-05 02:05:34 +02:00
ISOLATED_TOPIC: {
borderColor: 'rgb(2,59,185)',
backgroundColor: 'rgb(224,229,239)',
fontStyle: {
font: 'Verdana',
size: 8,
style: 'normal',
weight: 'normal',
color: 'rgb(82,92,97)',
2021-07-16 16:41:58 +02:00
},
2021-10-05 02:05:34 +02:00
msgKey: 'ISOLATED_TOPIC',
shapeType: TopicShape.LINE,
},
2021-07-16 16:41:58 +02:00
};
export default TopicStyle;