@@ -119,7 +119,10 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
119119 /**
120120 * paint object used for darwing the bitmap to the screen
121121 */
122- protected Paint mDrawPaint ;
122+ protected Paint mDrawPaint ;
123+
124+ /** paint used for highlighting values */
125+ protected Paint mHighlightPaint ;
123126
124127 /**
125128 * paint object used for drawing the description text in the bottom right
@@ -188,7 +191,7 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
188191 protected boolean mDrawLegend = true ;
189192
190193 /** this rectangle defines the area in which graph values can be drawn */
191- protected Rect mContentRect = new Rect ();
194+ protected RectF mContentRect = new RectF ();
192195
193196 /** the legend object containing all data associated with the legend */
194197 protected Legend mLegend ;
@@ -262,7 +265,12 @@ protected void init() {
262265 mLegendFormPaint .setStrokeWidth (3f );
263266
264267 mLegendLabelPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
265- mLegendLabelPaint .setTextSize (Utils .convertDpToPixel (9f ));
268+ mLegendLabelPaint .setTextSize (Utils .convertDpToPixel (9f ));
269+
270+ mHighlightPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
271+ mHighlightPaint .setStyle (Paint .Style .STROKE );
272+ mHighlightPaint .setStrokeWidth (2f );
273+ mHighlightPaint .setColor (Color .rgb (255 , 187 , 115 ));
266274 }
267275
268276 // public void initWithDummyData() {
@@ -1028,60 +1036,64 @@ protected void drawMarkers() {
10281036 for (int i = 0 ; i < mIndicesToHightlight .length ; i ++) {
10291037
10301038 int xIndex = mIndicesToHightlight [i ].getXIndex ();
1039+ int dataSetIndex = mIndicesToHightlight [i ].getDataSetIndex ();
1040+
1041+ if (xIndex <= mDeltaX && xIndex <= mDeltaX * mPhaseX ) {
1042+
1043+ Entry e = getEntryByDataSetIndex (xIndex , dataSetIndex );
1044+
1045+ // make sure entry not null
1046+ if (e == null )
1047+ continue ;
1048+
1049+ float [] pos = getMarkerPosition (e , dataSetIndex );
10311050
1032- if (xIndex <= mDeltaX && xIndex <= mDeltaX * mPhaseX )
1033- drawMarkerView (xIndex , mIndicesToHightlight [i ].getDataSetIndex ());
1051+ // callbacks to update the content
1052+ mMarkerView .refreshContent (e , dataSetIndex );
1053+
1054+ mMarkerView .draw (mDrawCanvas , pos [0 ], pos [1 ]);
1055+ }
10341056 }
10351057 }
10361058
10371059 /**
1038- * Draws the view that is displayed when a value is highlighted.
1060+ * Returns the actual position in pixels of the MarkerView for the given
1061+ * Entry in the given DataSet.
10391062 *
1040- * @param xIndex the selected x-index
1041- * @param dataSetIndex the index of the selected DataSet
1063+ * @param xIndex
1064+ * @param dataSetIndex
1065+ * @return
10421066 */
1043- private void drawMarkerView ( int xIndex , int dataSetIndex ) {
1067+ private float [] getMarkerPosition ( Entry e , int dataSetIndex ) {
10441068
1045- Entry e = getEntryByDataSetIndex (xIndex , dataSetIndex );
1046-
1047- // make sure the entry is not null
1048- if (e == null ) {
1049- return ;
1050- }
1051-
1052- float xPos = (float ) xIndex ;
1069+ float xPos = (float ) e .getXIndex ();
10531070
10541071 // make sure the marker is in the center of the bars in BarChart and
10551072 // CandleStickChart
10561073 if (this instanceof CandleStickChart )
10571074 xPos += 0.5f ;
1058-
1059- else if (this instanceof BarChart ) {
1060-
1075+
1076+ else if (this instanceof BarChart ) {
1077+
10611078 BarData bd = (BarData ) mCurrentData ;
10621079 float space = bd .getGroupSpace ();
1063- float j = mCurrentData .getDataSetByIndex (dataSetIndex ).getEntryPosition (e );
1064-
1065- float x = (j * (mCurrentData .getDataSetCount () - 1 )) + dataSetIndex + space * j + space / 2f + 0.5f ;
1066-
1067- xPos += x ;
1080+ float j = mCurrentData .getDataSetByIndex (dataSetIndex )
1081+ .getEntryPosition (e );
1082+
1083+ float x = (j * (mCurrentData .getDataSetCount () - 1 )) + dataSetIndex + space * j + space
1084+ / 2f + 0.5f ;
1085+
1086+ xPos += x ;
10681087 }
10691088
10701089 // position of the marker depends on selected value index and value
10711090 float [] pts = new float [] {
10721091 xPos , e .getVal () * mPhaseY
10731092 };
1093+
10741094 transformPointArray (pts );
10751095
1076- float posX = pts [0 ];
1077- float posY = pts [1 ];
1078-
1079- // callbacks to update the content
1080- mMarkerView .refreshContent (e , dataSetIndex );
1081-
1082- // call the draw method of the markerview that will translate to the
1083- // given position and draw the view
1084- mMarkerView .draw (mDrawCanvas , posX , posY );
1096+ return pts ;
10851097 }
10861098
10871099 /**
@@ -1365,7 +1377,7 @@ public int getValueCount() {
13651377 * @return
13661378 */
13671379 public PointF getCenter () {
1368- return new PointF (getWidth () / 2 , getHeight () / 2 );
1380+ return new PointF (getWidth () / 2f , getHeight () / 2f );
13691381 }
13701382
13711383 /**
@@ -1559,7 +1571,7 @@ public Legend getLegend() {
15591571 *
15601572 * @return
15611573 */
1562- public Rect getContentRect () {
1574+ public RectF getContentRect () {
15631575 return mContentRect ;
15641576 }
15651577
0 commit comments