aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Stoffalette Joao2012-05-02 14:53:52 (EDT)
committerOtavio Pontes2012-05-07 11:39:53 (EDT)
commitce8794d35d256aad1eaefda71308dc54375320d2 (patch)
tree8938b139178e8a0355751b89a0f5c67a84ec1eaa
parentc5ea644e21b3cf7d6a0f50882604e8fc16a86a56 (diff)
downloadorg.eclipse.linuxtools-ce8794d35d256aad1eaefda71308dc54375320d2.zip
org.eclipse.linuxtools-ce8794d35d256aad1eaefda71308dc54375320d2.tar.gz
org.eclipse.linuxtools-ce8794d35d256aad1eaefda71308dc54375320d2.tar.bz2
This is a piechart implementation.
PieChart class extends Chart from SWTChart. It adds a PaintListener and a PieChartSeries methods. PieChartPaintListener implements a PaintListener, gets the PieSeriesArray and calculates the angles to draws the primitives in the paintControl method. IColorsConstants is an interface of swt.graphics.RGB colors.
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/.classpath7
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/.project28
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF12
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/build.properties4
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java215
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java50
-rw-r--r--profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java87
8 files changed, 410 insertions, 0 deletions
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/.classpath b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/.project b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.project
new file mode 100644
index 0000000..eaed9a8
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.linuxtools.dataviewers.piechart</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/.settings/org.eclipse.jdt.core.prefs b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..c537b63
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4f64706
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Piechart
+Bundle-SymbolicName: org.eclipse.linuxtools.dataviewers.piechart
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: IBM
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.swtchart
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.linuxtools.dataviewers.piechart
diff --git a/profiling/org.eclipse.linuxtools.dataviewers.piechart/build.properties b/profiling/org.eclipse.linuxtools.dataviewers.piechart/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
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
new file mode 100644
index 0000000..1cb6461
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/IColorsConstants.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Renato Stoffalette Joao <rsjoao@br.ibm.com>
+ *******************************************************************************/
+package org.eclipse.linuxtools.dataviewers.piechart;
+
+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),
+
+ };
+
+
+}
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
new file mode 100644
index 0000000..6a5b26a
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Renato Stoffalette Joao <rsjoao@br.ibm.com>
+ *******************************************************************************/
+package org.eclipse.linuxtools.dataviewers.piechart;
+
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+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 {
+
+ public PieChart(Composite parent, int style) {
+ super(parent, style);
+ for (Control child : getChildren()) {
+ if (child.getClass().getName().equals("org.swtchart.internal.axis.AxisTitle") ||
+ child.getClass().getName().equals("org.swtchart.internal.PlotArea")) {
+ child.setVisible(false); //Don't show original Plot Area and axis
+ }
+ }
+ this.addPaintListener(new PieChartPaintListener(this));
+ }
+
+ public void addPaintListener(PaintListener listener) {
+ if (!listener.getClass().getName().startsWith("org.swtchart.internal.axis"))
+ super.addPaintListener(listener);
+ }
+
+ public void addPieChartSeries(String labels[], double val[]) {
+ 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 [1];
+ d[0] = val[i];
+ s.setXSeries(d);
+ s.setBarColor(new Color(this.getDisplay(), IColorsConstants.COLORS[i]));
+ }
+ }
+}
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
new file mode 100644
index 0000000..2e35ef4
--- /dev/null
+++ b/profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Renato Stoffalette Joao <rsjoao@br.ibm.com>
+ *******************************************************************************/
+package org.eclipse.linuxtools.dataviewers.piechart;
+
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.swtchart.ISeries;
+
+public class PieChartPaintListener implements PaintListener {
+
+ private PieChart chart;
+
+ public PieChartPaintListener(PieChart chart) {
+ this.chart = chart;
+ }
+
+ public void paintControl(PaintEvent e) {
+ int nelemSeries = 0;
+ int sumTotal = 0;
+ double[] percentage = null;
+ double[] angle = null;
+ int sweepAngle=0;
+ int incrementAngle=0;
+ int initialAngle=90;
+ double[] series = this.getPieSeriesArray();
+ nelemSeries = series.length;
+ percentage = new double[nelemSeries];
+ angle = new double[nelemSeries];
+ for(int i = 0; i < nelemSeries; i++){
+ sumTotal += series[i];
+ }
+ float factor = 100 / sumTotal;
+ for(int i=0; i < nelemSeries; i++) {
+ percentage[i]= series[i] * factor;
+ angle[i] = (float) (percentage[i] * 3.6) ;
+
+ }
+ GC gc = e.gc;
+ Rectangle bounds = gc.getClipping();
+ Color[] colors = new Color[nelemSeries];
+ int pieWidth = Math.min(bounds.width, bounds.height)/2;
+ gc.setLineWidth(1);
+
+ for (int i=0; i < nelemSeries; i++) {
+ colors[i] = new Color(e.display, IColorsConstants.COLORS[i]);
+
+ sweepAngle = (int) Math.round(angle[i]);
+ gc.setBackground(colors[i]);
+
+ if (i==(nelemSeries-1)){
+ sweepAngle = 360 - incrementAngle;
+ gc.fillArc(bounds.width/3,bounds.height/4,pieWidth,pieWidth,initialAngle,(-sweepAngle));
+ gc.drawArc(bounds.width/3,bounds.height/4,pieWidth,pieWidth,initialAngle,(-sweepAngle));
+ }
+ gc.fillArc(bounds.width/3,bounds.height/4,pieWidth,pieWidth,initialAngle,(-sweepAngle));
+ gc.drawArc(bounds.width/3,bounds.height/4,pieWidth,pieWidth,initialAngle,(-sweepAngle));
+ incrementAngle +=sweepAngle;
+ initialAngle += (-sweepAngle);
+ }
+ }
+
+ private double[] getPieSeriesArray() {
+ ISeries series[] = this.chart.getSeriesSet().getSeries();
+ double result[] = new double[series.length];
+
+ for (int i=0; i<result.length; i++) {
+ double d[] = series[i].getXSeries();
+ if (d != null && d.length > 0)
+ result[i] = d[0];
+ else
+ result[i] = 0;
+ }
+
+ return result;
+ }
+}