use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class BoxWhiskerScaleBar method setLimits.
public void setLimits(double min, double max) {
axisScale = new AxisScale(min, max);
repaint();
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class ChromosomeScaleTrack method paintComponent.
/* (non-Javadoc)
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
DisplayPreferences dp = DisplayPreferences.getInstance();
if (dp.getCurrentLocation() != lastLocation) {
// We need to rescale the frequency with which we're drawing points
scale = new AxisScale(0, SequenceRead.length(dp.getCurrentLocation()));
lastLocation = dp.getCurrentLocation();
}
height = getHeight();
width = getWidth();
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.setColor(Color.DARK_GRAY);
// Draw a line along the top
g.drawLine(0, 3, width, 3);
// Now go through all the scale positions figuring out whether they
// need to be displayed
int startBp = SequenceRead.start(lastLocation);
int endBp = SequenceRead.end(lastLocation);
int currentBase = 0;
while (currentBase < endBp) {
if (currentBase < startBp) {
currentBase += scale.getInterval();
continue;
}
String name = commify(currentBase);
int nameWidth = g.getFontMetrics().stringWidth(name);
int thisX = bpToPixel(currentBase);
g.drawString(name, thisX - (nameWidth / 2), getHeight() - 2);
g.drawLine(thisX, 3, thisX, height - (g.getFontMetrics().getAscent() + 3));
currentBase += scale.getInterval();
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class GradientScaleAxis method setLimits.
public void setLimits(double min, double max) {
if (max < min)
throw new IllegalArgumentException("Max cannot be <= min max=" + max + " min=" + min);
axisScale = new AxisScale(min, max);
maxX = getMaxWidth();
repaint();
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class MAPlotPanel method paint.
/* (non-Javadoc)
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
FontMetrics metrics = getFontMetrics(g.getFont());
if (!readyToDraw) {
g.setColor(Color.GRAY);
String message = "Calculating Plot";
g.drawString(message, (getWidth() / 2) - (metrics.stringWidth(message) / 2), (getHeight() / 2 - 2));
return;
}
// Check to see if we need to work out the counts for this size
if (nonRedundantValues == null || lastNonredWidth != getWidth() || lastNonredHeight != getHeight()) {
calculateNonredundantSet();
}
// If we're here then we can actually draw the graphs
g.setColor(Color.BLACK);
// X axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
// Centre line
g.setColor(Color.GRAY);
g.drawLine(X_AXIS_SPACE, getY(0), getWidth() - 10, getY(0));
g.setColor(Color.BLACK);
AxisScale xAxisScale = new AxisScale(minValueX, maxValueX);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < maxValueX) {
g.drawString(xAxisScale.format(currentXValue), getX(currentXValue), getHeight() - (Y_AXIS_SPACE - (3 + g.getFontMetrics().getHeight())));
g.drawLine(getX(currentXValue), getHeight() - Y_AXIS_SPACE, getX(currentXValue), getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
AxisScale yAxisScale = new AxisScale(minValueY, maxValueY);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxValueY) {
g.drawString(yAxisScale.format(currentYValue), 5, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// X label
String xLabel = "Average of " + xStore.name() + " and " + yStore.name();
g.drawString(xLabel, (getWidth() / 2) - (metrics.stringWidth(xLabel) / 2), getHeight() - 3);
// Y label
String yLabel = "Difference " + xStore.name() + " - " + yStore.name();
g.drawString(yLabel, X_AXIS_SPACE + 3, 15);
// If we have sublists draw them below this in the right colours
if (subLists != null) {
for (int s = 0; s < subLists.length; s++) {
g.setColor(ColourIndexSet.getColour(s));
g.drawString(subLists[s].name(), X_AXIS_SPACE + 3, 15 + (g.getFontMetrics().getHeight() * (s + 1)));
}
g.setColor(Color.BLACK);
}
// ProbeList
g.drawString(probeList.name(), getWidth() - 10 - metrics.stringWidth(probeList.name()), 15);
g.setColor(Color.BLUE);
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].yValue >= Math.min(ySelectionStart, ySelectionEnd) && nonRedundantValues[p].yValue <= Math.max(ySelectionStart, ySelectionEnd)) {
g.setColor(Color.BLACK);
} else {
// if (nonRedundantValues[p].color == null) {
// nonRedundantValues[p].color = Color.YELLOW;
// }
g.setColor(nonRedundantValues[p].color);
}
g.fillRect(nonRedundantValues[p].x - (dotSize / 2), nonRedundantValues[p].y - (dotSize / 2), dotSize, dotSize);
}
// Finally we draw the current measures if the mouse is inside the plot
if (cursorX > 0) {
g.setColor(Color.BLACK);
// System.out.println("Drawing label at x="+cursorX+" y="+cursorY+" x*="+getValueFromX(cursorX)+" y*="+getValueFromY(cursorY));
String label = "x=" + df.format(getValueFromX(cursorX)) + " y=" + df.format(getValueFromY(cursorY));
int labelXPos = X_AXIS_SPACE + ((getWidth() - (X_AXIS_SPACE + 10)) / 2) - (g.getFontMetrics().stringWidth(label) / 2);
g.drawString(label, labelXPos, getHeight() - (Y_AXIS_SPACE + 3));
// We also draw the names on the closest point if there is one
if (closestPoint != null && closestPoint.probe() != null) {
g.drawString(closestPoint.probe().name(), closestPoint.x + 1, closestPoint.y - 1);
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class PCAScatterPlotPanel method paint.
/* (non-Javadoc)
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
FontMetrics metrics = getFontMetrics(g.getFont());
if (!readyToDraw) {
g.setColor(Color.GRAY);
String message = "Calculating Plot";
g.drawString(message, (getWidth() / 2) - (metrics.stringWidth(message) / 2), (getHeight() / 2 - 2));
return;
}
// Check to see if we need to work out the counts for this size
if (nonRedundantValues == null || lastNonredWidth != getWidth() || lastNonredHeight != getHeight()) {
calculateNonredundantSet();
}
// If we're here then we can actually draw the graphs
g.setColor(Color.BLACK);
// X axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
AxisScale xAxisScale = new AxisScale(minValueX, maxValueX);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < maxValueX) {
g.drawString(xAxisScale.format(currentXValue), getX(currentXValue), getHeight() - (Y_AXIS_SPACE - (3 + g.getFontMetrics().getHeight())));
g.drawLine(getX(currentXValue), getHeight() - Y_AXIS_SPACE, getX(currentXValue), getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
AxisScale yAxisScale = new AxisScale(minValueY, maxValueY);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxValueY) {
g.drawString(yAxisScale.format(currentYValue), 5, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// X label
String xLabel = data.getPCName(xIndex);
g.drawString(xLabel, (getWidth() / 2) - (metrics.stringWidth(xLabel) / 2), getHeight() - 3);
// Y label
String yLabel = data.getPCName(yIndex);
g.drawString(yLabel, X_AXIS_SPACE + 3, 15);
// If we have sublists draw them below this in the right colours
if (highlightedSets != null) {
for (int s = 0; s < highlightedSets.length; s++) {
g.setColor(ColourIndexSet.getColour(s));
g.drawString(highlightedSets[s].name(), X_AXIS_SPACE + 3, 15 + (g.getFontMetrics().getHeight() * (s + 1)));
}
g.setColor(Color.BLACK);
}
// ProbeList
g.drawString(data.probeListName(), getWidth() - 10 - metrics.stringWidth(data.probeListName()), 15);
// 0 lines
g.setColor(Color.GRAY);
g.drawLine(getX(0), getHeight() - Y_AXIS_SPACE, getX(0), 10);
g.drawLine(X_AXIS_SPACE, getY(0), getWidth() - 10, getY(0));
g.setColor(Color.BLUE);
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].difference() >= Math.min(diffStart, diffEnd) && nonRedundantValues[p].difference() <= Math.max(diffStart, diffEnd)) {
g.setColor(Color.BLACK);
} else {
// if (nonRedundantValues[p].color == null) {
// nonRedundantValues[p].color = Color.YELLOW;
// }
g.setColor(nonRedundantValues[p].color);
}
g.fillRect(nonRedundantValues[p].x - (dotSize / 2), nonRedundantValues[p].y - (dotSize / 2), dotSize, dotSize);
}
// Finally we draw the current measures if the mouse is inside the plot
if (cursorX > 0) {
g.setColor(Color.BLACK);
// System.out.println("Drawing label at x="+cursorX+" y="+cursorY+" x*="+getValueFromX(cursorX)+" y*="+getValueFromY(cursorY));
String label = "x=" + df.format(getValueFromX(cursorX)) + " y=" + df.format(getValueFromY(cursorY)) + " diff=" + df.format(getValueFromX(cursorX) - getValueFromY(cursorY));
int labelXPos = X_AXIS_SPACE + ((getWidth() - (X_AXIS_SPACE + 10)) / 2) - (g.getFontMetrics().stringWidth(label) / 2);
g.drawString(label, labelXPos, getHeight() - (Y_AXIS_SPACE + 3));
// We also draw the names on the closest point if there is one
if (closestPoint != null && closestPoint.store() != null) {
int closestX = closestPoint.x + 1;
if (closestX + g.getFontMetrics().stringWidth(closestPoint.store.name()) > getWidth()) {
closestX = closestPoint.x - (1 + g.getFontMetrics().stringWidth(closestPoint.store.name()));
}
g.drawString(closestPoint.store().name(), closestX, closestPoint.y - 1);
}
}
// Draw all the labels if we're asked to
if (showLabels) {
g.setColor(Color.BLACK);
for (int i = 0; i < nonRedundantValues.length; i++) {
ProbePairValue thisPoint = nonRedundantValues[i];
if (thisPoint == null) {
throw new IllegalStateException("Point was null when it should never be");
}
if (thisPoint.store == null) {
throw new IllegalStateException("Store was null when it should never be");
}
int closestX = thisPoint.x + 1;
if (closestX + g.getFontMetrics().stringWidth(thisPoint.store.name()) > getWidth()) {
closestX = thisPoint.x - (1 + g.getFontMetrics().stringWidth(thisPoint.store.name()));
}
g.drawString(thisPoint.store().name(), closestX, thisPoint.y - 1);
}
}
}
Aggregations