1、如果需要将label靠左边对齐,则必须重写底层源码

新增mxText的一个构造器,主要是增加了一个参数:x(代表当前的cell)

 function mxText(a, b, c, d, e, f, g, h, k, i, l, m, n, o, p, q, t, u, v, w, x) {
this.value = a;
this.bounds = b;
this.color = e != null ? e : "black";
this.align = c != null ? c : "";
this.valign = d != null ? d : "";
this.family = f != null ? f : mxConstants.DEFAULT_FONTFAMILY;
this.size = g != null ? g : mxConstants.DEFAULT_FONTSIZE;
this.fontStyle = h != null ? h : 0;
this.spacing = 0;
this.spacingTop = 0;
//this.spacingRight = x.cell.geometry.height/2 - (this.size * 1.25 * a.length);
this.spacingRight = 0;
this.spacingBottom = 0;
this.spacingLeft = 0;
this.horizontal = true;
this.background = p;
this.border = q;
this.wrap = t != null ? t : false;
this.clipped = u != null ? u : false;
this.overflow = v != null ? v : "visible";
this.labelPadding = w != null ? w : 0
}

重写createTabel方法

 mxCellRenderer.prototype.createLabel = function(a, b) {
var c = a.view.graph;
c.getModel().isEdge(a.cell);
if (a.style[mxConstants.STYLE_FONTSIZE] > 0 || a.style[mxConstants.STYLE_FONTSIZE] == null) {
var d = (c.isHtmlLabel(a.cell) || b != null && mxUtils.isNode(b)) && c.dialect == mxConstants.DIALECT_SVG;
//alert(a.cell.value + '-' + b);
//dongyj add :其中b=a.cell.value
if (!a.cell.id && a.cell.id.indexOf("_swimlane") >= 0 && b) {
a.text = new mxText(b, new mxRectangle, a.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER, c.getVerticalAlign(a), a.style[mxConstants.STYLE_FONTCOLOR], a.style[mxConstants.STYLE_FONTFAMILY], a.style[mxConstants.STYLE_FONTSIZE],
a.style[mxConstants.STYLE_FONTSTYLE], a.style[mxConstants.STYLE_SPACING], a.style[mxConstants.STYLE_SPACING_TOP], a.style[mxConstants.STYLE_SPACING_RIGHT], a.style[mxConstants.STYLE_SPACING_BOTTOM], a.style[mxConstants.STYLE_SPACING_LEFT], a.style[mxConstants.STYLE_HORIZONTAL], a.style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR], a.style[mxConstants.STYLE_LABEL_BORDERCOLOR], c.isWrapping(a.cell) && c.isHtmlLabel(a.cell), c.isLabelClipped(a.cell), a.style[mxConstants.STYLE_OVERFLOW], a.style[mxConstants.STYLE_LABEL_PADDING], a);
} else {
//alert(a.cell.geometry.width);
//a.cell.geometry.height; a.text = new mxText(b, new mxRectangle, a.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER, c.getVerticalAlign(a), a.style[mxConstants.STYLE_FONTCOLOR], a.style[mxConstants.STYLE_FONTFAMILY], a.style[mxConstants.STYLE_FONTSIZE],
a.style[mxConstants.STYLE_FONTSTYLE], a.style[mxConstants.STYLE_SPACING], a.style[mxConstants.STYLE_SPACING_TOP], a.style[mxConstants.STYLE_SPACING_RIGHT], a.style[mxConstants.STYLE_SPACING_BOTTOM], a.style[mxConstants.STYLE_SPACING_LEFT], a.style[mxConstants.STYLE_HORIZONTAL], a.style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR], a.style[mxConstants.STYLE_LABEL_BORDERCOLOR], c.isWrapping(a.cell) && c.isHtmlLabel(a.cell), c.isLabelClipped(a.cell), a.style[mxConstants.STYLE_OVERFLOW], a.style[mxConstants.STYLE_LABEL_PADDING], a);
}
a.text.opacity = a.style[mxConstants.STYLE_TEXT_OPACITY];
a.text.dialect = d ? mxConstants.DIALECT_STRICTHTML : a.view.graph.dialect;
this.initializeLabel(a);
var e = false,
f = function(b) {
var d = a;
if (mxClient.IS_TOUCH || e) {
d = mxEvent.getClientX(b);
b = mxEvent.getClientY(b);
b = mxUtils.convertPoint(c.container, d, b);
d = c.view.getState(c.getCellAt(b.x, b.y))
}
return d
},
d = mxClient.IS_TOUCH ? "touchmove" : "mousemove",
g = mxClient.IS_TOUCH ? "touchend" : "mouseup";
mxEvent.addListener(a.text.node, mxClient.IS_TOUCH ? "touchstart" : "mousedown", mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(b, a));
e = c.dialect != mxConstants.DIALECT_SVG && mxEvent.getSource(b).nodeName == "IMG"
}
}));
mxEvent.addListener(a.text.node, d, mxUtils.bind(this, function(b) {
this.isLabelEvent(a, b) && c.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(b, f(b)))
}));
mxEvent.addListener(a.text.node, g, mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(b, f(b)));
e = false
}
}));
mxEvent.addListener(a.text.node, "dblclick", mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.dblClick(b, a.cell);
mxEvent.consume(b)
}
}))
}
};

