Skip to content

Commit 32aef31

Browse files
RobertZagorskihannesa2
authored andcommitted
Removed mLabelRotatedWidth/Height variables from XAxis model.
Those 2 variables were used only if mLabelRotationAngle was different than 0. In such situation mLabelWidth/Height became unused. This was removes this unnecessary overhead - merges those two cases into one making use of mLabelWidth/Height variables in XAxis.
1 parent ed25db3 commit 32aef31

10 files changed

Lines changed: 27 additions & 35 deletions

File tree

MPChartExample/res/menu/bar.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,10 @@
4545
android:id="@+id/actionToggleBarBorders"
4646
android:title="Show Bar Borders">
4747
</item>
48+
<item
49+
android:id="@+id/actionRotateXAxisLabelsBy45Deg"
50+
android:title="rotate X Axis labels">
51+
52+
</item>
4853

4954
</menu>

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
211211
.show();
212212
break;
213213
}
214+
case R.id.actionRotateXAxisLabelsBy45Deg: {
215+
mChart.getXAxis().setLabelRotationAngle(45);
216+
mChart.notifyDataSetChanged();
217+
mChart.invalidate();
218+
}
214219
}
215220
return true;
216221
}

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void calculateOffsets() {
486486

487487
if (mXAxis.isEnabled() && mXAxis.isDrawLabelsEnabled()) {
488488

489-
float xLabelHeight = mXAxis.mLabelRotatedHeight + mXAxis.getYOffset();
489+
float xLabelHeight = mXAxis.mLabelHeight + mXAxis.getYOffset();
490490

491491
// offsets for x-labels
492492
if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {

MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ public void calculateOffsets() {
8181
offsetBottom += mAxisRight.getRequiredHeightSpace(mAxisRendererRight.getPaintAxisLabels());
8282
}
8383

84-
float xlabelwidth = mXAxis.mLabelRotatedWidth;
84+
float xLabelWidth = mXAxis.mLabelWidth;
8585

8686
if (mXAxis.isEnabled()) {
8787

8888
// offsets for x-labels
8989
if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
9090

91-
offsetLeft += xlabelwidth;
91+
offsetLeft += xLabelWidth;
9292

9393
} else if (mXAxis.getPosition() == XAxisPosition.TOP) {
9494

95-
offsetRight += xlabelwidth;
95+
offsetRight += xLabelWidth;
9696

9797
} else if (mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) {
9898

99-
offsetLeft += xlabelwidth;
100-
offsetRight += xlabelwidth;
99+
offsetLeft += xLabelWidth;
100+
offsetRight += xLabelWidth;
101101
}
102102
}
103103

MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieRadarChartBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void calculateOffsets() {
228228
XAxis x = this.getXAxis();
229229

230230
if (x.isEnabled() && x.isDrawLabelsEnabled()) {
231-
minOffset = Math.max(minOffset, x.mLabelRotatedWidth);
231+
minOffset = Math.max(minOffset, x.mLabelWidth);
232232
}
233233
}
234234

MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ protected float getRequiredLegendOffset() {
326326
@Override
327327
protected float getRequiredBaseOffset() {
328328
return mXAxis.isEnabled() && mXAxis.isDrawLabelsEnabled() ?
329-
mXAxis.mLabelRotatedWidth :
329+
mXAxis.mLabelWidth :
330330
Utils.convertDpToPixel(10f);
331331
}
332332

MPChartLib/src/main/java/com/github/mikephil/charting/components/XAxis.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ public class XAxis extends AxisBase {
2424
*/
2525
public int mLabelHeight = 1;
2626

27-
/**
28-
* width of the (rotated) x-axis labels in pixels - this is automatically
29-
* calculated by the computeSize() methods in the renderers
30-
*/
31-
public int mLabelRotatedWidth = 1;
32-
33-
/**
34-
* height of the (rotated) x-axis labels in pixels - this is automatically
35-
* calculated by the computeSize() methods in the renderers
36-
*/
37-
public int mLabelRotatedHeight = 1;
38-
3927
/**
4028
* This is the angle for drawing the X axis labels (in degrees)
4129
*/

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ protected void computeSize() {
9292
mXAxis.getLabelRotationAngle());
9393

9494

95-
mXAxis.mLabelWidth = Math.round(labelWidth);
96-
mXAxis.mLabelHeight = Math.round(labelHeight);
97-
mXAxis.mLabelRotatedWidth = Math.round(labelRotatedSize.width);
98-
mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
95+
mXAxis.mLabelWidth = Math.round(labelRotatedSize.width);
96+
mXAxis.mLabelHeight = Math.round(labelRotatedSize.height);
9997

10098
FSize.recycleInstance(labelRotatedSize);
10199
FSize.recycleInstance(labelSize);
@@ -109,8 +107,6 @@ public void renderAxisLabels(Canvas c) {
109107

110108
float yoffset = mXAxis.getYOffset();
111109

112-
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
113-
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
114110
mAxisLabelPaint.setColor(mXAxis.getTextColor());
115111

116112
MPPointF pointF = MPPointF.getInstance(0,0);
@@ -122,7 +118,7 @@ public void renderAxisLabels(Canvas c) {
122118
} else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
123119
pointF.x = 0.5f;
124120
pointF.y = 1.0f;
125-
drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelRotatedHeight, pointF);
121+
drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelHeight, pointF);
126122

127123
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
128124
pointF.x = 0.5f;
@@ -132,7 +128,7 @@ public void renderAxisLabels(Canvas c) {
132128
} else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
133129
pointF.x = 0.5f;
134130
pointF.y = 0.0f;
135-
drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelRotatedHeight, pointF);
131+
drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelHeight, pointF);
136132

137133
} else { // BOTH SIDED
138134
pointF.x = 0.5f;

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ protected void computeSize() {
7272
final float labelHeight = labelSize.height;
7373

7474
final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
75-
labelSize.width,
75+
labelWidth,
7676
labelHeight,
7777
mXAxis.getLabelRotationAngle());
7878

79-
mXAxis.mLabelWidth = Math.round(labelWidth);
80-
mXAxis.mLabelHeight = Math.round(labelHeight);
81-
mXAxis.mLabelRotatedWidth = (int)(labelRotatedSize.width + mXAxis.getXOffset() * 3.5f);
82-
mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
79+
mXAxis.mLabelWidth = Math.round(labelRotatedSize.width);
80+
mXAxis.mLabelHeight = Math.round(labelRotatedSize.height);
8381

8482
FSize.recycleInstance(labelRotatedSize);
8583
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void renderAxisLabels(Canvas c) {
4848
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
4949

5050
Utils.getPosition(center, mChart.getYRange() * factor
51-
+ mXAxis.mLabelRotatedWidth / 2f, angle, pOut);
51+
+ mXAxis.mLabelWidth / 2f, angle, pOut);
5252

53-
drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelRotatedHeight / 2.f,
53+
drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelHeight / 2.f,
5454
drawLabelAnchor, labelRotationAngleDegrees);
5555
}
5656

0 commit comments

Comments
 (0)