diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart1.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart1.kt index c04c1d508..249a41339 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart1.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart1.kt @@ -33,11 +33,13 @@ import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState import com.patrykandpatrick.vico.compose.common.data.rememberExtraLambda import com.patrykandpatrick.vico.compose.common.fill +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer import com.patrykandpatrick.vico.core.cartesian.data.lineSeries import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer +import com.patrykandpatrick.vico.core.common.Defaults import com.patrykandpatrick.vico.databinding.Chart1Binding import com.patrykandpatrick.vico.sample.showcase.UIFramework import com.patrykandpatrick.vico.sample.showcase.rememberMarker @@ -66,26 +68,34 @@ internal fun Chart1(uiFramework: UIFramework, modifier: Modifier) { @Composable private fun ComposeChart1(modelProducer: CartesianChartModelProducer, modifier: Modifier) { val marker = rememberMarker() + val lineThickness = Defaults.LINE_SPEC_THICKNESS_DP.dp + val requiredPaddingForLine = lineThickness.div(other = 2F) + CartesianChartHost( chart = - rememberCartesianChart( - rememberLineCartesianLayer( - LineCartesianLayer.LineProvider.series( - LineCartesianLayer.rememberLine( - remember { LineCartesianLayer.LineFill.single(fill(Color(0xffa485e0))) } - ) - ) - ), - startAxis = VerticalAxis.rememberStart(), - bottomAxis = - HorizontalAxis.rememberBottom( - guideline = null, - itemPlacer = remember { HorizontalAxis.ItemPlacer.segmented() }, + rememberCartesianChart( + rememberLineCartesianLayer( + LineCartesianLayer.LineProvider.series( + LineCartesianLayer.rememberLine( + remember { LineCartesianLayer.LineFill.single(fill(Color(0xffa485e0))) }, ), - marker = marker, - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), - persistentMarkers = rememberExtraLambda(marker) { marker at PERSISTENT_MARKER_X }, + ), + ), + startAxis = VerticalAxis.rememberStart(), + bottomAxis = + HorizontalAxis.rememberBottom( + guideline = null, + itemPlacer = remember { HorizontalAxis.ItemPlacer.segmented() }, ), + marker = marker, + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding( + unscalableStart = requiredPaddingForLine, + unscalableEnd = requiredPaddingForLine, + unscalableTop = requiredPaddingForLine, + unscalableBottom = requiredPaddingForLine, + )), + persistentMarkers = rememberExtraLambda(marker) { marker at PERSISTENT_MARKER_X }, + ), modelProducer = modelProducer, modifier = modifier, zoomState = rememberVicoZoomState(zoomEnabled = false), diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart4.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart4.kt index d6543b724..eeba8f112 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart4.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart4.kt @@ -35,6 +35,7 @@ import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent import com.patrykandpatrick.vico.compose.common.fill import com.patrykandpatrick.vico.compose.common.shape.rounded +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer @@ -117,8 +118,8 @@ private fun ComposeChart4(modelProducer: CartesianChartModelProducer, modifier: ), endAxis = VerticalAxis.rememberEnd(), marker = rememberMarker(), - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), - ), + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), + )), modelProducer = modelProducer, modifier = modifier, zoomState = rememberVicoZoomState(zoomEnabled = false), diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart5.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart5.kt index 21fdc24d2..949fd8507 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart5.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart5.kt @@ -31,6 +31,7 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesian import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer @@ -119,7 +120,7 @@ private fun ComposeChart5(modelProducer: CartesianChartModelProducer, modifier: itemPlacer = remember { HorizontalAxis.ItemPlacer.segmented() }, ), marker = rememberMarker(), - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp)), ), modelProducer = modelProducer, modifier = modifier, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart6.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart6.kt index 67130a1bb..a529cf912 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart6.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart6.kt @@ -35,6 +35,7 @@ import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent import com.patrykandpatrick.vico.compose.common.component.shapeComponent import com.patrykandpatrick.vico.compose.common.dimensions +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer @@ -109,7 +110,7 @@ private fun ComposeChart6(modelProducer: CartesianChartModelProducer, modifier: itemPlacer = remember { HorizontalAxis.ItemPlacer.segmented() }, ), marker = rememberMarker(), - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp)), decorations = listOf(rememberComposeHorizontalBox()), ), modelProducer = modelProducer, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart7.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart7.kt index 3781e51e2..fa5b36b73 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart7.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart7.kt @@ -45,6 +45,7 @@ import com.patrykandpatrick.vico.compose.common.shape.rounded import com.patrykandpatrick.vico.compose.common.vicoTheme import com.patrykandpatrick.vico.core.cartesian.CartesianDrawingContext import com.patrykandpatrick.vico.core.cartesian.CartesianMeasuringContext +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer @@ -117,7 +118,7 @@ private fun ComposeChart7(modelProducer: CartesianChartModelProducer, modifier: bottomAxis = HorizontalAxis.rememberBottom(itemPlacer = HorizontalAxis.ItemPlacer.segmented()), marker = rememberMarker(), - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp)), legend = rememberLegend(), ), modelProducer = modelProducer, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart8.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart8.kt index b37dcd149..ec7e7a4b1 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart8.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart8.kt @@ -35,6 +35,7 @@ import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent import com.patrykandpatrick.vico.compose.common.fill +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.Axis import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis @@ -123,7 +124,7 @@ private fun ComposeChart8(modelProducer: CartesianChartModelProducer, modifier: itemPlacer = remember { HorizontalAxis.ItemPlacer.segmented() } ), marker = rememberMarker(), - layerPadding = cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp), + paddingProvider = PaddingProvider.fixed(cartesianLayerPadding(scalableStart = 16.dp, scalableEnd = 16.dp)), ), modelProducer = modelProducer, modifier = modifier, diff --git a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChart.kt b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChart.kt index 64f5a5e23..1ef4f10fa 100644 --- a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChart.kt +++ b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChart.kt @@ -26,6 +26,7 @@ import com.patrykandpatrick.vico.core.cartesian.CartesianDrawingContext import com.patrykandpatrick.vico.core.cartesian.CartesianLayerPadding import com.patrykandpatrick.vico.core.cartesian.CartesianMeasuringContext import com.patrykandpatrick.vico.core.cartesian.FadingEdges +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.Axis import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModel import com.patrykandpatrick.vico.core.cartesian.decoration.Decoration @@ -52,7 +53,7 @@ public fun rememberCartesianChart( bottomAxis: Axis? = null, marker: CartesianMarker? = null, markerVisibilityListener: CartesianMarkerVisibilityListener? = null, - layerPadding: CartesianLayerPadding = cartesianLayerPadding(), + paddingProvider: PaddingProvider = PaddingProvider.fixed(), legend: Legend? = null, fadingEdges: FadingEdges? = null, decorations: List = emptyList(), @@ -68,7 +69,7 @@ public fun rememberCartesianChart( bottomAxis, marker, markerVisibilityListener, - layerPadding, + paddingProvider, legend, fadingEdges, decorations, @@ -84,7 +85,7 @@ public fun rememberCartesianChart( bottomAxis = bottomAxis, marker = marker, markerVisibilityListener = markerVisibilityListener, - layerPadding = layerPadding, + paddingProvider = paddingProvider, legend = legend, fadingEdges = fadingEdges, decorations = decorations, @@ -99,7 +100,7 @@ public fun rememberCartesianChart( bottomAxis = bottomAxis, marker = marker, markerVisibilityListener = markerVisibilityListener, - layerPadding = layerPadding, + layerPaddingProvider = paddingProvider, legend = legend, fadingEdges = fadingEdges, decorations = decorations, diff --git a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChartHost.kt b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChartHost.kt index f6372c077..889c89f33 100644 --- a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChartHost.kt +++ b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianChartHost.kt @@ -146,7 +146,7 @@ internal fun CartesianChartHostImpl( ranges = ranges, scrollEnabled = scrollState.scrollEnabled, zoomEnabled = scrollState.scrollEnabled && zoomState.zoomEnabled, - layerPadding = chart.layerPadding, + paddingProvider = chart.layerPaddingProvider, spToPx = with(LocalContext.current) { ::spToPx }, ) diff --git a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianLayerPadding.kt b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianLayerPadding.kt index e87b86825..54b9afb3d 100644 --- a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianLayerPadding.kt +++ b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianLayerPadding.kt @@ -26,10 +26,14 @@ public fun cartesianLayerPadding( scalableEnd: Dp = 0.dp, unscalableStart: Dp = 0.dp, unscalableEnd: Dp = 0.dp, + unscalableTop: Dp = 0.dp, + unscalableBottom: Dp = 0.dp, ): CartesianLayerPadding = CartesianLayerPadding( - scalableStart.value, - scalableEnd.value, - unscalableStart.value, - unscalableEnd.value, + scalableStartDp = scalableStart.value, + scalableEndDp = scalableEnd.value, + unscalableStartDp = unscalableStart.value, + unscalableEndDp = unscalableEnd.value, + unscalableTopDp = unscalableTop.value, + unscalableBottomDp = unscalableBottom.value, ) diff --git a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianMeasuringContext.kt b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianMeasuringContext.kt index 2c9581998..7cdfd1ab7 100644 --- a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianMeasuringContext.kt +++ b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/cartesian/CartesianMeasuringContext.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.LayoutDirection import com.patrykandpatrick.vico.core.cartesian.CartesianLayerPadding import com.patrykandpatrick.vico.core.cartesian.MutableCartesianMeasuringContext +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModel import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartRanges @@ -34,7 +35,7 @@ internal fun rememberCartesianMeasuringContext( ranges: CartesianChartRanges, scrollEnabled: Boolean, zoomEnabled: Boolean, - layerPadding: CartesianLayerPadding, + paddingProvider: PaddingProvider, spToPx: (Float) -> Float, ): MutableCartesianMeasuringContext = remember { @@ -46,7 +47,7 @@ internal fun rememberCartesianMeasuringContext( ranges = ranges, scrollEnabled = scrollEnabled, zoomEnabled = zoomEnabled, - layerPadding = layerPadding, + paddingProvider = paddingProvider, spToPx = spToPx, ) } @@ -57,6 +58,6 @@ internal fun rememberCartesianMeasuringContext( this.ranges = ranges this.scrollEnabled = scrollEnabled this.zoomEnabled = zoomEnabled - this.layerPadding = layerPadding + this.paddingProvider = paddingProvider this.spToPx = spToPx } diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianChart.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianChart.kt index 62b97eab8..d9925e4e6 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianChart.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianChart.kt @@ -77,7 +77,7 @@ public open class CartesianChart( @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public val marker: CartesianMarker? = null, protected val markerVisibilityListener: CartesianMarkerVisibilityListener? = null, @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public val layerPadding: CartesianLayerPadding = CartesianLayerPadding(), + public val layerPaddingProvider: PaddingProvider = PaddingProvider.fixed(), protected val legend: Legend? = null, protected val fadingEdges: FadingEdges? = null, protected val decorations: List = emptyList(), @@ -387,7 +387,7 @@ public open class CartesianChart( bottomAxis: Axis? = this.bottomAxis, marker: CartesianMarker? = this.marker, markerVisibilityListener: CartesianMarkerVisibilityListener? = this.markerVisibilityListener, - layerPadding: CartesianLayerPadding = this.layerPadding, + paddingProvider: PaddingProvider = this.layerPaddingProvider, legend: Legend? = this.legend, fadingEdges: FadingEdges? = this.fadingEdges, decorations: List = this.decorations, @@ -402,7 +402,7 @@ public open class CartesianChart( bottomAxis = bottomAxis, marker = marker, markerVisibilityListener = markerVisibilityListener, - layerPadding = layerPadding, + layerPaddingProvider = paddingProvider, legend = legend, fadingEdges = fadingEdges, decorations = decorations, @@ -417,7 +417,7 @@ public open class CartesianChart( id == other.id && marker == other.marker && markerVisibilityListener == other.markerVisibilityListener && - layerPadding == other.layerPadding && + layerPaddingProvider == other.layerPaddingProvider && legend == other.legend && fadingEdges == other.fadingEdges && decorations == other.decorations && @@ -430,7 +430,7 @@ public open class CartesianChart( id, marker, markerVisibilityListener, - layerPadding, + layerPaddingProvider, legend, fadingEdges, decorations, diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianLayerPadding.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianLayerPadding.kt index 49c832486..c7049bb71 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianLayerPadding.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianLayerPadding.kt @@ -16,8 +16,42 @@ package com.patrykandpatrick.vico.core.cartesian +import androidx.annotation.Dimension import androidx.compose.runtime.Immutable import com.patrykandpatrick.vico.core.cartesian.layer.CartesianLayer +import com.patrykandpatrick.vico.core.common.data.ExtraStore + + +@Immutable +public fun interface PaddingProvider { + public fun getCartesianLayerPadding( + extraStore: ExtraStore, + ): CartesianLayerPadding + + public companion object { + public fun fixed(layerPadding: CartesianLayerPadding): PaddingProvider = PaddingProvider { + layerPadding + } + + public fun fixed( + scalableStartDp: Float = 0f, + scalableEndDp: Float = 0f, + unscalableStartDp: Float = 0f, + unscalableEndDp: Float = 0f, + unscalableTopDp: Float = 0f, + unscalableBottomDp: Float = 0f, + ): PaddingProvider = PaddingProvider { _ -> + CartesianLayerPadding( + scalableStartDp = scalableStartDp, + scalableEndDp = scalableEndDp, + unscalableStartDp = unscalableStartDp, + unscalableEndDp = unscalableEndDp, + unscalableTopDp = unscalableTopDp, + unscalableBottomDp = unscalableBottomDp, + ) + } + } +} /** * Stores [CartesianLayer] padding values. [scalableStartDp] and [scalableEndDp] are multiplied by @@ -29,14 +63,16 @@ public class CartesianLayerPadding( internal val scalableEndDp: Float = 0f, internal val unscalableStartDp: Float = 0f, internal val unscalableEndDp: Float = 0f, + internal val unscalableTopDp: Float = 0f, + internal val unscalableBottomDp: Float = 0f, ) { override fun equals(other: Any?): Boolean = this === other || other is CartesianLayerPadding && - scalableStartDp == other.scalableStartDp && - scalableEndDp == other.scalableEndDp && - unscalableStartDp == other.unscalableStartDp && - unscalableEndDp == other.unscalableEndDp + scalableStartDp == other.scalableStartDp && + scalableEndDp == other.scalableEndDp && + unscalableStartDp == other.unscalableStartDp && + unscalableEndDp == other.unscalableEndDp override fun hashCode(): Int { var result = scalableStartDp.hashCode() diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianMeasuringContext.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianMeasuringContext.kt index 0d85ed69e..5257c3114 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianMeasuringContext.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/CartesianMeasuringContext.kt @@ -36,5 +36,5 @@ public interface CartesianMeasuringContext : MeasuringContext { public val zoomEnabled: Boolean /** Stores the [CartesianLayer] padding values. */ - public val layerPadding: CartesianLayerPadding + public val paddingProvider: PaddingProvider } diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/MutableCartesianMeasuringContext.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/MutableCartesianMeasuringContext.kt index faae42808..eb8499e6f 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/MutableCartesianMeasuringContext.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/MutableCartesianMeasuringContext.kt @@ -32,7 +32,7 @@ public class MutableCartesianMeasuringContext( override var ranges: CartesianChartRanges, override var scrollEnabled: Boolean, override var zoomEnabled: Boolean, - override var layerPadding: CartesianLayerPadding, + override var paddingProvider: PaddingProvider, spToPx: (Float) -> Float, ) : MutableMeasuringContext( diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/CandlestickCartesianLayer.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/CandlestickCartesianLayer.kt index 9702ce5ff..eb21e7a68 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/CandlestickCartesianLayer.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/CandlestickCartesianLayer.kt @@ -266,12 +266,15 @@ protected constructor( with(context) { val candleWidth = candles.getWidestCandle(model.extraStore).widthDp.pixels val xSpacing = candleWidth + candleSpacingDp.pixels + + val padding = paddingProvider.getCartesianLayerPadding(extraStore = model.extraStore) + horizontalDimensions.ensureValuesAtLeast( xSpacing = xSpacing, - scalableStartPadding = candleWidth.half + layerPadding.scalableStartDp.pixels, - scalableEndPadding = candleWidth.half + layerPadding.scalableEndDp.pixels, - unscalableStartPadding = layerPadding.unscalableStartDp.pixels, - unscalableEndPadding = layerPadding.unscalableEndDp.pixels, + scalableStartPadding = padding.scalableStartDp.pixels, + scalableEndPadding = padding.scalableEndDp.pixels, + unscalableStartPadding = padding.unscalableStartDp.pixels, + unscalableEndPadding = padding.unscalableEndDp.pixels, ) } } diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/ColumnCartesianLayer.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/ColumnCartesianLayer.kt index d8c502f44..f54edf3de 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/ColumnCartesianLayer.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/ColumnCartesianLayer.kt @@ -396,12 +396,15 @@ protected constructor( mergeMode(model.extraStore), ) val xSpacing = columnCollectionWidth + columnCollectionSpacingDp.pixels + + val padding = paddingProvider.getCartesianLayerPadding(extraStore = model.extraStore) + horizontalDimensions.ensureValuesAtLeast( xSpacing = xSpacing, - scalableStartPadding = columnCollectionWidth.half + layerPadding.scalableStartDp.pixels, - scalableEndPadding = columnCollectionWidth.half + layerPadding.scalableEndDp.pixels, - unscalableStartPadding = layerPadding.unscalableStartDp.pixels, - unscalableEndPadding = layerPadding.unscalableEndDp.pixels, + scalableStartPadding = padding.scalableStartDp.pixels, + scalableEndPadding = padding.scalableEndDp.pixels, + unscalableStartPadding = padding.unscalableStartDp.pixels, + unscalableEndPadding = padding.unscalableEndDp.pixels, ) } } diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt index ca9476c19..06b7c727e 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt @@ -571,12 +571,14 @@ protected constructor( } .pixels val xSpacing = maxPointSize + pointSpacingDp.pixels + + val padding = paddingProvider.getCartesianLayerPadding(model.extraStore) horizontalDimensions.ensureValuesAtLeast( xSpacing = xSpacing, - scalableStartPadding = layerPadding.scalableStartDp.pixels, - scalableEndPadding = layerPadding.scalableEndDp.pixels, - unscalableStartPadding = maxPointSize.half + layerPadding.unscalableStartDp.pixels, - unscalableEndPadding = maxPointSize.half + layerPadding.unscalableEndDp.pixels, + scalableStartPadding = padding.scalableStartDp.pixels, + scalableEndPadding = padding.scalableEndDp.pixels, + unscalableStartPadding = padding.unscalableStartDp.pixels, + unscalableEndPadding = padding.unscalableEndDp.pixels, ) } } @@ -598,15 +600,11 @@ protected constructor( insets: Insets, ) { with(context) { - val verticalInset = - (0.. - if (newValue != null) measuringContext.layerPadding = newValue.layerPadding + if (newValue != null) measuringContext.paddingProvider = newValue.layerPaddingProvider tryInvalidate(chart = newValue, model = model, updateRanges = true) } diff --git a/vico/views/src/main/java/com/patrykandpatrick/vico/views/common/theme/ThemeHandler.kt b/vico/views/src/main/java/com/patrykandpatrick/vico/views/common/theme/ThemeHandler.kt index 3b08c5243..75663219a 100644 --- a/vico/views/src/main/java/com/patrykandpatrick/vico/views/common/theme/ThemeHandler.kt +++ b/vico/views/src/main/java/com/patrykandpatrick/vico/views/common/theme/ThemeHandler.kt @@ -25,6 +25,7 @@ import android.view.animation.AccelerateInterpolator import com.patrykandpatrick.vico.core.cartesian.CartesianChart import com.patrykandpatrick.vico.core.cartesian.CartesianLayerPadding import com.patrykandpatrick.vico.core.cartesian.FadingEdges +import com.patrykandpatrick.vico.core.cartesian.PaddingProvider import com.patrykandpatrick.vico.core.cartesian.axis.Axis import com.patrykandpatrick.vico.core.cartesian.axis.HorizontalAxis import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis @@ -227,7 +228,7 @@ internal class ThemeHandler(private val context: Context, attrs: AttributeSet?) endAxis = baseTypedArray.getAxis(Axis.Position.Vertical.End), bottomAxis = baseTypedArray.getAxis(Axis.Position.Horizontal.Bottom), fadingEdges = baseTypedArray.getFadingEdges(), - layerPadding = baseTypedArray.getLayerPadding(), + layerPaddingProvider = PaddingProvider.fixed(baseTypedArray.getLayerPadding()), ) }