@@ -42,6 +42,9 @@ public abstract class PieRadarChartBase<T extends ChartData<? extends DataSet<?
42
42
/** flag that indicates if rotation is enabled or not */
43
43
protected boolean mRotateEnabled = true ;
44
44
45
+ /** Sets the minimum offset (padding) around the chart, defaults to 10 */
46
+ protected float mMinOffset = 10.f ;
47
+
45
48
public PieRadarChartBase (Context context ) {
46
49
super (context );
47
50
}
@@ -184,23 +187,38 @@ public void calculateOffsets() {
184
187
|| mLegend .getPosition () == LegendPosition .BELOW_CHART_RIGHT
185
188
|| mLegend .getPosition () == LegendPosition .BELOW_CHART_CENTER ) {
186
189
187
- float yOffset = getRequiredBottomOffset (); // It's possible that we do not need this offset anymore as it is available through the extraOffsets
190
+ // It's possible that we do not need this offset anymore as it
191
+ // is available through the extraOffsets, but changing it can mean
192
+ // changing default visibility for existing apps.
193
+ float yOffset = getRequiredLegendOffset ();
194
+
188
195
legendBottom = Math .min (mLegend .mNeededHeight + yOffset , mViewPortHandler .getChartHeight () * mLegend .getMaxSizePercent ());
189
196
197
+ } else if (mLegend .getPosition () == LegendPosition .ABOVE_CHART_LEFT
198
+ || mLegend .getPosition () == LegendPosition .ABOVE_CHART_RIGHT
199
+ || mLegend .getPosition () == LegendPosition .ABOVE_CHART_CENTER ) {
200
+
201
+ // It's possible that we do not need this offset anymore as it
202
+ // is available through the extraOffsets, but changing it can mean
203
+ // changing default visibility for existing apps.
204
+ float yOffset = getRequiredLegendOffset ();
205
+
206
+ legendTop = Math .min (mLegend .mNeededHeight + yOffset , mViewPortHandler .getChartHeight () * mLegend .getMaxSizePercent ());
207
+
190
208
}
191
209
192
210
legendLeft += getRequiredBaseOffset ();
193
211
legendRight += getRequiredBaseOffset ();
194
212
legendTop += getRequiredBaseOffset ();
195
213
}
196
214
197
- float min = Utils .convertDpToPixel (10f );
215
+ float minOffset = Utils .convertDpToPixel (mMinOffset );
198
216
199
217
if (this instanceof RadarChart ) {
200
218
XAxis x = ((RadarChart ) this ).getXAxis ();
201
219
202
220
if (x .isEnabled () && x .isDrawLabelsEnabled ()) {
203
- min = Math .max (Utils . convertDpToPixel ( 10f ) , x .mLabelWidth );
221
+ minOffset = Math .max (minOffset , x .mLabelWidth );
204
222
}
205
223
}
206
224
@@ -209,10 +227,10 @@ public void calculateOffsets() {
209
227
legendBottom += getExtraBottomOffset ();
210
228
legendLeft += getExtraLeftOffset ();
211
229
212
- float offsetLeft = Math .max (min , legendLeft );
213
- float offsetTop = Math .max (min , legendTop );
214
- float offsetRight = Math .max (min , legendRight );
215
- float offsetBottom = Math .max (min , Math .max (getRequiredBaseOffset (), legendBottom ));
230
+ float offsetLeft = Math .max (minOffset , legendLeft );
231
+ float offsetTop = Math .max (minOffset , legendTop );
232
+ float offsetRight = Math .max (minOffset , legendRight );
233
+ float offsetBottom = Math .max (minOffset , Math .max (getRequiredBaseOffset (), legendBottom ));
216
234
217
235
mViewPortHandler .restrainViewPort (offsetLeft , offsetTop , offsetRight , offsetBottom );
218
236
@@ -383,11 +401,11 @@ public float getDiameter() {
383
401
public abstract float getRadius ();
384
402
385
403
/**
386
- * Returns the required bottom offset for the chart.
404
+ * Returns the required offset for the chart legend .
387
405
*
388
406
* @return
389
407
*/
390
- protected abstract float getRequiredBottomOffset ();
408
+ protected abstract float getRequiredLegendOffset ();
391
409
392
410
/**
393
411
* Returns the base offset needed for the chart without calculating the
0 commit comments