动态更新矩形的宽度和高度
Update width and height of rectangle dynamically
我正在尝试在单击提交时将矩形添加到父矩形。我希望在向父级添加新矩形时增加父级矩形的高度,以便子元素看起来像这样驻留在父级中:
$('.modeler_add_button').click(function (e)
{
var parentValues = parent1.getBBox();
var parentHeight = parentValues.height;
// parent1.attr('height', parentHeight+25);
// parent1.prop('height', parentHeight+25);
parent1.set('height', parentHeight + 25);
var newRect = new joint.shapes.tm.Actor({
isInteractive: false,
position: {x: pos.x + 1, y: pos.y + 25},
size: {width: 120, height: 25},
attrs: {
text: {text: 'res', fill: 'black', 'font-weight': 'bold', 'font-size': 12},
rect: {
fill: '#F1F1F1', rx: 7, ry: 15, opacity: .80, 'stroke-width': 0, stroke: '#fff'
}
}
});
parent1.embed(newRect);
graph.addCells([newRect]);
});
我尝试了 element.set
、element.attr
和 element.prop
方法,但均无效。我该如何实现?
使用 jointjs 的 resize()
方法修复了它。
我正在尝试在单击提交时将矩形添加到父矩形。我希望在向父级添加新矩形时增加父级矩形的高度,以便子元素看起来像这样驻留在父级中:
$('.modeler_add_button').click(function (e)
{
var parentValues = parent1.getBBox();
var parentHeight = parentValues.height;
// parent1.attr('height', parentHeight+25);
// parent1.prop('height', parentHeight+25);
parent1.set('height', parentHeight + 25);
var newRect = new joint.shapes.tm.Actor({
isInteractive: false,
position: {x: pos.x + 1, y: pos.y + 25},
size: {width: 120, height: 25},
attrs: {
text: {text: 'res', fill: 'black', 'font-weight': 'bold', 'font-size': 12},
rect: {
fill: '#F1F1F1', rx: 7, ry: 15, opacity: .80, 'stroke-width': 0, stroke: '#fff'
}
}
});
parent1.embed(newRect);
graph.addCells([newRect]);
});
我尝试了 element.set
、element.attr
和 element.prop
方法,但均无效。我该如何实现?
使用 jointjs 的 resize()
方法修复了它。