JointJS 模型 - 未分配文本属性
JointJS Models - Text attr is not assigned
我正在创建一个简单的 joint.shapes.devs.Model 并分配一个文本属性,但文本没有出现,而是标记为 "Model"。
function makeEditableElement(label) {
var maxLineLength = _.max(label.split('\n'), function(l) { return l.length; }).length;
// Compute width/height of the rectangle based on the number
// of lines in the label and the letter size. 0.6 * letterSize is
// an approximation of the monospace font letter width.
var letterSize = 15;
var width = 2 * (letterSize * (0.3 * maxLineLength + 1));
var height = 2 * ((label.split('\n').length + 1) * letterSize);
return new joint.shapes.devs.Model({
'.label': label,
size: { width: width, height: height },
inPorts: [''],
outPorts: [''],
attrs: { '.inPorts circle': { r: 3 ,fill: 'gray', type: 'input',magnet: 'passive'},
'.outPorts circle': { r: 3 ,fill: 'gray', type: 'output',magnet:'true' },
rect: { width: width, height: height, fill: '#FFF' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#555' },
text: { text: label, fill: '#555' , 'font-size': 13, magnet: true,'font-weight': 'normal'}
}
});
}
graph.addCell(makeEditableElement("foo"));
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false });
如果我遗漏了什么,请指出,因为我是 JointJS 的新手。提前致谢。
'.label'
需要分配一个包含文本 属性 的对象——您只为其分配字符串 "foo"
请尝试以下操作:
...
'.label': { text: label },
...
我通过将 attrs 中“.label”的位置更改为以下方式使其工作:
function makeEditableElement(label,x,y) {
var maxLineLength = _.max(label.split('\n'), function(l) { return l.length; }).length;
// Compute width/height of the rectangle based on the number
// of lines in the label and the letter size. 0.6 * letterSize is
// an approximation of the monospace font letter width.
var letterSize = 15;
var width = 2 * (letterSize * (0.3 * maxLineLength + 1));
var height = 2 * ((label.split('\n').length + 1) * letterSize);
return new joint.shapes.devs.Model({
id: label,
position: {x:x, y:y},
size: { width: width, height: height, fill: 'transparent' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#31d0c6' },
inPorts: [''],
outPorts: [''],
attrs: { '.label': {text: label},
'.inPorts circle': { r: 3 ,fill: 'gray', type: 'input',magnet: 'passive'},
'.outPorts circle': { r: 3 ,fill: 'gray', type: 'output',magnet:'true' },
rect: { width: width, height: height, fill: 'transparent' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#31d0c6' },
text: { text: label, magnet: true, 'font-size': letterSize, 'font-family': 'monospace' }
}
});
}
我正在创建一个简单的 joint.shapes.devs.Model 并分配一个文本属性,但文本没有出现,而是标记为 "Model"。
function makeEditableElement(label) {
var maxLineLength = _.max(label.split('\n'), function(l) { return l.length; }).length;
// Compute width/height of the rectangle based on the number
// of lines in the label and the letter size. 0.6 * letterSize is
// an approximation of the monospace font letter width.
var letterSize = 15;
var width = 2 * (letterSize * (0.3 * maxLineLength + 1));
var height = 2 * ((label.split('\n').length + 1) * letterSize);
return new joint.shapes.devs.Model({
'.label': label,
size: { width: width, height: height },
inPorts: [''],
outPorts: [''],
attrs: { '.inPorts circle': { r: 3 ,fill: 'gray', type: 'input',magnet: 'passive'},
'.outPorts circle': { r: 3 ,fill: 'gray', type: 'output',magnet:'true' },
rect: { width: width, height: height, fill: '#FFF' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#555' },
text: { text: label, fill: '#555' , 'font-size': 13, magnet: true,'font-weight': 'normal'}
}
});
}
graph.addCell(makeEditableElement("foo"));
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false });
如果我遗漏了什么,请指出,因为我是 JointJS 的新手。提前致谢。
'.label'
需要分配一个包含文本 属性 的对象——您只为其分配字符串 "foo"
请尝试以下操作:
...
'.label': { text: label },
...
我通过将 attrs 中“.label”的位置更改为以下方式使其工作:
function makeEditableElement(label,x,y) {
var maxLineLength = _.max(label.split('\n'), function(l) { return l.length; }).length;
// Compute width/height of the rectangle based on the number
// of lines in the label and the letter size. 0.6 * letterSize is
// an approximation of the monospace font letter width.
var letterSize = 15;
var width = 2 * (letterSize * (0.3 * maxLineLength + 1));
var height = 2 * ((label.split('\n').length + 1) * letterSize);
return new joint.shapes.devs.Model({
id: label,
position: {x:x, y:y},
size: { width: width, height: height, fill: 'transparent' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#31d0c6' },
inPorts: [''],
outPorts: [''],
attrs: { '.label': {text: label},
'.inPorts circle': { r: 3 ,fill: 'gray', type: 'input',magnet: 'passive'},
'.outPorts circle': { r: 3 ,fill: 'gray', type: 'output',magnet:'true' },
rect: { width: width, height: height, fill: 'transparent' ,rx: 5,ry: 5, 'stroke-width':1.5, 'stroke': '#31d0c6' },
text: { text: label, magnet: true, 'font-size': letterSize, 'font-family': 'monospace' }
}
});
}