UNPKG

jointjs

Version:

JavaScript diagramming library

125 lines (109 loc) 3.24 kB
(function linkLabelsDistance() { var graph = new joint.dia.Graph; new joint.dia.Paper({ el: document.getElementById('paper-link-labels-distance'), model: graph, width: 600, height: 300, gridSize: 10, drawGrid: true, background: { color: 'rgba(0, 255, 0, 0.3)' }, interactive: false }); var link = new joint.shapes.standard.Link(); link.source(new g.Point(100, 110)); link.target(new g.Point(500, 110)); link.vertices([{ x: 300, y: 190 }]); link.appendLabel({ attrs: { text: { text: '0.25' } }, position: { distance: 0.25 } }); link.appendLabel({ attrs: { text: { text: '150' } }, position: { distance: 150 } }); link.appendLabel({ attrs: { text: { text: '-100' } }, position: { distance: -100 } }); link.addTo(graph); function contract(link) { link.transition('source', { x: 200, y: 110 }, { delay: 1000, duration: 4000, timingFunction: function(time) { return (time <= 0.5) ? (2 * time) : (2 * (1 - time)); }, valueFunction: joint.util.interpolate.object }); link.transition('target', { x: 400, y: 110 }, { delay: 1000, duration: 4000, timingFunction: function(time) { return (time <= 0.5) ? (2 * time) : (2 * (1 - time)); }, valueFunction: joint.util.interpolate.object }); link.oscillateToggle = true; } function oscillate(link) { link.transition('source', { x: 100, y: 190 }, { delay: 1000, duration: 4000, timingFunction: function(time) { return (time <= 0.5) ? (2 * time) : (2 * (1 - time)); }, valueFunction: joint.util.interpolate.object }); link.transition('vertices/0', { x: 300, y: 110 }, { delay: 1000, duration: 4000, timingFunction: function(time) { return (time <= 0.5) ? (2 * time) : (2 * (1 - time)); }, valueFunction: joint.util.interpolate.object }); link.transition('target', { x: 500, y: 190 }, { delay: 1000, duration: 4000, timingFunction: function(time) { return (time <= 0.5) ? (2 * time) : (2 * (1 - time)); }, valueFunction: joint.util.interpolate.object }); link.oscillateToggle = false; } link.currentTransitions = 0; link.oscillateToggle = 0; contract(link); link.on('transition:start', function(link) { link.currentTransitions += 1; }); link.on('transition:end', function(link) { link.currentTransitions -= 1; if (link.currentTransitions === 0) { if (link.oscillateToggle) oscillate(link); else contract(link); } }); }());