Skip to content

Commit

Permalink
Update Axis-creating composable functions to use remember
Browse files Browse the repository at this point in the history
Co-authored-by: Patryk Goworowski <[email protected]>
  • Loading branch information
patrickmichalik and Gowsky committed Aug 6, 2023
1 parent fb6f3df commit e884ce8
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ 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.component.lineComponent
Expand Down Expand Up @@ -91,11 +91,11 @@ public fun HorizontalAxisTextInside() {
Chart(
chart = columnChart(),
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 @@ -121,16 +121,16 @@ public fun HorizontalAxisTextInsideAndBottomAxis() {
Chart(
chart = columnChart(),
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 @@ -142,10 +142,10 @@ public fun HorizontalAxisTextOutside() {
Chart(
chart = columnChart(),
model = model,
startAxis = startAxis(
startAxis = rememberStartAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside,
),
endAxis = endAxis(
endAxis = rememberEndAxis(
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside,
guideline = null,
),
Expand All @@ -160,10 +160,10 @@ public fun HorizontalAxisGuidelineDoesNotOverlayBottomAxisLine() {
Chart(
chart = columnChart(),
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,8 +23,8 @@ 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.core.axis.AxisItemPlacer
Expand All @@ -49,8 +49,8 @@ public fun SingleColumnChartWithNegativeValues() {
),
),
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 @@ -64,8 +64,8 @@ public fun SingleColumnChartWithNegativeValuesAndDataLabels() {
dataLabel = textComponent(),
),
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -82,8 +82,8 @@ public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden() {
),
),
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 @@ -100,8 +100,8 @@ public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden2() {
),
),
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,9 +22,9 @@ 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
Expand Down Expand Up @@ -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,7 +24,7 @@ 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
Expand Down Expand Up @@ -79,7 +79,7 @@ public fun RegularLineChart() {
Chart(
chart = lineChart(),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

Expand All @@ -94,7 +94,7 @@ public fun RegularLineChartExpanded() {
),
),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

Expand All @@ -109,7 +109,7 @@ public fun RegularLineChartCollapsed() {
),
),
model = model1,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

Expand All @@ -131,7 +131,7 @@ public fun ComposedLineChart() {
),
),
model = model1 + model2,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}

Expand All @@ -151,6 +151,6 @@ public fun ComposedLineChartCollapsed() {
),
),
model = model1 + model2,
startAxis = startAxis(),
startAxis = rememberStartAxis(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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.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.component.lineComponent
Expand Down Expand Up @@ -68,8 +68,8 @@ public fun StackedColumnChartWithNegativeValues() {
mergeMode = Stack,
),
model = model,
startAxis = startAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -85,8 +85,8 @@ public fun StackedColumnChartWithNegativeValuesAndDataLabels() {
mergeMode = Stack,
),
model = model,
startAxis = startAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }),
bottomAxis = rememberBottomAxis(),
)
}
}
Expand All @@ -105,8 +105,8 @@ public fun StackedColumnChartWithNegativeValuesAndAxisValuesOverridden() {
mergeMode = Stack,
),
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 @@ -125,8 +125,8 @@ public fun StackedColumnChartWithNegativeValuesAndAxisValuesOverridden2() {
mergeMode = Stack,
),
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 @@ -27,8 +27,8 @@ import androidx.compose.ui.graphics.Brush
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.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.scroll.rememberChartScrollSpec
Expand Down Expand Up @@ -95,8 +95,8 @@ public fun ThresholdLine() {
)
},
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false),
)
}
Expand Down Expand Up @@ -156,8 +156,8 @@ public fun ThresholdLineWithCustomText() {
)
},
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false),
)
}
Expand All @@ -179,8 +179,8 @@ public fun RangedThresholdLine() {
)
},
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false),
)
}
Expand Down Expand Up @@ -210,8 +210,8 @@ public fun RangedThresholdLineWithBrushShader() {
)
},
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false),
)
}
Expand Down Expand Up @@ -241,8 +241,8 @@ public fun RangedThresholdLineWithComponentShader() {
)
},
model = model,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(),
chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.viewinterop.AndroidViewBinding
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.line.lineChart
import com.patrykandpatrick.vico.compose.style.ProvideChartStyle
Expand All @@ -47,8 +47,8 @@ private fun ComposeChart1(chartEntryModelProducer: ChartEntryModelProducer) {
Chart(
chart = lineChart(persistentMarkers = remember(marker) { mapOf(PERSISTENT_MARKER_X to marker) }),
chartModelProducer = chartEntryModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(guideline = null),
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(guideline = null),
marker = marker,
runInitialAnimation = false,
)
Expand Down
Loading

0 comments on commit e884ce8

Please sign in to comment.