Skip to content

Add custom View PieChartView.kt. It show a cost by Category#127

Open
BestPricklyCactus wants to merge 2 commits intoOtus-Android:masterfrom
BestPricklyCactus:master
Open

Add custom View PieChartView.kt. It show a cost by Category#127
BestPricklyCactus wants to merge 2 commits intoOtus-Android:masterfrom
BestPricklyCactus:master

Conversation

@BestPricklyCactus
Copy link

Screen_recording_20251019_175131.mp4


binding.pieChartView.setData(testPayData)
binding.pieChartView.setOnCategoryClickListener { category ->
{

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо

return paint
}

fun drowPieElement(

This comment was marked as resolved.

path.addArc(rect, pieElement.startAngle, pieElement.angle)
canvas.drawArc(rect, pieElement.startAngle, pieElement.angle, true, paint)
canvas.drawTextOnPath(pieElement.angle.toUInt().toString() + "%", path, 0f,0f, paintText)
invalidate()

This comment was marked as resolved.

rect: RectF,
pieElement: PieElement
) {
val path: Path = Path()

This comment was marked as resolved.


override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val midHeight = height / 2f

This comment was marked as resolved.

}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)

This comment was marked as resolved.

val categoryAmount = it.value.sumOf { it.amount }
val partSize = categoryAmount / (totalAmount * 1f)
val angle = partSize * 360f;
pieElements.add(PieElement(colorSet.get(counter), startAngle, angle, it.key, categoryAmount))

This comment was marked as resolved.

@@ -0,0 +1,15 @@
package otus.homework.customview

enum class ColorSet (val hexCode: String){

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants