[Swift-commit] r7067 - trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Mon Sep 16 02:02:29 CDT 2013
Author: hategan
Date: 2013-09-16 02:02:28 -0500 (Mon, 16 Sep 2013)
New Revision: 7067
Modified:
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphPanel.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphsPanel.java
Log:
set a maximum range for graphs since jfreechart becomes very slow when there is a lot of data; also add a slider to control the maximum range
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphPanel.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphPanel.java 2013-09-16 07:01:03 UTC (rev 7066)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphPanel.java 2013-09-16 07:02:28 UTC (rev 7067)
@@ -54,9 +54,12 @@
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
+import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.ChartChangeEvent;
import org.jfree.chart.event.ChartChangeEventType;
import org.jfree.chart.event.ChartChangeListener;
+import org.jfree.chart.event.PlotChangeEvent;
+import org.jfree.chart.event.PlotChangeListener;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.Range;
@@ -71,6 +74,7 @@
public static final DateFormat DATE = DateFormat.getDateInstance();
public static final DateFormat TIME = DateFormat.getTimeInstance();
+
private SystemState state;
private DataSampler sampler;
private JFreeChart chart;
@@ -84,6 +88,7 @@
private TimerTask tooltipTimerTask;
private JToolTip toolTip;
private double toolTipValue;
+ private int maxRange;
public GraphPanel(SystemState state, GraphsPanel gp) {
this.state = state;
@@ -122,6 +127,7 @@
@Override
public void chartChanged(ChartChangeEvent e) {
if (e.getType() == ChartChangeEventType.DATASET_UPDATED) {
+ updateMaxRange();
updateToolTipLocation();
}
}
@@ -490,7 +496,23 @@
gp.saveLayout();
}
}
+
+ public void setMaxRange(int value) {
+ this.maxRange = value;
+ updateMaxRange();
+ }
+ private void updateMaxRange() {
+ ValueAxis x = chart.getXYPlot().getDomainAxis();
+ if (maxRange == 0) {
+ x.setAutoRange(true);
+ }
+ else {
+ Range dr = chart.getXYPlot().getDataRange(x);
+ x.setRange(Math.max(dr.getLowerBound(), dr.getUpperBound() - maxRange * 60 * 1000), dr.getUpperBound());
+ }
+ }
+
public void store(Preferences p) {
p.putInt("enabledCount", enabled.size());
for (int i = 0; i < enabled.size(); i++) {
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphsPanel.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphsPanel.java 2013-09-16 07:01:03 UTC (rev 7066)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GraphsPanel.java 2013-09-16 07:02:28 UTC (rev 7067)
@@ -19,10 +19,14 @@
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
+import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
import org.griphyn.vdl.karajan.monitor.SystemState;
import org.griphyn.vdl.karajan.monitor.common.DataSampler;
@@ -30,6 +34,9 @@
import org.griphyn.vdl.karajan.monitor.monitors.swing.GridView.Tree;
public class GraphsPanel extends JPanel {
+ public static final int RANGE_MIN = 1;
+ public static final int RANGE_MAX = 4 * 60 + 1;
+
private static final int V = GridView.Tree.V;
private static final int H = GridView.Tree.H;
@@ -81,6 +88,8 @@
private JPopupMenu layoutPopup;
private LinkedList<GraphPanel> graphs;
private GridView grid;
+ private JSlider rangeSlider;
+ private JLabel rangeLabel;
public GraphsPanel(SystemState state) {
this.state = state;
@@ -99,8 +108,20 @@
@Override
public void actionPerformed(ActionEvent e) {
displayLayoutPopup(layout);
+ }
+ });
+
+ toolBar.add(new JLabel("Max. range: "));
+ toolBar.add(rangeSlider = new JSlider(JSlider.HORIZONTAL, RANGE_MIN, RANGE_MAX, 30));
+ rangeSlider.addChangeListener(new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ setGraphRanges(rangeSlider.getValue());
}
});
+ toolBar.add(rangeSlider);
+ toolBar.add(rangeLabel = new JLabel("00:01"));
+ setGraphRanges(rangeSlider.getValue());
makeLayoutPopup();
@@ -110,6 +131,33 @@
loadLayout();
}
+ protected void setGraphRanges(int value) {
+ if (value == RANGE_MAX) {
+ rangeLabel.setText("unlimited");
+ for (GraphPanel gp : graphs) {
+ gp.setMaxRange(0);
+ }
+ }
+ else {
+ int mins = value / 60;
+ int secs = value % 60;
+
+ rangeLabel.setText(pad(mins) + ":" + pad(secs));
+ for (GraphPanel gp : graphs) {
+ gp.setMaxRange(value);
+ }
+ }
+ }
+
+ private String pad(int ms) {
+ if (ms < 10) {
+ return "0" + ms;
+ }
+ else {
+ return String.valueOf(ms);
+ }
+ }
+
private void makeLayoutPopup() {
layoutPopup = new JPopupMenu();
JMenu crt = null;
More information about the Swift-commit
mailing list