~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/ScatterGraph.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
 
 *******************************************************************************/
11
 
 
12
 
package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs;
13
 
 
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;
21
 
 
22
 
 
23
 
 
24
 
/**
25
 
 * A generic scatter plot implementation.
26
 
 * @author Ryan Morse
27
 
 * @author Henry Hughes
28
 
 */
29
 
public class ScatterGraph extends AGraph implements IScrollGraph {
30
 
        /**
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.
33
 
         */
34
 
        public ScatterGraph(GraphComposite parent, int style, String title, ScrollAdapter adapter) {
35
 
                super(parent, style, title, adapter);
36
 
                this.adapter = adapter;
37
 
                handleUpdateEvent();
38
 
        }
39
 
 
40
 
        @Override
41
 
        public void paintElementList(GC gc) {
42
 
                DataPoint[] points = new DataPoint[0];
43
 
 
44
 
                Color temp = gc.getForeground();
45
 
                Color temp1 = gc.getBackground();
46
 
                Color c;
47
 
 
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());
52
 
 
53
 
                double px, py;
54
 
 
55
 
                for(int j=0; j<elementList.length; j++) {
56
 
                        points = elementList[j].toArray(points);
57
 
 
58
 
                        c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]);
59
 
                        gc.setForeground(c);
60
 
                        gc.setBackground(c);
61
 
 
62
 
                        for(DataPoint point:points) {
63
 
                                px = (point.x-super.getLocalXMin());
64
 
                                px *= xSize;
65
 
                                px += super.getXPadding() - (DIAMETER>>1);
66
 
 
67
 
                                py = super.getLocalYMax() - point.y;
68
 
                                py *= ySize;
69
 
                                py += super.getYPadding() - (DIAMETER>>1);
70
 
 
71
 
                                gc.fillOval((int)px, (int)py, DIAMETER, DIAMETER);
72
 
                        }
73
 
                }
74
 
 
75
 
                gc.setForeground(temp);
76
 
                gc.setBackground(temp1);
77
 
        }
78
 
 
79
 
        @Override
80
 
        public boolean isMultiGraph() {
81
 
                return adapter.getSeriesCount() > 0;
82
 
        }
83
 
 
84
 
        /**
85
 
         * Updates the graph when the <code>IDataSet</code> has more data, adding the new samples to the graph.
86
 
         */
87
 
        @Override
88
 
        public void handleUpdateEvent() {
89
 
                if(null == adapter) return;
90
 
 
91
 
                this.getDisplay().syncExec(new Runnable() {
92
 
                        @Override
93
 
                        public void run() {
94
 
                                Object[][] data = adapter.getData(removedItems, adapter.getRecordCount());
95
 
 
96
 
                                if(normalize) {
97
 
                                        double max;
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));
104
 
                                                }
105
 
                                        }
106
 
                                } else {
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()));
112
 
                                                }
113
 
                                        }
114
 
                                }
115
 
                        }
116
 
                });
117
 
                this.repaint();
118
 
        }
119
 
 
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;
123
 
}