use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class VarianceLineGraphPanel method paint.
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
// Draw the axes
// X-axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
// Y-axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, X_AXIS_SPACE, 10);
// Draw the Y scale
AxisScale yAxisScale = new AxisScale(usedMin, usedMax);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < usedMax) {
g.drawString(yAxisScale.format(currentYValue), 5, getYPixels(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getYPixels(currentYValue), X_AXIS_SPACE - 3, getYPixels(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// Draw x ticks
for (int s = 0; s < values.length; s++) {
int xTick = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (values.length - 1)));
g.drawLine(xTick, getHeight() - Y_AXIS_SPACE, xTick, getHeight() - (Y_AXIS_SPACE - 3));
}
for (int s = 0; s < values.length; s++) {
int xTick = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (values.length - 1)));
int stringWidth = g.getFontMetrics().stringWidth("PC" + (s + 1));
int xStart = xTick - (stringWidth / 2);
if (xStart < 1)
xStart = 1;
if (xStart + stringWidth > (getWidth() - 1))
xStart = (getWidth() - 1) - stringWidth;
g.drawString("PC" + (s + 1), xStart, getHeight() - (Y_AXIS_SPACE - (g.getFontMetrics().getHeight() + 3)));
}
// Put the probe list name at the top
String listName = "Variance";
g.drawString(listName, X_AXIS_SPACE, 10);
// Now draw the probes
int lastX = 0;
int lastY = 0;
int thisX = 0;
int thisY = 0;
double value = 0;
g.setColor(BLUE);
for (int s = 0; s < values.length; s++) {
thisX = getXPixels(s);
value = values[s];
if (value < usedMin)
value = usedMin;
if (value > usedMax)
value = usedMax;
thisY = getYPixels(value);
if (s > 0) {
g.drawLine(lastX, lastY, thisX, thisY);
}
g.fillOval(thisX - 4, thisY - 4, 8, 8);
lastX = thisX;
lastY = thisY;
}
// Now highlight the selected index
thisX = getXPixels(selectedIndex);
g.setColor(Color.BLACK);
g.drawLine(thisX, getHeight() - Y_AXIS_SPACE, thisX, 10);
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class TrendOverProbePanel 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());
// Don't draw anything if the calculation isn't done.
if (counts == null) {
return;
}
// First work out the amount of space we need to leave for the X axis
int X_AXIS_SPACE = 0;
AxisScale yAxisScale = new AxisScale(minCount, maxCount);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxCount) {
int stringWidth = g.getFontMetrics().stringWidth(yAxisScale.format(currentYValue)) + 10;
if (stringWidth > X_AXIS_SPACE) {
X_AXIS_SPACE = stringWidth;
}
currentYValue += yAxisScale.getInterval();
}
if (Y_AXIS_SPACE == 0) {
Y_AXIS_SPACE = g.getFontMetrics().getAscent() * 3;
}
// 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);
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
// X labels
String xLabel;
if (sameLength) {
xLabel = "Bases 1 - " + fixedLength;
} else {
xLabel = "Relative distance across probe";
}
g.drawString(xLabel, (getWidth() / 2) - (metrics.stringWidth(xLabel) / 2), getHeight() - 5);
if (sameLength) {
AxisScale xAxisScale = new AxisScale(1, fixedLength);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue + xAxisScale.getInterval() < fixedLength) {
int thisX = X_AXIS_SPACE;
double xProportion = (double) currentXValue / fixedLength;
thisX += (int) (xProportion * (getWidth() - (X_AXIS_SPACE + 10)));
g.drawString(xAxisScale.format(currentXValue), thisX - (g.getFontMetrics().stringWidth(xAxisScale.format(currentXValue)) / 2), (int) ((getHeight() - Y_AXIS_SPACE) + 15));
g.drawLine(thisX, getHeight() - Y_AXIS_SPACE, thisX, getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
}
// Labels on the y-axis
currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxCount) {
g.drawString(yAxisScale.format(currentYValue), 2, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// Now go through the various datastores
for (int p = 0; p < probeLists.length; p++) {
for (int s = 0; s < stores.length; s++) {
int d = (p * stores.length) + s;
g.setColor(ColourIndexSet.getColour(d));
String name = probeLists[p].name() + " - " + stores[s].name();
g.drawString(name, getWidth() - 10 - metrics.stringWidth(name), 15 + (15 * d));
int lastX = X_AXIS_SPACE;
int lastY = getY(counts[d][0]);
boolean drawnCrossHair = false;
for (int x = 1; x < counts[d].length; x++) {
int thisX = X_AXIS_SPACE;
double xProportion = (double) x / (counts[d].length - 1);
thisX += (int) (xProportion * (getWidth() - (X_AXIS_SPACE + 10)));
if (thisX == lastX)
continue;
int thisY = getY(counts[d][x]);
if (drawCrossHair && !drawnCrossHair && thisX >= mouseX) {
String label = df.format(counts[d][x]);
// Clean up the ends if we can
label = label.replaceAll("0+$", "");
label = label.replaceAll("\\.$", "");
g.drawString(label, thisX + 2, thisY);
drawnCrossHair = true;
if (d == 0) {
Color oldColor = g.getColor();
g.setColor(Color.GRAY);
g.drawLine(thisX, 10, thisX, getHeight() - 20);
g.drawString("" + x, thisX + 2, getHeight() - 27);
g.setColor(oldColor);
}
}
g.drawLine(lastX, lastY, thisX, thisY);
lastX = thisX;
lastY = thisY;
}
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class ScatterPlotPanel 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
g.drawString(xStore.name(), (getWidth() / 2) - (metrics.stringWidth(xStore.name()) / 2), getHeight() - 3);
// Y label
g.drawString(yStore.name(), 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);
// R-value
g.drawString(rValue, getWidth() - 10 - metrics.stringWidth(rValue), getHeight() - (Y_AXIS_SPACE + 3));
// 45 degree line
g.setColor(Color.GRAY);
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, 10);
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.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 QuantitationTrendPlotPanel 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());
// Don't draw anything if the calculation isn't done.
if (counts == null) {
return;
}
// First work out the amount of space we need to leave for the X axis
int X_AXIS_SPACE = 0;
AxisScale yAxisScale = new AxisScale(minCount, maxCount);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxCount) {
int stringWidth = g.getFontMetrics().stringWidth(yAxisScale.format(currentYValue)) + 10;
if (stringWidth > X_AXIS_SPACE) {
X_AXIS_SPACE = stringWidth;
}
currentYValue += yAxisScale.getInterval();
}
if (!leftMost) {
X_AXIS_SPACE = 0;
}
if (Y_AXIS_SPACE == 0) {
Y_AXIS_SPACE = g.getFontMetrics().getAscent() * 3;
}
// 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(), getHeight() - Y_AXIS_SPACE);
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
// X labels
String xLabel;
if (sameLength) {
xLabel = "Bases 1 - " + fixedLength;
} else {
xLabel = "Relative distance across " + featureName;
}
g.drawString(xLabel, (getWidth() / 2) - (metrics.stringWidth(xLabel) / 2), getHeight() - 5);
if (sameLength) {
AxisScale xAxisScale = new AxisScale(1, fixedLength);
double currentXValue = xAxisScale.getStartingValue();
double lastXLabelEnd = -1;
while (currentXValue + xAxisScale.getInterval() <= fixedLength) {
int thisX = X_AXIS_SPACE;
double xProportion = (double) currentXValue / fixedLength;
thisX += (int) (xProportion * (getWidth() - X_AXIS_SPACE));
int thisHalfLabelWidth = (g.getFontMetrics().stringWidth(xAxisScale.format(currentXValue)) / 2);
if (thisX - thisHalfLabelWidth <= lastXLabelEnd) {
currentXValue += xAxisScale.getInterval();
continue;
}
lastXLabelEnd = thisX + thisHalfLabelWidth;
g.drawString(xAxisScale.format(currentXValue), thisX - thisHalfLabelWidth, (int) ((getHeight() - Y_AXIS_SPACE) + 15));
g.drawLine(thisX, getHeight() - Y_AXIS_SPACE, thisX, getHeight() - (Y_AXIS_SPACE - 3));
}
}
if (leftMost) {
currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxCount) {
g.drawString(yAxisScale.format(currentYValue), 2, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
}
// Now go through the various datastores
for (int d = 0; d < counts.length; d++) {
g.setColor(ColourIndexSet.getColour(d));
if (rightMost) {
g.drawString(stores[d].name(), getWidth() - 10 - metrics.stringWidth(stores[d].name()), 15 + (15 * d));
}
int lastX = X_AXIS_SPACE;
int lastY = getY(counts[d][0]);
boolean drawnCrossHair = false;
for (int x = 1; x < counts[d].length; x++) {
int thisX = X_AXIS_SPACE;
double xProportion = (double) x / (counts[d].length - 1);
thisX += (int) (xProportion * (getWidth() - X_AXIS_SPACE));
// Only draw something when we've moving somewhere.
if (thisX == lastX)
continue;
int thisY = getY(counts[d][x]);
if (drawCrossHair && !drawnCrossHair && thisX >= mouseX) {
String label = df.format(counts[d][x]);
// Clean up the ends if we can
label = label.replaceAll("0+$", "");
label = label.replaceAll("\\.$", "");
g.drawString(label, thisX + 2, thisY);
drawnCrossHair = true;
if (d == 0) {
Color oldColor = g.getColor();
g.setColor(Color.GRAY);
g.drawLine(thisX, 10, thisX, getHeight() - 20);
g.drawString("" + x, thisX + 2, getHeight() - 27);
g.setColor(oldColor);
}
}
g.drawLine(lastX, lastY, thisX, thisY);
lastX = thisX;
lastY = thisY;
}
}
}
Aggregations