// Generated by CoffeeScript 1.10.0 (function() { var height, redraw, svg, width; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; svg.attr({ viewBox: (-width / 2) + " " + (-height + 60) + " " + width + " " + height }); width -= 60; redraw = function() { var j, ref, results, sequence, x; sequence = d3.select('#sequence_input').node().value; x = d3.scale.ordinal().domain((function() { results = []; for (var j = 0, ref = sequence.length; 0 <= ref ? j <= ref : j >= ref; 0 <= ref ? j++ : j--){ results.push(j); } return results; }).apply(this)).rangeBands([-width / 2, width / 2]); return d3.json("main.php?sequence=" + sequence, function(matches) { var arcs, characters, enter_arcs, subsequence; svg.selectAll('.character').remove(); svg.selectAll('.arc').remove(); svg.select('.subsequence').remove(); characters = svg.selectAll('.character').data(sequence); characters.enter().append('text').text(function(d) { return d; }).attr({ "class": 'character', x: function(d, i) { return x(i) + x.rangeBand() / 2; }, dy: '1em' }); arcs = svg.selectAll('.arc').data(matches.filter(function(m) { return m.length > 1; })); enter_arcs = arcs.enter().append('path').attr({ "class": 'arc', d: function(match) { var big_radius, end_left, end_right, small_radius, start_left, start_right; start_left = x(match.source); start_right = x(match.source + match.length); end_left = x(match.target); end_right = x(match.target + match.length); big_radius = (end_right - start_left) / 2; small_radius = (end_left - start_right) / 2; return "M" + start_left + " 0 A" + big_radius + " " + big_radius + " 0 1 1 " + end_right + " 0 L" + end_left + " 0 A" + small_radius + " " + small_radius + " 0 1 0 " + start_right + " 0 z"; } }); subsequence = svg.append('text').attr({ "class": 'subsequence', y: -350 }); enter_arcs.on('click', function(d1) { subsequence.text(d1.subsequence); svg.selectAll('.arc').classed('selected', function(d2) { return d1.subsequence === d2.subsequence; }).classed('dimmed', function(d2) { return d1.subsequence !== d2.subsequence; }); return d3.event.stopPropagation(); }); return svg.on('click', function() { subsequence.text(''); return svg.selectAll('.arc').classed('selected', false).classed('dimmed', false); }); }); }; redraw(); d3.select('#sequence_input').on('change', function() { console.log('change'); return redraw(); }); }).call(this);