X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FContactMapRenderer.java;h=10f87b1e041ef78fc3f7efcf4fe0fc033911c643;hb=a059dd46fe149a476bd274562cd27b2dc7d390dd;hp=aaa8a6118ae3c12ffb14f1ac4610708aff932fdd;hpb=59f8f1014e5ef09bf93c8a2cabe11b846012a521;p=jalview.git diff --git a/src/jalview/renderer/ContactMapRenderer.java b/src/jalview/renderer/ContactMapRenderer.java index aaa8a61..10f87b1 100644 --- a/src/jalview/renderer/ContactMapRenderer.java +++ b/src/jalview/renderer/ContactMapRenderer.java @@ -3,6 +3,9 @@ */ package jalview.renderer; +import java.awt.Color; +import java.awt.Graphics; + import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -12,9 +15,6 @@ import jalview.datamodel.ContactRange; import jalview.datamodel.HiddenColumns; import jalview.renderer.api.AnnotationRowRendererI; -import java.awt.Color; -import java.awt.Graphics; - /** * @author jprocter * @@ -24,10 +24,10 @@ public class ContactMapRenderer implements AnnotationRowRendererI @Override public void renderRow(Graphics g, int charWidth, int charHeight, - boolean hasHiddenColumns, AlignViewportI viewport, HiddenColumns hiddenColumns, - ColumnSelection columnSelection, AlignmentAnnotation _aa, - Annotation[] aa_annotations, int sRes, int eRes, float min, - float max, int y) + boolean hasHiddenColumns, AlignViewportI viewport, + HiddenColumns hiddenColumns, ColumnSelection columnSelection, + AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes, + int eRes, float min, float max, int y) { if (sRes > aa_annotations.length) { @@ -50,6 +50,12 @@ public class ContactMapRenderer implements AnnotationRowRendererI { column = hiddenColumns.visibleToAbsoluteColumn(column); } + // // TODO: highlight columns selected + // boolean colsel = false; + // if (columnSelection != null) + // { + // colsel = columnSelection.contains(column); + // } if (column > aaMax) { @@ -72,27 +78,50 @@ public class ContactMapRenderer implements AnnotationRowRendererI return; } int contact_height = contacts.getContactHeight(); - // fractional pixel height to render each contact cell - double pixels_per_contact = ((double) _aa.graphHeight) - / (double) contact_height; // fractional number of contacts covering each pixel - double contacts_per_pixel = 1d/pixels_per_contact; - // number of contacts to render at a time - int step = (pixels_per_contact<1) ? (int) Math.floor(contacts_per_pixel) : (int) Math.ceil(pixels_per_contact); - - int pixels_step = (int) Math.ceil(step*pixels_per_contact); - int cstart, cend = -1; - for (int ht = y2, eht = y2 - _aa.graphHeight; ht >= eht; ht -= pixels_step) + double contacts_per_pixel = ((double) contact_height) + / ((double) _aa.graphHeight); + + int pixels_step; + + if (contacts_per_pixel >= 1) { - cstart = cend + 1; - cend = (int) Math.min(contact_height, cstart + step); - // TODO show maximum colour for range - sort of done - // also need a 'getMaxPosForRange(start,end)' - g.setColor(getColorForRange(min, max, contacts, cstart, cend)); + // many contacts rendered per pixel + pixels_step = 1; + } + else + { + // pixel height for each contact + pixels_step = (int) Math + .ceil(((double) _aa.graphHeight) / (double) contact_height); + } + + int cstart = 0, cend; + + for (int ht = y2, + eht = y2 - _aa.graphHeight; ht >= eht; ht -= pixels_step) + { + cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel); + cend = (int) Math.min(contact_height, + Math.ceil(cstart + contacts_per_pixel * pixels_step)); - if (pixels_step>1) + // TODO show maximum colour for range - sort of done + // also need a 'getMaxPosForRange(start,end)' to accurately render + Color col = getColorForRange(min, max, contacts, cstart, cend); + + // TODO: show selected region + // if (colsel || columnSelection!=null && + // columnSelection.intersects(cstart,cend)) + // { + // g.setColor(col.brighter()); + // } + // else + { + g.setColor(col); + } + if (pixels_step > 1) { - g.fillRect(x * charWidth, ht, charWidth, 1 + (int) pixels_step); + g.fillRect(x * charWidth, ht, charWidth, 1 + pixels_step); } else { @@ -106,7 +135,6 @@ public class ContactMapRenderer implements AnnotationRowRendererI Color minColor = Color.white, maxColor = Color.magenta; - Color shadeFor(float min, float max, float value) { return jalview.util.ColorUtils.getGraduatedColour(value, 0, minColor,