Udi Bauman avatar Udi Bauman committed 24da9db

generalized rows layout

Comments (0)

Files changed (5)

                             +method2<br/>
                             -method3<br/>
                             <br/>
-                            Class2 : BaseClass2<br/>
+                            Class2 : BaseClass1<br/>
+                            +method1<br/>
+                            +method2<br/>
+                            -method3<br/>
+                            <br/>
+                            Class3 : Class2<br/>
                             +method1<br/>
                             +method2<br/>
                             -method3<br/>

model_app/models.coffee

 
     result
 
+  get_super_classes: =>
+    return (@collection.find_by_name(name) for name in @get("super_classes"))
+
+  get_inheritance_depth: =>
+    if @get("super_classes").length > 0
+      supers_depth = (s.get_inheritance_depth() for s in @get_super_classes())
+      supers_max = Math.max supers_depth...
+      return supers_max + 1
+    0
+
 class ClassDiagram extends Backbone.Collection
   model: Class
   source: ""
   get_classes: =>
     (model.get 'name' for model in @models)
 
+  find_by_name: (name) =>
+    # TODO use the Backbone.Collection find method
+    for m in @models
+      if m.get("name") is name
+        return m
+    null
 
 exports = this
 exports.Class = Class

model_app/views.coffee

     @default_member_height = dimensions.default_member_height
     @default_member_spacing = dimensions.default_member_spacing
 
+  get_offset: (level) =>
+    if not @offset[level]
+      @offset[level] = 0
+    @offset[level]
+
+  set_offset: (level, offset) =>
+    @offset[level] = offset
+
   render: =>
     data = @model.get_all_members()
     if data.length < 2
       data.push(" ")
       data.push(" ")
-    level = "l0"
-    if @model.has_super()
-      y = 200
-      level = "l1"
-    else
-      y = 50
-      level = "l0"
-    x = @offset[level]
+    level = @model.get_inheritance_depth()
+    y = level * 120 + 20
+    x = @get_offset(level)
     h = data.length * @default_member_height
     w = @default_class_width
     margin = 10
       .attr("y1", y + @default_member_height)
       .attr("x2", x + @default_class_width)
       .attr("y2", y + @default_member_height)
-    @offset[level] += @default_class_width + @default_member_spacing
+    @set_offset level, x + @default_class_width + @default_member_spacing
 
     @top_connect_point =
         x: x + w/2

static/js/models.js

     __extends(Class, _super);
 
     function Class() {
+      this.get_inheritance_depth = __bind(this.get_inheritance_depth, this);
+      this.get_super_classes = __bind(this.get_super_classes, this);
       this.get_all_members = __bind(this.get_all_members, this);
       this.has_super = __bind(this.has_super, this);
       Class.__super__.constructor.apply(this, arguments);
       return result;
     };
 
+    Class.prototype.get_super_classes = function() {
+      var name;
+      return (function() {
+        var _i, _len, _ref, _results;
+        _ref = this.get("super_classes");
+        _results = [];
+        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+          name = _ref[_i];
+          _results.push(this.collection.find_by_name(name));
+        }
+        return _results;
+      }).call(this);
+    };
+
+    Class.prototype.get_inheritance_depth = function() {
+      var s, supers_depth, supers_max;
+      if (this.get("super_classes").length > 0) {
+        supers_depth = (function() {
+          var _i, _len, _ref, _results;
+          _ref = this.get_super_classes();
+          _results = [];
+          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+            s = _ref[_i];
+            _results.push(s.get_inheritance_depth());
+          }
+          return _results;
+        }).call(this);
+        supers_max = Math.max.apply(Math, supers_depth);
+        return supers_max + 1;
+      }
+      return 0;
+    };
+
     return Class;
 
   })(DiagramElement);
     __extends(ClassDiagram, _super);
 
     function ClassDiagram() {
+      this.find_by_name = __bind(this.find_by_name, this);
       this.get_classes = __bind(this.get_classes, this);
       ClassDiagram.__super__.constructor.apply(this, arguments);
     }
       return _results;
     };
 
+    ClassDiagram.prototype.find_by_name = function(name) {
+      var m, _i, _len, _ref;
+      _ref = this.models;
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+        m = _ref[_i];
+        if (m.get("name") === name) return m;
+      }
+      return null;
+    };
+
     return ClassDiagram;
 
   })(Backbone.Collection);

static/js/views.js

 
     function ClassView() {
       this.render = __bind(this.render, this);
+      this.set_offset = __bind(this.set_offset, this);
+      this.get_offset = __bind(this.get_offset, this);
       this.set_dimensions = __bind(this.set_dimensions, this);
       this.set_container = __bind(this.set_container, this);
       this.initialize = __bind(this.initialize, this);
       return this.default_member_spacing = dimensions.default_member_spacing;
     };
 
+    ClassView.prototype.get_offset = function(level) {
+      if (!this.offset[level]) this.offset[level] = 0;
+      return this.offset[level];
+    };
+
+    ClassView.prototype.set_offset = function(level, offset) {
+      return this.offset[level] = offset;
+    };
+
     ClassView.prototype.render = function() {
       var data, h, level, margin, path_d, points, sc, super_view, w, x, y, _i, _len, _ref,
         _this = this;
         data.push(" ");
         data.push(" ");
       }
-      level = "l0";
-      if (this.model.has_super()) {
-        y = 200;
-        level = "l1";
-      } else {
-        y = 50;
-        level = "l0";
-      }
-      x = this.offset[level];
+      level = this.model.get_inheritance_depth();
+      y = level * 120 + 20;
+      x = this.get_offset(level);
       h = data.length * this.default_member_height;
       w = this.default_class_width;
       margin = 10;
         return y + margin + i * _this.default_member_height;
       }).attr("dy", ".35em").text(String);
       this.el.append("line").attr("x1", x).attr("y1", y + this.default_member_height).attr("x2", x + this.default_class_width).attr("y2", y + this.default_member_height);
-      this.offset[level] += this.default_class_width + this.default_member_spacing;
+      this.set_offset(level, x + this.default_class_width + this.default_member_spacing);
       this.top_connect_point = {
         x: x + w / 2,
         y: y
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.