Skip to content

Commit

Permalink
release/0.0.1 реализовали circle chart в виде первой версии
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Goncharov authored and Evgeny Goncharov committed Jul 8, 2021
1 parent 22dd5cc commit 4695689
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,21 @@ class CircleChartFragment : Fragment(R.layout.fragment_circle_chart) {
.addDataValue("Fuchsia", 50, colorTest3)
.addDataValue("Harmonia", 96, colorTest4)
.create()

val crcExample11 = requireView().findViewById<CircleChartView>(R.id.crcExample11)
crcExample11.Builder()
.addDataValue("Android", 100, colorTest1)
.addDataValue("Ios", 100, colorTest2)
.addDataValue("Fuchsia", 50, colorTest3)
.addDataValue("Harmonia", 96, colorTest4)
.create()

val crcExample12 = requireView().findViewById<CircleChartView>(R.id.crcExample12)
crcExample12.Builder()
.addDataValue("Android", 100, colorTest1)
.addDataValue("Ios", 100, colorTest2)
.addDataValue("Fuchsia", 50, colorTest3)
.addDataValue("Harmonia", 96, colorTest4)
.create()
}
}
17 changes: 17 additions & 0 deletions app/src/main/res/layout/fragment_circle_chart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,22 @@
app:arcPieMode="stroke"
app:arcPieSpacePixels="3dp"
app:arcPieStrokeSize="30dp" />

<com.saradey.studio.circlechart.CircleChartView
android:id="@+id/crcExample11"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="16dp"
app:arcPieElevation="true"
app:arcPieMode="fill"
app:arcPieSpacePixels="3dp" />

<com.saradey.studio.circlechart.CircleChartView
android:id="@+id/crcExample12"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="16dp"
app:arcPieElevation="true"
app:arcPieMode="fill" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CircleChartView : View {
/** Для внешней отрисовки elevation */
private var rectOutsideElevation = RectF()

/** Радиус круга в пикселях */
private var radius = 0f

init {
Expand All @@ -88,8 +89,6 @@ class CircleChartView : View {
if (arcPieElevation) {
arcPieElevationF =
resources.getDimensionPixelSize(R.dimen.max_size_elevation_circle).toFloat()
}
if (arcPieElevation) {
paintElevation.isAntiAlias = true
paintElevation.strokeWidth = arcPieElevationF
paintElevation.style = Paint.Style.STROKE
Expand All @@ -108,15 +107,15 @@ class CircleChartView : View {
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
var width = 0
var height = 0
val dimensionPixelSize = resources.getDimensionPixelSize(R.dimen.min_chart_size)
val dimensionMinSize = resources.getDimensionPixelSize(R.dimen.min_chart_size)
//если у нас выставлено wrap_content для ширины
//или у нас widthSize меньше минимальной ширины
//то мы делаем ширины по умолчанию, иначе мы делаем ширины
//как задано в dp
width = if (widthMode == MeasureSpec.AT_MOST ||
dimensionPixelSize > widthSize
dimensionMinSize > widthSize
) {
dimensionPixelSize
dimensionMinSize
} else {
widthSize
}
Expand All @@ -125,9 +124,9 @@ class CircleChartView : View {
//то мы делаем высоту по умолчанию, иначе мы делаем высоту
//как задано в dp
height = if (heightMode == MeasureSpec.AT_MOST ||
dimensionPixelSize > heightSize
dimensionMinSize > heightSize
) {
dimensionPixelSize
dimensionMinSize
} else {
heightSize
}
Expand Down Expand Up @@ -185,13 +184,15 @@ class CircleChartView : View {

private fun drawElevationCircle(canvas: Canvas) {
chartsInfo.forEach { model ->
canvas.drawArc(
rectInsideElevation,
model.startAngle,
model.endAngle,
useCenter,
paintElevation
)
if (arcPieMode == ARC_MODE_STROKE) {
canvas.drawArc(
rectInsideElevation,
model.startAngle,
model.endAngle,
useCenter,
paintElevation
)
}
canvas.drawArc(
rectOutsideElevation,
model.startAngle,
Expand Down

0 comments on commit 4695689

Please sign in to comment.