@@ -72,12 +72,20 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
7272 */
7373 protected T mData = null ;
7474
75+ /** If set to true, chart continues to scroll after touch up */
76+ private boolean mDragDecelerationEnabled = true ;
77+
78+ /**
79+ * Decelaration friction coefficient in [0 ; 1] interval, higher values
80+ * indicate that speed will decrease slowly, for example if it set to 0, it
81+ * will stop immediately, if set to 1, it will scroll with constant speed,
82+ * until the last point
83+ */
84+ private float mDragDecelerationFrictionCoef = 0.9f ;
85+
7586 /** default value-formatter, number of digits depends on provided chart-data */
7687 protected ValueFormatter mDefaultFormatter ;
7788
78- /** the canvas that is used for drawing on the bitmap */
79- // protected Canvas mDrawCanvas;
80-
8189 /**
8290 * paint object used for drawing the description text in the bottom right
8391 * corner of the chart
@@ -181,7 +189,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
181189 });
182190
183191 // initialize the utils
184- Utils .init (getContext (). getResources () );
192+ Utils .init (getContext ());
185193
186194 mDefaultFormatter = new DefaultValueFormatter (1 );
187195
@@ -618,6 +626,50 @@ public ChartAnimator getAnimator() {
618626 return mAnimator ;
619627 }
620628
629+ /**
630+ * If set to true, chart continues to scroll after touch up default: true
631+ */
632+ public boolean isDragDecelerationEnabled () {
633+ return mDragDecelerationEnabled ;
634+ }
635+
636+ /**
637+ * If set to true, chart continues to scroll after touch up. Default: true.
638+ *
639+ * @param enabled
640+ */
641+ public void setDragDecelerationEnabled (boolean enabled ) {
642+ mDragDecelerationEnabled = enabled ;
643+ }
644+
645+ /**
646+ * Returns drag deceleration friction coefficient
647+ *
648+ * @return
649+ */
650+ public float getDragDecelerationFrictionCoef () {
651+ return mDragDecelerationFrictionCoef ;
652+ }
653+
654+ /**
655+ * Deceleration friction coefficient in [0 ; 1] interval, higher values
656+ * indicate that speed will decrease slowly, for example if it set to 0, it
657+ * will stop immediately. 1 is an invalid value, and will be converted to 0.999f
658+ * automatically.
659+ *
660+ * @param newValue
661+ */
662+ public void setDragDecelerationFrictionCoef (float newValue ) {
663+
664+ if (newValue < 0.f )
665+ newValue = 0.f ;
666+
667+ if (newValue >= 1f )
668+ newValue = 0.999f ;
669+
670+ mDragDecelerationFrictionCoef = newValue ;
671+ }
672+
621673 /**
622674 * ################ ################ ################ ################
623675 * ANIMATIONS ONLY WORK FOR API LEVEL 11 (Android 3.0.x) AND HIGHER.
0 commit comments