1 /* <lambda>null2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.spa.gallery.chart 18 19 import com.android.settingslib.spa.framework.common.SettingsEntryBuilder 20 import com.android.settingslib.spa.framework.common.SettingsPage 21 import com.android.settingslib.spa.widget.chart.BarChart 22 import com.android.settingslib.spa.widget.chart.BarChartData 23 import com.android.settingslib.spa.widget.chart.BarChartModel 24 import com.android.settingslib.spa.widget.chart.ColorPalette 25 import com.android.settingslib.spa.widget.preference.Preference 26 import com.android.settingslib.spa.widget.preference.PreferenceModel 27 import com.github.mikephil.charting.formatter.IAxisValueFormatter 28 29 fun createBarChartEntry(owner: SettingsPage) = SettingsEntryBuilder.create("Bar Chart", owner) 30 .setUiLayoutFn { 31 Preference(object : PreferenceModel { 32 override val title = "Bar Chart" 33 }) 34 BarChart( 35 barChartModel = object : BarChartModel { 36 override val chartDataList = listOf( 37 BarChartData(x = 0f, y = listOf(12f, 2f)), 38 BarChartData(x = 1f, y = listOf(5f, 1f)), 39 BarChartData(x = 2f, y = listOf(21f, 2f)), 40 BarChartData(x = 3f, y = listOf(5f, 1f)), 41 BarChartData(x = 4f, y = listOf(10f, 0f)), 42 BarChartData(x = 5f, y = listOf(9f, 1f)), 43 BarChartData(x = 6f, y = listOf(1f, 1f)), 44 ) 45 override val colors = listOf(ColorPalette.green, ColorPalette.yellow) 46 override val xValueFormatter = IAxisValueFormatter { value, _ -> 47 "4/${value.toInt() + 1}" 48 } 49 override val yValueFormatter = IAxisValueFormatter { value, _ -> 50 "${value.toInt()}m" 51 } 52 override val yAxisMaxValue = 30f 53 } 54 ) 55 }.build() 56