@@ -12,12 +12,14 @@ import android.graphics.Color
1212import android.graphics.Paint
1313import android.graphics.RectF
1414import android.util.AttributeSet
15+ import android.util.Log
1516import android.view.Gravity
1617import android.view.LayoutInflater
1718import android.view.MotionEvent
1819import android.view.View
1920import android.widget.*
2021import androidx.core.content.ContextCompat
22+ import androidx.core.view.doOnPreDraw
2123import androidx.core.widget.ImageViewCompat
2224import kotlin.math.atan2
2325import kotlin.math.cos
@@ -150,13 +152,29 @@ class ClickablePieChart @JvmOverloads constructor(
150152 val currentViewLocation = IntArray (2 )
151153 this .getLocationOnScreen(currentViewLocation)
152154
155+ val halfOfSliceWidth = (sliceWidth / 2 ).toInt()
156+ val popupWindowX =
157+ (currentViewLocation[0 ] + halfRadius.toInt()) + calculatedX -
158+ (if (calculatedX < 0 ) - halfOfSliceWidth else halfOfSliceWidth)
159+ val popupWindowY =
160+ (currentViewLocation[1 ] + halfRadius.toInt()) + calculatedY -
161+ (if (calculatedY < 0 ) - halfOfSliceWidth else halfOfSliceWidth)
153162 popupWindow.showAtLocation(
154163 this ,
155164 Gravity .NO_GRAVITY ,
156- (currentViewLocation[ 0 ] + halfRadius.toInt()) + calculatedX ,
157- (currentViewLocation[ 1 ] + halfRadius.toInt()) + calculatedY
165+ popupWindowX ,
166+ popupWindowY
158167 )
159168
169+ popupView.doOnPreDraw {
170+ popupWindow.update(
171+ (popupWindowX - (it.width / 2 )),
172+ popupWindowY,
173+ popupWindow.width,
174+ popupWindow.height
175+ )
176+ }
177+
160178 val currentData = dataPoints[index]
161179
162180 }
0 commit comments