aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2013-05-28 11:24:20 (EDT)
committerRoland Grunberg2013-05-29 13:34:16 (EDT)
commit0c7bf2973d55b93311e33e2d641c5880e4ef6dd7 (patch)
tree01a4854ae3c169cbfb70b2d7dca81aeb137e9349
parente95a05d8b5433240b630a710fedf996ddc33d71c (diff)
downloadorg.eclipse.linuxtools-0c7bf2973d55b93311e33e2d641c5880e4ef6dd7.zip
org.eclipse.linuxtools-0c7bf2973d55b93311e33e2d641c5880e4ef6dd7.tar.gz
org.eclipse.linuxtools-0c7bf2973d55b93311e33e2d641c5880e4ef6dd7.tar.bz2
Improvement to pie chart slice colours.refs/changes/82/13282/2
First 15 slices still use the statically-defined colours from IColorConstants, but later slices are now given randomized colours so as to make adjacent slices more visually distinct. Change-Id: Id932b214a4c220bad9eb796609b41fcabcd1e3a0 Reviewed-on: https://git.eclipse.org/r/13282 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java4
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java34
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java2
3 files changed, 36 insertions, 4 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 d21aa81..d065173 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
@@ -16,7 +16,7 @@ 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, 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),
@@ -60,7 +60,7 @@ public interface IColorsConstants {
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(51, 0, 204), new RGB(51, 0, 153), new RGB(51, 0, 102), new RGB(51, 0, 51), new RGB(51, 0, 0),*/
};
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 d25014e..90087f1 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,8 +10,12 @@
*******************************************************************************/
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;
@@ -20,6 +24,8 @@ 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);
@@ -70,7 +76,33 @@ public class PieChart extends Chart {
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)));
}
}
+
+ private 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 5c746ef..d323271 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
@@ -70,7 +70,7 @@ public class PieChartPaintListener implements PaintListener {
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.colorList.get(i)));
if (i == (nelemSeries - 1))
sweepAngle = 360 - incrementAngle;