55import android .graphics .Color ;
66import android .graphics .Matrix ;
77import android .graphics .Paint ;
8- import android .graphics .Paint .Style ;
98import android .graphics .Path ;
109import android .graphics .RectF ;
1110import android .util .AttributeSet ;
@@ -51,62 +50,74 @@ protected void init() {
5150 // set alpha after color
5251 mHighlightPaint .setAlpha (120 );
5352 }
53+
54+ @ Override
55+ public void setColorTemplate (ColorTemplate ct ) {
56+ super .setColorTemplate (ct );
57+
58+ calculate3DColors ();
59+ }
5460
5561 /** array that holds all the colors for the top 3D effect */
56- private int [] mTopColors ;
62+ private ArrayList < ArrayList < Integer >> mTopColors ;
5763
5864 /** array that holds all the colors for the side 3D effect */
59- private int [] mSideColors ;
65+ private ArrayList < ArrayList < Integer >> mSideColors ;
6066
61- @ Override
62- protected void prepareDataPaints (ColorTemplate ct ) {
63-
64- // // prepare the paints
65- // mDrawPaints = new Paint[ct.getColors().size()];
66- //
67- // for (int i = 0; i < ct.getColors().size(); i++) {
68- // mDrawPaints[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
69- // mDrawPaints[i].setStyle(Style.FILL);
70- // mDrawPaints[i].setColor(Color.BLACK);
71- // }
72-
73- // // generate the colors for the 3D effect
74- // mTopColors = new int[mDrawPaints.length];
75- // mSideColors = new int[mDrawPaints.length];
76- //
77- // float[] hsv = new float[3];
78- //
79- // for (int i = 0; i < mSideColors.length; i++) {
80- //
81- // // extract the color
82- // int c = mDrawPaints[i].getColor();
83- // Color.colorToHSV(c, hsv); // convert to hsv
84- //
85- // // make brighter
86- // hsv[1] = hsv[1] - 0.1f; // less saturation
87- // hsv[2] = hsv[2] + 0.1f; // more brightness
88- //
89- // // convert back
90- // c = Color.HSVToColor(hsv);
91- //
92- // // assign
93- // mTopColors[i] = c;
94- //
95- // // get color again
96- // c = mDrawPaints[i].getColor();
97- //
98- // // convert
99- // Color.colorToHSV(c, hsv);
100- //
101- // // make darker
102- // hsv[1] = hsv[1] + 0.1f; // more saturation
103- // hsv[2] = hsv[2] - 0.1f; // less brightness
104- //
105- // // reassing
106- // c = Color.HSVToColor(hsv);
107- //
108- // mSideColors[i] = c;
109- // }
67+ /**
68+ * calculates the 3D color arrays
69+ */
70+ protected void calculate3DColors () {
71+
72+ // generate the colors for the 3D effect
73+ mTopColors = new ArrayList <ArrayList <Integer >>();
74+ mSideColors = new ArrayList <ArrayList <Integer >>();
75+
76+ float [] hsv = new float [3 ];
77+
78+ for (int i = 0 ; i < mCt .getColors ().size (); i ++) {
79+
80+ // Get the colors for the DataSet at the current index. If the index
81+ // is out of bounds, reuse DataSet colors.
82+ ArrayList <Integer > colors = mCt .getDataSetColors (i );
83+ ArrayList <Integer > topColors = new ArrayList <Integer >();
84+ ArrayList <Integer > sideColors = new ArrayList <Integer >();
85+
86+ for (int j = 0 ; j < colors .size (); j ++) {
87+
88+ // extract the color
89+ int c = colors .get (j );
90+ Color .colorToHSV (c , hsv ); // convert to hsv
91+
92+ // make brighter
93+ hsv [1 ] = hsv [1 ] - 0.1f ; // less saturation
94+ hsv [2 ] = hsv [2 ] + 0.1f ; // more brightness
95+
96+ // convert back
97+ c = Color .HSVToColor (hsv );
98+
99+ // assign
100+ topColors .add (c );
101+
102+ // get color again
103+ c = colors .get (j );
104+
105+ // convert
106+ Color .colorToHSV (c , hsv );
107+
108+ // make darker
109+ hsv [1 ] = hsv [1 ] + 0.1f ; // more saturation
110+ hsv [2 ] = hsv [2 ] - 0.1f ; // less brightness
111+
112+ // reassing
113+ c = Color .HSVToColor (hsv );
114+
115+ sideColors .add (c );
116+ }
117+
118+ mTopColors .add (topColors );
119+ mSideColors .add (sideColors );
120+ }
110121 }
111122
112123 @ Override
@@ -159,15 +170,6 @@ protected void drawHighlights() {
159170 transformPath (arrow );
160171 mDrawCanvas .drawPath (arrow , mHighlightPaint );
161172 }
162-
163- // float[] pts = new float[] {
164- // index + 0.5f, mYChartMax, index + 0.5f, mYChartMin,
165- // 0, mYVals.get(index), mDeltaX, mYVals.get(index)
166- // };
167- //
168- // transformPointArray(pts);
169- // // draw the highlight lines
170- // mDrawCanvas.drawLines(pts, mHighlightPaint);
171173 }
172174 }
173175 }
@@ -181,6 +183,9 @@ protected void drawData() {
181183 ArrayList <Path > topPaths = new ArrayList <Path >();
182184 ArrayList <Path > sidePaths = new ArrayList <Path >();
183185
186+ ArrayList <DataSet > dataSets = mData .getDataSets ();
187+
188+ // 3D drawing
184189 if (m3DEnabled ) {
185190
186191 float [] pts = new float [] {
@@ -209,37 +214,45 @@ protected void drawData() {
209214
210215 float depth = Math .abs (pts [3 ] - pts [1 ]) * mDepth ;
211216
212- for (int i = 0 ; i < mData .getYValCount (); i ++) {
217+ for (int i = 0 ; i < mData .getDataSetCount (); i ++) {
213218
214- float y = getYValue (i );
215- float left = i + mBarSpace / 2f ;
216- float right = i + 1f - mBarSpace / 2f ;
217- float top = y >= 0 ? y : 0 ;
219+ DataSet dataSet = dataSets .get (i );
220+ ArrayList <Series > series = dataSet .getYVals ();
221+
222+ for (int j = 0 ; j < series .size (); j ++) {
223+
224+ float x = series .get (j ).getXIndex ();
225+ float y = series .get (j ).getVal ();
226+ float left = x + mBarSpace / 2f ;
227+ float right = x + 1f - mBarSpace / 2f ;
228+ float top = y >= 0 ? y : 0 ;
218229
219- // create the 3D effect paths for the top and side
220- Path topPath = new Path ();
221- topPath .moveTo (left , top );
222- topPath .lineTo (left + mSkew , top + depth );
223- topPath .lineTo (right + mSkew , top + depth );
224- topPath .lineTo (right , top );
230+ // create the 3D effect paths for the top and side
231+ Path topPath = new Path ();
232+ topPath .moveTo (left , top );
233+ topPath .lineTo (left + mSkew , top + depth );
234+ topPath .lineTo (right + mSkew , top + depth );
235+ topPath .lineTo (right , top );
225236
226- topPaths .add (topPath );
237+ topPaths .add (topPath );
227238
228- Path sidePath = new Path ();
229- sidePath .moveTo (right , top );
230- sidePath .lineTo (right + mSkew , top + depth );
231- sidePath .lineTo (right + mSkew , depth );
232- sidePath .lineTo (right , 0 );
239+ Path sidePath = new Path ();
240+ sidePath .moveTo (right , top );
241+ sidePath .lineTo (right + mSkew , top + depth );
242+ sidePath .lineTo (right + mSkew , depth );
243+ sidePath .lineTo (right , 0 );
233244
234- sidePaths .add (sidePath );
245+ sidePaths .add (sidePath );
246+ }
235247 }
236248
237249 transformPaths (topPaths );
238250 transformPaths (sidePaths );
239251 }
252+
253+ int cnt = 0 ;
240254
241- ArrayList <DataSet > dataSets = mData .getDataSets ();
242-
255+ // 2D drawing
243256 for (int i = 0 ; i < mData .getDataSetCount (); i ++) {
244257
245258 DataSet dataSet = dataSets .get (i );
@@ -248,6 +261,8 @@ protected void drawData() {
248261 // Get the colors for the DataSet at the current index. If the index
249262 // is out of bounds, reuse DataSet colors.
250263 ArrayList <Integer > colors = mCt .getDataSetColors (i % mCt .getColors ().size ());
264+ ArrayList <Integer > colors3DTop = mTopColors .get (i % mCt .getColors ().size ());
265+ ArrayList <Integer > colors3DSide = mSideColors .get (i % mCt .getColors ().size ());
251266
252267 // do the drawing
253268 for (int j = 0 ; j < dataSet .getSeriesCount (); j ++) {
@@ -266,21 +281,27 @@ protected void drawData() {
266281 mBarRect .set (left , top , right , bottom );
267282
268283 transformRect (mBarRect );
284+
285+ // avoid drawing outofbounds values
286+ if (isOffContentRight (mBarRect .left )) break ;
287+
288+ if (isOffContentLeft (mBarRect .right )) {
289+ cnt ++;
290+ continue ;
291+ }
269292
270293 mDrawCanvas .drawRect (mBarRect , mRenderPaint );
271294
272295 if (m3DEnabled ) {
273296
274- int c = mRenderPaint .getColor ();
275-
276- mRenderPaint .setColor (mTopColors [j % mTopColors .length ]);
277- mDrawCanvas .drawPath (topPaths .get (j ), mRenderPaint );
278-
279- mRenderPaint .setColor (mSideColors [j % mSideColors .length ]);
280- mDrawCanvas .drawPath (sidePaths .get (j ), mRenderPaint );
297+ mRenderPaint .setColor (colors3DTop .get (j % colors3DTop .size ()));
298+ mDrawCanvas .drawPath (topPaths .get (cnt ), mRenderPaint );
281299
282- mRenderPaint .setColor (c );
300+ mRenderPaint .setColor (colors3DSide .get (j % colors3DSide .size ()));
301+ mDrawCanvas .drawPath (sidePaths .get (cnt ), mRenderPaint );
283302 }
303+
304+ cnt ++;
284305 }
285306 }
286307 }
@@ -399,24 +420,6 @@ public boolean is3DEnabled() {
399420 return m3DEnabled ;
400421 }
401422
402- /**
403- * returns the top colors that define the color of the top 3D effect path
404- *
405- * @return
406- */
407- public int [] getTopColors () {
408- return mTopColors ;
409- }
410-
411- /**
412- * returns the side colors that define the color of the side 3D effect path
413- *
414- * @return
415- */
416- public int [] getSideColors () {
417- return mSideColors ;
418- }
419-
420423 /**
421424 * set this to true to draw the highlightning arrow
422425 *
0 commit comments