Skip to content

Commit

Permalink
Update selected CandlestickCartesianLayer defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalik committed Apr 6, 2024
1 parent 5f8144a commit 8ed12dc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)
}

Expand All @@ -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)
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/chart_10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
23 changes: 23 additions & 0 deletions sample/src/main/res/values/chart_10_styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2024 by Patryk Goworowski and Patrick Michalik.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<style name="Chart10BottomAxisStyle">
<item name="addExtremeHorizontalAxisLabelPadding">true</item>
<item name="horizontalAxisLabelSpacing">3</item>
<item name="showGuideline">false</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ed12dc

Please sign in to comment.