javascript - 在 Raphael/Joint.js 中将多部电影围成一圈

标签 javascript jointjs

我在 joint.js 中有一个 FSA,我需要使状态(圆圈)从圆圈底部开始按特定比例半填充,例如 1/2 或 1/6。棘手的部分是它需要完成两次 - 一个更大的半填充和一个更小的半填充。

这就是我想要做的:

partially filled circle

我不知道如何完成这个。

最佳答案

诀窍是创建三个 SVG 圆并为它们定义剪辑路径。以下示例使用自定义 SVG 标记创建自定义 JointJS 形状(继承自 fsa.State),以启用您在图像中显示的颜色:

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);

关于javascript - 在 Raphael/Joint.js 中将多部电影围成一圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20363951/

相关文章:

javascript - 通过按索引将对象推送到数组来对数组进行排序

Javascript 检查鼠标在圆或多边形内单击

javascript - Javascript 中有多维数组类型吗?

javascript - 在 BinaryJS 中访问字节

javascript - jointjs:防止通过单击链接添加顶点

javascript - 缺少 <a> 创建逻辑

javascript - 如何向 JointJs HTML View 添加另一个 Paper 变量?

javascript - 在jointJS中获取外部元素来扩展论文

javascript - JointJS - 主干错误无法读取未定义的属性 '_listenerId'

javascript - 模型端口的 JointJS 2.2.1 样式