Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 27, 2024
1 parent ef7edae commit 2ab3235
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine
import com.patrykandpatrick.vico.core.chart.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.component.shape.LineComponent
import com.patrykandpatrick.vico.core.component.shape.shader.ColorShader
import com.patrykandpatrick.vico.core.component.text.textComponent
import com.patrykandpatrick.vico.core.model.CartesianChartModel
import com.patrykandpatrick.vico.core.model.LineCartesianLayerModel
import com.patrykandpatrick.vico.views.chart.CartesianChartView
import com.patrykandpatrick.vico.core.entry.FloatEntry
import com.patrykandpatrick.vico.core.entry.entryModelOf
import com.patrykandpatrick.vico.views.chart.ChartView
import org.koin.android.ext.android.inject
import org.piepmeyer.gauguin.R
import org.piepmeyer.gauguin.databinding.ActivityStatisticsBinding
Expand Down Expand Up @@ -68,39 +62,39 @@ class StatisticsActivity : AppCompatActivity() {
fillChart(
binding.overallDifficulty,
statisticeManager.statistics().overall.solvedDifficulty,
statisticeManager.statistics().overall.solvedDifficulty.average(),
statisticeManager.statistics().overall.solvedDifficulty.average().toFloat(),
com.google.android.material.R.attr.colorPrimary,
com.google.android.material.R.attr.colorOnPrimary,
)

fillChart(
binding.overallDuration,
statisticeManager.statistics().overall.solvedDuration,
statisticeManager.statistics().overall.solvedDuration.average(),
statisticeManager.statistics().overall.solvedDuration.average().toFloat(),
com.google.android.material.R.attr.colorSecondary,
com.google.android.material.R.attr.colorOnSecondary,
)
}

private fun <T : Number> fillChart(
chartView: CartesianChartView,
chartView: ChartView,
chartData: List<T>,
average: Double,
average: Float,
lineColor: Int,
areaColor: Int,
) {
val wrappedChartData = dublicateIfSingleItem(chartData)

val chartFloatData = wrappedChartData.mapIndexed { index, value -> FloatEntry(index.toFloat(), value.toFloat()) }

chartView.setModel(
CartesianChartModel(
LineCartesianLayerModel.build {
series(wrappedChartData)
},
entryModelOf(
chartFloatData,
),
)

if (wrappedChartData.any { it.toDouble() != average }) {
chartView.chart!!.addDecoration(
if (chartFloatData.any { it.y != average }) {
/*chartView.chart!!.addDecoration(
ThresholdLine(
thresholdValue = average.toFloat(),
thresholdLabel = "Mittelwert",
Expand All @@ -113,7 +107,7 @@ class StatisticsActivity : AppCompatActivity() {
color = MaterialColors.getColor(binding.root, R.attr.colorCustomColor1)
},
),
)
)*/
}

addColorToLine(
Expand Down Expand Up @@ -142,11 +136,11 @@ class StatisticsActivity : AppCompatActivity() {
}

private fun addColorToLine(
chartView: CartesianChartView,
chartView: ChartView,
foregroundColor: Int,
backgroundColor: Int,
) {
val lineLayer = chartView.chart!!.layers.first() as LineCartesianLayer
/*val lineLayer = chartView.chart!!.layers.first() as LineCartesianLayer
val line = lineLayer.lines.first()
line.shader =
Expand All @@ -159,7 +153,7 @@ class StatisticsActivity : AppCompatActivity() {
MaterialColors.getColor(binding.root, backgroundColor),
128,
),
)
)*/
}

private fun solveRate(): Double {
Expand Down
6 changes: 2 additions & 4 deletions gauguin-app/src/main/res/layout/activity_statistics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@
app:layout_constraintStart_toStartOf="parent"
/>

<com.patrykandpatrick.vico.views.chart.CartesianChartView
<com.patrykandpatrick.vico.views.chart.ChartView
android:id="@+id/overallDifficulty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:horizontalLayout="fullWidth"
app:layers="line"
app:showBottomAxis="false"
app:showStartAxis="true"
app:layout_constraintTop_toBottomOf="@id/labelOverallDifficulty"
Expand All @@ -61,14 +60,13 @@
app:layout_constraintStart_toStartOf="parent"
/>

<com.patrykandpatrick.vico.views.chart.CartesianChartView
<com.patrykandpatrick.vico.views.chart.ChartView
android:id="@+id/overallDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:horizontalLayout="fullWidth"
app:layers="line"
app:showBottomAxis="false"
app:showStartAxis="true"
app:layout_constraintTop_toBottomOf="@id/label_overall_duration"
Expand Down
2 changes: 1 addition & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ thirdparty-konfetti = { group = "nl.dionsegijn", name = "konfetti-xml", version
thirdparty-ferriswheel = { group = "ru.github.igla", name = "ferriswheel", version = "1.2" }
thirdparty-navigationdrawer = { group = "com.mikepenz", name = "materialdrawer", version = "9.0.2" }
thirdparty-balloon = { group = "com.github.skydoves", name = "balloon", version = "1.6.4" }
thirdparty-vico = { group = "com.patrykandpatrick.vico", name = "views", version = "2.0.0-alpha.6" }
thirdparty-vico = { group = "com.patrykandpatrick.vico", name = "views", version = "1.13.1" }

[plugins]

Expand Down

0 comments on commit 2ab3235

Please sign in to comment.