1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs;
14
import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants;
15
import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.ScrollAdapter;
16
import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.DataPoint;
17
import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.NumberType;
18
import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite;
19
import org.eclipse.swt.graphics.Color;
20
import org.eclipse.swt.graphics.GC;
25
* A generic scatter plot implementation.
27
* @author Henry Hughes
29
public class ScatterGraph extends AGraph implements IScrollGraph {
31
* Default constructor for ScatterGraph. Simply invokes the constructor from <code>Graph</code>
32
* and fires the Update Event when its done, causing the graph to draw itself.
34
public ScatterGraph(GraphComposite parent, int style, String title, ScrollAdapter adapter) {
35
super(parent, style, title, adapter);
36
this.adapter = adapter;
41
public void paintElementList(GC gc) {
42
DataPoint[] points = new DataPoint[0];
44
Color temp = gc.getForeground();
45
Color temp1 = gc.getBackground();
48
double xSize = super.getSize().x - (super.getXPadding()<<1);
49
xSize /= (super.getLocalWidth());
50
double ySize = super.getSize().y - (super.getYPadding()<<1);
51
ySize /= (super.getLocalHeight());
55
for(int j=0; j<elementList.length; j++) {
56
points = elementList[j].toArray(points);
58
c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]);
62
for(DataPoint point:points) {
63
px = (point.x-super.getLocalXMin());
65
px += super.getXPadding() - (DIAMETER>>1);
67
py = super.getLocalYMax() - point.y;
69
py += super.getYPadding() - (DIAMETER>>1);
71
gc.fillOval((int)px, (int)py, DIAMETER, DIAMETER);
75
gc.setForeground(temp);
76
gc.setBackground(temp1);
80
public boolean isMultiGraph() {
81
return adapter.getSeriesCount() > 0;
85
* Updates the graph when the <code>IDataSet</code> has more data, adding the new samples to the graph.
88
public void handleUpdateEvent() {
89
if(null == adapter) return;
91
this.getDisplay().syncExec(new Runnable() {
94
Object[][] data = adapter.getData(removedItems, adapter.getRecordCount());
98
for(int j,i=0; i<adapter.getSeriesCount(); i++) {
99
elementList[i].clear(); //TODO: Only temparary
100
max = adapter.getYSeriesMax(i, removedItems, adapter.getRecordCount()).doubleValue() / 100;
101
for(j=0; j<data.length; j++) {
102
elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(),
103
NumberType.obj2num(data[j][i+1]).doubleValue() / max));
107
for(int j,i=0; i<adapter.getSeriesCount(); i++) {
108
elementList[i].clear(); //TODO: Only temparary
109
for(j=0; j<data.length; j++) {
110
elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(),
111
NumberType.obj2num(data[j][i+1]).doubleValue()));
120
private ScrollAdapter adapter;
121
public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.scattergraph"; //$NON-NLS-1$
122
private static final int DIAMETER = 5;