JAL-2349 fixed rendering method and switched to using color from contact range to...
[jalview.git] / src / jalview / renderer / ContactMapRenderer.java
index a504b4d..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,25 +69,26 @@ public class ContactMapRenderer implements AnnotationRowRendererI
         return;
       }
 
-
       // 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++)
+      int cstart, cend = -1;
+      for (int ht = y2, eht = y2 - _aa.graphHeight; ht >= eht; ht -= scale)
       {
-        g.setColor(contacts
-                .getColorForScore((int) (stp * step * ((double) _aa.graphHeight / (double) contacts
-                        .getContactHeight()))));
+        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, 1 + (int) scale);
-        } else {
+        }
+        else
+        {
           g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
         }
       }