如果要求泳道的label居中,则不需要重写底层方法,只需要重写createLabel方法即可

 mxCellRenderer.prototype.createLabel = function(a, b) {
var c = a.view.graph;
c.getModel().isEdge(a.cell);
if (a.style[mxConstants.STYLE_FONTSIZE] > 0 || a.style[mxConstants.STYLE_FONTSIZE] == null) {
var d = (c.isHtmlLabel(a.cell) || b != null && mxUtils.isNode(b)) && c.dialect == mxConstants.DIALECT_SVG; /*****************泳道图样式修改start*******************/ var tempSwinlaneHorizontal = a.style[mxConstants.STYLE_HORIZONTAL];
if(c.isSwimlane(a.cell)){
tempsHorizontal = true;
} var tempSwinlaneVertical = c.getVerticalAlign(a);
if(c.isSwimlane(a.cell)){
tempSwinlaneVertical = 'middle';
}
/*****************泳道图样式修改end*******************/ a.text = new mxText(b, new mxRectangle, a.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER, tempSwinlaneVertical, a.style[mxConstants.STYLE_FONTCOLOR], a.style[mxConstants.STYLE_FONTFAMILY], a.style[mxConstants.STYLE_FONTSIZE],
a.style[mxConstants.STYLE_FONTSTYLE], a.style[mxConstants.STYLE_SPACING], a.style[mxConstants.STYLE_SPACING_TOP], a.style[mxConstants.STYLE_SPACING_RIGHT], a.style[mxConstants.STYLE_SPACING_BOTTOM], a.style[mxConstants.STYLE_SPACING_LEFT], tempsHorizontal, a.style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR], a.style[mxConstants.STYLE_LABEL_BORDERCOLOR], c.isWrapping(a.cell) && c.isHtmlLabel(a.cell), c.isLabelClipped(a.cell), a.style[mxConstants.STYLE_OVERFLOW], a.style[mxConstants.STYLE_LABEL_PADDING]);
a.text.opacity = a.style[mxConstants.STYLE_TEXT_OPACITY];
a.text.dialect = d ? mxConstants.DIALECT_STRICTHTML : a.view.graph.dialect;
this.initializeLabel(a);
var e = false, f = function(b) {
var d = a;
if (mxClient.IS_TOUCH || e) {
d = mxEvent.getClientX(b);
b = mxEvent.getClientY(b);
b = mxUtils.convertPoint(c.container, d, b);
d = c.view.getState(c.getCellAt(b.x, b.y))
}
return d
}, d = mxClient.IS_TOUCH ? "touchmove" : "mousemove", g = mxClient.IS_TOUCH ? "touchend" : "mouseup";
mxEvent.addListener(a.text.node, mxClient.IS_TOUCH ? "touchstart" : "mousedown", mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(b, a));
e = c.dialect != mxConstants.DIALECT_SVG && mxEvent.getSource(b).nodeName == "IMG"
}
}));
mxEvent.addListener(a.text.node, d, mxUtils.bind(this, function(b) {
this.isLabelEvent(a, b) && c.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(b, f(b)))
}));
mxEvent.addListener(a.text.node, g, mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(b, f(b)));
e = false
}
}));
mxEvent.addListener(a.text.node, "dblclick", mxUtils.bind(this, function(b) {
if (this.isLabelEvent(a, b)) {
c.dblClick(b, a.cell);
mxEvent.consume(b)
}
}))
}
};

