JAL-2349 contact renderer prototype (that doesn’t hang!)
authorJim Procter <jprocter@issues.jalview.org>
Sun, 4 Dec 2016 12:23:05 +0000 (12:23 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 4 Dec 2016 12:23:19 +0000 (12:23 +0000)
src/jalview/renderer/ContactMapRenderer.java

index 313e3db..a504b4d 100644 (file)
@@ -82,25 +82,29 @@ public class ContactMapRenderer implements AnnotationRowRendererI
       }
 
 
-      int scale = Math
-              .max(1, _aa.graphHeight / contacts.getContactHeight());
-      int step = _aa.graphHeight / scale;
-      int valuesProcessed = 0;
+      // cell height to render
+      double scale = (_aa.graphHeight < contacts.getContactHeight()) ? 1
+              : (((double) _aa.graphHeight) / (double) contacts
+                      .getContactHeight());
+      // distance between contact map per cell
+      int step = (int) ((contacts.getContactHeight()) * scale / _aa.graphHeight);
+
       // profl[1] is the number of values in the profile
-      for (int stp = 0, ht = y2, eht = y2 + _aa.graphHeight; ht < eht; ht += scale, stp++)
+      for (int stp = 0, ht = y2, eht = y2 - _aa.graphHeight; ht > eht; ht -= scale, stp++)
       {
-        valuesProcessed = stp * step;
-        g.setColor(contacts.getColorForScore(stp * step));
+        g.setColor(contacts
+                .getColorForScore((int) (stp * step * ((double) _aa.graphHeight / (double) contacts
+                        .getContactHeight()))));
 
         if (scale > 1)
         {
-          g.fillRect(x * charWidth, ht, charWidth, scale);
+          g.fillRect(x * charWidth, ht, charWidth, 1 + (int) scale);
         } else {
           g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
         }
       }
+      x++;
     }
-    x++;
 
   }
 }