From 4bc1cd2cbab7e95e770abb5c438f2c054d0a432d Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 24 Jun 2022 17:22:18 +0100 Subject: [PATCH] JAL-2349 debugged and simplified (a little) the scaled rendering of contact maps - still got a rounding error somewhere ! --- src/jalview/renderer/ContactMapRenderer.java | 49 +++++++++++++++++--------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/jalview/renderer/ContactMapRenderer.java b/src/jalview/renderer/ContactMapRenderer.java index aaa8a61..c4f308e 100644 --- a/src/jalview/renderer/ContactMapRenderer.java +++ b/src/jalview/renderer/ContactMapRenderer.java @@ -72,27 +72,43 @@ 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) + { + // 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 = cend + 1; - cend = (int) Math.min(contact_height, cstart + 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)); + // TODO show maximum colour for range - sort of done - // also need a 'getMaxPosForRange(start,end)' - g.setColor(getColorForRange(min, max, contacts, cstart, cend)); + // also need a 'getMaxPosForRange(start,end)' to accurately render + Color col = getColorForRange(min, max, contacts, cstart, cend); - if (pixels_step>1) { - g.fillRect(x * charWidth, ht, charWidth, 1 + (int) pixels_step); + g.setColor(col); + } + if (pixels_step > 1) + { + g.fillRect(x * charWidth, ht, charWidth, 1 + pixels_step); } else { @@ -106,7 +122,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, -- 1.7.10.2