MxGraph上下文按钮实现

1 介绍

mxGraph是一个强大的JavaScript图形前端库,可以快速创建交互式图表和图表应用程序,国内外著名的ProcessOne和draw.io都是使用该库创建的强大的在线流程图绘制网站.

1.1 编写顶点事件

function mxVertexToolHandler(state) {
	mxVertexHandler.apply(this, arguments);
};

mxVertexToolHandler.prototype = new mxVertexHandler();
mxVertexToolHandler.prototype.constructor = mxVertexToolHandler;
mxVertexToolHandler.prototype.domNode = null;

mxVertexToolHandler.prototype.init = function () {
	mxVertexHandler.prototype.init.apply(this, arguments);

	this.domNode = document.createElement('div');
	this.domNode.style.position = 'absolute';
	this.domNode.style.whiteSpace = 'nowrap';


	var html = "";
	if (this.state.cell.isSwimlane()) {
		html += '<button class="publishBtn" title="发布"></button>';
	} else {
		html += '<button class="modifyBtn" title="修改"></button>';
		html += '<button class="deleteBtn" title="删除"></button>';
	}

	$(this.domNode).addClass("entityToolDiv")
	$(this.domNode).html(html);

	this.graph.container.appendChild(this.domNode);
	this.redrawTools();
	this.initEvent();
};

mxVertexToolHandler.prototype.redraw = function () {
	mxVertexHandler.prototype.redraw.apply(this);
	this.redrawTools();
};

mxVertexToolHandler.prototype.redrawTools = function () {
	if (this.state != null && this.domNode != null) {
		var dy = (mxClient.IS_VML && document.compatMode == 'CSS1Compat') ? 20 : 4;
		this.domNode.style.left = (this.state.x) + 'px';
		this.domNode.style.top = (this.state.y - $(this.domNode).height()) + 'px';
	}
};

mxVertexToolHandler.prototype.destroy = function (sender, me) {
	mxVertexHandler.prototype.destroy.apply(this, arguments);
	if (this.domNode != null) {
		this.domNode.parentNode.removeChild(this.domNode);
		this.domNode = null;
	}
};


/**
 * 初始化事件
 */
mxVertexToolHandler.prototype.initEvent = function () {
	var self = this;

	var container = $(this.domNode);
	

	//修改实体
	$(".modifyBtn", container).on("click", function () {
		var cell = self.state.cell
		var id = cell.attr("Id");
	});
		

};

按钮可以结合jquery编写html 和事件,提升了方便性。

2.2 事件注册

graph.createHandler = function (state) {
				if (state != null &&
					this.model.isVertex(state.cell)) {
					var cell = state.cell;
					if (cell.isSwimlane() || cell.getParent().isSwimlane()) {
						var handler = new mxVertexToolHandler(state);
						return handler;
					}
				}

				return mxGraph.prototype.createHandler.apply(this, arguments);
			};

可以根据顶点的信息,是否注册“顶点工具事件”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随风九天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值