Skip to content

Initial JFreeChart port of Time Profile #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 63 additions & 55 deletions src/projections/Tools/TimeProfile/TimeProfileWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package projections.Tools.TimeProfile;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
Expand All @@ -9,6 +10,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.util.*;

import javax.swing.JButton;
Expand All @@ -19,6 +21,16 @@
import javax.swing.JTabbedPane;
import javax.swing.SwingWorker;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StackedXYBarRenderer;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.data.xy.CategoryTableXYDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.labels.XYToolTipGenerator;

import projections.analysis.LogReader;
import projections.analysis.ProjMain;
import projections.analysis.TimedProgressThreadExecutor;
Expand Down Expand Up @@ -62,18 +74,14 @@ public class TimeProfileWindow extends GenericGraphWindow
private JMenuItem mDisplayLegend;
private JMenuItem mDisplayLegendFull;

private JCheckBox showMarkersCheckBox;
private JCheckBox analyzeSlopesCheckBox;
private JCheckBox hideMouseoversCheckBox;
private JPanel graphPanel;

private long intervalSize;
private int startInterval;
private int endInterval;

private long startTime;

private boolean displaySlopes = false;

// Markers that are drawn at certain times (doubles in units of x axis bins) to identify phases or iterations
private TreeMap<Double, String> phaseMarkers = new TreeMap<Double, String>();

Expand Down Expand Up @@ -102,6 +110,20 @@ public class TimeProfileWindow extends GenericGraphWindow
// here overhead, idle time
private final static int special = 2;


public class CustomToolTipGenerator implements XYToolTipGenerator {
CustomToolTipGenerator() {
super();
}

public String generateToolTip(XYDataset dataset, int row, int column) {
String name = "Entry Method Name: " + dataset.getSeriesKey(row) + ", ";
String execTime = "Time Interval: " + U.humanReadableString((column+startInterval)*intervalSize) + " to " + U.humanReadableString((column+startInterval+1)*intervalSize) + ", ";
String timeTaken = "Time taken: " + dataset.getXValue(row, column) + " microseconds";
return (String) name + execTime + timeTaken;
}
}

