From 0c7bf2973d55b93311e33e2d641c5880e4ef6dd7 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 28 May 2013 11:24:20 -0400 Subject: Improvement to pie chart slice colours. 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 IP-Clean: Roland Grunberg Tested-by: Roland Grunberg --- .../dataviewers/piechart/IColorsConstants.java | 4 +-- .../linuxtools/dataviewers/piechart/PieChart.java | 34 +++++++++++++++++++++- .../piechart/PieChartPaintListener.java | 2 +- 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 d21aa810e7..d065173e35 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 d25014efef..90087f169e 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 colorList = new ArrayList(); 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 5c746efce3..d3232711dc 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; -- cgit v1.2.3