Skip to content

Commit

Permalink
Turn Dimensions into immutable data class. Remove MutableDimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowsky committed Apr 9, 2024
1 parent 5af544a commit da388b3
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.patrykandpatrick.vico.sample.previews

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -27,12 +28,11 @@ import com.patrykandpatrick.vico.compose.cartesian.axis.rememberEndAxis
import com.patrykandpatrick.vico.compose.cartesian.axis.rememberStartAxis
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesianLayer
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.common.Dimensions
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis
import com.patrykandpatrick.vico.core.cartesian.model.CartesianChartModel
import com.patrykandpatrick.vico.core.cartesian.model.ColumnCartesianLayerModel
import com.patrykandpatrick.vico.core.common.MutableDimensions
import com.patrykandpatrick.vico.core.common.shape.Corner
import com.patrykandpatrick.vico.core.common.shape.CorneredShape
import com.patrykandpatrick.vico.core.common.shape.CutCornerTreatment
Expand Down Expand Up @@ -66,16 +66,17 @@ fun HorizontalAxisTextInside() {
strokeWidth = 1.dp,
),
padding =
MutableDimensions.of(
Dimensions(
horizontal = 2.dp,
vertical = 8.dp,
),
margins =
MutableDimensions.of(
Dimensions(
horizontal = 4.dp,
vertical = 4.dp,
),
)
PaddingValues()
CartesianChartHost(
chart =
rememberCartesianChart(
Expand Down Expand Up @@ -107,12 +108,12 @@ fun HorizontalAxisTextInsideAndBottomAxis() {
color = Color.LightGray,
),
padding =
MutableDimensions.of(
Dimensions(
horizontal = 2.dp,
vertical = 8.dp,
),
margins =
MutableDimensions.of(
Dimensions(
horizontal = 4.dp,
vertical = 4.dp,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ import com.patrykandpatrick.vico.compose.cartesian.decoration.rememberHorizontal
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesianLayer
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoScrollState
import com.patrykandpatrick.vico.compose.common.Dimensions
import com.patrykandpatrick.vico.compose.common.ProvideVicoTheme
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.shader.toDynamicShader
import com.patrykandpatrick.vico.compose.common.vicoTheme
import com.patrykandpatrick.vico.core.cartesian.model.CartesianChartModel
import com.patrykandpatrick.vico.core.cartesian.model.ColumnCartesianLayerModel
import com.patrykandpatrick.vico.core.common.MutableDimensions
import com.patrykandpatrick.vico.core.common.VerticalPosition
import com.patrykandpatrick.vico.core.common.shader.ComponentShader
import com.patrykandpatrick.vico.core.common.shape.Shape
Expand Down Expand Up @@ -92,7 +91,7 @@ fun ThresholdLine() {
labelComponent =
rememberTextComponent(
Color.Black,
padding = MutableDimensions.of(horizontal = 8.dp),
padding = Dimensions(horizontal = 8.dp),
),
),
),
Expand Down Expand Up @@ -131,13 +130,13 @@ fun ThresholdLineWithCustomText() {
color = Color.Black,
),
padding =
MutableDimensions.of(
Dimensions(
start = 8.dp,
top = 2.dp,
end = 8.dp,
bottom = 4.dp,
),
margins = MutableDimensions.of(horizontal = 4.dp),
margins = Dimensions(horizontal = 4.dp),
),
label = { "Horizontal line 1 📐" },
verticalLabelPosition = VerticalPosition.Bottom,
Expand All @@ -159,13 +158,13 @@ fun ThresholdLineWithCustomText() {
color = Color.DarkGray,
),
padding =
MutableDimensions.of(
Dimensions(
start = 8.dp,
top = 4.dp,
end = 8.dp,
bottom = 2.dp,
),
margins = MutableDimensions.of(horizontal = 4.dp),
margins = Dimensions(horizontal = 4.dp),
),
label = { "Horizontal line 2 📐" },
),
Expand Down Expand Up @@ -196,7 +195,7 @@ fun RangedThresholdLine() {
labelComponent =
rememberTextComponent(
color = Color.Black,
padding = MutableDimensions.of(horizontal = 8.dp),
padding = Dimensions(horizontal = 8.dp),
),
),
),
Expand Down Expand Up @@ -237,7 +236,7 @@ fun RangedThresholdLineWithBrushShader() {
labelComponent =
rememberTextComponent(
color = Color.Black,
padding = MutableDimensions.of(horizontal = 8.dp),
padding = Dimensions(horizontal = 8.dp),
),
),
),
Expand Down Expand Up @@ -277,7 +276,7 @@ fun RangedThresholdLineWithComponentShader() {
labelComponent =
rememberTextComponent(
color = Color.Black,
padding = MutableDimensions.of(horizontal = 8.dp),
padding = Dimensions(horizontal = 8.dp),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -40,10 +41,10 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesian
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineSpec
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.common.Dimensions
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.shader.fromComponent
import com.patrykandpatrick.vico.compose.common.shader.verticalGradient
Expand All @@ -54,7 +55,6 @@ import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
import com.patrykandpatrick.vico.core.cartesian.model.CartesianChartModel
import com.patrykandpatrick.vico.core.cartesian.model.ColumnCartesianLayerModel
import com.patrykandpatrick.vico.core.cartesian.model.LineCartesianLayerModel
import com.patrykandpatrick.vico.core.common.MutableDimensions
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shape.DashedShape
import com.patrykandpatrick.vico.core.common.shape.Shape.Companion.Pill
Expand All @@ -67,7 +67,7 @@ private val chartModifier = Modifier.height(100.dp)
@Composable
fun ColumnChartCard(): Unit =
VicoTheme {
val colors = MaterialTheme.colors
val colors = MaterialTheme.colorScheme

SampleCard {
CartesianChartHost(
Expand Down Expand Up @@ -102,7 +102,7 @@ fun ColumnChartCard(): Unit =
).toVicoShape(),
color = colors.primary.copy(alpha = 0.1f),
),
padding = MutableDimensions.of(end = 8.dp, start = 4.dp),
padding = Dimensions(end = 8.dp, start = 4.dp),
),
axis = null,
tick = null,
Expand All @@ -118,7 +118,7 @@ fun ColumnChartCard(): Unit =
@Composable
fun LineChartCard(): Unit =
VicoTheme {
val colors = MaterialTheme.colors
val colors = MaterialTheme.colorScheme

SampleCard {
CartesianChartHost(
Expand All @@ -134,8 +134,11 @@ fun LineChartCard(): Unit =
DynamicShader.fromComponent(
componentSize = 4.dp,
component =
rememberShapeComponent(shape = Pill, color = colors.primary)
.apply { setMargins(0.5.dp.value) },
rememberShapeComponent(
shape = Pill,
color = colors.primary,
margins = Dimensions(0.5.dp),
),
),
),
),
Expand All @@ -148,7 +151,7 @@ fun LineChartCard(): Unit =
color = colors.onSurface,
textSize = 10.sp,
background = rememberShapeComponent(shape = Rect, color = Color.LightGray),
padding = MutableDimensions.of(horizontal = 4.dp, vertical = 2.dp),
padding = Dimensions(horizontal = 4.dp, vertical = 2.dp),
),
axis = null,
tick = null,
Expand Down Expand Up @@ -187,18 +190,18 @@ private fun SampleCard(chart: @Composable ColumnScope.() -> Unit) {
Card(
modifier = Modifier.padding(8.dp),
shape = RoundedCornerShape(8.dp),
elevation = 4.dp,
elevation = CardDefaults.elevatedCardElevation(4.dp),
) {
Column(modifier = Modifier.padding(16.dp)) {
chart()
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Title",
style = MaterialTheme.typography.h6,
style = MaterialTheme.typography.titleMedium,
)
Text(
text = "This is a subtitle. It may be long.",
style = MaterialTheme.typography.subtitle1,
style = MaterialTheme.typography.bodyMedium,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.cartesian.axis.rememberAxisGuidelineComponent
import com.patrykandpatrick.vico.compose.common.Dimensions
import com.patrykandpatrick.vico.compose.common.component.fixed
import com.patrykandpatrick.vico.compose.common.component.rememberLayeredComponent
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.shape.markerCornered
import com.patrykandpatrick.vico.core.cartesian.CartesianMeasureContext
import com.patrykandpatrick.vico.core.cartesian.HorizontalDimensions
import com.patrykandpatrick.vico.core.cartesian.insets.Insets
import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarker
import com.patrykandpatrick.vico.core.cartesian.marker.DefaultCartesianMarker
import com.patrykandpatrick.vico.core.common.MutableDimensions
import com.patrykandpatrick.vico.core.common.component.TextComponent
import com.patrykandpatrick.vico.core.common.extension.copyColor
import com.patrykandpatrick.vico.core.common.shape.Corner
Expand All @@ -57,7 +56,7 @@ internal fun rememberMarker(
rememberTextComponent(
color = MaterialTheme.colorScheme.onSurface,
background = labelBackground,
padding = MutableDimensions.of(8.dp, 4.dp),
padding = Dimensions(8.dp, 4.dp),
typeface = Typeface.MONOSPACE,
textAlignment = Layout.Alignment.ALIGN_CENTER,
minWidth = TextComponent.MinWidth.fixed(40.dp),
Expand All @@ -72,9 +71,9 @@ internal fun rememberMarker(
rememberLayeredComponent(
rear = indicatorCenterComponent,
front = indicatorFrontComponent,
padding = MutableDimensions.of(5.dp),
padding = Dimensions(5.dp),
),
padding = MutableDimensions.of(10.dp),
padding = Dimensions(10.dp),
)
val guideline = rememberAxisGuidelineComponent()
return remember(label, labelPosition, indicator, showIndicator, guideline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import com.patrykandpatrick.vico.compose.cartesian.decoration.rememberHorizontal
import com.patrykandpatrick.vico.compose.cartesian.fullWidth
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesianLayer
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.common.Dimensions
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.core.cartesian.CartesianValueFormatter
import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout
import com.patrykandpatrick.vico.core.cartesian.axis.AxisItemPlacer
Expand All @@ -43,7 +43,7 @@ import com.patrykandpatrick.vico.core.cartesian.decoration.HorizontalLine
import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
import com.patrykandpatrick.vico.core.cartesian.model.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.model.columnSeries
import com.patrykandpatrick.vico.core.common.MutableDimensions
import com.patrykandpatrick.vico.core.common.Dimensions
import com.patrykandpatrick.vico.core.common.component.LineComponent
import com.patrykandpatrick.vico.core.common.component.ShapeComponent
import com.patrykandpatrick.vico.core.common.component.TextComponent
Expand Down Expand Up @@ -146,11 +146,11 @@ private fun rememberComposeHorizontalLine(): HorizontalLine {
rememberTextComponent(
background = rememberShapeComponent(Shape.Pill, color),
padding =
MutableDimensions.of(
Dimensions(
HORIZONTAL_LINE_LABEL_HORIZONTAL_PADDING_DP.dp,
HORIZONTAL_LINE_LABEL_VERTICAL_PADDING_DP.dp,
),
margins = MutableDimensions.of(HORIZONTAL_LINE_LABEL_MARGIN_DP.dp),
margins = Dimensions(HORIZONTAL_LINE_LABEL_MARGIN_DP.dp),
typeface = Typeface.MONOSPACE,
),
)
Expand All @@ -164,11 +164,11 @@ private fun getViewHorizontalLine() =
TextComponent.build {
background = ShapeComponent(Shape.Pill, HORIZONTAL_LINE_COLOR)
padding =
MutableDimensions.of(
Dimensions(
HORIZONTAL_LINE_LABEL_VERTICAL_PADDING_DP,
HORIZONTAL_LINE_LABEL_HORIZONTAL_PADDING_DP,
)
margins = MutableDimensions.of(HORIZONTAL_LINE_LABEL_MARGIN_DP)
margins = Dimensions(HORIZONTAL_LINE_LABEL_MARGIN_DP)
typeface = Typeface.MONOSPACE
},
)
Expand Down
Loading

0 comments on commit da388b3

Please sign in to comment.