aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2013-11-12 10:24:54 (EST)
committerJeff Johnston2013-11-25 18:03:40 (EST)
commit64bbd5261020b9fe4f3297e7781133270962180d (patch)
tree986df9573d5701933df4ccb32fdd3d79d6f516e3
parentc4dde12d9db197c4bd39edc15b45ea5594f907bb (diff)
downloadorg.eclipse.linuxtools-64bbd5261020b9fe4f3297e7781133270962180d.zip
org.eclipse.linuxtools-64bbd5261020b9fe4f3297e7781133270962180d.tar.gz
org.eclipse.linuxtools-64bbd5261020b9fe4f3297e7781133270962180d.tar.bz2
Systemtap: Make improvents to graph display.refs/changes/97/18297/7
1) When capturing a script's output to display it in a graph, don't attempt to plot null or invalid values so as to avoid causing an error. 2) Add labels on individual pie charts to signify which series each pie represents. Also show a "No data" label when all pie charts are empty. Change-Id: I326f583ae7924c397e4771f2cc49fb605ff548a8 Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/18297 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> IP-Clean: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java13
-rwxr-xr-xprofiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/dialogs/ChartDialog.java2
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java7
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java41
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java15
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java48
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java56
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java8
8 files changed, 151 insertions, 39 deletions
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java
index e1c577b..5bc1fed 100755
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java
@@ -60,7 +60,13 @@ public class ChartFactory {
view = (ChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView(ChartView.VIEW_ID, String.valueOf(ChartView.getSecId()), IWorkbenchPage.VIEW_ACTIVATE);
- PieChart chart = new PieChart(view.getParent(), SWT.NONE);
+
+ String[] pieChartNames = new String [valFields.size()];
+ for (int i = 0; i < valFields.size(); i++) {
+ pieChartNames[i] = valFields.get(i).getColumnHeaderText();
+ }
+
+ PieChart chart = new PieChart(view.getParent(), SWT.NONE, pieChartNames);
chart.setBackground(WHITE);
chart.setBackgroundInPlotArea(GRAD);
@@ -75,11 +81,6 @@ public class ChartFactory {
valueLabels[i] = nameField.getValue(objects[i]);
}
- /*
- * String [] pieChartNames = new String [valFields.size()]; for (int i = 0; i < valFields.size(); i++) {
- * pieChartNames[i] = valFields.get(i).getColumnHeaderText(); }
- */
-
// pie chart data is grouped by columns
// row size is the number of pie charts
// column size is the number of data per pie chart
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/dialogs/ChartDialog.java b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/dialogs/ChartDialog.java
index c0f8e7f..697701b 100755
--- a/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/dialogs/ChartDialog.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/internal/dataviewers/charts/dialogs/ChartDialog.java
@@ -43,7 +43,7 @@ import org.eclipse.swt.widgets.Text;
import org.swtchart.Chart;
/**
- * The dialog used to customize the chart before cerating it.
+ * The dialog used to customize the chart before creating it.
*/
public class ChartDialog extends Dialog {
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java
index d9a3a62..adabc5f 100644
--- a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java
@@ -27,6 +27,10 @@ public class PieChart extends Chart {
protected List<RGB> colorList = new ArrayList<RGB>();
public PieChart(Composite parent, int style) {
+ this(parent, style, new String[0]);
+ }
+
+ public PieChart(Composite parent, int style, String labels[]) {
super(parent, style);
Control plotArea = null;
for (Control child : getChildren()) {
@@ -37,7 +41,7 @@ public class PieChart extends Chart {
plotArea = child;
}
}
- this.addPaintListener(new PieChartPaintListener(this, plotArea));
+ this.addPaintListener(new PieChartPaintListener(this, plotArea, labels));
}
@Override
@@ -50,6 +54,7 @@ public class PieChart extends Chart {
/*
* Add data to this Pie Chart. A single pie Chart will be drawn with the data provided.
*/
+ @Deprecated
public void addPieChartSeries(String labels[], double val[]) {
for (ISeries s : this.getSeriesSet().getSeries()) {
this.getSeriesSet().deleteSeries(s.getId());
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java
index 5b6856d..50cc59b 100644
--- a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java
@@ -10,23 +10,36 @@
*******************************************************************************/
package org.eclipse.linuxtools.dataviewers.piechart;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.swtchart.ISeries;
public class PieChartPaintListener implements PaintListener {
private PieChart chart;
private Control plotArea;
+ private String[] seriesNames;
private static final int X_GAP = 10;
+ protected static final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+ protected static final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
+
public PieChartPaintListener(PieChart chart, Control plotArea) {
+ this(chart, plotArea, new String[0]);
+ }
+
+ public PieChartPaintListener(PieChart chart, Control plotArea, String[] seriesNames) {
this.chart = chart;
this.plotArea = plotArea;
+ this.seriesNames = seriesNames;
}
@Override
@@ -39,16 +52,28 @@ public class PieChartPaintListener implements PaintListener {
bounds = plotArea.getBounds();
}
double[][] series = this.getPieSeriesArray();
+ if (series.length == 0) {
+ Rectangle allBounds = chart.getBounds();
+ Font font = new Font(Display.getDefault(), "Arial", 15, SWT.BOLD); //$NON-NLS-1$
+ gc.setForeground(BLACK);
+ gc.setFont(font);
+ String text = "No data"; //$NON-NLS-1$
+ Point textSize = e.gc.textExtent(text);
+ gc.drawText(text, (allBounds.width - textSize.x) / 2, (allBounds.height - textSize.y) / 2);
+ font.dispose();
+ return;
+ }
int width = (bounds.width - bounds.x) / series.length;
int x = bounds.x;
- for (double s[] : series) {
- drawPieChart(e, s, new Rectangle(x, bounds.y, width, bounds.height));
+ for (int i = 0; i < series.length; i++) {
+ double[] s = series[i];
+ drawPieChart(e, i, s, new Rectangle(x, bounds.y, width, bounds.height));
x += width;
}
}
- private void drawPieChart(PaintEvent e, double series[], Rectangle bounds) {
+ private void drawPieChart(PaintEvent e, int chartnum, double series[], Rectangle bounds) {
int nelemSeries = series.length;
double sumTotal = 0;
@@ -84,6 +109,16 @@ public class PieChartPaintListener implements PaintListener {
initialAngle += (-sweepAngle);
}
}
+ if (chartnum < seriesNames.length) {
+ Font font = new Font(Display.getDefault(), "Arial", 15, SWT.BOLD); //$NON-NLS-1$
+ gc.setForeground(BLACK);
+ gc.setBackground(WHITE);
+ gc.setFont(font);
+ String text = seriesNames[chartnum];
+ Point textSize = e.gc.textExtent(text);
+ gc.drawText(text, pieX + (pieWidth - textSize.x) / 2, pieY + pieWidth + textSize.y);
+ font.dispose();
+ }
}
private double[][] getPieSeriesArray() {
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java
index 32b20f2..25ee92a 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java
@@ -169,14 +169,21 @@ public abstract class AbstractChartBuilder extends Composite implements IUpdateL
handleUpdateEvent();
}
- protected double getDoubleValue(Object o) {
+ protected Double getDoubleValue(Object o) {
+ if (o == null) {
+ return null;
+ }
if (o instanceof Integer) {
- return ((Integer)o).intValue();
+ return ((Integer)o).doubleValue();
}
if (o instanceof Double) {
- return ((Double)o).doubleValue();
+ return (Double) o;
+ }
+ try {
+ return new Double(o.toString());
+ } catch (NumberFormatException e) {
+ return null;
}
- return new Double(o.toString()).doubleValue();
}
@Override
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java
index f5db729..448a120 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java
@@ -95,32 +95,56 @@ public abstract class AbstractChartWithAxisBuilder extends AbstractChartBuilder
return;
int totalMaxItems = (int)Math.round(this.maxItems * scale);
- int start = 0, len = Math.min(totalMaxItems, data.length);
+ int start = 0, len = Math.min(totalMaxItems, data.length), leny = data[0].length-1;
if (totalMaxItems < data.length) {
start = data.length - totalMaxItems;
}
- double[] valx = new double[len];
- double[][] valy = new double[data[0].length-1][len];
+ Double[] all_valx = new Double[len];
+ Double[][] all_valy = new Double[leny][len];
ISeries allSeries[] = chart.getSeriesSet().getSeries();
- for (int i = 0; i < valx.length; i++)
- for (int j = 0; j < data[start + i].length; j++) {
- if (j == 0)
- valx[i] = getDoubleValue(data[start + i][j]);
- else
- valy[j-1][i] = getDoubleValue(data[start + i][j]);
+ for (int i = 0; i < len; i++) {
+ for (int j = 0; j < leny + 1; j++) {
+ Double val = getDoubleValue(data[start + i][j]);
+ if (j == 0) {
+ if (val != null) {
+ all_valx[i] = val;
+ } else {
+ break;
+ }
+ } else if (val != null) {
+ all_valy[j-1][i] = val;
+ }
}
+ }
- for (int i = 0; i < valy.length; i++) {
+ for (int i = 0; i < leny; i++) {
ISeries series;
if (i >= allSeries.length) {
series = createChartISeries(i);
} else {
series = chart.getSeriesSet().getSeries()[i];
}
- series.setXSeries(valx);
- series.setYSeries(valy[i]);
+
+ double[] valx = new double[len];
+ double[] valy = new double[len];
+ int len_trim = 0;
+ for (int j = 0; j < len; j++) {
+ if (all_valx[j] != null && all_valy[i][j] != null) {
+ valx[len_trim] = all_valx[j].doubleValue();
+ valy[len_trim] = all_valy[i][j].doubleValue();
+ len_trim++;
+ }
+ }
+ double[] valx_trim = new double[len_trim];
+ double[] valy_trim = new double[len_trim];
+ for (int j = 0; j < len_trim; j++) {
+ valx_trim[j] = valx[j];
+ valy_trim[j] = valy[j];
+ }
+ series.setXSeries(valx_trim);
+ series.setYSeries(valy_trim);
}
chart.getAxisSet().adjustRange();
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java
index c1e6223..c7a1389 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java
@@ -22,13 +22,18 @@ import org.eclipse.swt.widgets.Composite;
public class PieChartBuilder extends AbstractChartWithoutAxisBuilder {
public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.piechartbuilder"; //$NON-NLS-1$
- public PieChartBuilder(Composite parent, int style, String title,IAdapter adapter) {
+ public PieChartBuilder(Composite parent, int style, String title, IAdapter adapter) {
super(adapter, parent, style, title);
}
@Override
protected void createChart() {
- this.chart = new PieChart(this, getStyle());
+ String[] allNames = adapter.getLabels();
+ String[] ySeriesNames = new String[allNames.length - 1];
+ for (int i = 0; i < ySeriesNames.length; i++) {
+ ySeriesNames[i] = allNames[i+1];
+ }
+ this.chart = new PieChart(this, getStyle(), ySeriesNames);
}
@Override
@@ -37,23 +42,54 @@ public class PieChartBuilder extends AbstractChartWithoutAxisBuilder {
if (data == null || data.length == 0 || data[0].length == 0)
return;
- int start = 0, len = Math.min(this.maxItems, data.length);
+ int start = 0, len = Math.min(this.maxItems, data.length), leny = data[0].length-1;
if (this.maxItems < data.length) {
start = data.length - this.maxItems;
}
- double[][] values = new double[len][data[0].length-1];
- String[] labels = new String[len];
+ Double[][] all_values = new Double[len][leny];
+ String[] all_labels = new String[len];
- for (int i = 0; i < labels.length; i++) {
+ for (int i = 0; i < all_labels.length; i++) {
if (data[i].length < 2)
return;
- labels[i] = data[start + i][0].toString();
- for (int j = 1; j < data[start + i].length; j++)
- values[i][j-1] = getDoubleValue(data[start + i][j]);
+ Object label = data[start + i][0];
+ if (label != null) {
+ all_labels[i] = data[start + i][0].toString();
+ for (int j = 1; j < data[start + i].length; j++) {
+ Double val = getDoubleValue(data[start + i][j]);
+ if (val != null) {
+ all_values[i][j-1] = val;
+ } else {
+ all_labels[i] = null;
+ break;
+ }
+ }
+ }
+ }
+
+ double[][] values = new double[len][leny];
+ String[] labels = new String[len];
+ int len_trim = 0;
+ for (int i = 0; i < len; i++) {
+ if (all_labels[i] != null) {
+ labels[len_trim] = all_labels[i];
+ for (int j = 0; j < leny; j++) {
+ values[len_trim][j] = all_values[i][j].doubleValue();
+ }
+ len_trim++;
+ }
+ }
+ double[][] values_trim = new double[len_trim][leny];
+ String[] labels_trim = new String[len_trim];
+ for (int i = 0; i < len_trim; i++) {
+ labels_trim[i] = labels[i];
+ for (int j = 0; j < leny; j++) {
+ values_trim[i][j] = values[i][j];
+ }
}
- ((PieChart)this.chart).addPieChartSeries(labels, values);
+ ((PieChart)this.chart).addPieChartSeries(labels_trim, values_trim);
chart.redraw();
}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java
index 2f0ddf4..4aef719 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java
@@ -291,8 +291,12 @@ public class DataGrid implements IUpdateListener {
os = filteredDataSet.getRow(i);
item.setText(0, "" + i); //$NON-NLS-1$
- for(j=0; j<os.length; j++)
- item.setText(j+1, columnFormat[j].format(os[j].toString()));
+ for(j=0; j<os.length; j++) {
+ //Ignore null items
+ if (os[j] != null) {
+ item.setText(j+1, columnFormat[j].format(os[j].toString()));
+ }
+ }
}
if(FULL_UPDATE != (style & FULL_UPDATE)) {