mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-13 10:47:56 +01:00
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
|
import CentralTopic from './CentralTopic';
|
||
|
import MainTopic from './MainTopic';
|
||
|
import INodeModel from './model/INodeModel';
|
||
|
|
||
|
/**
|
||
|
* creates a new topic from the given node model
|
||
|
* @memberof mindplot.Nodegraph
|
||
|
* @param {mindplot.model.NodeModel} nodeModel
|
||
|
* @param {Object} options
|
||
|
* @throws will throw an error if nodeModel is null or undefined
|
||
|
* @throws will throw an error if the nodeModel's type is null or undefined
|
||
|
* @throws will throw an error if the node type cannot be recognized as either central or main
|
||
|
* topic type
|
||
|
* @return {mindplot.CentralTopic|mindplot.MainTopic} the new topic
|
||
|
*/
|
||
|
export const create = (nodeModel, options) => {
|
||
|
$assert(nodeModel, 'Model can not be null');
|
||
|
|
||
|
const type = nodeModel.getType();
|
||
|
$assert(type, 'Node model type can not be null');
|
||
|
|
||
|
let result;
|
||
|
if (type === INodeModel.CENTRAL_TOPIC_TYPE) {
|
||
|
result = new CentralTopic(nodeModel, options);
|
||
|
} else if (type === INodeModel.MAIN_TOPIC_TYPE) {
|
||
|
result = new MainTopic(nodeModel, options);
|
||
|
} else {
|
||
|
$assert(false, `unsupported node type:${type}`);
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
};
|
||
|
|
||
|
export default {
|
||
|
create,
|
||
|
};
|