/** * Render the track in the given rectangle. * * @param track * @param locusScores * @param context * @param arect */ public synchronized void renderScores( Track track, List<LocusScore> locusScores, RenderContext context, Rectangle arect) { boolean showMissingData = PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SHOW_MISSING_DATA_KEY); Graphics2D noDataGraphics = context.getGraphic2DForColor(UIConstants.NO_DATA_COLOR); Graphics2D tickGraphics = context.getGraphic2DForColor(Color.BLACK); Rectangle adjustedRect = calculateDrawingRect(arect); double origin = context.getOrigin(); double locScale = context.getScale(); Color posColor = track.getColor(); Color negColor = track.getAltColor(); // Get the Y axis definition, consisting of minimum, maximum, and base value. Often // the base value is == min value which is == 0. DataRange dataRange = track.getDataRange(); float maxValue = dataRange.getMaximum(); float baseValue = dataRange.getBaseline(); float minValue = dataRange.getMinimum(); boolean isLog = dataRange.isLog(); if (isLog) { minValue = (float) (minValue == 0 ? 0 : Math.log10(minValue)); maxValue = (float) Math.log10(maxValue); } // Calculate the Y scale factor. double delta = (maxValue - minValue); double yScaleFactor = adjustedRect.getHeight() / delta; // Calculate the Y position in pixels of the base value. Clip to bounds of rectangle double baseDelta = maxValue - baseValue; int baseY = (int) (adjustedRect.getY() + baseDelta * yScaleFactor); if (baseY < adjustedRect.y) { baseY = adjustedRect.y; } else if (baseY > adjustedRect.y + adjustedRect.height) { baseY = adjustedRect.y + adjustedRect.height; } int lastPx = 0; for (LocusScore score : locusScores) { // Note -- don't cast these to an int until the range is checked. // could get an overflow. double pX = ((score.getStart() - origin) / locScale); double dx = Math.ceil((Math.max(1, score.getEnd() - score.getStart())) / locScale) + 1; if ((pX + dx < 0)) { continue; } else if (pX > adjustedRect.getMaxX()) { break; } float dataY = score.getScore(); if (isLog && dataY <= 0) { continue; } if (!Float.isNaN(dataY)) { // Compute the pixel y location. Clip to bounds of rectangle. double dy = isLog ? Math.log10(dataY) - baseValue : (dataY - baseValue); int pY = baseY - (int) (dy * yScaleFactor); if (pY < adjustedRect.y) { pY = adjustedRect.y; } else if (pY > adjustedRect.y + adjustedRect.height) { pY = adjustedRect.y + adjustedRect.height; } Color color = (dataY >= baseValue) ? posColor : negColor; drawDataPoint(color, (int) dx, (int) pX, baseY, pY, context); } if (showMissingData) { // Draw from lastPx + 1 to pX - 1; int w = (int) pX - lastPx - 4; if (w > 0) { noDataGraphics.fillRect(lastPx + 2, (int) arect.getY(), w, (int) arect.getHeight()); } } if (!Float.isNaN(dataY)) { lastPx = (int) pX + (int) dx; } } if (showMissingData) { int w = (int) arect.getMaxX() - lastPx - 4; if (w > 0) { noDataGraphics.fillRect(lastPx + 2, (int) arect.getY(), w, (int) arect.getHeight()); } } }