88import com .github .mikephil .charting .animation .ChartAnimator ;
99import com .github .mikephil .charting .data .BubbleData ;
1010import com .github .mikephil .charting .data .BubbleEntry ;
11- import com .github .mikephil .charting .data .DataSet ;
1211import com .github .mikephil .charting .highlight .Highlight ;
1312import com .github .mikephil .charting .interfaces .dataprovider .BubbleDataProvider ;
1413import com .github .mikephil .charting .interfaces .datasets .IBubbleDataSet ;
2221 * Bubble chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed
2322 * under Apache License 2.0 Ported by Daniel Cohen Gindi
2423 */
25- public class BubbleChartRenderer extends DataRenderer {
24+ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
2625
2726 protected BubbleDataProvider mChart ;
2827
@@ -57,13 +56,9 @@ public void drawData(Canvas c) {
5756 private float [] sizeBuffer = new float [4 ];
5857 private float [] pointBuffer = new float [2 ];
5958
60- protected float getShapeSize (float entrySize ,
61- float maxSize ,
62- float reference ,
63- boolean normalizeSize ) {
64- final float factor = normalizeSize
65- ? ((maxSize == 0f ) ? 1f : (float ) Math .sqrt (entrySize / maxSize ))
66- : entrySize ;
59+ protected float getShapeSize (float entrySize , float maxSize , float reference , boolean normalizeSize ) {
60+ final float factor = normalizeSize ? ((maxSize == 0f ) ? 1f : (float ) Math .sqrt (entrySize / maxSize )) :
61+ entrySize ;
6762 final float shapeSize = reference * factor ;
6863 return shapeSize ;
6964 }
@@ -72,17 +67,9 @@ protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {
7267
7368 Transformer trans = mChart .getTransformer (dataSet .getAxisDependency ());
7469
75- float phaseX = Math .max (0.f , Math .min (1.f , mAnimator .getPhaseX ()));
7670 float phaseY = mAnimator .getPhaseY ();
7771
78- float low = mChart .getLowestVisibleX ();
79- float high = mChart .getHighestVisibleX ();
80-
81- BubbleEntry entryFrom = dataSet .getEntryForXPos (low , DataSet .Rounding .DOWN );
82- BubbleEntry entryTo = dataSet .getEntryForXPos (high , DataSet .Rounding .UP );
83-
84- int minx = Math .max (dataSet .getEntryIndex (entryFrom ), 0 );
85- int maxx = Math .min (dataSet .getEntryIndex (entryTo ) + 1 , dataSet .getEntryCount ());
72+ XBounds bounds = getXBounds (mChart , dataSet );
8673
8774 sizeBuffer [0 ] = 0f ;
8875 sizeBuffer [2 ] = 1f ;
@@ -96,12 +83,12 @@ protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {
9683 final float maxBubbleHeight = Math .abs (mViewPortHandler .contentBottom () - mViewPortHandler .contentTop ());
9784 final float referenceSize = Math .min (maxBubbleHeight , maxBubbleWidth );
9885
99- for (int j = minx ; j < maxx ; j ++) {
86+ for (int j = bounds . min ; j <= bounds . range + bounds . min ; j ++) {
10087
10188 final BubbleEntry entry = dataSet .getEntryForIndex (j );
10289
103- pointBuffer [0 ] = ( float ) ( entry .getX () - minx ) * phaseX + ( float ) minx ;
104- pointBuffer [1 ] = (float ) ( entry .getY ()) * phaseY ;
90+ pointBuffer [0 ] = entry .getX ();
91+ pointBuffer [1 ] = (entry .getY ()) * phaseY ;
10592 trans .pointValuesToPixel (pointBuffer );
10693
10794 float shapeHalf = getShapeSize (entry .getSize (), dataSet .getMaxSize (), referenceSize , normalizeSize ) / 2f ;
@@ -151,23 +138,16 @@ public void drawValues(Canvas c) {
151138 final float phaseX = Math .max (0.f , Math .min (1.f , mAnimator .getPhaseX ()));
152139 final float phaseY = mAnimator .getPhaseY ();
153140
154- float low = mChart .getLowestVisibleX ();
155- float high = mChart .getHighestVisibleX ();
156-
157- BubbleEntry entryFrom = dataSet .getEntryForXPos (low , DataSet .Rounding .DOWN );
158- BubbleEntry entryTo = dataSet .getEntryForXPos (high , DataSet .Rounding .UP );
159-
160- int minx = dataSet .getEntryIndex (entryFrom );
161- int maxx = Math .min (dataSet .getEntryIndex (entryTo ) + 1 , dataSet .getEntryCount ());
141+ XBounds bounds = getXBounds (mChart , dataSet );
162142
163143 final float [] positions = mChart .getTransformer (dataSet .getAxisDependency ())
164- .generateTransformedValuesBubble (dataSet , phaseX , phaseY , minx , maxx );
144+ .generateTransformedValuesBubble (dataSet , phaseY , bounds . min , bounds . max );
165145
166146 final float alpha = phaseX == 1 ? phaseY : phaseX ;
167147
168148 for (int j = 0 ; j < positions .length ; j += 2 ) {
169149
170- int valueTextColor = dataSet .getValueTextColor (j / 2 + minx );
150+ int valueTextColor = dataSet .getValueTextColor (j / 2 + bounds . min );
171151 valueTextColor = Color .argb (Math .round (255.f * alpha ), Color .red (valueTextColor ),
172152 Color .green (valueTextColor ), Color .blue (valueTextColor ));
173153
@@ -180,7 +160,7 @@ public void drawValues(Canvas c) {
180160 if ((!mViewPortHandler .isInBoundsLeft (x ) || !mViewPortHandler .isInBoundsY (y )))
181161 continue ;
182162
183- BubbleEntry entry = dataSet .getEntryForIndex (j / 2 + minx );
163+ BubbleEntry entry = dataSet .getEntryForIndex (j / 2 + bounds . min );
184164
185165 drawValue (c , dataSet .getValueFormatter (), entry .getSize (), entry , i , x ,
186166 y + (0.5f * lineHeight ), valueTextColor );
@@ -200,7 +180,6 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
200180
201181 BubbleData bubbleData = mChart .getBubbleData ();
202182
203- float phaseX = Math .max (0.f , Math .min (1.f , mAnimator .getPhaseX ()));
204183 float phaseY = mAnimator .getPhaseY ();
205184
206185 for (Highlight high : indices ) {
@@ -213,27 +192,19 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
213192 : (high .getDataSetIndex () + 1 );
214193 if (maxDataSetIndex - minDataSetIndex < 1 ) continue ;
215194
216- for (int dataSetIndex = minDataSetIndex ;
217- dataSetIndex < maxDataSetIndex ;
218- dataSetIndex ++) {
195+ for (int dataSetIndex = minDataSetIndex ; dataSetIndex < maxDataSetIndex ; dataSetIndex ++) {
219196
220197 IBubbleDataSet dataSet = bubbleData .getDataSetByIndex (dataSetIndex );
221198
222199 if (dataSet == null || !dataSet .isHighlightEnabled ())
223200 continue ;
224201
225202 final BubbleEntry entry = (BubbleEntry ) bubbleData .getEntryForHighlight (high );
226- if (entry == null || entry .getX () != high .getX ())
227- continue ;
228-
229- float low = mChart .getLowestVisibleX ();
230- float highX = mChart .getHighestVisibleX ();
231203
232- BubbleEntry entryFrom = dataSet . getEntryForXPos ( low , DataSet . Rounding . DOWN );
233- BubbleEntry entryTo = dataSet . getEntryForXPos ( highX , DataSet . Rounding . UP ) ;
204+ if ( entry == null )
205+ continue ;
234206
235- int minx = dataSet .getEntryIndex (entryFrom );
236- int maxx = Math .min (dataSet .getEntryIndex (entryTo ) + 1 , dataSet .getEntryCount ());
207+ XBounds bounds = getXBounds (mChart , dataSet );
237208
238209 Transformer trans = mChart .getTransformer (dataSet .getAxisDependency ());
239210
@@ -250,8 +221,8 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
250221 mViewPortHandler .contentBottom () - mViewPortHandler .contentTop ());
251222 final float referenceSize = Math .min (maxBubbleHeight , maxBubbleWidth );
252223
253- pointBuffer [0 ] = ( float ) ( entry .getX () - minx ) * phaseX + ( float ) minx ;
254- pointBuffer [1 ] = (float ) ( entry .getY ()) * phaseY ;
224+ pointBuffer [0 ] = entry .getX ();
225+ pointBuffer [1 ] = (entry .getY ()) * phaseY ;
255226 trans .pointValuesToPixel (pointBuffer );
256227
257228 float shapeHalf = getShapeSize (entry .getSize (),
@@ -269,7 +240,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
269240 if (!mViewPortHandler .isInBoundsRight (pointBuffer [0 ] - shapeHalf ))
270241 break ;
271242
272- if (high .getX () < minx || high .getX () >= maxx )
243+ if (high .getX () < bounds . min || high .getX () > bounds . max )
273244 continue ;
274245
275246 final int originalColor = dataSet .getColor ((int ) entry .getX ());
0 commit comments