在 jointjs 图中一次调整所有单元格(矩形)的大小

Resize all cells (rect) at once in jointjs diagram

本文关键字:单元格 矩形 一次 jointjs 调整      更新时间:2023-09-26
加载

jointjs图后,我想调整所有单元格(矩形)的大小,以便它们与具有较大文本的单元格具有相同的高度。

我设法一次调整所有元素的大小,如下所示:

_.each(paper.model.getElements(), function(el) {
    el.set({ size: { width: 170 , height: newHeight} })         
 })

在我的元素中,有像"Rect"这样的元素和我用"path"创建的一些形状。当我设置新大小时,使用"path"创建的元素不仅会调整大小,还会更改它们在 Y 轴上的位置。

知道为什么我的"路径"元素重新定位吗?

我的"路径"形状如下所示:

joint.shapes.basic.CustomShape = joint.shapes.basic.Generic.extend({
markup: '<g class="rotatable"><g class="scalable"><path/></g><text><tspan class="word1"></tspan> <tspan class="word2"></tspan></text></g>',
defaults: joint.util.deepSupplement({
    type: 'my.CustomShape',
    attrs: {
        path : {d: 'M 0 20 L 17 50 0 80 100 80  100 20  z',  fill: '#ffffd9', stroke: '#4d4d4d', width: 100, height: 60,  'stroke-width':'0.03em'},
        text: { ref: 'path' , 'line-height': 24 },
        '.word1': { 'font-size': 12, fill: '#58ab00', 'font-weight': 'bold', 'font-family': 'Arial, helvetica, sans-serif', 'x':'4em' , 'y' : '5em'},
        '.word2': { 'font-size': 11, fill: '#000000', 'font-family': 'Arial, helvetica, sans-serif', 'x':'37', 'y' : '7.5em'}
    }      
}, joint.shapes.basic.Generic.prototype.defaults)
});

我设法一次调整所有元素的大小,如下所示:

_.each(paper.model.getElements(), function(el) {
    el.set({ size: { width: 170 , height: newHeight} })         
 })

在我的元素中,有像"Rect"这样的元素和我用"path"创建的一些形状。当我设置新大小时,使用"path"创建的元素不仅会调整大小,还会更改它们在 Y 轴上的位置。

知道为什么我的"路径"元素重新定位吗?

我的"路径"形状如下所示:

joint.shapes.basic.CustomShape = joint.shapes.basic.Generic.extend({
 markup: '<g class="rotatable"><g class="scalable"><path/></g><text><tspan class="word1"></tspan> <tspan class="word2"></tspan></text></g>',
defaults: joint.util.deepSupplement({
    type: 'my.CustomShape',
    attrs: {
        path : {d: 'M 0 20 L 17 50 0 80 100 80  100 20  z',  fill: '#ffffd9', stroke: '#4d4d4d', width: 100, height: 60,  'stroke-width':'0.03em'},
        text: { ref: 'path' , 'line-height': 24 },
        '.word1': { 'font-size': 12, fill: '#58ab00', 'font-weight': 'bold', 'font-family': 'Arial, helvetica, sans-serif', 'x':'4em' , 'y' : '5em'},
        '.word2': { 'font-size': 11, fill: '#000000', 'font-family': 'Arial, helvetica, sans-serif', 'x':'37', 'y' : '7.5em'}
    }      
}, joint.shapes.basic.Generic.prototype.defaults)
});

谢谢!