From 8ed12dce0cb2208c9808177aa3002d9997da1c58 Mon Sep 17 00:00:00 2001 From: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:15:06 +0200 Subject: [PATCH] Update selected `CandlestickCartesianLayer` defaults --- .../vico/sample/showcase/charts/Chart10.kt | 26 +++++++++---------- sample/src/main/res/layout/chart_10.xml | 2 ++ .../src/main/res/values/chart_10_styles.xml | 23 ++++++++++++++++ .../vico/core/common/Defaults.kt | 6 ++--- 4 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 sample/src/main/res/values/chart_10_styles.xml diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart10.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart10.kt index 76bd0dc94..f8eccf501 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart10.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart10.kt @@ -20,15 +20,16 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.viewinterop.AndroidViewBinding import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost import com.patrykandpatrick.vico.compose.cartesian.axis.rememberBottomAxis import com.patrykandpatrick.vico.compose.cartesian.axis.rememberStartAxis +import com.patrykandpatrick.vico.compose.cartesian.fullWidth import com.patrykandpatrick.vico.compose.cartesian.layer.rememberCandlestickCartesianLayer import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout import com.patrykandpatrick.vico.core.cartesian.RandomCartesianModelGenerator -import com.patrykandpatrick.vico.core.cartesian.axis.BaseAxis +import com.patrykandpatrick.vico.core.cartesian.axis.AxisItemPlacer import com.patrykandpatrick.vico.core.cartesian.model.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart10Binding import com.patrykandpatrick.vico.sample.showcase.Defaults @@ -72,11 +73,17 @@ private fun ComposeChart10( rememberCartesianChart( rememberCandlestickCartesianLayer(), startAxis = rememberStartAxis(), - bottomAxis = rememberBottomAxis(guideline = null), + bottomAxis = + rememberBottomAxis( + guideline = null, + itemPlacer = + remember { AxisItemPlacer.Horizontal.default(spacing = 3, addExtremeLabelPadding = true) }, + ), ), modelProducer = modelProducer, marker = marker, modifier = modifier, + horizontalLayout = HorizontalLayout.fullWidth(), ) } @@ -87,16 +94,7 @@ private fun ViewChart10( ) { val marker = rememberMarker(showIndicator = false) AndroidViewBinding(Chart10Binding::inflate, modifier = modifier) { - with(chartView) { - runInitialAnimation = false - this.modelProducer = modelProducer - (chart?.bottomAxis as BaseAxis).guideline = null - this.marker = marker - } + chartView.modelProducer = modelProducer + chartView.marker = marker } } - -private const val COLOR_1_CODE = 0xffa485e0 - -private val color1 = Color(COLOR_1_CODE) -private val chartColors = listOf(color1) diff --git a/sample/src/main/res/layout/chart_10.xml b/sample/src/main/res/layout/chart_10.xml index 2b9c13320..af5e03b26 100644 --- a/sample/src/main/res/layout/chart_10.xml +++ b/sample/src/main/res/layout/chart_10.xml @@ -23,6 +23,8 @@ android:id="@+id/chart_view" android:layout_width="match_parent" android:layout_height="wrap_content" + app:bottomAxisStyle="@style/Chart10BottomAxisStyle" + app:horizontalLayout="fullWidth" app:layers="candlestick" app:showBottomAxis="true" app:showStartAxis="true" /> diff --git a/sample/src/main/res/values/chart_10_styles.xml b/sample/src/main/res/values/chart_10_styles.xml new file mode 100644 index 000000000..989618271 --- /dev/null +++ b/sample/src/main/res/values/chart_10_styles.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/common/Defaults.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/common/Defaults.kt index 0f9bc7978..9d7a739c9 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/common/Defaults.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/common/Defaults.kt @@ -45,9 +45,9 @@ public object Defaults { public const val COLUMN_ROUNDNESS_PERCENT: Int = 40 public const val CANDLE_BODY_WIDTH_DP: Float = 8f public const val MIN_CANDLE_BODY_HEIGHT_DP: Float = 4f - public const val WICK_DEFAULT_WIDTH_DP: Float = 2f - public const val HOLLOW_CANDLE_STROKE_WIDTH_DP: Float = 2f - public const val CANDLE_SPACING_DP: Float = 16f + public const val WICK_DEFAULT_WIDTH_DP: Float = 1f + public const val HOLLOW_CANDLE_STROKE_WIDTH_DP: Float = 1f + public const val CANDLE_SPACING_DP: Float = 4f public const val CUBIC_STRENGTH: Float = 1f public const val DASH_LENGTH: Float = 4f public const val DASH_GAP: Float = 2f