Improve legend display
- Draw box around legend - Prefix graph titles with colored line - Allow toggling of grid in FunctionArea refs #48
This commit is contained in:
parent
fa1c0a052e
commit
f0716a3576
@ -53,7 +53,7 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Indicate whether graph legend entries should show their unique number.
|
* Indicate whether graph legend entries should show their unique number.
|
||||||
*/
|
*/
|
||||||
private boolean appendIndexInLegend = true;
|
private boolean appendIndexInLegend = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -162,64 +162,36 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
xPos = e.getX();
|
xPos = e.getX();
|
||||||
yPos = e.getY();
|
yPos = e.getY();
|
||||||
|
|
||||||
addMenuItem(graphPopupMenu, "Rename graph", new ActionListener() {
|
addMenuItem(graphPopupMenu, "Rename graph", ee -> renameGraph(getNearestGraphIndex(FunctionArea.this.xPos, FunctionArea.this.yPos)));
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
renameGraph(getNearestGraphIndex(FunctionArea.this.xPos, FunctionArea.this.yPos));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// General entries
|
// General entries
|
||||||
String togGTTName = (isShowGraphToolTips() ? "Deactivate"
|
String togGTTName = (isShowGraphToolTips() ? "Deactivate"
|
||||||
: "Activate")
|
: "Activate")
|
||||||
+ " graph tool tips";
|
+ " graph tool tips";
|
||||||
addMenuItem(graphPopupMenu, togGTTName,
|
addMenuItem(graphPopupMenu, togGTTName, ee -> setShowGraphToolTips(!isShowGraphToolTips()));
|
||||||
new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
setShowGraphToolTips(!isShowGraphToolTips());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String togLName = (isShowLegend() ? "Hide" : "Show")
|
String toggleLegend = (isShowLegend() ? "Hide" : "Show") + " legend";
|
||||||
+ " legend";
|
addMenuItem(graphPopupMenu, toggleLegend, ee -> toggleLegend());
|
||||||
addMenuItem(graphPopupMenu, togLName, new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
toggleLegend();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addMenuItem(graphPopupMenu, "Toggle scientific format", new ActionListener() {
|
String toggleGrid = (isShowGrid() ? "Hide" : "Show") + " grid";
|
||||||
@Override
|
addMenuItem(graphPopupMenu, toggleGrid, ee -> toggleShowGrid());
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
toggleScientificY(true);
|
addMenuItem(graphPopupMenu, "Toggle scientific format", ee -> toggleScientificY(true));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (FunctionArea.this.pointSetContainer.size() > 0) {
|
if (FunctionArea.this.pointSetContainer.size() > 0) {
|
||||||
addMenuItem(graphPopupMenu, "Recolor all graphs",
|
addMenuItem(graphPopupMenu, "Recolor all graphs", ee -> recolorAllGraphsByIndex());
|
||||||
new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
recolorAllGraphsByIndex();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refPointListener != null) {
|
if (refPointListener != null) {
|
||||||
DPoint temp = getDMeasures().getDPoint(xPos, yPos);
|
DPoint temp = getDMeasures().getDPoint(xPos, yPos);
|
||||||
addMenuItem(graphPopupMenu, "Select Reference Point:("
|
addMenuItem(graphPopupMenu, "Select Reference Point:("
|
||||||
+ temp.x + "/" + temp.y + ")",
|
+ temp.x + "/" + temp.y + ")",
|
||||||
new ActionListener() {
|
ee -> {
|
||||||
@Override
|
DPoint temp1 = getDMeasures().getDPoint(
|
||||||
public void actionPerformed(ActionEvent ee) {
|
xPos, yPos);
|
||||||
DPoint temp = getDMeasures().getDPoint(
|
double[] point = new double[2];
|
||||||
xPos, yPos);
|
point[0] = temp1.x;
|
||||||
double[] point = new double[2];
|
point[1] = temp1.y;
|
||||||
point[0] = temp.x;
|
refPointListener.refPointGiven(point);
|
||||||
point[1] = temp.y;
|
|
||||||
refPointListener.refPointGiven(point);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,20 +201,11 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
// the point info element
|
// the point info element
|
||||||
addMenuItem(graphPopupMenu, "Nearest point: ("
|
addMenuItem(graphPopupMenu, "Nearest point: ("
|
||||||
+ point.x + "/" + point.y + ")",
|
+ point.x + "/" + point.y + ")",
|
||||||
new ActionListener() {
|
ee -> {}, false);
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
addMenuItem(graphPopupMenu, " Remove point",
|
addMenuItem(graphPopupMenu, " Remove point",
|
||||||
new ActionListener() {
|
ee -> removePoint(FunctionArea.this.xPos,
|
||||||
@Override
|
FunctionArea.this.yPos));
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
removePoint(FunctionArea.this.xPos,
|
|
||||||
FunctionArea.this.yPos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (point.getIcon() instanceof InterfaceSelectablePointIcon) {
|
if (point.getIcon() instanceof InterfaceSelectablePointIcon) {
|
||||||
currentPointIcon = point.getIcon();
|
currentPointIcon = point.getIcon();
|
||||||
@ -251,27 +214,15 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
String selectTitle = indy.isMarked() ? " Deselect individual"
|
String selectTitle = indy.isMarked() ? " Deselect individual"
|
||||||
: " Select individual";
|
: " Select individual";
|
||||||
addMenuItem(graphPopupMenu, selectTitle,
|
addMenuItem(graphPopupMenu, selectTitle,
|
||||||
new ActionListener() {
|
ee -> ((InterfaceSelectablePointIcon) currentPointIcon).getSelectionListener().individualSelected(
|
||||||
@Override
|
((InterfaceSelectablePointIcon) currentPointIcon).getEAIndividual()));
|
||||||
public void actionPerformed(
|
|
||||||
ActionEvent ee) {
|
|
||||||
((InterfaceSelectablePointIcon) currentPointIcon).getSelectionListener().individualSelected(
|
|
||||||
((InterfaceSelectablePointIcon) currentPointIcon).getEAIndividual());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (point.getIcon() instanceof InterfaceDPointWithContent) {
|
if (point.getIcon() instanceof InterfaceDPointWithContent) {
|
||||||
currentPointIcon = point.getIcon();
|
currentPointIcon = point.getIcon();
|
||||||
addMenuItem(graphPopupMenu, " Show individual",
|
addMenuItem(graphPopupMenu, " Show individual",
|
||||||
new ActionListener() {
|
ee -> ((InterfaceDPointWithContent) currentPointIcon).showIndividual());
|
||||||
@Override
|
|
||||||
public void actionPerformed(
|
|
||||||
ActionEvent ee) {
|
|
||||||
((InterfaceDPointWithContent) currentPointIcon).showIndividual();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -282,46 +233,31 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
// e.getY());
|
// e.getY());
|
||||||
addMenuItem(graphPopupMenu, "Graph Info: "
|
addMenuItem(graphPopupMenu, "Graph Info: "
|
||||||
+ getGraphInfo(e.getX(), e.getY()),
|
+ getGraphInfo(e.getX(), e.getY()),
|
||||||
new ActionListener() {
|
ee -> {
|
||||||
@Override
|
DPoint temp = FunctionArea.this.getDMeasures().getDPoint(
|
||||||
public void actionPerformed(ActionEvent ee) {
|
FunctionArea.this.xPos,
|
||||||
DPoint temp = FunctionArea.this.getDMeasures().getDPoint(
|
FunctionArea.this.yPos);
|
||||||
FunctionArea.this.xPos,
|
DPointIcon icon1 = new DPointIcon() {
|
||||||
FunctionArea.this.yPos);
|
@Override
|
||||||
DPointIcon icon1 = new DPointIcon() {
|
public DBorder getDBorder() {
|
||||||
@Override
|
return new DBorder(4, 4, 4, 4);
|
||||||
public DBorder getDBorder() {
|
}
|
||||||
return new DBorder(4, 4, 4, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
g.drawLine(-2, 0, 2, 0);
|
g.drawLine(-2, 0, 2, 0);
|
||||||
g.drawLine(0, 0, 0, 4);
|
g.drawLine(0, 0, 0, 4);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
temp.setIcon(icon1);
|
temp.setIcon(icon1);
|
||||||
FunctionArea.this.addDElement(temp);
|
FunctionArea.this.addDElement(temp);
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
addMenuItem(graphPopupMenu, " Remove graph",
|
addMenuItem(graphPopupMenu, " Remove graph",
|
||||||
new ActionListener() {
|
ee -> clearGraph(FunctionArea.this.xPos, FunctionArea.this.yPos));
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
clearGraph(FunctionArea.this.xPos,
|
|
||||||
FunctionArea.this.yPos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addMenuItem(graphPopupMenu, " Change graph color",
|
addMenuItem(graphPopupMenu, " Change graph color",
|
||||||
new ActionListener() {
|
ee -> changeColorGraph(FunctionArea.this.xPos, FunctionArea.this.yPos));
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent ee) {
|
|
||||||
changeColorGraph(FunctionArea.this.xPos,
|
|
||||||
FunctionArea.this.yPos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
graphPopupMenu.show(FunctionArea.this, e.getX(), e.getY());
|
graphPopupMenu.show(FunctionArea.this, e.getX(), e.getY());
|
||||||
}
|
}
|
||||||
@ -1049,8 +985,7 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
if (!on) {
|
if (!on) {
|
||||||
legendBox = null;
|
legendBox = null;
|
||||||
} else {
|
} else {
|
||||||
legendBox = new GraphPointSetLegend(pointSetContainer,
|
legendBox = new GraphPointSetLegend(pointSetContainer, isAppendIndexInLegend());
|
||||||
isAppendIndexInLegend());
|
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
@ -1148,8 +1083,7 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
* Recreate the legend object with the current point sets.
|
* Recreate the legend object with the current point sets.
|
||||||
*/
|
*/
|
||||||
public void updateLegend() {
|
public void updateLegend() {
|
||||||
GraphPointSetLegend lb = new GraphPointSetLegend(pointSetContainer,
|
GraphPointSetLegend lb = new GraphPointSetLegend(pointSetContainer, isAppendIndexInLegend());
|
||||||
isAppendIndexInLegend());
|
|
||||||
setLegend(lb);
|
setLegend(lb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,24 +136,12 @@ public class GraphPointSetLegend {
|
|||||||
g.setColor(origCol);
|
g.setColor(origCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void paintIn(Graphics g, Dimension dim) {
|
|
||||||
// paintIn(g, dim.width);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void paintIn(Graphics g, Rectangle rect) {
|
|
||||||
// paintIn(g, rect.width);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void paintIn(Graphics g, DRectangle rect) {
|
|
||||||
// paintIn(g, (int)rect.width);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Called from FunctionArea
|
||||||
|
* @see FunctionArea#paint
|
||||||
*/
|
*/
|
||||||
public void paintIn(Graphics g, SlimRect rect) {
|
public void paintIn(Graphics g, SlimRect rect) {
|
||||||
paintIn(g, (int) rect.getX(), (int) rect.getY(), (int) rect.getX()
|
paintIn(g, (int) rect.getX(), (int) rect.getY(), (int) rect.getX() + (int) rect.getWidth());
|
||||||
+ (int) rect.getWidth());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,21 +152,35 @@ public class GraphPointSetLegend {
|
|||||||
*/
|
*/
|
||||||
private void paintIn(Graphics g, int x, int y, int maxX) {
|
private void paintIn(Graphics g, int x, int y, int maxX) {
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
// System.out.println("In LegendBox.paintIn!");
|
double fontHeightSum = 0.0;
|
||||||
int yOffs = 5 + y + fm.getHeight();
|
int yOffs = 5 + y + fm.getHeight();
|
||||||
int xOffs = x;
|
int xOffs;
|
||||||
|
int minX = Integer.MAX_VALUE;
|
||||||
|
int padding = 5;
|
||||||
Color origCol = g.getColor();
|
Color origCol = g.getColor();
|
||||||
|
|
||||||
|
// Draw bounding box
|
||||||
|
for (Pair<String, Color> legendEntry : legendEntries) {
|
||||||
|
Rectangle2D stringBounds = fm.getStringBounds(legendEntry.head, g);
|
||||||
|
minX = Math.min(minX, (int) (maxX - stringBounds.getWidth() - 15));
|
||||||
|
fontHeightSum += stringBounds.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
int boxHeight = (int)(fontHeightSum + padding * legendEntries.size());
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.fillRect(minX - 20, padding + y, maxX, boxHeight);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawRect(minX - 20, padding + y, maxX, boxHeight);
|
||||||
|
|
||||||
// avoid that an entry with identical label and color occurs multiple
|
// avoid that an entry with identical label and color occurs multiple
|
||||||
// times.
|
// times.
|
||||||
for (Pair<String, Color> legendEntry : legendEntries) {
|
for (Pair<String, Color> legendEntry : legendEntries) {
|
||||||
// System.out.println(legendEntries[i].toString() + "\tcontaines: "
|
|
||||||
// + set.contains(legendEntries[i]));
|
|
||||||
g.setColor(legendEntry.tail);
|
g.setColor(legendEntry.tail);
|
||||||
Rectangle2D stringBounds = fm.getStringBounds(legendEntry.head, g);
|
Rectangle2D stringBounds = fm.getStringBounds(legendEntry.head, g);
|
||||||
xOffs = (int) (maxX - stringBounds.getWidth() - 5);
|
xOffs = (int) (maxX - stringBounds.getWidth() - 10);
|
||||||
g.drawString(legendEntry.head, xOffs, yOffs);
|
g.drawString(legendEntry.head, xOffs, yOffs);
|
||||||
// g.drawString(legendEntries[i].head, 80, 80);
|
g.drawLine(xOffs - 20, yOffs - (int)(stringBounds.getHeight()/2) + 1, xOffs - padding, yOffs - (int)(stringBounds.getHeight()/2) + 1);
|
||||||
yOffs += (5 + stringBounds.getHeight());
|
yOffs += (padding + stringBounds.getHeight());
|
||||||
}
|
}
|
||||||
g.setColor(origCol);
|
g.setColor(origCol);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
// unite the point sets for a multirun
|
// unite the point sets for a multirun
|
||||||
for (int i = 0; i < fitnessGraph.length; i++) {
|
for (int i = 0; i < fitnessGraph.length; i++) {
|
||||||
for (int j = 0; j < fitnessGraph[i].length; j++) {
|
for (int j = 0; j < fitnessGraph[i].length; j++) {
|
||||||
|
// Shown in the legend of the plot window
|
||||||
statGraph[i][j].setInfoString(
|
statGraph[i][j].setInfoString(
|
||||||
(fitnessGraph[i][j].getInfo().length() > 0 ? (fitnessGraph[i][j].getInfo() + "_") : "")
|
(fitnessGraph[i][j].getInfo().length() > 0 ? (fitnessGraph[i][j].getInfo() + "_") : "")
|
||||||
+ "Mean_of_" + fullRuns + " ",
|
+ "Mean_of_" + fullRuns + " ",
|
||||||
|
@ -310,6 +310,13 @@ public class DArea extends JComponent implements DParent, Printable {
|
|||||||
return grid.isVisible();
|
return grid.isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle visibility of the grid
|
||||||
|
*/
|
||||||
|
public void toggleShowGrid() {
|
||||||
|
grid.toggleVisible();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paints the DArea by a Graphics object
|
* paints the DArea by a Graphics object
|
||||||
*
|
*
|
||||||
|
@ -157,4 +157,12 @@ public abstract class DComponent implements DElement {
|
|||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toggles visibility of the component
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void toggleVisible() {
|
||||||
|
setVisible(!isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,6 +22,8 @@ public interface DElement {
|
|||||||
|
|
||||||
boolean isVisible();
|
boolean isVisible();
|
||||||
|
|
||||||
|
void toggleVisible();
|
||||||
|
|
||||||
void setColor(Color color);
|
void setColor(Color color);
|
||||||
|
|
||||||
Color getColor();
|
Color getColor();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user