use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.
the class StapGraph method drawAggregateView.
/**
* Draws nodes according to the name of the function (not accounting for
* call heirarchies). Uses colour to indicate the number of calls and size
* to indicate the percentage time spent.
*/
private void drawAggregateView() {
if (aggregateNodes == null) {
aggregateNodes = new ArrayList<>();
} else {
aggregateNodes.clear();
}
// -------------Format numbers
float percentage_time;
float percentage_count;
int maxTimesCalled = 0;
final int colorLevels = 15;
final int colorLevelDifference = 12;
int primary;
int secondary;
NumberFormat num = NumberFormat.getInstance(Locale.CANADA);
num.setMinimumFractionDigits(2);
num.setMaximumFractionDigits(2);
// FIND THE MOST TIMES A FUNCTION IS CALLED
for (int val : aggregateCount.values()) {
if (val > maxTimesCalled) {
maxTimesCalled = val;
}
}
// TEMPORARY STORAGE OF THE ENTRIES
// IMPLEMENTS A COMPARATOR TO STORE BY ORDER OF THE VALUE
TreeSet<Entry<String, Long>> sortedValues = new TreeSet<>(StapGraph.VALUE_ORDER);
HashMap<String, Long> tempMap = new HashMap<>();
tempMap.putAll(aggregateTime);
for (String key : tempMap.keySet()) {
long time = aggregateTime.get(key);
while (time < 0) {
time += endTime;
}
tempMap.put(key, time);
}
sortedValues.addAll(tempMap.entrySet());
// -------------Draw nodes
for (Entry<String, Long> ent : sortedValues) {
String key = ent.getKey();
GraphNode n = new GraphNode(this.getGraphModel(), SWT.NONE);
aggregateNodes.add(n);
percentage_count = (float) aggregateCount.get(key) / (float) maxTimesCalled;
percentage_time = ((float) ent.getValue() / this.getTotalTime() * 100);
n.setText(// $NON-NLS-1$
key + "\n" + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$
"\n" + aggregateCount.get(key) + // $NON-NLS-1$
"\n");
// $NON-NLS-1$
n.setData("AGGREGATE_NAME", key);
primary = (int) (percentage_count * colorLevels * colorLevelDifference);
secondary = (colorLevels * colorLevelDifference) - (int) (percentage_count * colorLevels * colorLevelDifference);
primary = Math.max(0, primary);
secondary = Math.max(0, secondary);
primary = Math.min(primary, 255);
secondary = Math.min(secondary, 255);
Color c = new Color(this.getDisplay(), primary, 0, secondary);
n.setBackgroundColor(c);
n.setHighlightColor(c);
n.setForegroundColor(new Color(this.getDisplay(), 255, 255, 255));
n.setTooltip(new Label(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("StapGraph.Func") + key + "\n" + Messages.getString("StapGraph.Time") + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"\n" + Messages.getString("StapGraph.NumOfCalls") + // $NON-NLS-1$
aggregateCount.get(key)));
n.setBorderWidth(2);
}
// Set layout to gridlayout
this.setLayoutAlgorithm(new AggregateLayoutAlgorithm(LayoutStyles.NONE, sortedValues, this.getTotalTime(), this.getBounds().width), true);
}
use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.
the class StapGraph method clearSelection.
/**
* Unhighlights all selected nodes and sets selection to null
*/
private void clearSelection() {
List<GraphNode> list = this.getSelection();
for (GraphNode n : list) {
if (n != null) {
n.unhighlight();
}
}
this.setSelection(null);
}
use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.
the class StapGraph method deleteAll.
/*
* Level/node management
*/
/**
* Delete all nodes except for the node with the specified nodeID
*
* @param exception
* - id of node NOT to delete (use -1 for 'no exceptions')
*/
private void deleteAll(int exception) {
// -------------Delete aggregate nodes
if (aggregateNodes != null) {
for (GraphNode n : aggregateNodes) {
n.dispose();
}
aggregateNodes.clear();
}
// -------------Save exception node's location
int x = -1;
int y = -1;
if (exception != -1 && nodeMap.get(exception) != null) {
x = nodeMap.get(exception).getLocation().x;
y = nodeMap.get(exception).getLocation().y;
}
// -------------Delete all nodes
for (StapNode node : nodeMap.values()) {
if (node == null) {
continue;
}
node.unhighlight();
node.dispose();
}
nodeMap.clear();
// -------------Recreate exception
if (x != -1 && y != -1) {
StapNode n = getNodeData(exception).makeNode(this);
n.setLocation(x, y);
n.highlight();
nodeMap.put(exception, n);
}
}
use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.
the class StapGraphMouseListener method getAggregateNodeFromSelection.
private GraphNode getAggregateNodeFromSelection() {
List<GraphNode> graphNodeList = graph.getSelection();
if (graphNodeList.isEmpty() || graphNodeList.size() != 1) {
graph.setSelection(null);
return null;
}
GraphNode node = null;
if (graphNodeList.get(0) != null) {
node = graphNodeList.remove(0);
} else {
graph.setSelection(null);
return null;
}
return node;
}
use of org.eclipse.zest.core.widgets.GraphNode in project linuxtools by eclipse.
the class StapGraphMouseListener method getNodeFromSelection.
private StapNode getNodeFromSelection() {
List<GraphNode> stapNodeList = graph.getSelection();
if (stapNodeList.isEmpty() || stapNodeList.size() != 1) {
graph.setSelection(null);
return null;
}
StapNode node = null;
if (stapNodeList.get(0) instanceof StapNode) {
node = (StapNode) stapNodeList.remove(0);
} else {
graph.setSelection(null);
return null;
}
return node;
}
Aggregations