55import android .util .AttributeSet ;
66
77import com .github .mikephil .charting .components .YAxis ;
8+ import com .github .mikephil .charting .renderer .HorizontalBarChartRenderer ;
9+ import com .github .mikephil .charting .renderer .YAxisRendererHorizontalBarChart ;
810
911/**
1012 * BarChart with horizontal bar orientation. In this implementation, x- and
1113 * y-axis are switched.
14+ *
15+ * @author Philipp Jahoda
1216 */
13- public class HorizontalBarChart extends BarChart
14- {
17+ public class HorizontalBarChart extends BarChart {
18+
1519 public HorizontalBarChart (Context context )
1620 {
1721 super (context );
@@ -31,115 +35,21 @@ public HorizontalBarChart(Context context, AttributeSet attrs,
3135 @ Override
3236 protected void init () {
3337 super .init ();
34- // setDrawYLabels(true);
35- // mTrans = new HorizontalBarChartTransformer();
38+
39+ mRenderer = new HorizontalBarChartRenderer (this , mAnimator , mViewPortHandler );
40+ mAxisRendererLeft = new YAxisRendererHorizontalBarChart (mViewPortHandler , mAxisLeft ,
41+ mLeftAxisTransformer );
42+ mAxisRendererRight = new YAxisRendererHorizontalBarChart (mViewPortHandler , mAxisRight ,
43+ mRightAxisTransformer );
3644 }
3745
38- /**
39- * Prepares a bar for drawing on the specified x-index and y-position. Also
40- * prepares the shadow-bar if enabled.
41- *
42- * @param x the x-position
43- * @param y the y-position
44- * @param barspace the space between bars
45- */
46- // @Override
47- // protected void prepareBar(float x, float y, float barspace) {
48- // super.prepareBar(x, y, barspace);
49- //
50- // float spaceHalf = barspace / 2f;
51- //
52- // float top = x + spaceHalf;
53- // float bottom = x + 1f - spaceHalf;
54- //
55- // mBarRect.set(0, top, y, bottom);
56- //
57- // mTrans.rectValueToPixel(mBarRect, mPhaseY);
58- //
59- // // if a shadow is drawn, prepare it too
60- // if (mDrawBarShadow) {
61- // mBarShadow.set(mBarRect.left, mOffsetTop, mBarRect.right, getHeight() - mOffsetBottom);
62- // }
63- // }
64-
65- // @Override
66- // protected void calcModulus() {
67- //
68- // float[] values = new float[9];
69- // mTrans.getTouchMatrix().getValues(values);
70- //
71- // mXLabels.mYAxisLabelModulus = (int) Math
72- // .ceil((mData.getXValCount() * mXLabels.mLabelHeight)
73- // / (mContentRect.height() * values[Matrix.MSCALE_Y]));
74- // }
75- //
76- // @Override
77- // protected void drawXLabels(float yPos)
78- // {
79- // if (!mDrawXLabels)
80- // return;
81- //
82- // mXLabelPaint.setTextAlign(Paint.Align.RIGHT);
83- // // pre allocate to save performance (dont allocate in loop)
84- // float[] position = new float[] {
85- // 0f, 0f
86- // };
87- //
88- // float offset = Utils.calcTextHeight(mXLabelPaint, mData.getXVals().get(0)) / 2f;
89- //
90- // int step = mData.getDataSetCount();
91- //
92- // for (int i = 0; i < mData.getXValCount(); i += mXLabels.mYAxisLabelModulus) {
93- //
94- // position[1] = i * step + i * mData.getGroupSpace()
95- // + mData.getGroupSpace() / 2f;
96- //
97- // // center the text
98- // if (mXLabels.isCenterXLabelsEnabled())
99- // position[1] += (step / 2f);
100- //
101- // mTrans.pointValuesToPixel(position);
102- //
103- // if (position[1] >= mOffsetTop && position[1] <= getHeight() - mOffsetBottom)
104- // {
105- // String label = mData.getXVals().get(i);
106- //
107- // mDrawCanvas.drawText(label, mOffsetLeft - 10, position[1] + offset, mXLabelPaint);
108- // }
109- // }
110- // }
111- //
112- // private static String TALL_VALUE = "100%";
113- //
114- // @Override
115- // protected float getPositiveYOffset(boolean drawAboveValueBar)
116- // {
117- // Rect bounds = new Rect();
118- // mValuePaint.getTextBounds(TALL_VALUE, 0, TALL_VALUE.length(), bounds);
119- //
120- // return bounds.height() / 2;
121- // }
122- //
123- // @Override
124- // protected float getNegativeYOffset(boolean drawAboveValueBar)
125- // {
126- // return getPositiveYOffset(drawAboveValueBar);
127- // }
128-
129- // /**
130- // * Sets up the y-axis labels. Computes the desired number of labels between
131- // * the two given extremes. Unlike the papareXLabels() method, this method
132- // * needs to be called upon every refresh of the view.
133- // *
134- // * @return
135- // */
136- // @Override
137- // protected void prepareYLabels()
138- // {
139- // mYLabels = new XLabelsAsYLabels();
140- // // super.prepareYLabels();
141- //
142- // }
46+ @ Override
47+ protected void prepareValuePxMatrix () {
48+ mRightAxisTransformer .prepareMatrixValuePx (mXChartMin , mAxisRight .mAxisRange , mDeltaX ,
49+ mAxisRight .mAxisMinimum );
50+ mLeftAxisTransformer .prepareMatrixValuePx (mXChartMin , mAxisLeft .mAxisRange , mDeltaX ,
51+ mAxisLeft .mAxisMinimum );
52+ }
14353
14454 private class XLabelsAsYLabels extends YAxis
14555 {
0 commit comments