mxGraph图形文本自动换行

来源:互联网 发布:50岁知天命是什么成语 编辑:程序博客网 时间:2024/05/18 01:10

两种方式。

1、直接设置默认样式

style[mxConstants.STYLE_WHITE_SPACE]='wrap'

2、重写mxCellRenderer.prototype.createLabel方法,将其中state.text进行更改,原来的代码如下
        state.text = new mxText(value, new mxRectangle(), (state.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER), graph.getVerticalAlign(state), state.style[mxConstants.STYLE_FONTCOLOR], state.style[mxConstants.STYLE_FONTFAMILY], state.style[mxConstants.STYLE_FONTSIZE], state.style[mxConstants.STYLE_FONTSTYLE], state.style[mxConstants.STYLE_SPACING], state.style[mxConstants.STYLE_SPACING_TOP], state.style[mxConstants.STYLE_SPACING_RIGHT], state.style[mxConstants.STYLE_SPACING_BOTTOM], state.style[mxConstants.STYLE_SPACING_LEFT], state.style[mxConstants.STYLE_HORIZONTAL], state.style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR], state.style[mxConstants.STYLE_LABEL_BORDERCOLOR], graph.isWrapping(state.cell), graph.isLabelClipped(state.cell), state.style[mxConstants.STYLE_OVERFLOW]);

更改如下

var isWrap = true;state.text = new mxText(value, rectangle, (state.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER),                        graph.getVerticalAlign(state), state.style[mxConstants.STYLE_FONTCOLOR], state.style[mxConstants.STYLE_FONTFAMILY],                        state.style[mxConstants.STYLE_FONTSIZE], state.style[mxConstants.STYLE_FONTSTYLE], 2, 1, 1, 1, 1, true,                        null, state.style[mxConstants.STYLE_LABEL_BORDERCOLOR], isWrap, graph.isLabelClipped(state.cell),                        state.style[mxConstants.STYLE_OVERFLOW]);

重写mxCellRenderer.prototype.createLabel方法可以设置label的各种样式。如果对label显示有更多要求,建议重写该方法。直接设置默认样式更为简单。

0 0
原创粉丝点击