Skip to content

Commit

Permalink
Rename textComponent composable function to rememberTextComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalik committed Dec 6, 2023
1 parent 5d229af commit 2b703ff
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import com.patrykandpatrick.vico.compose.chart.layer.rememberColumnCartesianLaye
import com.patrykandpatrick.vico.compose.chart.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.color
import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.core.axis.Axis
import com.patrykandpatrick.vico.core.axis.AxisItemPlacer
import com.patrykandpatrick.vico.core.axis.AxisPosition.Vertical
Expand Down Expand Up @@ -89,14 +89,14 @@ private fun getLineLayer(verticalAxisPosition: Vertical? = null) =
private val startAxis: Axis<Start>
@Composable get() =
rememberStartAxis(
label = textComponent(color = Color.Black),
label = rememberTextComponent(color = Color.Black),
itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 5) },
)

private val endAxis: Axis<End>
@Composable get() =
rememberEndAxis(
label = textComponent(color = Color.DarkGray),
label = rememberTextComponent(color = Color.DarkGray),
itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 7) },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import com.patrykandpatrick.vico.compose.chart.layer.lineSpec
import com.patrykandpatrick.vico.compose.chart.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.chart.layout.fullWidth
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.color
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.core.axis.AxisItemPlacer
import com.patrykandpatrick.vico.core.chart.layout.HorizontalLayout
import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider
Expand Down Expand Up @@ -97,7 +97,10 @@ public fun SingleLineChartWithNegativeValuesAndDataLabels() {
rememberLineCartesianLayer(
lines =
listOf(
lineSpec(shader = DynamicShaders.color(Color.DarkGray), dataLabel = textComponent()),
lineSpec(
shader = DynamicShaders.color(Color.DarkGray),
dataLabel = rememberTextComponent(),
),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import com.patrykandpatrick.vico.compose.chart.layer.rememberColumnCartesianLaye
import com.patrykandpatrick.vico.compose.chart.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.color
import com.patrykandpatrick.vico.compose.component.shape.shader.fromComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.core.axis.horizontal.createHorizontalAxis
import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis
Expand Down Expand Up @@ -87,7 +87,7 @@ public fun ColumnChartCard(): Unit =
startAxis =
createVerticalAxis {
label =
textComponent(
rememberTextComponent(
color = colors.primary,
textSize = 10.sp,
background =
Expand Down Expand Up @@ -153,7 +153,7 @@ public fun LineChartCard(): Unit =
startAxis =
createVerticalAxis {
label =
textComponent(
rememberTextComponent(
color = colors.onSurface,
textSize = 10.sp,
background = shapeComponent(shape = rectShape, color = Color.LightGray),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import com.patrykandpatrick.vico.compose.chart.layer.rememberColumnCartesianLaye
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.chart.scroll.rememberChartScrollSpec
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.toDynamicShader
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.style.LocalChartStyle
import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine
Expand Down Expand Up @@ -100,7 +100,8 @@ public fun ThresholdLine() {
ThresholdLine(
thresholdValue = 2f,
lineComponent = shapeComponent(color = Color.Black),
labelComponent = textComponent(Color.Black, padding = dimensionsOf(horizontal = 8.dp)),
labelComponent =
rememberTextComponent(Color.Black, padding = dimensionsOf(horizontal = 8.dp)),
),
),
),
Expand Down Expand Up @@ -128,7 +129,7 @@ public fun ThresholdLineWithCustomText() {
thresholdLabel = "Threshold line 1 📐",
lineComponent = shapeComponent(color = Color.Black),
labelComponent =
textComponent(
rememberTextComponent(
color = Color.White,
lineCount = 3,
background =
Expand Down Expand Up @@ -156,7 +157,7 @@ public fun ThresholdLineWithCustomText() {
thresholdLabel = "Threshold line 2 📐",
lineComponent = shapeComponent(color = Color.DarkGray),
labelComponent =
textComponent(
rememberTextComponent(
color = Color.White,
lineCount = 3,
background =
Expand Down Expand Up @@ -203,7 +204,7 @@ public fun RangedThresholdLine() {
thresholdRange = 2f..3f,
lineComponent = shapeComponent(color = Color.Black.copy(alpha = 0.5f)),
labelComponent =
textComponent(
rememberTextComponent(
color = Color.Black,
padding = dimensionsOf(horizontal = 8.dp),
),
Expand Down Expand Up @@ -244,7 +245,7 @@ public fun RangedThresholdLineWithBrushShader() {
).toDynamicShader(),
),
labelComponent =
textComponent(
rememberTextComponent(
color = Color.Black,
padding = dimensionsOf(horizontal = 8.dp),
),
Expand Down Expand Up @@ -284,7 +285,7 @@ public fun RangedThresholdLineWithComponentShader() {
strokeColor = Color.Black,
),
labelComponent =
textComponent(
rememberTextComponent(
color = Color.Black,
padding = dimensionsOf(horizontal = 8.dp),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.overlayingComponent
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.core.chart.dimensions.HorizontalDimensions
import com.patrykandpatrick.vico.core.chart.insets.Insets
Expand All @@ -52,7 +52,7 @@ internal fun rememberMarker(): Marker {
)
}
val label =
textComponent(
rememberTextComponent(
background = labelBackground,
lineCount = LABEL_LINE_COUNT,
padding = labelPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.CartesianChartHost
import com.patrykandpatrick.vico.compose.chart.layer.rememberColumnCartesianLayer
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.style.ProvideChartStyle
import com.patrykandpatrick.vico.compose.style.currentChartStyle
Expand Down Expand Up @@ -108,7 +108,7 @@ private fun ViewChart2(modelProducer: CartesianChartModelProducer) {
private fun rememberThresholdLine(): ThresholdLine {
val line = shapeComponent(color = color2)
val label =
textComponent(
rememberTextComponent(
color = Color.Black,
background = shapeComponent(Shapes.pillShape, color2),
padding = thresholdLineLabelPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.patrykandpatrick.vico.compose.chart.edges.rememberFadingEdges
import com.patrykandpatrick.vico.compose.chart.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.chart.layout.fullWidth
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.style.ProvideChartStyle
import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis
Expand Down Expand Up @@ -68,7 +68,7 @@ private fun ComposeChart3(modelProducer: CartesianChartModelProducer) {
guideline = null,
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
titleComponent =
textComponent(
rememberTextComponent(
color = Color.Black,
background = shapeComponent(Shapes.pillShape, color1),
padding = axisTitlePadding,
Expand All @@ -80,7 +80,7 @@ private fun ComposeChart3(modelProducer: CartesianChartModelProducer) {
bottomAxis =
rememberBottomAxis(
titleComponent =
textComponent(
rememberTextComponent(
background = shapeComponent(Shapes.pillShape, color2),
color = Color.White,
padding = axisTitlePadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.CartesianChartHost
import com.patrykandpatrick.vico.compose.chart.layer.rememberColumnCartesianLayer
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.style.ProvideChartStyle
import com.patrykandpatrick.vico.compose.style.currentChartStyle
Expand Down Expand Up @@ -106,7 +106,7 @@ private fun ViewChart6(modelProducer: CartesianChartModelProducer) {
@Composable
private fun rememberThresholdLine(): ThresholdLine {
val label =
textComponent(
rememberTextComponent(
color = Color.Black,
background = shapeComponent(Shapes.rectShape, color4),
padding = thresholdLineLabelPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.CartesianChartHost
import com.patrykandpatrick.vico.compose.chart.layer.rememberLineCartesianLayer
import com.patrykandpatrick.vico.compose.chart.rememberCartesianChart
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.roundedCornerShape
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.legend.legendItem
import com.patrykandpatrick.vico.compose.legend.verticalLegend
Expand Down Expand Up @@ -120,7 +120,7 @@ private fun rememberLegend() =
legendItem(
icon = shapeComponent(Shapes.pillShape, chartColor),
label =
textComponent(
rememberTextComponent(
color = currentChartStyle.axis.axisLabelColor,
textSize = legendItemLabelTextSize,
typeface = Typeface.MONOSPACE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.component.shape.chartShape
import com.patrykandpatrick.vico.compose.component.shape.shader.BrushShader
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf
import com.patrykandpatrick.vico.compose.style.currentChartStyle
import com.patrykandpatrick.vico.core.component.shape.LineComponent
Expand Down Expand Up @@ -72,7 +72,7 @@ public fun axisLabelComponent(
typeface: Typeface = currentChartStyle.axis.axisLabelTypeface,
textAlignment: Layout.Alignment = currentChartStyle.axis.axisLabelTextAlignment,
): TextComponent =
textComponent(
rememberTextComponent(
color,
textSize,
background,
Expand Down Expand Up @@ -117,7 +117,7 @@ public fun axisLabelComponent(
typeface: Typeface = currentChartStyle.axis.axisLabelTypeface,
textAlignment: Layout.Alignment = currentChartStyle.axis.axisLabelTextAlignment,
): TextComponent =
textComponent(
rememberTextComponent(
color,
textSize,
background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public fun overlayingComponent(
)

/**
* Creates a [TextComponent].
* Creates and remembers a [TextComponent].
*
* @param color the text color.
* @param textSize the text size.
Expand All @@ -250,7 +250,7 @@ public fun overlayingComponent(
* @param textAlignment the text alignment.
*/
@Composable
public fun textComponent(
public fun rememberTextComponent(
color: Color = Color.Black,
textSize: TextUnit = DefaultDimens.TEXT_COMPONENT_TEXT_SIZE.sp,
background: ShapeComponent? = null,
Expand Down

0 comments on commit 2b703ff

Please sign in to comment.