|
(function() { |
|
var arcs, char, characters, five, four, height, i, matches, one, sequence, svg, three, two, width, x, _i, _ref, _results; |
|
|
|
sequence = (function() { |
|
var _i, _len, _ref, _results; |
|
|
|
_ref = 'Tre tigri contro tre tigri'; |
|
_results = []; |
|
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { |
|
char = _ref[i]; |
|
_results.push({ |
|
'char': char, |
|
'i': i |
|
}); |
|
} |
|
return _results; |
|
})(); |
|
|
|
one = sequence.slice(0, 9); |
|
|
|
two = sequence.slice(17, 26); |
|
|
|
three = sequence.slice(0, 2); |
|
|
|
four = sequence.slice(13, 15); |
|
|
|
five = sequence.slice(17, 19); |
|
|
|
matches = [ |
|
{ |
|
source: one, |
|
target: two |
|
}, { |
|
source: three, |
|
target: four |
|
}, { |
|
source: four, |
|
target: five |
|
} |
|
]; |
|
|
|
svg = d3.select('svg'); |
|
|
|
width = svg.node().getBoundingClientRect().width; |
|
|
|
height = svg.node().getBoundingClientRect().height; |
|
|
|
svg.attr({ |
|
viewBox: "" + (-width / 2) + " " + (-height + 40) + " " + width + " " + height |
|
}); |
|
|
|
width -= 60; |
|
|
|
x = d3.scale.ordinal().domain((function() { |
|
_results = []; |
|
for (var _i = 0, _ref = sequence.length; 0 <= _ref ? _i < _ref : _i > _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); } |
|
return _results; |
|
}).apply(this)).rangeBands([-width / 2, width / 2]); |
|
|
|
characters = svg.selectAll('.character').data(sequence); |
|
|
|
characters.enter().append('text').text(function(item) { |
|
return item.char; |
|
}).attr({ |
|
"class": 'character', |
|
x: function(item) { |
|
return x(item.i) + x.rangeBand() / 2; |
|
}, |
|
dy: '1em' |
|
}); |
|
|
|
arcs = svg.selectAll('.arc').data(matches); |
|
|
|
arcs.enter().append('path').attr({ |
|
"class": 'arc', |
|
d: function(link) { |
|
var big_radius, end_left, end_right, small_radius, start_left, start_right; |
|
|
|
start_left = x(link.source[0].i); |
|
start_right = x(link.source[link.source.length - 1].i) + x.rangeBand(); |
|
end_left = x(link.target[0].i); |
|
end_right = x(link.target[link.target.length - 1].i) + x.rangeBand(); |
|
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"; |
|
} |
|
}); |
|
|
|
}).call(this); |