@@ -28,7 +28,7 @@ public class BarChartRenderer extends DataRenderer {
2828 protected RectF mBarRect = new RectF ();
2929
3030 protected BarBuffer [] mBarBuffers ;
31-
31+
3232 protected Paint mShadowPaint ;
3333
3434 public BarChartRenderer (BarDataProvider chart , ChartAnimator animator ,
@@ -41,7 +41,7 @@ public BarChartRenderer(BarDataProvider chart, ChartAnimator animator,
4141 mHighlightPaint .setColor (Color .rgb (0 , 0 , 0 ));
4242 // set alpha after color
4343 mHighlightPaint .setAlpha (120 );
44-
44+
4545 mShadowPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
4646 mShadowPaint .setStyle (Paint .Style .FILL );
4747 }
@@ -79,7 +79,7 @@ protected void drawDataSet(Canvas c, BarDataSet dataSet, int index) {
7979
8080 Transformer trans = mChart .getTransformer (dataSet .getAxisDependency ());
8181 calcXBounds (trans );
82-
82+
8383 mShadowPaint .setColor (dataSet .getBarShadowColor ());
8484
8585 float phaseX = mAnimator .getPhaseX ();
@@ -97,26 +97,51 @@ protected void drawDataSet(Canvas c, BarDataSet dataSet, int index) {
9797
9898 trans .pointValuesToPixel (buffer .buffer );
9999
100- for (int j = 0 ; j < buffer .size (); j += 4 ) {
100+ // if multiple colors
101+ if (dataSet .getColors ().size () > 1 ) {
101102
102- if (!mViewPortHandler .isInBoundsLeft (buffer .buffer [j + 2 ]))
103- continue ;
103+ for (int j = 0 ; j < buffer .size (); j += 4 ) {
104+
105+ if (!mViewPortHandler .isInBoundsLeft (buffer .buffer [j + 2 ]))
106+ continue ;
107+
108+ if (!mViewPortHandler .isInBoundsRight (buffer .buffer [j ]))
109+ break ;
104110
105- if (!mViewPortHandler .isInBoundsRight (buffer .buffer [j ]))
106- break ;
107-
108- if (mChart .isDrawBarShadowEnabled ()) {
109- c .drawRect (buffer .buffer [j ], mViewPortHandler .contentTop (),
110- buffer .buffer [j +2 ],
111- mViewPortHandler .contentBottom (), mShadowPaint );
111+ if (mChart .isDrawBarShadowEnabled ()) {
112+ c .drawRect (buffer .buffer [j ], mViewPortHandler .contentTop (),
113+ buffer .buffer [j + 2 ],
114+ mViewPortHandler .contentBottom (), mShadowPaint );
115+ }
116+
117+ // Set the color for the currently drawn value. If the index
118+ // is
119+ // out of bounds, reuse colors.
120+ mRenderPaint .setColor (dataSet .getColor (j / 4 ));
121+ c .drawRect (buffer .buffer [j ], buffer .buffer [j + 1 ], buffer .buffer [j + 2 ],
122+ buffer .buffer [j + 3 ], mRenderPaint );
112123 }
124+ } else {
125+
126+ mRenderPaint .setColor (dataSet .getColor ());
113127
114- // Set the color for the currently drawn value. If the index
115- // is
116- // out of bounds, reuse colors.
117- mRenderPaint .setColor (dataSet .getColor (j / 4 ));
118- c .drawRect (buffer .buffer [j ], buffer .buffer [j + 1 ], buffer .buffer [j + 2 ],
119- buffer .buffer [j + 3 ], mRenderPaint );
128+ for (int j = 0 ; j < buffer .size (); j += 4 ) {
129+
130+ if (!mViewPortHandler .isInBoundsLeft (buffer .buffer [j + 2 ]))
131+ continue ;
132+
133+ if (!mViewPortHandler .isInBoundsRight (buffer .buffer [j ]))
134+ break ;
135+
136+ if (mChart .isDrawBarShadowEnabled ()) {
137+ c .drawRect (buffer .buffer [j ], mViewPortHandler .contentTop (),
138+ buffer .buffer [j + 2 ],
139+ mViewPortHandler .contentBottom (), mShadowPaint );
140+ }
141+
142+ c .drawRect (buffer .buffer [j ], buffer .buffer [j + 1 ], buffer .buffer [j + 2 ],
143+ buffer .buffer [j + 3 ], mRenderPaint );
144+ }
120145 }
121146 }
122147
@@ -159,7 +184,7 @@ public void drawValues(Canvas c) {
159184 // calculate the correct offset depending on the draw position of
160185 // the value
161186 float plus = Utils .convertDpToPixel (6f );
162-
187+
163188 posOffset = (drawValueAboveBar ? -Utils .convertDpToPixel (5 ) : Utils .calcTextHeight (
164189 mValuePaint ,
165190 "8" ) + plus );
@@ -172,7 +197,7 @@ public void drawValues(Canvas c) {
172197
173198 if (!dataSet .isDrawValuesEnabled ())
174199 continue ;
175-
200+
176201 // apply the text-styling defined by the DataSet
177202 applyValueTextStyle (dataSet );
178203
0 commit comments