// Generated by CoffeeScript 1.10.0 (function() { var NetworkView, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; global(NetworkView = (function(superClass) { extend(NetworkView, superClass); function NetworkView(conf) { this.redraw = bind(this.redraw, this); var svg, zoom; if (conf == null) { conf = {}; } conf.events = ['action_on_point', 'action_on_node', 'action_on_link', 'hover_on_point']; NetworkView.__super__.constructor.call(this, conf); this.graph = conf.graph; svg = this.d3el.append('svg'); this.zoomable_layer = svg.append('g'); zoom = d3.zoom().scaleExtent([-Infinity, Infinity]).on('zoom', (function(_this) { return function() { _this.current_zoom_t = d3.event.transform; _this.zoomable_layer.attrs({ transform: _this.current_zoom_t }); _this.nodes_layer.selectAll('.node > *').attrs({ transform: "scale(" + (1 / _this.current_zoom_t.k) + ")" }); return _this.links_layer.selectAll('.link .label > *').attrs({ transform: "scale(" + (1 / _this.current_zoom_t.k) + ")" }); }; })(this)); svg.call(zoom); this.current_zoom_t = d3.zoomTransform(svg); this.links_layer = this.zoomable_layer.append('g'); this.nodes_layer = this.zoomable_layer.append('g'); this.tools_overlay = this.zoomable_layer.append('g'); this.graph.on('change', this.redraw); svg.on('click', (function(_this) { return function() { var ref, x, y; ref = d3.mouse(_this.zoomable_layer.node()), x = ref[0], y = ref[1]; return _this.trigger('action_on_point', x, y); }; })(this)); svg.on('mousemove', (function(_this) { return function() { var ref, x, y; ref = d3.mouse(_this.zoomable_layer.node()), x = ref[0], y = ref[1]; return _this.trigger('hover_on_point', x, y); }; })(this)); } NetworkView.prototype.redraw = function() { var all_links, all_nodes, enter_labels, enter_links, enter_nodes, links, nodes; nodes = this.nodes_layer.selectAll('.node').data(this.graph.get_nodes(), function(d) { return d.id; }); enter_nodes = nodes.enter().append('g').attrs({ "class": 'node' }).on('click', (function(_this) { return function(d) { var ref, x, y; ref = d3.mouse(_this.zoomable_layer.node()), x = ref[0], y = ref[1]; _this.trigger('action_on_node', d, x, y); return d3.event.stopPropagation(); }; })(this)); enter_nodes.append('circle'); enter_nodes.append('text'); all_nodes = enter_nodes.merge(nodes); all_nodes.select('circle').attrs({ r: function(d) { return 4; }, transform: "scale(" + (1 / this.current_zoom_t.k) + ")" }); all_nodes.select('text').text(function(d) { return "(" + (d3.format('.2f')(d.x)) + ", " + (d3.format('.2f')(d.y)) + ")"; }).attrs({ y: 16, transform: "scale(" + (1 / this.current_zoom_t.k) + ")" }); all_nodes.classed('selected', function(d) { return d.selected; }).attrs({ transform: function(d) { return "translate(" + d.x + "," + d.y + ")"; } }); nodes.exit().remove(); links = this.links_layer.selectAll('.link').data(this.graph.get_links(), function(d) { return d.id; }); enter_links = links.enter().append('g').attrs({ "class": 'link' }).on('click', (function(_this) { return function(d) { var ref, x, y; ref = d3.mouse(_this.zoomable_layer.node()), x = ref[0], y = ref[1]; _this.trigger('action_on_link', d, x, y); return d3.event.stopPropagation(); }; })(this)); enter_links.append('line').attrs({ "class": 'background' }); enter_links.append('line').attrs({ "class": 'foreground' }); enter_labels = enter_links.append('g').attrs({ "class": 'label' }); enter_labels.append('text'); all_links = enter_links.merge(links); all_links.selectAll('line').attrs({ x1: function(d) { return d.source.x; }, y1: function(d) { return d.source.y; }, x2: function(d) { return d.target.x; }, y2: function(d) { return d.target.y; } }); all_links.selectAll('.label').attrs({ transform: function(d) { return "translate(" + ((d.source.x + d.target.x) / 2) + "," + ((d.source.y + d.target.y) / 2) + ")"; } }); all_links.selectAll('.label text').text(function(d) { return d3.format('.2f')(d.d); }).attrs({ dy: '0.35em', transform: "scale(" + (1 / this.current_zoom_t.k) + ")" }); all_links.classed('selected', function(d) { return d.selected; }); return links.exit().remove(); }; return NetworkView; })(View)); }).call(this);