JAL-2349 fixed rendering method and switched to using color from contact range to...
[jalview.git] / src / jalview / renderer / ContactMapRenderer.java
index 313e3db..809ced0 100644 (file)
@@ -11,7 +11,6 @@ import jalview.datamodel.ContactListI;
 import jalview.renderer.api.AnnotationRowRendererI;
 
 import java.awt.Color;
-import java.awt.Font;
 import java.awt.Graphics;
 
 /**
@@ -20,17 +19,7 @@ import java.awt.Graphics;
  */
 public class ContactMapRenderer implements AnnotationRowRendererI
 {
-  /*
-   * 
-   *     // TODO Auto-generated method stub
-      void drawProfileDensity(Graphics g, AlignmentAnnotation _aa,
-              Annotation[] aa_annotations, int sRes, int eRes, float min,
-              float max, int y)
-      {
 
-   * 
-   * 
-   */
   @Override
   public void renderRow(Graphics g, int charWidth, int charHeight,
           boolean hasHiddenColumns, AlignViewportI viewport,
@@ -42,7 +31,6 @@ public class ContactMapRenderer implements AnnotationRowRendererI
     {
       return;
     }
-    Font ofont = g.getFont();
     eRes = Math.min(eRes, aa_annotations.length);
 
     int x = 0, y2 = y;
@@ -81,26 +69,31 @@ public class ContactMapRenderer implements AnnotationRowRendererI
         return;
       }
 
-
-      int scale = Math
-              .max(1, _aa.graphHeight / contacts.getContactHeight());
-      int step = _aa.graphHeight / scale;
-      int valuesProcessed = 0;
-      // 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++)
+      // cell height to render
+      double scale = (_aa.graphHeight < contacts.getContactHeight()) ? 1
+              : (((double) _aa.graphHeight) / (double) contacts
+                      .getContactHeight());
+      int cstart, cend = -1;
+      for (int ht = y2, eht = y2 - _aa.graphHeight; ht >= eht; ht -= scale)
       {
-        valuesProcessed = stp * step;
-        g.setColor(contacts.getColorForScore(stp * step));
+        cstart = cend + 1;
+        cend = -1
+                + (contacts.getContactHeight() * (ht - eht) / _aa.graphHeight);
+        // TODO show maximum colour for range - sort of done
+        // also need a 'getMaxPosForRange(start,end)'
+        g.setColor(contacts.getColorForRange(cstart, cend));
 
         if (scale > 1)
         {
-          g.fillRect(x * charWidth, ht, charWidth, scale);
-        } else {
+          g.fillRect(x * charWidth, ht, charWidth, 1 + (int) scale);
+        }
+        else
+        {
           g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
         }
       }
+      x++;
     }
-    x++;
 
   }
 }