public TimeProfileWindow(MainWindow mainWindow) {
super("Projections Time Profile Graph - " + MainWindow.runObject[myRun].getFilename() + ".sts", mainWindow);

Expand Down Expand Up @@ -162,29 +184,12 @@ private void createLayout() {
setRanges = new JButton("Select New Range");
setRanges.addActionListener(this);

showMarkersCheckBox = new JCheckBox("Show Iteration/Phase Markers");
showMarkersCheckBox.setSelected(false);
showMarkersCheckBox.setToolTipText("Draw vertical lines at time associated with any user supplied notes containing\"***\"?");
showMarkersCheckBox.addActionListener(this);

analyzeSlopesCheckBox = new JCheckBox("Analyze slope");
analyzeSlopesCheckBox.setToolTipText("Select a point on the graph to measure the slope");
analyzeSlopesCheckBox.addActionListener(this);

hideMouseoversCheckBox = new JCheckBox("Hide Mouseovers");
hideMouseoversCheckBox.setSelected(false);
hideMouseoversCheckBox.setToolTipText("Disable the displaying of information associated with the data under the mouse pointer.");
hideMouseoversCheckBox.addActionListener(this);

controlPanel = new JPanel();
controlPanel.setLayout(gbl);
// Util.gblAdd(controlPanel, epSelection, gbc, 0,0, 1,1, 0,0);
Util.gblAdd(controlPanel, setRanges, gbc, 0,0, 1,1, 0,0);
Util.gblAdd(controlPanel, showMarkersCheckBox, gbc, 3,0, 1,1, 0,0);
Util.gblAdd(controlPanel, analyzeSlopesCheckBox, gbc, 4,0, 1,1, 0,0);
Util.gblAdd(controlPanel, hideMouseoversCheckBox, gbc, 5,0, 1,1, 0,0);

JPanel graphPanel = getMainPanel();
graphPanel = new JPanel();
Util.gblAdd(mainPanel, graphPanel, gbc, 0,0, 1,1, 1,1);
Util.gblAdd(mainPanel, controlPanel, gbc, 0,1, 1,0, 0,0);
}
Expand Down Expand Up @@ -555,24 +560,49 @@ private void setOutputGraphData() {
}
if (outSize > 0) {
// actually create and fill the data and color array
CategoryTableXYDataset dataset = new CategoryTableXYDataset();
int numIntervals = endInterval-startInterval+1;
outputData = new double[numIntervals][outSize];
outputData = new double[outSize][numIntervals];
for (int i=0; i<numIntervals; i++) {
int count = 0;
for (int ep=0; ep<numEPs+special; ep++) {
if (stateArray[ep]) {
outputData[i][count] = graphData[i][ep];
String epName = MainWindow.runObject[myRun].getEntryNameByIndex(ep);
if (epName.length() > 30) {
epName = epName.substring(0,30);
}
dataset.add(i, (double) graphData[i][ep], epName);
outputData[count++][i] = graphData[i][ep];

}
}

}

setYAxis("Percentage Utilization", "%");
String xAxisLabel = "Time (" + U.humanReadableString(intervalSize) + " resolution)";
setXAxis(xAxisLabel, "Time", startTime, intervalSize);
setDataSource("Time Profile", outputData, new TimeProfileColorer(outSize, numIntervals), thisWindow);
graphCanvas.setMarkers(phaseMarkers);
refreshGraph();
NumberAxis domainAxis = new NumberAxis("Bin");
domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
NumberAxis rangeAxis = new NumberAxis("Time in Microseconds");
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
StackedXYBarRenderer stackedRenderer = new StackedXYBarRenderer();
stackedRenderer.setDefaultToolTipGenerator((XYToolTipGenerator) new CustomToolTipGenerator());
stackedRenderer.setShadowVisible(false);

XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, stackedRenderer);

JFreeChart chart = new JFreeChart("Time Profile", plot);
chart.setAntiAlias(false);
ChartPanel chartPanel = new ChartPanel(chart);
// arbitrarily large size to prevent stretching of fonts
chartPanel.setMaximumDrawHeight(100000);
chartPanel.setMaximumDrawWidth(100000);



graphPanel.removeAll();
graphPanel.setLayout(new java.awt.BorderLayout());
graphPanel.add(chartPanel, BorderLayout.CENTER);
graphPanel.validate();
graphPanel.repaint();
pack();
}
}

Expand Down Expand Up @@ -631,20 +661,7 @@ public void actionPerformed(ActionEvent e) {
// } else


if (e.getSource() == analyzeSlopesCheckBox) {
if(analyzeSlopesCheckBox.isSelected()){
displaySlopes = true;
graphCanvas.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
} else {
displaySlopes = false;
graphCanvas.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
graphCanvas.clearPolynomial();
}
} else if (e.getSource() == showMarkersCheckBox){
graphCanvas.showMarkers(showMarkersCheckBox.isSelected());
} else if (e.getSource() == hideMouseoversCheckBox) {
graphCanvas.showBubble(! hideMouseoversCheckBox.isSelected());
} else if (e.getSource() == setRanges) {
if (e.getSource() == setRanges) {
showDialog();
} else if(e.getSource() == mDisplayLegend){
generateLegend(true);
Expand Down Expand Up @@ -706,18 +723,9 @@ private void createPolynomial(int xVal, int yVal){


public void toolMouseMovedResponse(MouseEvent e, int xVal, int yVal) {
if(displaySlopes){
createPolynomial(xVal, yVal);
}
}

public void toolClickResponse(MouseEvent e, int xVal, int yVal) {

if(displaySlopes){
// create a screenshot of the
JPanelToImage.saveToFileChooserSelection(graphCanvas, "Save Screenshot Image", "./TimeProfileScreenshot.png");
}

}

}