# HG changeset patch # User cavaliet # Date 1361986939 -3600 # Node ID 5a3d8a3eb34d0f9bd0ee111aa6d1146efe8405e5 # Parent 14c40542dfbbf366c1a9a3edcdeffed391b90adc Display fragment only in all_fragment template. diff -r 14c40542dfbb -r 5a3d8a3eb34d src/egonomy/models.py --- a/src/egonomy/models.py Tue Feb 26 17:52:44 2013 +0100 +++ b/src/egonomy/models.py Wed Feb 27 18:42:19 2013 +0100 @@ -82,4 +82,70 @@ title = models.CharField(max_length=2048, blank=True, null=True) description = models.TextField(blank=True, null=True) tags = models.TextField(blank=True, null=True) + + + def get_viewbox_info(self): + if not self.coordinates: + return None,None,None,None + # Now we split the coordinates to get the path points's max and min x and y + # A typical path is M0.1995 0.1574L0.3718 0.0131L0.7731 0.0597L0.5126 0.2915Z + points_str = self.coordinates.strip("M").strip("Z").split("L") + points_x = [] + points_y = [] + for p in points_str: + xy = p.split(" ") + points_x.append(float(xy[0])) + points_y.append(float(xy[1])) + # At this point, values are floats like 19.95, 15.74... + min_x = min(points_x) + max_x = max(points_x) + min_y = min(points_y) + max_y = max(points_y) + # At this point, values are floats like 19, 15... + # Now we build the viewbox, which is min_x min_y (max_x-min_x) (max_y-min_y) with number like 0.19 0.15... + # We use floor and +2 for the viewbox to be a bit larger than the strict fragment + vb_x = min_x + vb_y = min_y + vb_w = max_x - min_x + vb_h = max_y - min_y + return vb_x, vb_y, vb_w, vb_h + + # This property returns a ratio between width and height + @property + def ratio(self): + if not self.coordinates: + return 0 + _, _, vb_w, vb_h = self.get_viewbox_info() + return vb_w/vb_h + + # This property returns a viewbox used in the swg xml and enbling to see the fragment only + @property + def viewbox(self): + if not self.coordinates: + return "0 0 1 1" + vb_x, vb_y, vb_w, vb_h = self.get_viewbox_info() + vb = str(vb_x) + " " + str(vb_y) + " " + str(vb_w) + " " + str(vb_h) + return vb + + # This property returns a square viewbox used in the swg xml and enbling to see the fragment only + @property + def viewbox_square(self): + if not self.coordinates: + return "0 0 1 1" + vb_x, vb_y, vb_w, vb_h = self.get_viewbox_info() + img_info = self.image.info + img_ratio = float(img_info.width) / float(img_info.height) + if vb_w > vb_h: + # If fragment w > h, we center the fragment on y ... + vb_y = max(0, vb_y - (((vb_w * img_ratio) - vb_h) / 2)) + # ... and resize the viewbox's h with image's ratio + vb_h = vb_w * img_ratio + else: + # If fragment w > h, we center the fragment on x ... + vb_x = max(0, vb_x - (((vb_h / img_ratio) - vb_w) / 2)) + # ... and we resize the viewbox's w with image's ratio + vb_w = vb_h / img_ratio + vb = str(vb_x) + " " + str(vb_y) + " " + str(vb_w) + " " + str(vb_h) + + return vb \ No newline at end of file diff -r 14c40542dfbb -r 5a3d8a3eb34d src/egonomy/static/egonomy/css/egonomy.css --- a/src/egonomy/static/egonomy/css/egonomy.css Tue Feb 26 17:52:44 2013 +0100 +++ b/src/egonomy/static/egonomy/css/egonomy.css Wed Feb 27 18:42:19 2013 +0100 @@ -254,6 +254,13 @@ position: absolute; top: 0; left: 0; width: 100%; height: 100%; } +.sub_svg_image { + opacity: .3; +} +.sub_svg_image:hover { + opacity: 1; +} + /* STYLES SPECIFIQUES A home.html */ .homeviz { diff -r 14c40542dfbb -r 5a3d8a3eb34d src/egonomy/templates/egonomy_all_fragments.html --- a/src/egonomy/templates/egonomy_all_fragments.html Tue Feb 26 17:52:44 2013 +0100 +++ b/src/egonomy/templates/egonomy_all_fragments.html Wed Feb 27 18:42:19 2013 +0100 @@ -28,34 +28,75 @@
+
+
{% endthumbnail %}
{% else %}
{% thumbnail image "110" format="PNG" crop="center" as im %}
-
+
+
{% endthumbnail %}
{% endif %}
{% else %}
-
+
+
{% endif %}
{% endwith %}
-
{% endwith %}
{{ frg.viewbox }} - {{ frg.viewbox_square }}
{% trans "Annotated by" %} {{ frg.author }}
{% endfor %} diff -r 14c40542dfbb -r 5a3d8a3eb34d src/egonomy/templates/egonomy_view_fragment.html --- a/src/egonomy/templates/egonomy_view_fragment.html Tue Feb 26 17:52:44 2013 +0100 +++ b/src/egonomy/templates/egonomy_view_fragment.html Wed Feb 27 18:42:19 2013 +0100 @@ -15,21 +15,52 @@ {% with fragment.image.info.image_file as image %} {% if image|ratio > 0.8 %} {% thumbnail image "476" format="PNG" crop="center" as im %} -
+
+
{% endthumbnail %}
{% else %}
{% thumbnail image "x600" format="PNG" crop="center" as im %}
-