1818
1919import android .graphics .*;
2020
21+ import com .androidplot .NumberLabelFormatter ;
2122import com .androidplot .exception .PlotRenderException ;
2223import com .androidplot .ui .BoxModel ;
2324import com .androidplot .ui .LayoutManager ;
@@ -106,11 +107,11 @@ public class XYGraphWidget extends Widget {
106107 private Mapping <Paint , Number > domainTickLabelPaintMap ;
107108 private Mapping <Paint , Number > rangeTickLabelPaintMap ;
108109
109- private ZHash <RectRegion , AxisValueLabelFormatter > axisValueLabelRegions ;
110+ private ZHash <RectRegion , NumberLabelFormatter > tickLabelRegionFormatters ;
110111
111112 private RenderStack <? extends XYSeries , ? extends XYSeriesFormatter > renderStack ;
112113
113- private static final float DEFAULT_TICK_LABEL_TEXT_SIZE_PX = PixelUtils .spToPix (15 ); // 15sp
114+ private static final float DEFAULT_TICK_LABEL_TEXT_SIZE_PX = PixelUtils .spToPix (15 );
114115
115116 public float getRangeLabelOrientation () {
116117 return rangeLabelOrientation ;
@@ -253,7 +254,7 @@ public void setRangeCursorPaint(Paint rangeCursorPaint) {
253254 setMarginBottom (4 );
254255 rangeValueFormat = new DecimalFormat ("0.0" );
255256 domainValueFormat = new DecimalFormat ("0.0" );
256- axisValueLabelRegions = new ZHash <>();
257+ tickLabelRegionFormatters = new ZHash <>();
257258 setClippingEnabled (true );
258259 }
259260
@@ -263,26 +264,25 @@ public XYGraphWidget(LayoutManager layoutManager, XYPlot plot, Size size) {
263264 renderStack = new RenderStack (plot );
264265 }
265266
266- public ZIndexable <RectRegion > getAxisValueLabelRegions () {
267- return axisValueLabelRegions ;
267+ public ZIndexable <RectRegion > getTickLabelRegionFormatters () {
268+ return tickLabelRegionFormatters ;
268269 }
269270
270271 /**
271- * Add a new Region used for rendering axis valuelabels . Note that it is
272- * possible to add multiple Region instances which overlap, in which cast
272+ * Add a new Region used for rendering tick labels . Note that it is
273+ * possible to add multiple Region instances which overlap, in which case
273274 * the last region to be added will be used. It is up to the developer to
274- * guard against this often undesireable situation.
275+ * guard against this often undesirable situation.
275276 *
276277 * @param region
277278 * @param formatter
278279 */
279- public void addAxisValueLabelRegion (RectRegion region ,
280- AxisValueLabelFormatter formatter ) {
281- axisValueLabelRegions .addToTop (region , formatter );
280+ public void addTickLabelFormatter (RectRegion region , NumberLabelFormatter formatter ) {
281+ tickLabelRegionFormatters .addToTop (region , formatter );
282282 }
283283
284284 /**
285- * Convenience method - wraps addAxisValueLabelRegion , using
285+ * Convenience method - wraps addDomainTickLabelFormatter , using
286286 * Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY to mask off range
287287 * axis value labels.
288288 *
@@ -291,25 +291,23 @@ public void addAxisValueLabelRegion(RectRegion region,
291291 * @param formatter
292292 *
293293 */
294- public void addDomainAxisValueLabelRegion (double min , double max ,
295- AxisValueLabelFormatter formatter ) {
296- addAxisValueLabelRegion (new RectRegion (min , max ,
294+ public void addDomainTickLabelFormatter (double min , double max , NumberLabelFormatter formatter ) {
295+ addTickLabelFormatter (new RectRegion (min , max ,
297296 Double .POSITIVE_INFINITY , Double .NEGATIVE_INFINITY , null ),
298297 formatter );
299298 }
300299
301300 /**
302- * Convenience method - wraps addAxisValueLabelRegion , using
301+ * Convenience method - wraps addDomainTickLabelFormatter , using
303302 * Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY to mask off domain
304303 * axis value labels.
305304 *
306305 * @param min
307306 * @param max
308307 * @param formatter
309308 */
310- public void addRangeAxisValueLabelRegion (double min , double max ,
311- AxisValueLabelFormatter formatter ) {
312- addAxisValueLabelRegion (new RectRegion (Double .POSITIVE_INFINITY ,
309+ public void addRangeTickLabelFormatter (double min , double max , NumberLabelFormatter formatter ) {
310+ addTickLabelFormatter (new RectRegion (Double .POSITIVE_INFINITY ,
313311 Double .NEGATIVE_INFINITY , min , max , null ), formatter );
314312 }
315313
@@ -322,31 +320,40 @@ public void addRangeAxisValueLabelRegion(double min, double max,
322320 * @return the formatter associated with the first (bottom) region
323321 * containing x and y. null otherwise.
324322 */
325- public AxisValueLabelFormatter getAxisValueLabelFormatterForVal (double x ,
326- double y ) {
327- for (RectRegion r : axisValueLabelRegions .elements ()) {
323+ public NumberLabelFormatter getTickLabelFormatter (double x , double y ) {
324+ for (RectRegion r : tickLabelRegionFormatters .elements ()) {
328325 if (r .containsValue (x , y )) {
329- return axisValueLabelRegions .get (r );
326+ return tickLabelRegionFormatters .get (r );
330327 }
331328 }
332329 return null ;
333330 }
334331
335- public AxisValueLabelFormatter getAxisValueLabelFormatterForDomainVal (
332+ /**
333+ *
334+ * @param val domain value
335+ * @return
336+ */
337+ public NumberLabelFormatter getDomainTickLabelFormatter (
336338 double val ) {
337- for (RectRegion r : axisValueLabelRegions .elements ()) {
339+ for (RectRegion r : tickLabelRegionFormatters .elements ()) {
338340 if (r .containsDomainValue (val )) {
339- return axisValueLabelRegions .get (r );
341+ return tickLabelRegionFormatters .get (r );
340342 }
341343 }
342344 return null ;
343345 }
344346
345- public AxisValueLabelFormatter getAxisValueLabelFormatterForRangeVal (
347+ /**
348+ *
349+ * @param val range value
350+ * @return
351+ */
352+ public NumberLabelFormatter getRangeTickLabelFormatter (
346353 double val ) {
347- for (RectRegion r : axisValueLabelRegions .elements ()) {
354+ for (RectRegion r : tickLabelRegionFormatters .elements ()) {
348355 if (r .containsRangeValue (val )) {
349- return axisValueLabelRegions .get (r );
356+ return tickLabelRegionFormatters .get (r );
350357 }
351358 }
352359 return null ;
@@ -451,20 +458,20 @@ private void calculateGridDimensions(RectF widgetRect) {
451458
452459 private void drawTickText (Canvas canvas , XYAxisType axis , Number value ,
453460 float xPix , float yPix , Paint labelPaint ) {
454- AxisValueLabelFormatter rf = null ;
455- String txt = null ;
461+ NumberLabelFormatter formatter ;
462+ String txt ;
456463 double v = value .doubleValue ();
457464
458465 int canvasState = canvas .save ();
459466 try {
460467 switch (axis ) {
461468 case DOMAIN :
462- rf = getAxisValueLabelFormatterForDomainVal (v );
469+ formatter = getDomainTickLabelFormatter (v );
463470 txt = getFormattedDomainValue (value );
464471 canvas .rotate (getDomainLabelOrientation (), xPix , yPix );
465472 break ;
466473 case RANGE :
467- rf = getAxisValueLabelFormatterForRangeVal (v );
474+ formatter = getRangeTickLabelFormatter (v );
468475 txt = getFormattedRangeValue (value );
469476 canvas .rotate (getRangeLabelOrientation (), xPix , yPix );
470477 break ;
@@ -476,9 +483,8 @@ private void drawTickText(Canvas canvas, XYAxisType axis, Number value,
476483 // of labelPaint and use the formatter's color. Otherwise
477484 // just use labelPaint:
478485 Paint p ;
479- if (rf != null ) {
480- p = new Paint (labelPaint );
481- p .setColor (rf .getColor ());
486+ if (formatter != null ) {
487+ p = formatter .getPaint (value );
482488 } else {
483489 p = labelPaint ;
484490 }
@@ -591,7 +597,6 @@ protected void drawGrid(Canvas canvas) {
591597 paddedGridRect , plot .getCalculatedMinX ().doubleValue (), plot
592598 .getCalculatedMaxX ().doubleValue ());
593599
594-
595600 // draw domain origin:
596601 if (domainOriginF >= paddedGridRect .left
597602 && domainOriginF <= paddedGridRect .right ) {
@@ -764,7 +769,6 @@ private void drawMarkerText(Canvas canvas, String text, ValueMarker marker,
764769
765770 canvas .drawText (text , textRect .left , textRect .bottom ,
766771 marker .getTextPaint ());
767-
768772 }
769773
770774 protected void drawMarkers (Canvas canvas ) {
0 commit comments