@@ -41,6 +41,33 @@ public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer t
41
41
}
42
42
}
43
43
44
+ /**
45
+ * Return the axis label x position based on axis dependency and label position
46
+ * @param dependency
47
+ * @param labelPosition
48
+ * @return
49
+ */
50
+ private float calculateAxisLabelsXPosition (AxisDependency dependency , YAxisLabelPosition labelPosition ) {
51
+ float viewPortBase = dependency == AxisDependency .LEFT ? mViewPortHandler .offsetLeft () : mViewPortHandler .contentRight ();
52
+ float xOffset = mYAxis .getXOffset () * (labelPosition == YAxisLabelPosition .OUTSIDE_CHART ? -1 : 1 );
53
+
54
+ return viewPortBase + xOffset ;
55
+ }
56
+
57
+ /**
58
+ * Return the text align based on axis dependency and label position
59
+ * @param dependency
60
+ * @param labelPosition
61
+ * @return
62
+ */
63
+ private Align getAxisLabelTextAlign (AxisDependency dependency , YAxisLabelPosition labelPosition ) {
64
+ if (dependency == AxisDependency .LEFT ^ labelPosition == YAxisLabelPosition .OUTSIDE_CHART ) {
65
+ return Align .LEFT ;
66
+ }
67
+
68
+ return Align .RIGHT ;
69
+ }
70
+
44
71
/**
45
72
* draws the y-axis labels to the screen
46
73
*/
@@ -56,36 +83,15 @@ public void renderAxisLabels(Canvas c) {
56
83
mAxisLabelPaint .setTextSize (mYAxis .getTextSize ());
57
84
mAxisLabelPaint .setColor (mYAxis .getTextColor ());
58
85
59
- float xoffset = mYAxis .getXOffset ();
60
- float yoffset = Utils .calcTextHeight (mAxisLabelPaint , "A" ) / 2.5f + mYAxis .getYOffset ();
86
+ float yOffset = Utils .calcTextHeight (mAxisLabelPaint , "A" ) / 2.5f + mYAxis .getYOffset ();
61
87
62
88
AxisDependency dependency = mYAxis .getAxisDependency ();
63
89
YAxisLabelPosition labelPosition = mYAxis .getLabelPosition ();
64
90
65
- float xPos = 0f ;
66
-
67
- if (dependency == AxisDependency .LEFT ) {
68
-
69
- if (labelPosition == YAxisLabelPosition .OUTSIDE_CHART ) {
70
- mAxisLabelPaint .setTextAlign (Align .RIGHT );
71
- xPos = mViewPortHandler .offsetLeft () - xoffset ;
72
- } else {
73
- mAxisLabelPaint .setTextAlign (Align .LEFT );
74
- xPos = mViewPortHandler .offsetLeft () + xoffset ;
75
- }
76
-
77
- } else {
78
-
79
- if (labelPosition == YAxisLabelPosition .OUTSIDE_CHART ) {
80
- mAxisLabelPaint .setTextAlign (Align .LEFT );
81
- xPos = mViewPortHandler .contentRight () + xoffset ;
82
- } else {
83
- mAxisLabelPaint .setTextAlign (Align .RIGHT );
84
- xPos = mViewPortHandler .contentRight () - xoffset ;
85
- }
86
- }
91
+ float xPos = calculateAxisLabelsXPosition (dependency , labelPosition );
92
+ mAxisLabelPaint .setTextAlign (getAxisLabelTextAlign (dependency , labelPosition ));
87
93
88
- drawYLabels (c , xPos , positions , yoffset );
94
+ drawYLabels (c , xPos , positions , yOffset );
89
95
}
90
96
91
97
@ Override
0 commit comments