*/
package jalview.renderer;
+import java.awt.Color;
+import java.awt.Graphics;
+
import jalview.api.AlignViewportI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.ContactListI;
import jalview.datamodel.ContactRange;
+import jalview.datamodel.HiddenColumns;
import jalview.renderer.api.AnnotationRowRendererI;
-import java.awt.Color;
-import java.awt.Graphics;
-
/**
* @author jprocter
*
@Override
public void renderRow(Graphics g, int charWidth, int charHeight,
boolean hasHiddenColumns, AlignViewportI viewport,
- ColumnSelection columnSelection, AlignmentAnnotation _aa,
- Annotation[] aa_annotations, int sRes, int eRes, float min,
- float max, int y)
+ HiddenColumns hiddenColumns, ColumnSelection columnSelection,
+ AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes,
+ int eRes, float min, float max, int y)
{
if (sRes > aa_annotations.length)
{
column = sRes + x;
if (hasHiddenColumns)
{
- column = columnSelection.adjustForHiddenColumns(column);
+ column = hiddenColumns.visibleToAbsoluteColumn(column);
}
+ // // TODO: highlight columns selected
+ // boolean colsel = false;
+ // if (columnSelection != null)
+ // {
+ // colsel = columnSelection.contains(column);
+ // }
if (column > aaMax)
{
x++;
continue;
}
- /*
- * {profile type, #values, total count, char1, pct1, char2, pct2...}
- */
+ if (_aa.sequenceRef != null)
+ {
+ // get the sequence position for the column
+ column = _aa.sequenceRef.findPosition(column) - 1;
+ }
ContactListI contacts = viewport.getContactList(_aa, column);
- min = _aa.graphMin;
- max = _aa.graphMax;
if (contacts == null)
{
return;
}
+ int contact_height = contacts.getContactHeight();
+ // fractional number of contacts covering each pixel
+ double contacts_per_pixel = ((double) contact_height)
+ / ((double) _aa.graphHeight);
- // 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)
+ int pixels_step;
+
+ if (contacts_per_pixel >= 1)
{
- 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(getColorForRange(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 (scale > 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.fillRect(x * charWidth, ht, charWidth, 1 + (int) scale);
+ g.setColor(col);
+ }
+ if (pixels_step > 1)
+ {
+ g.fillRect(x * charWidth, ht, charWidth, 1 + pixels_step);
}
else
{
}
+ // Shading parameters
Color minColor = Color.white, maxColor = Color.magenta;
- float min, max;
-
- Color shadeFor(float value)
+ Color shadeFor(float min, float max, float value)
{
return jalview.util.ColorUtils.getGraduatedColour(value, 0, minColor,
max, maxColor);
}
- public Color getColorForRange(ContactListI cl, int i, int j)
+ public Color getColorForRange(float min, float max, ContactListI cl,
+ int i, int j)
{
ContactRange cr = cl.getRangeFor(i, j);
// average for moment - probably more interested in maxIntProj though
- return shadeFor((float) cr.getMean());
+ return shadeFor(min, max, (float) cr.getMean());
}
}