【问题标题】:Resize all cells (rect) at once in jointjs diagram在jointjs图中一次调整所有单元格(矩形)的大小
【发布时间】:2015-06-15 06:45:38
【问题描述】:

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

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

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

在我的元素中,有像“矩形”这样的元素和我用“路径”创建的一些形状。 当我设置新大小时,使用“路径”创建的元素不仅会调整大小,还会改变它们在 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)
});

【问题讨论】:

    标签: javascript jointjs


    【解决方案1】:

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

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

    在我的元素中,有像“矩形”这样的元素和我用“路径”创建的一些形状。 当我设置新大小时,使用“路径”创建的元素不仅会调整大小,还会改变它们在 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)
    });
    

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      相关资源
      最近更新 更多