如何将 <text> 和 <line> 元素添加到 mxGraph 图形
How to add <text> and <line> elements to mxGraph graph
我需要向 mxGraph 库呈现的 SVG 添加自定义 <line>
和 <text>
元素。
有谁知道怎么做(或者根本不可能)?
我找到了一个解决方法,方法是创建一个顶点长度为 0 的文本元素(标签)。
参见 http://jgraph.github.io/mxgraph/javascript/examples/labels.html
var v1 = graph.insertVertex(parent, null, 'vertexLabelsMovable', 20, 20, 80, 30);
// Places sublabels inside the vertex
var label11 = graph.insertVertex(v1, null, 'Label1', 0.5, 1, 0, 0, null, true);
var label12 = graph.insertVertex(v1, null, 'Label2', 0.5, 0, 0, 0, null, true);
但是,这对我来说仍然是一个很糟糕的解决方案。
this.addEntry('vertical Line', mxUtils.bind(this, function() {
var cell = new mxCell('', new mxGeometry(0, 0, 10, 160), 'line;strokeWidth=2;direction=south;html=1;');
cell.vertex = true;
this.graph.setAttributeForCell(cell, 'placeholders', '1');
this.graph.setAttributeForCell(cell, 'capacity', '0');
return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Vertical Line');
}))
竖线代码
我需要向 mxGraph 库呈现的 SVG 添加自定义 <line>
和 <text>
元素。
有谁知道怎么做(或者根本不可能)?
我找到了一个解决方法,方法是创建一个顶点长度为 0 的文本元素(标签)。 参见 http://jgraph.github.io/mxgraph/javascript/examples/labels.html
var v1 = graph.insertVertex(parent, null, 'vertexLabelsMovable', 20, 20, 80, 30);
// Places sublabels inside the vertex
var label11 = graph.insertVertex(v1, null, 'Label1', 0.5, 1, 0, 0, null, true);
var label12 = graph.insertVertex(v1, null, 'Label2', 0.5, 0, 0, 0, null, true);
但是,这对我来说仍然是一个很糟糕的解决方案。
this.addEntry('vertical Line', mxUtils.bind(this, function() {
var cell = new mxCell('', new mxGeometry(0, 0, 10, 160), 'line;strokeWidth=2;direction=south;html=1;');
cell.vertex = true;
this.graph.setAttributeForCell(cell, 'placeholders', '1');
this.graph.setAttributeForCell(cell, 'capacity', '0');
return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Vertical Line');
}))
竖线代码