7

I m new to jointJS, I need to create custom shapes using JointJS, I have tried creating the diamond shape using the Rectangle, making its height and width same, and then rotate by 45 degrees as follows,

var diamond =  new joint.shapes.basic.Rect({
        position: { x: 100, y: 100 },
        size: { width: 100, height: 100 },
        attrs: { diamond: { width: 100, height: 30 } }
    }); 
    diamond.attr({

        rect: { fill: '#cccccc', 'stroke-width': 2, stroke: 'black' },
        text: {
            text: 'Diamond', fill: '#3498DB',
            'font-size': 18, 'font-weight': 'bold', 
            'font-variant': 'small-caps', 
            'text-transform': 'capitalize'
        }
    });
  diamond.rotate(45);

However, the text present inside the rectangle also gets rotated, Any Ideas how can i proceed.... Also I need to create hexagon with a label... Any help will be much appreciated ....

Thanks In Advance,

Mayuri

4

2 回答 2

6

无需旋转整个元素。尝试为模型添加一个transform属性joint.dia.basic.Rect

rect: { transform: 'rotate(45)' }

另一种选择是使用joint.dia.basic.Path模型。

var diamond = new joint.shapes.basic.Path({
    size: { width: 100, height: 100 },
    attrs: {
        path: { d: 'M 30 0 L 60 30 30 60 0 30 z' },
        text: {
            text: 'Diamond',
            'ref-y': .5 // basic.Path text is originally positioned under the element
        }
    }
});

为了实现六边形,joint.dia.basic.Path再次使用模型,但这次使用以下路径数据。

path: { d: 'M 50 0 L 0 20 0 80 50 100 100 80 100 20 z'}

最后但最不重要的是,您可以在其标记中使用 SVG 多边形创建自定义形状。

于 2014-01-23T00:35:37.453 回答
3

非常感谢罗马,我遵循了钻石的第一个解决方案,它的效果就像一个魅力!

这是任何想要使用joint.js制作菱形的人,我在joint.js中添加了以下内容

joint.shapes.basic.Diamond = joint.shapes.basic.Generic.extend({

    markup: '<g class="rotatable"><g class="scalable"><rect/></g><text/></g>',

    defaults: joint.util.deepSupplement({

        type: 'basic.Rect',
        attrs: {
            'rect': { fill: '#FFFFFF', stroke: 'black', width: 1, height: 1,transform: 'rotate(45)' },
            'text': { 'font-size': 14, text: '', 'ref-x': .5, 'ref-y': .5, ref: 'rect', 'y-alignment': 'middle', 'x-alignment': 'middle', fill: 'black', 'font-family': 'Arial, helvetica, sans-serif' }
        }

    }, joint.shapes.basic.Generic.prototype.defaults)
});

而对于它的实现如下,

var diamond =  new joint.shapes.basic.Diamond({
        position: { x: 100, y: 100 },
        size: { width: 100, height: 100 },
        attrs: { diamond: { width: 100, height: 30 } }
    }); 
    diamond.attr({

        rect: { fill: '#cccccc', 'stroke-width': 2, stroke: 'black' },
        text: {
            text: 'Diamond', fill: '#3498DB',
            'font-size': 18, 'font-weight': 'bold', 
            'font-variant': 'small-caps', 
            'text-transform': 'capitalize'
        }
    });
于 2014-01-23T16:57:06.143 回答