Commits

Udi Bauman committed a104459

arrows

Comments (0)

Files changed (4)

model_app/controllers.coffee

   ->
     source = $("#source_input").val()
     unless source is previous_source
+      current_diagram.reset()
       previous_source = source
       lines = source.split("\n")
       _.each lines, (line) ->

model_app/views.coffee

         @el.append("path")
           .attr("d", path_d)
           .attr("stroke", "black")
+          .attr("stroke-width", "0.75px")
           .attr("fill", "none")
+          .attr("marker-end", "url(#triangle)")
 
     return @
 
+  destroy: =>
+
 
 class ClassDiagramView extends Backbone.View
   svg: null
 
   initialize: =>
     @render()
+    current_diagram.on "reset", @clear
     current_diagram.on "add", @add_class
 
   render: =>
       .attr("width", w)
       .attr("height", h)
       .attr("class", "pack")
+
+
+    @svg.append("defs")
+      .selectAll("marker")
+      .data(["triangle"])
+      .enter()
+      .append("marker")
+      .attr("id", String)
+      .attr("viewBox", "0 -5 10 10")
+      .attr("refX", 10)
+      .attr("refY", -0.5)
+      .attr("markerWidth", 10)
+      .attr("markerHeight", 10)
+      .attr("orient", "auto")
+      .append("svg:path")
+      .attr("d", "M0,-5L10,0L0,5")
+
+    @svg = @svg.selectAll("g")
+      .data(["root"]).enter()
       .append("g")
       .attr("transform", "translate(2, 2)")
 
+  clear: =>
+    @svg[0][0].removeChild(v.el[0][0]) for k, v of @class_views_by_name
+    @class_views_by_name = {}
+    @current_offset = {}
+
   add_class: (model) =>
     class_view = new ClassView(model: model)
     class_view.set_container @svg

static/js/controllers.js

       var lines, source;
       source = $("#source_input").val();
       if (source !== previous_source) {
+        current_diagram.reset();
         previous_source = source;
         lines = source.split("\n");
         _.each(lines, function(line) {

static/js/views.js

     __extends(ClassView, _super);
 
     function ClassView() {
+      this.destroy = __bind(this.destroy, this);
       this.render = __bind(this.render, this);
       this.set_offset = __bind(this.set_offset, this);
       this.get_offset = __bind(this.get_offset, this);
           path_d += " C" + points[0].x + "," + (points[0].y - 50);
           path_d += " " + points[1].x + "," + (points[1].y + 50);
           path_d += " " + points[1].x + "," + points[1].y;
-          this.el.append("path").attr("d", path_d).attr("stroke", "black").attr("fill", "none");
+          this.el.append("path").attr("d", path_d).attr("stroke", "black").attr("stroke-width", "0.75px").attr("fill", "none").attr("marker-end", "url(#triangle)");
         }
       }
       return this;
     };
 
+    ClassView.prototype.destroy = function() {};
+
     return ClassView;
 
   })(Backbone.View);
 
     function ClassDiagramView() {
       this.add_class = __bind(this.add_class, this);
+      this.clear = __bind(this.clear, this);
       this.render = __bind(this.render, this);
       this.initialize = __bind(this.initialize, this);
       ClassDiagramView.__super__.constructor.apply(this, arguments);
 
     ClassDiagramView.prototype.initialize = function() {
       this.render();
+      current_diagram.on("reset", this.clear);
       return current_diagram.on("add", this.add_class);
     };
 
       pack = d3.layout.pack().size([w - 4, h - 4]).value(function(d) {
         return d.size;
       });
-      return this.svg = d3.select("#chart").append("svg").attr("width", w).attr("height", h).attr("class", "pack").append("g").attr("transform", "translate(2, 2)");
+      this.svg = d3.select("#chart").append("svg").attr("width", w).attr("height", h).attr("class", "pack");
+      this.svg.append("defs").selectAll("marker").data(["triangle"]).enter().append("marker").attr("id", String).attr("viewBox", "0 -5 10 10").attr("refX", 10).attr("refY", -0.5).attr("markerWidth", 10).attr("markerHeight", 10).attr("orient", "auto").append("svg:path").attr("d", "M0,-5L10,0L0,5");
+      return this.svg = this.svg.selectAll("g").data(["root"]).enter().append("g").attr("transform", "translate(2, 2)");
+    };
+
+    ClassDiagramView.prototype.clear = function() {
+      var k, v, _ref;
+      _ref = this.class_views_by_name;
+      for (k in _ref) {
+        v = _ref[k];
+        this.svg[0][0].removeChild(v.el[0][0]);
+      }
+      this.class_views_by_name = {};
+      return this.current_offset = {};
     };
 
     ClassDiagramView.prototype.add_class = function(model) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.