diff options
10 files changed, 182 insertions, 43 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 e1c577b3a4..5bc1fed245 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 c0f8e7fc91..697701b703 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/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF index d0a33a8c2c..0e8fcce511 100644 --- a/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF +++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.linuxtools.dataviewers.piechart -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Vendor: %bundleProvider Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/pom.xml b/profiling/org.eclipse.linuxtools.dataviewers.piechart/pom.xml index 3f575b8b9c..f023bea780 100644 --- a/profiling/org.eclipse.linuxtools.dataviewers.piechart/pom.xml +++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/pom.xml @@ -18,7 +18,7 @@ </parent> <artifactId>org.eclipse.linuxtools.dataviewers.piechart</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <name>Linux Tools PieChart plug-in</name> 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 d9a3a6232a..57115710e4 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 @@ -26,7 +26,24 @@ public class PieChart extends Chart { protected List<RGB> colorList = new ArrayList<RGB>(); + /** + * A PieChart with no titles given to its pies. + * @param parent + * @param style + */ public PieChart(Composite parent, int style) { + this(parent, style, new String[0]); + } + + /** + * A PieChart with titles given to each pie it draws. + * @param parent The parent composite. + * @param style The style of the parent composite. + * @param labels The title of each pie chart that is to be drawn. + * A null / not present title indicates no title. + * @since 1.1 + */ + public PieChart(Composite parent, int style, String labels[]) { super(parent, style); Control plotArea = null; for (Control child : getChildren()) { @@ -37,7 +54,7 @@ public class PieChart extends Chart { plotArea = child; } } - this.addPaintListener(new PieChartPaintListener(this, plotArea)); + this.addPaintListener(new PieChartPaintListener(this, plotArea, labels)); } @Override @@ -47,9 +64,11 @@ public class PieChart extends Chart { } } - /* + /** * Add data to this Pie Chart. A single pie Chart will be drawn with the data provided. + * @deprecated see {@link #addPieChartSeries(String[], double[][])} */ + @Deprecated public void addPieChartSeries(String labels[], double val[]) { for (ISeries s : this.getSeriesSet().getSeries()) { this.getSeriesSet().deleteSeries(s.getId()); @@ -61,11 +80,12 @@ public class PieChart extends Chart { addPieChartSeries(labels, newVal); } - /* + /** * Add data to this Pie Chart. We'll build one pie chart for each value in the array provided. The val matrix must * have an array of an array of values. Ex. labels = {'a', 'b'} val = {{1,2,3}, {4,5,6}} This will create 3 pie * charts. For the first one, 'a' will be 1 and 'b' will be 4. For the second chart 'a' will be 2 and 'b' will be 5. * For the third 'a' will be 3 and 'b' will be 6. + * @param labels The titles of each series. (These are not the same as titles given to pies.) */ public void addPieChartSeries(String labels[], double val[][]) { for (ISeries s : this.getSeriesSet().getSeries()) { 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 5b6856da04..31752f059c 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,48 @@ *******************************************************************************/ 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); + + /** + * Draws pie charts with no titles given to each pie. + * @param chart + * @param plotArea + */ public PieChartPaintListener(PieChart chart, Control plotArea) { + this(chart, plotArea, new String[0]); + } + + /** + * Handles drawing & updating of a PieChart, with titles given to each of its pies. + * @param chart The PieChart to draw & update. + * @param plotArea The area in which to draw the pies. + * @param seriesNames The titles given to individual pies. + * @since 1.1 + */ + public PieChartPaintListener(PieChart chart, Control plotArea, String[] seriesNames) { this.chart = chart; this.plotArea = plotArea; + this.seriesNames = seriesNames; } @Override @@ -39,16 +64,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 +121,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 32b20f2caf..25ee92aa54 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 f5db7291b6..448a1200cb 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 c1e6223aac..c7a1389e60 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 2f0ddf4a46..4aef7194d1 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)) { |