1919import java .util .List ;
2020
2121/**
22- * Bubble chart implementation:
23- * Copyright 2015 Pierre-Marc Airoldi
24- * Licensed under Apache License 2.0
25- *
26- * Ported by Daniel Cohen Gindi
22+ * Bubble chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed
23+ * under Apache License 2.0 Ported by Daniel Cohen Gindi
2724 */
2825public class BubbleChartRenderer extends DataRenderer {
2926
3027 protected BubbleDataProvider mChart ;
3128
3229 public BubbleChartRenderer (BubbleDataProvider chart , ChartAnimator animator ,
33- ViewPortHandler viewPortHandler ) {
30+ ViewPortHandler viewPortHandler ) {
3431 super (animator , viewPortHandler );
3532 mChart = chart ;
3633
3734 mRenderPaint .setStyle (Style .FILL );
3835
3936 mHighlightPaint .setStyle (Style .STROKE );
40- mHighlightPaint .setStrokeWidth (Utils .convertDpToPixel (1f ));
37+ mHighlightPaint .setStrokeWidth (Utils .convertDpToPixel (1.5f ));
4138 }
4239
4340 @ Override
44- public void initBuffers ()
45- {
41+ public void initBuffers () {
4642
4743 }
4844
@@ -82,17 +78,19 @@ protected void drawDataSet(Canvas c, BubbleDataSet dataSet) {
8278 mViewPortHandler .contentWidth () * mViewPortHandler .getScaleX () :
8379 mViewPortHandler .contentHeight () * mViewPortHandler .getScaleY ();
8480
85- final float bubbleSizeFactor = (float )(bubbleData .getXVals ().size () > 0 ? bubbleData .getXVals ().size () : 1 );
81+ final float bubbleSizeFactor = (float ) (bubbleData .getXVals ().size () > 0 ? bubbleData
82+ .getXVals ().size () : 1 );
8683
8784 for (int j = minx ; j < maxx ; j ++) {
8885
8986 final BubbleEntry entry = entries .get (j );
9087
91- _pointBuffer [0 ] = (float )(entry .getXIndex () - minx ) * phaseX + (float )minx ;
92- _pointBuffer [1 ] = (float )(entry .getVal ()) * phaseY ;
88+ _pointBuffer [0 ] = (float ) (entry .getXIndex () - minx ) * phaseX + (float ) minx ;
89+ _pointBuffer [1 ] = (float ) (entry .getVal ()) * phaseY ;
9390 trans .pointValuesToPixel (_pointBuffer );
9491
95- final float shapeSize = (chartSize / bubbleSizeFactor ) * (float )(Math .sqrt (entry .getSize ()/dataSet .getMaxSize ()));
92+ final float shapeSize = (chartSize / bubbleSizeFactor )
93+ * (float ) (Math .sqrt (entry .getSize () / dataSet .getMaxSize ()));
9694 final float shapeHalf = shapeSize / 2.f ;
9795
9896 if (!mViewPortHandler .isInBoundsY (_pointBuffer [1 ]))
@@ -109,18 +107,20 @@ protected void drawDataSet(Canvas c, BubbleDataSet dataSet) {
109107 public void drawValues (Canvas c ) {
110108
111109 BubbleData bubbleData = mChart .getBubbleData ();
110+
112111 if (bubbleData == null )
113112 return ;
114113
115114 // if values are drawn
116- if (bubbleData .getYValCount () < (int )(Math .ceil ((float )(mChart .getMaxVisibleCount ()) * mViewPortHandler .getScaleX ())))
117- {
115+ if (bubbleData .getYValCount () < (int ) (Math .ceil ((float ) (mChart .getMaxVisibleCount ())
116+ * mViewPortHandler .getScaleX ()))) {
117+
118118 final List <BubbleDataSet > dataSets = bubbleData .getDataSets ();
119119
120- float lineHeight = - mValuePaint . ascent () + mValuePaint . descent ( );
120+ float lineHeight = Utils . calcTextHeight ( mValuePaint , "1" );
121121
122122 for (BubbleDataSet dataSet : dataSets ) {
123-
123+
124124 if (!dataSet .isDrawValuesEnabled ())
125125 continue ;
126126
@@ -129,7 +129,8 @@ public void drawValues(Canvas c) {
129129
130130 final float alpha = phaseX == 1 ? phaseY : phaseX ;
131131 int valueTextColor = dataSet .getValueTextColor ();
132- valueTextColor = Color .argb (Math .round (255.f * alpha ), Color .red (valueTextColor ), Color .green (valueTextColor ), Color .blue (valueTextColor ));
132+ valueTextColor = Color .argb (Math .round (255.f * alpha ), Color .red (valueTextColor ),
133+ Color .green (valueTextColor ), Color .blue (valueTextColor ));
133134
134135 mValuePaint .setColor (valueTextColor );
135136
@@ -141,7 +142,8 @@ public void drawValues(Canvas c) {
141142 int minx = dataSet .getEntryPosition (entryFrom );
142143 int maxx = Math .min (dataSet .getEntryPosition (entryTo ) + 1 , dataSet .getEntryCount ());
143144
144- final float [] positions = mChart .getTransformer (dataSet .getAxisDependency ()).generateTransformedValuesBubble (entries , phaseX , phaseY , minx , maxx );
145+ final float [] positions = mChart .getTransformer (dataSet .getAxisDependency ())
146+ .generateTransformedValuesBubble (entries , phaseX , phaseY , minx , maxx );
145147
146148 for (int j = 0 ; j < positions .length ; j += 2 ) {
147149
@@ -151,10 +153,8 @@ public void drawValues(Canvas c) {
151153 if (!mViewPortHandler .isInBoundsRight (x ))
152154 break ;
153155
154- if ((!mViewPortHandler .isInBoundsLeft (x ) || !mViewPortHandler .isInBoundsY (y )))
155- {
156+ if ((!mViewPortHandler .isInBoundsLeft (x ) || !mViewPortHandler .isInBoundsY (y )))
156157 continue ;
157- }
158158
159159 final BubbleEntry entry = entries .get (j / 2 + minx );
160160
@@ -167,7 +167,7 @@ public void drawValues(Canvas c) {
167167 }
168168 }
169169 }
170-
170+
171171 }
172172
173173 @ Override
@@ -189,7 +189,8 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
189189 mViewPortHandler .contentWidth () * mViewPortHandler .getScaleX () :
190190 mViewPortHandler .contentHeight () * mViewPortHandler .getScaleY ();
191191
192- final float bubbleSizeFactor = (float )(bubbleData .getXVals ().size () > 0 ? bubbleData .getXVals ().size () : 1 );
192+ final float bubbleSizeFactor = (float ) (bubbleData .getXVals ().size () > 0 ? bubbleData
193+ .getXVals ().size () : 1 );
193194
194195 for (Highlight indice : indices ) {
195196
@@ -212,7 +213,8 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
212213 _pointBuffer [1 ] = (float ) (entry .getVal ()) * phaseY ;
213214 trans .pointValuesToPixel (_pointBuffer );
214215
215- final float shapeSize = (chartSize / bubbleSizeFactor ) * (float ) (Math .sqrt (entry .getSize () / dataSet .getMaxSize ()));
216+ final float shapeSize = (chartSize / bubbleSizeFactor )
217+ * (float ) (Math .sqrt (entry .getSize () / dataSet .getMaxSize ()));
216218 final float shapeHalf = shapeSize / 2.f ;
217219
218220 if (indice .getXIndex () < minx || indice .getXIndex () >= maxx )
@@ -223,11 +225,13 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
223225
224226 final int originalColor = dataSet .getColor (entry .getXIndex ());
225227
226- Color .RGBToHSV (Color .red (originalColor ), Color .green (originalColor ), Color .blue (originalColor ), _hsvBuffer );
228+ Color .RGBToHSV (Color .red (originalColor ), Color .green (originalColor ),
229+ Color .blue (originalColor ), _hsvBuffer );
227230 _hsvBuffer [2 ] *= 0.5f ;
228231 final int color = Color .HSVToColor (Color .alpha (originalColor ), _hsvBuffer );
229232
230233 mHighlightPaint .setColor (color );
234+ mHighlightPaint .setStrokeWidth (dataSet .getHighLightCircleWidth ());
231235 c .drawCircle (_pointBuffer [0 ], _pointBuffer [1 ], shapeHalf , mHighlightPaint );
232236 }
233237 }
0 commit comments