Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java48
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java66
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java38
3 files changed, 73 insertions, 79 deletions
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java
index d21aa810e7..df40023ede 100644
--- a/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java
@@ -15,52 +15,8 @@ import org.eclipse.swt.graphics.RGB;
public interface IColorsConstants {
static final RGB[] COLORS = new RGB[] { new RGB(255, 0, 0), new RGB(0, 255, 0), new RGB(0, 0, 255),
new RGB(255, 255, 0), new RGB(255, 0, 255), new RGB(0, 255, 255), new RGB(255, 255, 255),
- new RGB(0, 100, 205), new RGB(100, 205, 0), new RGB(205, 0, 100), new RGB(0, 0, 0), new RGB(100, 255, 255),
- new RGB(255, 100, 255), new RGB(255, 255, 100), new RGB(255, 255, 255), new RGB(255, 255, 204),
- new RGB(255, 255, 153), new RGB(255, 255, 102), new RGB(255, 255, 51), new RGB(255, 255, 0),
- new RGB(255, 204, 255), new RGB(255, 204, 204), new RGB(255, 204, 153), new RGB(255, 204, 102),
- new RGB(255, 204, 51), new RGB(255, 204, 0), new RGB(255, 153, 255), new RGB(255, 153, 204),
- new RGB(255, 153, 153), new RGB(255, 153, 102), new RGB(255, 153, 51), new RGB(255, 153, 0),
- new RGB(255, 102, 255), new RGB(255, 102, 204), new RGB(255, 102, 153), new RGB(255, 102, 102),
- new RGB(255, 102, 51), new RGB(255, 102, 0), new RGB(255, 51, 255), new RGB(255, 51, 204),
- new RGB(255, 51, 153), new RGB(255, 51, 102), new RGB(255, 51, 51), new RGB(255, 51, 0),
- new RGB(255, 0, 255), new RGB(255, 0, 204), new RGB(255, 0, 153), new RGB(255, 0, 102),
- new RGB(255, 0, 51), new RGB(255, 0, 0), new RGB(204, 255, 255), new RGB(204, 255, 204),
- new RGB(204, 255, 153), new RGB(204, 255, 102), new RGB(204, 255, 51), new RGB(204, 255, 0),
- new RGB(204, 204, 255), new RGB(204, 204, 204), new RGB(204, 204, 153), new RGB(204, 204, 102),
- new RGB(204, 204, 51), new RGB(204, 204, 0), new RGB(204, 153, 255), new RGB(204, 153, 204),
- new RGB(204, 153, 153), new RGB(204, 153, 102), new RGB(204, 153, 51), new RGB(204, 153, 0),
- new RGB(204, 102, 255), new RGB(204, 102, 204), new RGB(204, 102, 153), new RGB(204, 102, 102),
- new RGB(204, 102, 51), new RGB(204, 102, 0), new RGB(204, 51, 255), new RGB(204, 51, 204),
- new RGB(204, 51, 153), new RGB(204, 51, 102), new RGB(204, 51, 51), new RGB(204, 51, 0),
- new RGB(204, 0, 255), new RGB(204, 0, 204), new RGB(204, 0, 153), new RGB(204, 0, 102),
- new RGB(204, 0, 51), new RGB(204, 0, 0), new RGB(153, 255, 255), new RGB(153, 255, 204),
- new RGB(153, 255, 153), new RGB(153, 255, 102), new RGB(153, 255, 51), new RGB(153, 255, 0),
- new RGB(153, 204, 255), new RGB(153, 204, 204), new RGB(153, 204, 153), new RGB(153, 204, 102),
- new RGB(153, 204, 51), new RGB(153, 204, 0), new RGB(153, 153, 255), new RGB(153, 153, 204),
- new RGB(153, 153, 153), new RGB(153, 153, 102), new RGB(153, 153, 51), new RGB(153, 153, 0),
- new RGB(153, 102, 255), new RGB(153, 102, 204), new RGB(153, 102, 153), new RGB(153, 102, 102),
- new RGB(153, 102, 51), new RGB(153, 102, 0), new RGB(153, 51, 255), new RGB(153, 51, 204),
- new RGB(153, 51, 153), new RGB(153, 51, 102), new RGB(153, 51, 51), new RGB(153, 51, 0),
- new RGB(153, 0, 255), new RGB(153, 0, 204), new RGB(153, 0, 153), new RGB(153, 0, 102),
- new RGB(153, 0, 51), new RGB(153, 0, 0), new RGB(102, 255, 255), new RGB(102, 255, 204),
- new RGB(102, 255, 153), new RGB(102, 255, 102), new RGB(102, 255, 51), new RGB(102, 255, 0),
- new RGB(102, 204, 255), new RGB(102, 204, 204), new RGB(102, 204, 153), new RGB(102, 204, 102),
- new RGB(102, 204, 51), new RGB(102, 204, 0), new RGB(102, 153, 255), new RGB(102, 153, 204),
- new RGB(102, 153, 153), new RGB(102, 153, 102), new RGB(102, 153, 51), new RGB(102, 153, 0),
- new RGB(102, 102, 255), new RGB(102, 102, 204), new RGB(102, 102, 153), new RGB(102, 102, 102),
- new RGB(102, 102, 51), new RGB(102, 102, 0), new RGB(102, 51, 255), new RGB(102, 51, 204),
- new RGB(102, 51, 153), new RGB(102, 51, 102), new RGB(102, 51, 51), new RGB(102, 51, 0),
- new RGB(102, 0, 255), new RGB(102, 0, 204), new RGB(102, 0, 153), new RGB(102, 0, 102),
- new RGB(102, 0, 51), new RGB(102, 0, 0), new RGB(51, 255, 255), new RGB(51, 255, 204),
- new RGB(51, 255, 153), new RGB(51, 255, 102), new RGB(51, 255, 51), new RGB(51, 255, 0),
- new RGB(51, 204, 255), new RGB(51, 204, 204), new RGB(51, 204, 153), new RGB(51, 204, 102),
- new RGB(51, 204, 51), new RGB(51, 204, 0), new RGB(51, 153, 255), new RGB(51, 153, 204),
- new RGB(51, 153, 153), new RGB(51, 153, 102), new RGB(51, 153, 51), new RGB(51, 153, 0),
- new RGB(51, 102, 255), new RGB(51, 102, 204), new RGB(51, 102, 153), new RGB(51, 102, 102),
- new RGB(51, 102, 51), new RGB(51, 102, 0), new RGB(51, 51, 255), new RGB(51, 51, 204),
- new RGB(51, 51, 153), new RGB(51, 51, 102), new RGB(51, 51, 51), new RGB(51, 51, 0), new RGB(51, 0, 255),
- new RGB(51, 0, 204), new RGB(51, 0, 153), new RGB(51, 0, 102), new RGB(51, 0, 51), new RGB(51, 0, 0),
+ new RGB(0, 100, 205), new RGB(0, 150, 100), new RGB(205, 0, 100), new RGB(0, 0, 0), new RGB(100, 255, 255),
+ new RGB(255, 100, 255)
};
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 d25014efef..d9a3a6232a 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
@@ -10,24 +10,29 @@
*******************************************************************************/
package org.eclipse.linuxtools.dataviewers.piechart;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
import org.swtchart.Chart;
import org.swtchart.IBarSeries;
import org.swtchart.ISeries;
public class PieChart extends Chart {
+ protected List<RGB> colorList = new ArrayList<RGB>();
+
public PieChart(Composite parent, int style) {
super(parent, style);
Control plotArea = null;
for (Control child : getChildren()) {
- if (child.getClass().getName().equals("org.swtchart.internal.axis.AxisTitle")) //$NON-NLS-1$
- child.setVisible(false); // Don't show original Plot Area and axis
- else if (child.getClass().getName().equals("org.swtchart.internal.PlotArea")) { //$NON-NLS-1$
+ if (child.getClass().getName().equals("org.swtchart.internal.axis.AxisTitle")) { //$NON-NLS-1$
+ child.setVisible(false); // Don't show original Plot Area and axis
+ } else if (child.getClass().getName().equals("org.swtchart.internal.PlotArea")) { //$NON-NLS-1$
child.setVisible(false); // Don't show original Plot Area and axis
plotArea = child;
}
@@ -37,19 +42,22 @@ public class PieChart extends Chart {
@Override
public void addPaintListener(PaintListener listener) {
- if (!listener.getClass().getName().startsWith("org.swtchart.internal.axis")) //$NON-NLS-1$
- super.addPaintListener(listener);
+ if (!listener.getClass().getName().startsWith("org.swtchart.internal.axis")) { //$NON-NLS-1$
+ super.addPaintListener(listener);
+ }
}
/*
* Add data to this Pie Chart. A single pie Chart will be drawn with the data provided.
*/
public void addPieChartSeries(String labels[], double val[]) {
- for (ISeries s : this.getSeriesSet().getSeries())
- this.getSeriesSet().deleteSeries(s.getId());
+ for (ISeries s : this.getSeriesSet().getSeries()) {
+ this.getSeriesSet().deleteSeries(s.getId());
+ }
double newVal[][] = new double[val.length][1];
- for (int i = 0; i < val.length; i++)
- newVal[i][0] = val[i];
+ for (int i = 0; i < val.length; i++) {
+ newVal[i][0] = val[i];
+ }
addPieChartSeries(labels, newVal);
}
@@ -60,17 +68,45 @@ public class PieChart extends Chart {
* For the third 'a' will be 3 and 'b' will be 6.
*/
public void addPieChartSeries(String labels[], double val[][]) {
- for (ISeries s : this.getSeriesSet().getSeries())
- this.getSeriesSet().deleteSeries(s.getId());
+ for (ISeries s : this.getSeriesSet().getSeries()) {
+ this.getSeriesSet().deleteSeries(s.getId());
+ }
int size = Math.min(labels.length, val.length);
for (int i = 0; i < size; i++) {
IBarSeries s = (IBarSeries) this.getSeriesSet().createSeries(ISeries.SeriesType.BAR, labels[i]);
double d[] = new double[val[i].length];
- for (int j = 0; j < val[i].length; j++)
- d[j] = val[i][j];
+ for (int j = 0; j < val[i].length; j++) {
+ d[j] = val[i][j];
+ }
s.setXSeries(d);
- s.setBarColor(new Color(this.getDisplay(), IColorsConstants.COLORS[i]));
+ s.setBarColor(new Color(this.getDisplay(), sliceColor(i)));
}
}
+
+ protected RGB sliceColor(int i) {
+ if (colorList.size() > i) {
+ return colorList.get(i);
+ }
+
+ RGB next;
+
+ if (colorList.size() < IColorsConstants.COLORS.length) {
+ next = IColorsConstants.COLORS[i];
+ }
+ else {
+ RGB prev = colorList.get(colorList.size()-1);
+ int mod = 192;
+ int red = (int) (mod * Math.random());
+ int green = (int) ((mod - red) * Math.random());
+ int blue = mod - red - green;
+ next = new RGB(0, 0, 0);
+ next.red = (prev.red + red) % 256;
+ next.green = (prev.green + green) % 256;
+ next.blue = (prev.blue + blue) % 256;
+ }
+
+ colorList.add(next);
+ return next;
+ }
}
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 5c746efce3..5b6856da04 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
@@ -16,7 +16,6 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
-
import org.swtchart.ISeries;
public class PieChartPaintListener implements PaintListener {
@@ -34,10 +33,11 @@ public class PieChartPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
Rectangle bounds;
- if (plotArea == null)
- bounds = gc.getClipping();
- else
- bounds = plotArea.getBounds();
+ if (plotArea == null) {
+ bounds = gc.getClipping();
+ } else {
+ bounds = plotArea.getBounds();
+ }
double[][] series = this.getPieSeriesArray();
int width = (bounds.width - bounds.x) / series.length;
int x = bounds.x;
@@ -62,19 +62,19 @@ public class PieChartPaintListener implements PaintListener {
int pieWidth = Math.min(bounds.width - X_GAP, bounds.height);
int pieX = bounds.x + (bounds.width - pieWidth) / 2;
int pieY = bounds.y + (bounds.height - pieWidth) / 2;
- if (sumTotal == 0)
- gc.drawOval(pieX, pieY, pieWidth, pieWidth);
- else {
+ if (sumTotal == 0) {
+ gc.drawOval(pieX, pieY, pieWidth, pieWidth);
+ } else {
double factor = 100 / sumTotal;
int sweepAngle = 0;
int incrementAngle = 0;
int initialAngle = 90;
for (int i = 0; i < nelemSeries; i++) {
- gc.setBackground(new Color(e.display, IColorsConstants.COLORS[i]));
+ gc.setBackground(new Color(e.display, chart.sliceColor(i)));
- if (i == (nelemSeries - 1))
- sweepAngle = 360 - incrementAngle;
- else {
+ if (i == (nelemSeries - 1)) {
+ sweepAngle = 360 - incrementAngle;
+ } else {
double angle = series[i] * factor * 3.6;
sweepAngle = (int) Math.round(angle);
}
@@ -88,17 +88,19 @@ public class PieChartPaintListener implements PaintListener {
private double[][] getPieSeriesArray() {
ISeries series[] = this.chart.getSeriesSet().getSeries();
- if (series == null || series.length == 0)
- return new double[0][0];
+ if (series == null || series.length == 0) {
+ return new double[0][0];
+ }
double result[][] = new double[series[0].getXSeries().length][series.length];
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result[i].length; j++) {
double d[] = series[j].getXSeries();
- if (d != null && d.length > 0)
- result[i][j] = d[i];
- else
- result[i][j] = 0;
+ if (d != null && d.length > 0) {
+ result[i][j] = d[i];
+ } else {
+ result[i][j] = 0;
+ }
}
}

Back to the top