Putting multiple films in a circle in Raphael/Joint.js

无人久伴 提交于 2019-12-23 00:52:19

问题


I have an FSA in joint.js, and I need to make the states (circles) semi-filled to specific ratios, like 1/2 or 1/6, starting from the bottom of the circle. The tricky part is that it needs to be done twice - A larger semi-fill and a smaller semi-fill over it.

This is what i am trying to do:

I'm lost as to how to accomplish this.


回答1:


The trick is to create three SVG circles and define clip paths for them. The following example creates a custom JointJS shape (inheriting from fsa.State) with custom SVG markup that enables the coloring that you have shown in the image:

var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({ el: $('#paper'), width: 650, height: 400, model: graph });

joint.shapes.fsa.MyState = joint.shapes.fsa.State.extend({

    markup: [
        '<g class="rotatable"><g class="scalable">',
        '<clipPath id="clip-top1"><rect x="-30" y="0" width="60" height="30"/></clipPath>',
        '<clipPath id="clip-top2"><rect x="-30" y="15" width="60" height="30"/></clipPath>',
        '<circle class="a"/><circle class="b"/><circle class="c"/>',
        '</g><text/></g>'
    ].join(''),

    defaults: joint.util.deepSupplement({
        type: 'fsa.MyState',
        size: { width: 60, height: 60 },
        attrs: {
            'circle': { fill: 'white' },
            '.b': { fill: 'red', 'clip-path': 'url(#clip-top1)' },
            '.c': { fill: 'blue', 'clip-path': 'url(#clip-top2)' }
        }
    }, joint.shapes.fsa.State.prototype.defaults)
});

var mystate1 = new joint.shapes.fsa.MyState({
    position: { x: 50, y: 50 },
    size: { width: 100, height: 100 },
    attrs: { text: { text: 'my state 1' } }
});
graph.addCell(mystate1);

var mystate2 = new joint.shapes.fsa.MyState({
    position: { x: 50, y: 160 },
    size: { width: 50, height: 50 }
});
graph.addCell(mystate2);


来源:https://stackoverflow.com/questions/20363951/putting-multiple-films-in-a-circle-in-raphael-joint-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!