jsMind在vue2中使用

一、安装

1.下载

npm install jsMind --s

2.引入

import "jsmind/style/jsmind.css";
import jsMind from "jsmind/js-legacy/jsmind.js";

二、使用

1.初始数据 

//数据格式  可以丢在data中
 mind: {
        /* 元数据,定义思维导图的名称、作者、版本等信息 */
        meta: {
          name: "思维导图",
          author: "",
          version: "0.2",
        },
        /* 数据格式声明 */
        format: "node_tree",
        /* 数据内容 */
        data: {    
 /* 数据 需要根据 format: "node_tree",来确定是树状结构还是数组结构  "format": "node_array",
格式如: 
          {"id": "root", "isroot": true, "topic": "jsMind"},
          {"id": "sub1", "parentid": "root", "topic": "sub node 1"},
 */

          id: "root",
          topic: "jsMind",
          children: [
            {
              id: "easy", // [必选] ID, 所有节点的ID不应有重复,否则ID重复的结节将被忽略
              topic: "Easy", // [必选] 节点上显示的内容
              direction: "right", // [可选] 节点的方向,此数据仅在第一层节点上有效,目前仅支持 left 和 right 两种,默认为 right
              // expanded: false, // [可选] 该节点是否是展开状态,默认为 true
              children: [
                {
                  id: "easy8",
                  topic: "Easy to show",
                  children: [
                    { id: "open7", topic: "on GitHub" },
                    { id: "easy7", topic: "Easy to embed" },
                  ],
                },
                { id: "easy2", topic: "Easy to edit" },
                { id: "easy3", topic: "Easy to store" },
                { id: "easy4", topic: "Easy to embed" },
              ],
            },
            {
              id: "open",
              topic: "Open Source",
              direction: "right",
              // expanded: false,
              children: [
                { id: "open1", topic: "on GitHub" },
                { id: "open2", topic: "BSD License" },
              ],
            },
 
            {
              id: "powerful",
              topic: "Powerful",
              direction: "right",
              // expanded: false,
 
              children: [
                { id: "powerful1", topic: "Base on Javascript" },
                { id: "powerful2", topic: "Base on HTML5" },
                { id: "powerful3", topic: "Depends on you" },
              ],
            },
            {
              id: "other",
              topic: "test node",
              direction: "right",
              // expanded: false,
 
              children: [
                { id: "other1", topic: "I'm from local variable" },
                { id: "other2", topic: "I can do everything" },
              ],
            },
          ],
        },
      },
      options: {
        container: "jsmind_container", // [必选] 容器的ID
        editable: true, // [可选] 是否启用编辑
        theme: "primary", // [可选] 主题
        view: {
          engine: "canvas", // 思维导图各节点之间线条的绘制引擎
          hmargin: 20, // 思维导图距容器外框的最小水平距离
          vmargin: 20, // 思维导图距容器外框的最小垂直距离
          line_width: 2, // 思维导图线条的粗细
          line_color: "#ddd", // 思维导图线条的颜色
          hide_scrollbars_when_draggable: true,
        },
        layout: {
          hspace: 100, // 节点之间的水平间距
          vspace: 20, // 节点之间的垂直间距
          pspace: 20, // 节点与连接线之间的水平间距(用于容纳节点收缩/展开控制器)
        },
        shortcut: {
          enable: false, // 是否启用快捷键 默认为true
        },
        // editableDrag:true,
        // get_selected_node:function(val){
        //     this.selectedNode=val
        // }
      },

2.渲染

   // 初始化
    this.jm = new jsMind(this.options);
    //渲染canvas
    this.jm.show(this.mind);

3.操作

1.获取节点

获取根节点 :  this.jm.get_root()
根据 id 查找节点 : this.jm.get_node(nodeid)
获取选中的节点 : this.jm.get_selected_node()
查找相邻的上一个节点 : this.jm.find_node_before(node|nodeid) 
查找相邻的下一个节点 : this.jm.find_node_after(node|nodeid)

2.操作节点
/* 
node:为某个节点,nodeid为某个节点的id,可在获取节点中获取
 */

选中节点 : this.jm.select_node(node)

收起子节点 : this.jm.collapse_node(node|nodeid)

展开子节点 : this.jm.expand_node(node|nodeid)

收起或展开子节点 :this.jm.toggle_node(node|nodeid) 方法可自动展开或收起子节点。

展开全部子节点 : this.jm.expand_all()

展开至指定层级 : this.jm.expand_to_depth(depth)

移动节点 :  this.jm.move_node(node|nodeid,beforeid)

启用编辑 : this.jm.enable_edit()

禁止编辑 : this.jm.disable_edit()

调整节点为编辑状态 : this.jm.begin_edit(node|nodeid)

调整节点为只读状态 : this.jm.end_edit(node|nodeid)

3.加减节点
/*
parent_node:上级节点
nodeid:节点id
topic:节点显示内容
data:节点数据
 */

添加节点 : this.jm.add_node(parent_node, nodeid, topic, data)

在指定位置前插入节点 : this.jm.insert_node_before(node_before, nodeid, topic)

在指定位置后插入节点 :  this.jm.insert_node_after(node_after, nodeid, topic)

删除节点及其子节点 : this.jm.remove_node(node|nodeid)

更新节点topic显示内容 : this.jm.update_node(nodeid, topic)

4.获取数据

获取元数据 :this.jm.get_meta() 。

获取指定格式的思维导图数据 : this.jm.get_data(data_format)

5.设置样式

设置主题 : this.jm.set_theme(theme)

设置背景色/前景色 : this.jm.set_node_color(nodeid, bgcolor, fgcolor)

设置字体 : this.jm.set_node_font_style(nodeid, size, weight, style)

设置背景图片 : this.jm.set_node_background_image(nodeid, image, width, height)

6.其他操作

清除节点的选中 : this.jm.select_clear() 。

判断节点是否可见 :  this.jm.is_node_visible(node)

三、最后

思维导图插件jsMind的操作指南目前先记录到这里,后续有问题继续更新 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值