@@ -118,6 +118,9 @@ public abstract class Chart extends View {
118118
119119 /** if true, y-values are drawn on the chart */
120120 protected boolean mDrawYValues = true ;
121+
122+ /** if true, value highlightning is enabled */
123+ protected boolean mHighlightEnabled = true ;
121124
122125 /** this rectangle defines the area in which graph values can be drawn */
123126 protected Rect mContentRect ;
@@ -240,7 +243,7 @@ protected void calcMinMax() {
240243
241244 // calc delta
242245 mDeltaY = mYMax - mYChartMin ;
243- mYChartMax = mYChartMin + mDeltaY ;
246+ mYChartMax = mYChartMin + mYMax ;
244247
245248 mDeltaX = mXVals .size () - 1 ;
246249
@@ -420,28 +423,6 @@ protected void transformPointArrayNoTouch(float[] pts) {
420423 mMatrixOffset .mapPoints (pts );
421424 }
422425
423- /** the x-position the marker appears on */
424- protected int mMarkerPosX = 100 ;
425-
426- /** the y-postion the marker appears on */
427- protected int mMarkerPosY = 100 ;
428-
429- /** the view that represents the marker */
430- protected RelativeLayout mMarkerView ;
431-
432- /**
433- * draws the view that is displayed when the chart is clicked
434- */
435- protected void drawMarkerView () {
436-
437- if (mMarkerView == null )
438- return ;
439-
440- mDrawCanvas .translate (mMarkerPosX , mMarkerPosY );
441- mMarkerView .draw (mDrawCanvas );
442- mDrawCanvas .translate (-mMarkerPosX , -mMarkerPosY );
443- }
444-
445426 /**
446427 * draws the description text in the bottom right corner of the chart
447428 */
@@ -479,30 +460,11 @@ protected int calcTextWidth(Paint paint, String demoText) {
479460 * draws additional stuff, whatever that might be
480461 */
481462 protected abstract void drawAdditional ();
482-
463+
483464 /**
484- * highlights the value at the given index of the values list
485- *
486- * @param indices
465+ * draws the values of the chart that need highlightning
487466 */
488- protected void highlightValues (int [] indices ) {
489-
490- if (mSelectionListener != null ) {
491-
492- if (indices [0 ] == -1 )
493- mSelectionListener .onNothingSelected ();
494- else {
495-
496- float [] values = new float [indices .length ];
497-
498- for (int i = 0 ; i < values .length ; i ++)
499- values [i ] = getYValue (indices [i ]);
500-
501- // notify the listener
502- mSelectionListener .onValuesSelected (values , indices );
503- }
504- }
505- }
467+ protected abstract void drawHighlights ();
506468
507469 /**
508470 * ################ ################ ################ ################
@@ -578,6 +540,102 @@ protected void limitTransAndScale(Matrix matrix) {
578540
579541 matrix .setValues (vals );
580542 }
543+
544+ /**
545+ * ################ ################ ################ ################
546+ */
547+ /** BELOW THIS CODE FOR HIGHLIGHTING */
548+
549+
550+ /**
551+ * array of integers that reference the highlighted slices in the pie chart
552+ */
553+ protected int [] mIndicesToHightlight = new int [0 ];
554+
555+ /**
556+ * checks if the given index is set for highlighting or not
557+ *
558+ * @param index
559+ * @return
560+ */
561+ public boolean needsHighlight (int index ) {
562+
563+ // no highlight
564+ if (!valuesToHighlight ()) return false ;
565+
566+ for (int i = 0 ; i < mIndicesToHightlight .length ; i ++)
567+ if (mIndicesToHightlight [i ] == index )
568+ return true ;
569+
570+ return false ;
571+ }
572+
573+ /**
574+ * returns true if there are values to highlight, false if there are not
575+ * @return
576+ */
577+ public boolean valuesToHighlight () {
578+ return mIndicesToHightlight == null || mIndicesToHightlight .length == 0 ? false : true ;
579+ }
580+
581+ /**
582+ * highlights the value at the given index of the values list
583+ *
584+ * @param indices
585+ */
586+ public void highlightValues (int [] indices ) {
587+
588+ // set the indices to highlight
589+ mIndicesToHightlight = indices ;
590+
591+ // redraw the chart
592+ invalidate ();
593+
594+ if (mSelectionListener != null ) {
595+
596+ if (indices == null ) return ;
597+
598+ if (indices [0 ] == -1 )
599+ mSelectionListener .onNothingSelected ();
600+ else {
601+
602+ float [] values = new float [indices .length ];
603+
604+ for (int i = 0 ; i < values .length ; i ++)
605+ values [i ] = getYValue (indices [i ]);
606+
607+ // notify the listener
608+ mSelectionListener .onValuesSelected (values , indices );
609+ }
610+ }
611+ }
612+
613+ /**
614+ * ################ ################ ################ ################
615+ */
616+ /** BELOW CODE IS FOR THE MARKER VIEW */
617+
618+ /** the x-position the marker appears on */
619+ protected int mMarkerPosX = 100 ;
620+
621+ /** the y-postion the marker appears on */
622+ protected int mMarkerPosY = 100 ;
623+
624+ /** the view that represents the marker */
625+ protected RelativeLayout mMarkerView ;
626+
627+ /**
628+ * draws the view that is displayed when the chart is clicked
629+ */
630+ protected void drawMarkerView () {
631+
632+ if (mMarkerView == null )
633+ return ;
634+
635+ mDrawCanvas .translate (mMarkerPosX , mMarkerPosY );
636+ mMarkerView .draw (mDrawCanvas );
637+ mDrawCanvas .translate (-mMarkerPosX , -mMarkerPosY );
638+ }
581639
582640 /**
583641 * ################ ################ ################ ################
@@ -593,6 +651,21 @@ protected void limitTransAndScale(Matrix matrix) {
593651 public void setOnTouchListener (OnTouchListener l ) {
594652 this .mListener = l ;
595653 }
654+ /**
655+ * if set to true, value highlightning is enabled
656+ * @param enabled
657+ */
658+ public void setHighlightEnabled (boolean enabled ) {
659+ mHighlightEnabled = enabled ;
660+ }
661+
662+ /**
663+ * returns true if highlightning of values is enabled, false if not
664+ * @return
665+ */
666+ public boolean isHighlightEnabled () {
667+ return mHighlightEnabled ;
668+ }
596669
597670 /**
598671 * returns the total value (sum) of all y-values
@@ -748,28 +821,6 @@ public void setDrawYValues(boolean enabled) {
748821 this .mDrawYValues = enabled ;
749822 }
750823
751- // /**
752- // * set this to true to make the x-legend exactly fill the whole chart with
753- // * all values being exacly correct, if the x-legend fits, it means that
754- // all
755- // * values use exactly the whole chart width, this can however lead to an
756- // * increased or decreased number of x-legend grid lines -> e.g. if the
757- // * number of x-values is a prime number only the first and last x-legend
758- // * grid line will be created. Nevertheless, the chart will always try to
759- // get
760- // * as close as possible to the actually specified number of x-legend grid
761- // * lines. if set to false, the chart will use exactly the specified number
762- // * of x-legend grid lines. This can however lead to small incorrectness of
763- // * the gridlines if the number of x-entries cannot be divided through the
764- // * number of X-legend entries. default: enabled true
765- // *
766- // * @param enabled
767- // */
768- // public void setFitXLegend(boolean enabled) {
769- // this.mFitXLegend = enabled;
770- // prepare();
771- // }
772-
773824 /**
774825 * sets the y- starting and ending value
775826 *
@@ -815,6 +866,24 @@ public View getMarkerView() {
815866 return mMarkerView ;
816867 }
817868
869+ /**
870+ * returns the x-position of the marker view
871+ *
872+ * @return
873+ */
874+ public int getMarkerPosX () {
875+ return mMarkerPosX ;
876+ }
877+
878+ /**
879+ * returns the y-position of the marker view
880+ *
881+ * @return
882+ */
883+ public int getMarkerPosY () {
884+ return mMarkerPosY ;
885+ }
886+
818887 /** paint for the lines of the linechart */
819888 public static final int PAINT_LINE = 1 ;
820889
@@ -859,6 +928,9 @@ public View getMarkerView() {
859928
860929 /** paint for the text in the middle of the pie chart */
861930 public static final int PAINT_CENTER_TEXT = 14 ;
931+
932+ /** paint for highlightning the values of a linechart */
933+ public static final int PAINT_HIGHLIGHT_LINE = 15 ;
862934
863935 /**
864936 * set a new paint object for the specified parameter in the chart e.g.
@@ -882,18 +954,6 @@ public void setPaint(Paint p, int which) {
882954 }
883955 }
884956
885- //
886- // /**
887- // * returns true if fitting x legend is enabled, false if not if the
888- // x-legend
889- // * fits, it means that all values use exactly the whole chart width
890- // *
891- // * @return
892- // */
893- // public boolean isFitXLegendEnabled() {
894- // return mFitXLegend;
895- // }
896-
897957 /**
898958 * returns true if y-value drawing is enabled, false if not
899959 *
0 commit comments