graph使泳道图的label横向显示的更多相关文章

  1. 关于echarts中的饼状图的label文字显示过长的问题

    label: { normal: { fontSize: 14, formatter(v) { let text = v.name let count = text.indexOf('¥') cons ...

  2. Paddle Graph Learning (PGL)图学习之图游走类模型[系列四]

    Paddle Graph Learning (PGL)图学习之图游走类模型[系列四] 更多详情参考:Paddle Graph Learning 图学习之图游走类模型[系列四] https://aist ...

  3. Flex中如何通过showAllDataTips属性使鼠标移动到图表时显示所有的数据Tips的例子

    原文 http://blog.minidx.com/2008/11/10/1616.html 接下来的例子演示了Flex中如何通过showAllDataTips属性,使鼠标移动到图表时显示所有的数据T ...

  4. ztree实现权限功能(横向显示)

    最近在做权限功能的时候,采用的ztree实现的,但是产品要求最后一层的权限节点要横向显示.开始在网上找的解决方案是用css样式把最后一层的display设置为inline.在我本地电脑上看了下.效果不 ...

  5. 用Visio画泳道图

    在一次会议中看到有个同事在讲解业务流程时画了一个与PD中很类似的泳道图,但是在图的左侧确有一个阶段的列,事后与他沟通,才知道他这个图是”拼”出来的,也就是说所有的图都是他一点点的在画图工具中做出来的. ...

  6. 怎样使MathType插入章节标记不显示

    作为专业的公式编辑器,MathType可以帮助大家在Word中插入数学公式,有的时候还需要插入章节标记,那么怎样使章节标记不显示呢?下面就教大家使MathType插入章节标记不显示的技巧. 实际问题如 ...

  7. ios label上显示特殊字符 % "

    今天在label上显示一个拼接的百分比 label.text = [NSString stringWithFormater:@"%d%",i]; 结果后面的%就是报错,然后查半天也 ...

  8. 小技巧,如何在Label中显示图片

    这个需求其实是有的,比如QQ聊天界面里面发送的信息,可以用label来显示文字(也可以用button显示),但是有时候用户可能会发送图片.如果能让Label遇到文字就显示文字,遇到图片就显示图片就好了 ...

  9. 8位灰度图在LCD上显示

    一.概述 1.灰度 灰度使用黑色调表示物体,即用黑色为基准色,不同的饱和度的黑色来显示图像.每个灰度对象都具有从 0%(白色)到灰度条100%(黑色)的亮度值. 使用黑白或灰度扫描仪生成的图像通常以灰 ...

随机推荐

  1. 浅析StackTrace【转】

    我们在学习函数调用时,都知道每个函数都拥有自己的栈空间.一个函数被调用时,就创建一个新的栈空间.那么通过函数的嵌套调用最后就形成了一个函数调用堆栈.在c#中,使用StackTrace记录这个堆栈.你可 ...

  2. 浅析WebGIS

    浅析WebGIS 摘要:随着网络的发展,利用Web公布信息越来越普及化.而地理信息系统(GIS)与网络的结合就产生了万维网地理信息系统(WebGIS),它引起了地理信息公布的新的变革,对实现GIS信息 ...

  3. OpenGL研究2.0 计算圆

    OpenGL研究2.0 计算圆 DionysosLai2014-06-18 在游戏中.常常有些地方涉及到一些圆的轨迹计算,例如一些转轴类的游戏,人物一般在角色转轴上面运动.这时,我们就要时刻计算角色的 ...

  4. ASP.NET MVC 学习之路-6

    本文在于巩固基础 上文中使用的Code First创建数据库 本文将使用数据库生成模型 这里使用ADO.NET实体数据模型来生成模型 下面按照指导完成操作 下面看看如何使用这个框架 数据访问修改主要是 ...

  5. UIScrollView基本使用

    - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMa ...

  6. poj 1450 Gridland

    Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. A==?B(A,B超级大)

    #include <iostream>#include <string.h>#include <cstring>using namespace std;struct ...

  8. mysql 批量更新

    bs_user 表,我们叫他 bu表, 字段user_id,len_id, think_wellUser 表,我们简称为tw表,中的user_id ,len_id 其中tw表的user_id 是bu表 ...

  9. 下拉条的连动-ajax方式

    客户端触发: <select id="category1" onchange="changecategory()">    <option v ...

  10. Eclipse选中变量名,相同变量都变色显示 的设置

    ava文件的设置"Window"-"preferences"-"Java"-"Editor"-"Mark Oc ...