12
12
*******************************************************************************/
13
13
package org .eclipse .swtchart .extensions .marker ;
14
14
15
- import java .math .BigDecimal ;
16
15
import java .util .Arrays ;
17
16
18
17
import org .eclipse .swt .SWT ;
19
18
import org .eclipse .swt .events .PaintEvent ;
20
19
import org .eclipse .swt .graphics .GC ;
21
20
import org .eclipse .swt .graphics .Rectangle ;
22
21
import org .eclipse .swt .widgets .Display ;
22
+ import org .eclipse .swtchart .IAxis ;
23
23
import org .eclipse .swtchart .ISeries ;
24
24
import org .eclipse .swtchart .ISeriesSet ;
25
25
import org .eclipse .swtchart .extensions .core .BaseChart ;
26
- import org .eclipse .swtchart .IAxis ;
27
26
28
27
public class BoxPlotMarker extends AbstractBaseChartPaintListener implements IBaseChartPaintListener {
29
28
@@ -35,6 +34,7 @@ public BoxPlotMarker(BaseChart baseChart) {
35
34
@ SuppressWarnings ("unused" )
36
35
@ Override
37
36
public void paintControl (PaintEvent e ) {
37
+
38
38
BaseChart baseChart = getBaseChart ();
39
39
ISeriesSet seriesSet = baseChart .getSeriesSet ();
40
40
GC gc = e .gc ;
@@ -52,64 +52,63 @@ public void paintControl(PaintEvent e) {
52
52
int xMax = 0 ;
53
53
int yMin = 0 ;
54
54
int yMax = 0 ;
55
- for (; index < xData .length ; index ++) {
55
+ for (; index < xData .length ; index ++) {
56
56
int x = xAxis .getPixelCoordinate (xData [index ], xLower , xUpper );
57
57
int y = yAxis .getPixelCoordinate (yData [index ], yLower , yUpper );
58
- if (0 == index ) {
59
- xMin = x ;
60
- xMax = x ;
61
- yMin = y ;
62
- yMax = y ;
58
+ if (0 == index ) {
59
+ xMin = x ;
60
+ xMax = x ;
61
+ yMin = y ;
62
+ yMax = y ;
63
63
} else {
64
- if (x > xMax ) {
64
+ if (x > xMax ) {
65
65
xMax = x ;
66
66
}
67
- if (x < xMin ) {
67
+ if (x < xMin ) {
68
68
xMin = x ;
69
69
}
70
- if (y > yMax ) {
70
+ if (y > yMax ) {
71
71
yMax = y ;
72
72
}
73
- if (y < yMin ) {
73
+ if (y < yMin ) {
74
74
yMin = y ;
75
75
}
76
- }
76
+ }
77
77
}
78
78
Arrays .sort (yData );
79
- double q1 = getValue (0.25 , yData );
80
- double q2 = getValue (0.50 , yData );
81
- double q3 = getValue (0.75 , yData );
79
+ double q1 = getValue (0.25 , yData );
80
+ double q2 = getValue (0.50 , yData );
81
+ double q3 = getValue (0.75 , yData );
82
82
int q1Y = yAxis .getPixelCoordinate (q1 , yLower , yUpper );
83
83
int q2Y = yAxis .getPixelCoordinate (q2 , yLower , yUpper );
84
84
int q3Y = yAxis .getPixelCoordinate (q3 , yLower , yUpper );
85
-
86
- Rectangle rectangle = new Rectangle (xMin , q1Y , xMax -xMin , q3Y -q1Y );
85
+ Rectangle rectangle = new Rectangle (xMin , q1Y , xMax - xMin , q3Y - q1Y );
87
86
gc .setLineStyle (SWT .LINE_SOLID );
88
87
gc .setLineWidth (2 );
89
88
gc .setBackground (Display .getDefault ().getSystemColor (SWT .COLOR_YELLOW ));
90
89
gc .setForeground (Display .getDefault ().getSystemColor (SWT .COLOR_BLACK ));
91
90
gc .setAlpha (100 );
92
- gc .fillRectangle (xMin , q1Y , xMax - xMin , q3Y - q1Y );
93
- gc .drawRectangle (xMin , q1Y , xMax - xMin , q3Y - q1Y );
91
+ gc .fillRectangle (xMin , q1Y , xMax - xMin , q3Y - q1Y );
92
+ gc .drawRectangle (xMin , q1Y , xMax - xMin , q3Y - q1Y );
94
93
gc .drawLine (xMin , yMin , xMax , yMin );
95
94
gc .drawLine (xMin , yMax , xMax , yMax );
96
95
gc .drawLine (xMin + (xMax - xMin ) / 2 , yMin , xMin + (xMax - xMin ) / 2 , q3Y );
97
96
gc .drawLine (xMin + (xMax - xMin ) / 2 , yMax , xMin + (xMax - xMin ) / 2 , q1Y );
98
- gc .drawLine (xMin , q2Y , xMax , q2Y );
97
+ gc .drawLine (xMin , q2Y , xMax , q2Y );
99
98
}
100
-
101
99
}
102
-
103
-
100
+
104
101
public int getIndex (double rate , int size ) {
102
+
105
103
/**
106
104
* This index is just an approximation and I will modify it.
107
105
*/
108
- int index = (int )(rate * (size +1 ));
106
+ int index = (int )(rate * (size + 1 ));
109
107
return index ;
110
108
}
111
-
109
+
112
110
public double getValue (double rate , double [] data ) {
111
+
113
112
int size = data .length ;
114
113
int index = getIndex (rate , size );
115
114
return data [index - 1 ];
0 commit comments