Skip to content

Commit

Permalink
Update selected composable functions to use remember, and rename `C…
Browse files Browse the repository at this point in the history
…hart`-creating composable functions

Co-authored-by: Patryk Goworowski <[email protected]>
  • Loading branch information
patrickmichalik and Gowsky committed Aug 5, 2023
1 parent 8797ec9 commit 8129268
Show file tree
Hide file tree
Showing 20 changed files with 545 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.axis.axisLabelComponent
import com.patrykandpatrick.vico.compose.axis.horizontal.bottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.endAxis
import com.patrykandpatrick.vico.compose.axis.vertical.startAxis
import com.patrykandpatrick.vico.compose.axis.horizontal.rememberBottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberEndAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.Chart
import com.patrykandpatrick.vico.compose.chart.column.columnChart
import com.patrykandpatrick.vico.compose.chart.column.rememberColumnChart
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.shapeComponent
import com.patrykandpatrick.vico.compose.style.LocalChartStyle
Expand Down Expand Up @@ -89,13 +89,13 @@ public fun HorizontalAxisTextInside() {
horizontalMargin = 4.dp,
)
Chart(
chart = columnChart(),
chart = rememberColumnChart(),
model = model,
startAxis = startAxis(
startAxis = rememberStartAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
label = label,
),
endAxis = endAxis(
endAxis = rememberEndAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
guideline = null,
label = label,
Expand All @@ -119,18 +119,18 @@ public fun HorizontalAxisTextInsideAndBottomAxis() {
horizontalMargin = 4.dp,
)
Chart(
chart = columnChart(),
chart = rememberColumnChart(),
model = model,
startAxis = startAxis(
startAxis = rememberStartAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
label = label,
),
endAxis = endAxis(
endAxis = rememberEndAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
guideline = null,
label = label,
),
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -140,12 +140,12 @@ public fun HorizontalAxisTextInsideAndBottomAxis() {
public fun HorizontalAxisTextOutside() {
ProvidePreviewChartStyle {
Chart(
chart = columnChart(),
chart = rememberColumnChart(),
model = model,
startAxis = startAxis(
startAxis = rememberStartAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside,
),
endAxis = endAxis(
endAxis = rememberEndAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside,
guideline = null,
),
Expand All @@ -158,12 +158,12 @@ public fun HorizontalAxisTextOutside() {
public fun HorizontalAxisGuidelineDoesNotOverlayBottomAxisLine() {
ProvidePreviewChartStyle {
Chart(
chart = columnChart(),
chart = rememberColumnChart(),
model = model,
startAxis = startAxis(
startAxis = rememberStartAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside,
),
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.axis.horizontal.bottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.startAxis
import com.patrykandpatrick.vico.compose.axis.horizontal.rememberBottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.Chart
import com.patrykandpatrick.vico.compose.chart.column.columnChart
import com.patrykandpatrick.vico.compose.chart.column.rememberColumnChart
import com.patrykandpatrick.vico.core.axis.AxisItemPlacer
import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider
import com.patrykandpatrick.vico.core.component.text.textComponent
Expand All @@ -42,15 +42,15 @@ public fun SingleColumnChartWithNegativeValues() {
Surface {
Chart(
modifier = Modifier.height(250.dp),
chart = columnChart(
chart = rememberColumnChart(
persistentMarkers = mapOf(
2f to marker,
3f to marker,
),
),
model = model,
startAxis = startAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 9) }),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 9) }),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -60,12 +60,12 @@ public fun SingleColumnChartWithNegativeValues() {
public fun SingleColumnChartWithNegativeValuesAndDataLabels() {
Surface {
Chart(
chart = columnChart(
chart = rememberColumnChart(
dataLabel = textComponent(),
),
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -75,15 +75,15 @@ public fun SingleColumnChartWithNegativeValuesAndDataLabels() {
public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden() {
Surface {
Chart(
chart = columnChart(
chart = rememberColumnChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = 1f,
maxY = 4f,
),
),
model = model,
startAxis = startAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 4) }),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 4) }),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -93,15 +93,15 @@ public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden() {
public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden2() {
Surface {
Chart(
chart = columnChart(
chart = rememberColumnChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = -2f,
maxY = 0f,
),
),
model = model,
startAxis = startAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 3) }),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 3) }),
bottomAxis = rememberBottomAxis(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.axis.horizontal.bottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.endAxis
import com.patrykandpatrick.vico.compose.axis.vertical.startAxis
import com.patrykandpatrick.vico.compose.axis.horizontal.rememberBottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberEndAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.Chart
import com.patrykandpatrick.vico.compose.chart.column.columnChart
import com.patrykandpatrick.vico.compose.chart.line.lineChart
import com.patrykandpatrick.vico.compose.chart.column.rememberColumnChart
import com.patrykandpatrick.vico.compose.chart.line.lineSpec
import com.patrykandpatrick.vico.compose.chart.line.rememberLineChart
import com.patrykandpatrick.vico.compose.component.lineComponent
import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient
import com.patrykandpatrick.vico.compose.component.textComponent
Expand Down Expand Up @@ -56,7 +56,7 @@ private val markerMap: Map<Float, Marker>
private fun getColumnChart(
markerMap: Map<Float, Marker> = emptyMap(),
targetVerticalAxisPosition: Vertical? = null,
): ColumnChart = columnChart(
): ColumnChart = rememberColumnChart(
columns = listOf(
lineComponent(
color = Color.Black,
Expand All @@ -72,7 +72,7 @@ private fun getColumnChart(
private fun getLineChart(
markerMap: Map<Float, Marker> = emptyMap(),
targetVerticalAxisPosition: Vertical? = null,
): LineChart = lineChart(
): LineChart = rememberLineChart(
lines = listOf(
lineSpec(
lineColor = Color.DarkGray,
Expand All @@ -86,13 +86,13 @@ private fun getLineChart(
)

private val startAxis: Axis<Start>
@Composable get() = startAxis(
@Composable get() = rememberStartAxis(
label = textComponent(color = Color.Black),
itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 5) },
)

private val endAxis: Axis<End>
@Composable get() = endAxis(
@Composable get() = rememberEndAxis(
label = textComponent(color = Color.DarkGray),
itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 7) },
)
Expand All @@ -109,7 +109,7 @@ public fun ChartWithIndependentAxes(modifier: Modifier = Modifier) {
chart = composedChart,
model = model1 + model2,
startAxis = startAxis,
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
endAxis = endAxis,
modifier = modifier,
)
Expand All @@ -126,7 +126,7 @@ public fun ChartWithDependentAxes(modifier: Modifier = Modifier) {
chart = composedChart,
model = model1 + model2,
startAxis = startAxis,
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
endAxis = endAxis,
modifier = modifier,
)
Expand All @@ -139,7 +139,7 @@ public fun ColumnChart(modifier: Modifier = Modifier) {
chart = getColumnChart(markerMap = markerMap),
model = model1,
startAxis = startAxis,
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
modifier = modifier,
)
}
Expand All @@ -151,7 +151,7 @@ public fun LineChart(modifier: Modifier = Modifier) {
chart = getLineChart(markerMap = markerMap),
model = model2,
startAxis = startAxis,
bottomAxis = bottomAxis(),
bottomAxis = rememberBottomAxis(),
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.compose.axis.vertical.startAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.Chart
import com.patrykandpatrick.vico.compose.chart.line.lineChart
import com.patrykandpatrick.vico.compose.chart.line.lineSpec
import com.patrykandpatrick.vico.compose.chart.line.rememberLineChart
import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient
import com.patrykandpatrick.vico.core.chart.composed.plus
import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider
Expand All @@ -51,7 +51,7 @@ public fun LineChartDark() {

Chart(
modifier = Modifier.padding(8.dp),
chart = lineChart(
chart = rememberLineChart(
lines = listOf(
lineSpec(
lineColor = yellow,
Expand All @@ -77,47 +77,47 @@ public fun LineChartDark() {
@Composable
public fun RegularLineChart() {
Chart(
chart = lineChart(),
chart = rememberLineChart(),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

@Preview("Line Chart Expanded", widthDp = 200)
@Composable
public fun RegularLineChartExpanded() {
Chart(
chart = lineChart(
chart = rememberLineChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = -1f,
maxY = 5f,
),
),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

@Preview("Line Chart Collapsed", widthDp = 200)
@Composable
public fun RegularLineChartCollapsed() {
Chart(
chart = lineChart(
chart = rememberLineChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = 1f,
maxY = 3f,
),
),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

@Preview("Composed Chart", widthDp = 200)
@Composable
public fun ComposedLineChart() {
Chart(
chart = lineChart() + lineChart(
chart = rememberLineChart() + rememberLineChart(
lines = listOf(
lineSpec(
lineColor = Color.Blue,
Expand All @@ -131,26 +131,26 @@ public fun ComposedLineChart() {
),
),
model = model1 + model2,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

@Preview("Composed Chart Collapsed", widthDp = 200)
@Composable
public fun ComposedLineChartCollapsed() {
Chart(
chart = lineChart(
chart = rememberLineChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = 1f,
maxY = 3f,
),
) + lineChart(
) + rememberLineChart(
axisValuesOverrider = AxisValuesOverrider.fixed(
minY = 1f,
maxY = 3f,
),
),
model = model1 + model2,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}
Loading

0 comments on commit 8129268

Please sign in to comment.