From d3a4ce5e2ee59f94f3e276b9ea31cb2fe2aed0cd Mon Sep 17 00:00:00 2001 From: Chinmaya Krishnan Mahesh Date: Wed, 19 Jun 2019 15:04:13 -0500 Subject: [PATCH 1/2] Initial JFreeChart port of Time Profile --- .../Tools/TimeProfile/TimeProfileWindow.java | 114 +++++++++--------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/src/projections/Tools/TimeProfile/TimeProfileWindow.java b/src/projections/Tools/TimeProfile/TimeProfileWindow.java index 2f092712..1e22e5d3 100644 --- a/src/projections/Tools/TimeProfile/TimeProfileWindow.java +++ b/src/projections/Tools/TimeProfile/TimeProfileWindow.java @@ -1,5 +1,6 @@ package projections.Tools.TimeProfile; +import java.awt.BorderLayout; import java.awt.Component; import java.awt.Cursor; import java.awt.GridBagConstraints; @@ -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; @@ -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; @@ -62,9 +74,7 @@ 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; @@ -72,8 +82,6 @@ public class TimeProfileWindow extends GenericGraphWindow 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 phaseMarkers = new TreeMap(); @@ -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); @@ -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); } @@ -557,24 +562,47 @@ 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 30) { + epName = epName.substring(0,30); + } + dataset.add(i, (double) graphData[i][ep], epName); + outputData[count++][i] = graphData[i][ep]; + } } } + 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()); + + XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, stackedRenderer); + + JFreeChart chart = new JFreeChart("Time Profile", plot); + ChartPanel chartPanel = new ChartPanel(chart); + // arbitrarily large size to prevent stretching of fonts + chartPanel.setMaximumDrawHeight(100000); + chartPanel.setMaximumDrawWidth(100000); + + - 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(); + graphPanel.removeAll(); + graphPanel.setLayout(new java.awt.BorderLayout()); + graphPanel.add(chartPanel, BorderLayout.CENTER); + graphPanel.validate(); + graphPanel.repaint(); + pack(); } } @@ -633,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); @@ -708,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"); - } - } } From 919ca138ab3f4172639dd36043d97c48ccf189ba Mon Sep 17 00:00:00 2001 From: Chinmaya Krishnan Mahesh Date: Thu, 20 Jun 2019 14:16:00 -0500 Subject: [PATCH 2/2] Disable shadows and anti-aliasing in JFreeChart TimeProfile --- src/projections/Tools/TimeProfile/TimeProfileWindow.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/projections/Tools/TimeProfile/TimeProfileWindow.java b/src/projections/Tools/TimeProfile/TimeProfileWindow.java index 1e22e5d3..a61936ef 100644 --- a/src/projections/Tools/TimeProfile/TimeProfileWindow.java +++ b/src/projections/Tools/TimeProfile/TimeProfileWindow.java @@ -586,10 +586,12 @@ private void setOutputGraphData() { 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);