diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/AxisLinePreviews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/AxisLinePreviews.kt index 2751f9203..5dc6bd7f7 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/AxisLinePreviews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/AxisLinePreviews.kt @@ -25,20 +25,22 @@ import com.patrykandpatrick.vico.compose.axis.axisLabelComponent 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.component.lineComponent import com.patrykandpatrick.vico.compose.component.shapeComponent import com.patrykandpatrick.vico.compose.style.LocalChartStyle import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel import com.patrykandpatrick.vico.core.component.shape.Shapes import com.patrykandpatrick.vico.core.component.shape.cornered.Corner import com.patrykandpatrick.vico.core.component.shape.cornered.CorneredShape import com.patrykandpatrick.vico.core.component.shape.cornered.CutCornerTreatment import com.patrykandpatrick.vico.core.component.shape.cornered.RoundedCornerTreatment -import com.patrykandpatrick.vico.core.entry.entryModelOf -private val model = entryModelOf(1, 2, 3, 4) +private val model = CartesianChartModel(ColumnCartesianLayerModel.build { series(1, 2, 3, 4) }) @Composable private fun ProvidePreviewChartStyle(content: @Composable () -> Unit) { @@ -48,8 +50,8 @@ private fun ProvidePreviewChartStyle(content: @Composable () -> Unit) { axisLineColor = Color.Black.copy(alpha = 0.5f), axisGuidelineColor = Color.Black.copy(alpha = 0.2f), ), - columnChart = LocalChartStyle.current.columnChart.copy( - columns = LocalChartStyle.current.columnChart.columns.map { + columnLayer = LocalChartStyle.current.columnLayer.copy( + columns = LocalChartStyle.current.columnLayer.columns.map { lineComponent( color = Color.Gray, thickness = it.thicknessDp.dp, @@ -88,8 +90,8 @@ public fun HorizontalAxisTextInside() { verticalMargin = 4.dp, horizontalMargin = 4.dp, ) - Chart( - chart = columnChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer()), model = model, startAxis = rememberStartAxis( horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside, @@ -118,8 +120,8 @@ public fun HorizontalAxisTextInsideAndBottomAxis() { verticalMargin = 4.dp, horizontalMargin = 4.dp, ) - Chart( - chart = columnChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer()), model = model, startAxis = rememberStartAxis( horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside, @@ -139,8 +141,8 @@ public fun HorizontalAxisTextInsideAndBottomAxis() { @Preview(showBackground = true, widthDp = 250) public fun HorizontalAxisTextOutside() { ProvidePreviewChartStyle { - Chart( - chart = columnChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer()), model = model, startAxis = rememberStartAxis( horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside, @@ -157,8 +159,8 @@ public fun HorizontalAxisTextOutside() { @Preview(showBackground = true, widthDp = 250) public fun HorizontalAxisGuidelineDoesNotOverlayBottomAxisLine() { ProvidePreviewChartStyle { - Chart( - chart = columnChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer()), model = model, startAxis = rememberStartAxis( horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Outside, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ColumnChartsWithNegativeValuesPreviews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ColumnChartsWithNegativeValuesPreviews.kt index 6c92f521d..0702615ce 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ColumnChartsWithNegativeValuesPreviews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ColumnChartsWithNegativeValuesPreviews.kt @@ -25,28 +25,28 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.core.axis.AxisItemPlacer -import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider import com.patrykandpatrick.vico.core.component.text.textComponent -import com.patrykandpatrick.vico.core.entry.entryModelOf import com.patrykandpatrick.vico.sample.showcase.rememberMarker -private val model = entryModelOf(2f, -1f, 4f, -2f, 1f, 5f, -3f) +private val model = CartesianChartModel(LineCartesianLayerModel.build { series(2f, -1f, 4f, -2f, 1f, 5f, -3f) }) @Preview @Composable public fun SingleColumnChartWithNegativeValues() { val marker = rememberMarker() Surface { - Chart( + CartesianChartHost( modifier = Modifier.height(250.dp), - chart = columnChart( - persistentMarkers = mapOf( - 2f to marker, - 3f to marker, - ), + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + persistentMarkers = mapOf(2f to marker, 3f to marker), ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 9) }), @@ -59,10 +59,8 @@ public fun SingleColumnChartWithNegativeValues() { @Composable public fun SingleColumnChartWithNegativeValuesAndDataLabels() { Surface { - Chart( - chart = columnChart( - dataLabel = textComponent(), - ), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer(dataLabel = textComponent())), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -74,12 +72,9 @@ public fun SingleColumnChartWithNegativeValuesAndDataLabels() { @Composable public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden() { Surface { - Chart( - chart = columnChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = 1f, - maxY = 4f, - ), + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(axisValueOverrider = AxisValueOverrider.fixed(minY = 1f, maxY = 4f)), ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 4) }), @@ -92,12 +87,9 @@ public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden() { @Composable public fun SingleColumnChartWithNegativeValuesAndAxisValuesOverridden2() { Surface { - Chart( - chart = columnChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = -2f, - maxY = 0f, - ), + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(axisValueOverrider = AxisValueOverrider.fixed(minY = -2f, maxY = 0f)), ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 3) }), diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ContainedChartsPreview.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ContainedChartsPreview.kt index 7f603b641..15b0fdd29 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ContainedChartsPreview.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ContainedChartsPreview.kt @@ -25,10 +25,11 @@ import androidx.compose.ui.unit.dp 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.chart.line.lineSpec +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.component.lineComponent import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient import com.patrykandpatrick.vico.compose.component.textComponent @@ -37,26 +38,23 @@ import com.patrykandpatrick.vico.core.axis.AxisItemPlacer import com.patrykandpatrick.vico.core.axis.AxisPosition.Vertical import com.patrykandpatrick.vico.core.axis.AxisPosition.Vertical.End import com.patrykandpatrick.vico.core.axis.AxisPosition.Vertical.Start -import com.patrykandpatrick.vico.core.chart.column.ColumnChart -import com.patrykandpatrick.vico.core.chart.composed.plus -import com.patrykandpatrick.vico.core.chart.line.LineChart +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.composed.plus -import com.patrykandpatrick.vico.core.entry.entryModelOf import com.patrykandpatrick.vico.core.marker.Marker import com.patrykandpatrick.vico.sample.showcase.rememberMarker -private val model1 = entryModelOf(0 to 1, 1 to 2, 2 to 4, 3 to 1, 4 to 4) -private val model2 = entryModelOf(1 to 4, 2 to 1, 3 to 8, 4 to 12, 5 to 5) +private val model = CartesianChartModel( + ColumnCartesianLayerModel.build { series(1, 2, 4, 1, 4) }, + LineCartesianLayerModel.build { series(4, 1, 8, 12, 5) }, +) private val markerMap: Map @Composable get() = mapOf(4f to rememberMarker()) @Composable -private fun getColumnChart( - markerMap: Map = emptyMap(), - targetVerticalAxisPosition: Vertical? = null, -): ColumnChart = columnChart( +private fun getColumnLayer(targetVerticalAxisPosition: Vertical? = null) = rememberColumnCartesianLayer( columns = listOf( lineComponent( color = Color.Black, @@ -64,15 +62,11 @@ private fun getColumnChart( shape = Shapes.pillShape, ), ), - persistentMarkers = markerMap, targetVerticalAxisPosition = targetVerticalAxisPosition, ) @Composable -private fun getLineChart( - markerMap: Map = emptyMap(), - targetVerticalAxisPosition: Vertical? = null, -): LineChart = lineChart( +private fun getLineLayer(targetVerticalAxisPosition: Vertical? = null) = rememberLineCartesianLayer( lines = listOf( lineSpec( lineColor = Color.DarkGray, @@ -81,7 +75,6 @@ private fun getLineChart( ), ), ), - persistentMarkers = markerMap, targetVerticalAxisPosition = targetVerticalAxisPosition, ) @@ -100,14 +93,9 @@ private val endAxis: Axis @Composable @Preview("Chart with independent axes", widthDp = 350) public fun ChartWithIndependentAxes(modifier: Modifier = Modifier) { - val composedChart = getColumnChart(targetVerticalAxisPosition = Start) + - getLineChart(targetVerticalAxisPosition = End) - - composedChart.setPersistentMarkers(markerMap) - - Chart( - chart = composedChart, - model = model1 + model2, + CartesianChartHost( + chart = rememberCartesianChart(getColumnLayer(Start), getLineLayer(End)), + model = model, startAxis = startAxis, bottomAxis = rememberBottomAxis(), endAxis = endAxis, @@ -118,13 +106,9 @@ public fun ChartWithIndependentAxes(modifier: Modifier = Modifier) { @Composable @Preview("Chart with dependent axes", widthDp = 350) public fun ChartWithDependentAxes(modifier: Modifier = Modifier) { - val composedChart = getColumnChart() + getLineChart() - - composedChart.setPersistentMarkers(markerMap) - - Chart( - chart = composedChart, - model = model1 + model2, + CartesianChartHost( + chart = rememberCartesianChart(getColumnLayer(), getLineLayer(), persistentMarkers = markerMap), + model = model, startAxis = startAxis, bottomAxis = rememberBottomAxis(), endAxis = endAxis, @@ -135,9 +119,9 @@ public fun ChartWithDependentAxes(modifier: Modifier = Modifier) { @Composable @Preview("Column chart", widthDp = 350) public fun ColumnChart(modifier: Modifier = Modifier) { - Chart( - chart = getColumnChart(markerMap = markerMap), - model = model1, + CartesianChartHost( + chart = rememberCartesianChart(getColumnLayer(), persistentMarkers = markerMap), + model = model, startAxis = startAxis, bottomAxis = rememberBottomAxis(), modifier = modifier, @@ -147,9 +131,9 @@ public fun ColumnChart(modifier: Modifier = Modifier) { @Composable @Preview("Line chart", widthDp = 350) public fun LineChart(modifier: Modifier = Modifier) { - Chart( - chart = getLineChart(markerMap = markerMap), - model = model2, + CartesianChartHost( + chart = rememberCartesianChart(getLineLayer(), persistentMarkers = markerMap), + model = model, startAxis = startAxis, bottomAxis = rememberBottomAxis(), modifier = modifier, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/LineChartPreviews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/LineChartPreviews.kt index 4dc2d74b7..6520a0287 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/LineChartPreviews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/LineChartPreviews.kt @@ -25,19 +25,26 @@ 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.rememberStartAxis -import com.patrykandpatrick.vico.compose.chart.Chart -import com.patrykandpatrick.vico.compose.chart.line.lineChart +import com.patrykandpatrick.vico.compose.chart.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart import com.patrykandpatrick.vico.compose.chart.line.lineSpec +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer 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 -import com.patrykandpatrick.vico.core.entry.composed.plus -import com.patrykandpatrick.vico.core.entry.entriesOf -import com.patrykandpatrick.vico.core.entry.entryModelOf +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider -private val model1 = entryModelOf(0, 2, 4, 0, 2) -private val model2 = entryModelOf(1, 3, 4, 1, 3) -private val model3 = entryModelOf(entriesOf(3, 2, 2, 3, 1), entriesOf(1, 3, 1, 2, 3)) +private val model1 = CartesianChartModel(LineCartesianLayerModel.build { series(0, 2, 4, 0, 2) }) +private val model2 = CartesianChartModel( + LineCartesianLayerModel.build { series(0, 2, 4, 0, 2) }, + LineCartesianLayerModel.build { series(1, 3, 4, 1, 3) }, +) +private val model3 = CartesianChartModel( + LineCartesianLayerModel.build { + series(3, 2, 2, 3, 1) + series(1, 3, 1, 2, 3) + }, +) @Preview("Line Chart Dark", widthDp = 200) @Composable @@ -49,24 +56,26 @@ public fun LineChartDark() { val yellow = Color(0xFFFFAA4A) val pink = Color(0xFFFF4AAA) - Chart( + CartesianChartHost( modifier = Modifier.padding(8.dp), - chart = lineChart( - lines = listOf( - lineSpec( - lineColor = yellow, - lineBackgroundShader = verticalGradient( - arrayOf(yellow.copy(0.5f), yellow.copy(alpha = 0f)), + chart = rememberCartesianChart( + rememberLineCartesianLayer( + listOf( + lineSpec( + lineColor = yellow, + lineBackgroundShader = verticalGradient( + arrayOf(yellow.copy(alpha = 0.5f), yellow.copy(alpha = 0f)), + ), ), - ), - lineSpec( - lineColor = pink, - lineBackgroundShader = verticalGradient( - arrayOf(pink.copy(0.5f), pink.copy(alpha = 0f)), + lineSpec( + lineColor = pink, + lineBackgroundShader = verticalGradient( + arrayOf(pink.copy(alpha = 0.5f), pink.copy(alpha = 0f)), + ), ), ), + axisValueOverrider = AxisValueOverrider.fixed(maxY = 4f), ), - axisValuesOverrider = AxisValuesOverrider.fixed(maxY = 4f), ), model = model3, ) @@ -76,8 +85,8 @@ public fun LineChartDark() { @Preview("Line Chart", widthDp = 200) @Composable public fun RegularLineChart() { - Chart( - chart = lineChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberLineCartesianLayer()), model = model1, startAxis = rememberStartAxis(), ) @@ -86,12 +95,9 @@ public fun RegularLineChart() { @Preview("Line Chart Expanded", widthDp = 200) @Composable public fun RegularLineChartExpanded() { - Chart( - chart = lineChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = -1f, - maxY = 5f, - ), + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer(axisValueOverrider = AxisValueOverrider.fixed(minY = -1f, maxY = 5f)), ), model = model1, startAxis = rememberStartAxis(), @@ -101,12 +107,9 @@ public fun RegularLineChartExpanded() { @Preview("Line Chart Collapsed", widthDp = 200) @Composable public fun RegularLineChartCollapsed() { - Chart( - chart = lineChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = 1f, - maxY = 3f, - ), + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer(axisValueOverrider = AxisValueOverrider.fixed(minY = 1f, maxY = 3f)), ), model = model1, startAxis = rememberStartAxis(), @@ -116,21 +119,21 @@ public fun RegularLineChartCollapsed() { @Preview("Composed Chart", widthDp = 200) @Composable public fun ComposedLineChart() { - Chart( - chart = lineChart() + lineChart( - lines = listOf( - lineSpec( - lineColor = Color.Blue, - lineBackgroundShader = verticalGradient( - colors = arrayOf( - Color.Blue.copy(alpha = 0.4f), - Color.Blue.copy(alpha = 0f), + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer(), + rememberLineCartesianLayer( + listOf( + lineSpec( + lineColor = Color.Blue, + lineBackgroundShader = verticalGradient( + arrayOf(Color.Blue.copy(alpha = 0.4f), Color.Blue.copy(alpha = 0f)), ), ), ), ), ), - model = model1 + model2, + model = model2, startAxis = rememberStartAxis(), ) } @@ -138,19 +141,22 @@ public fun ComposedLineChart() { @Preview("Composed Chart Collapsed", widthDp = 200) @Composable public fun ComposedLineChartCollapsed() { - Chart( - chart = lineChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = 1f, - maxY = 3f, + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer( + axisValueOverrider = AxisValueOverrider.fixed( + minY = 1f, + maxY = 3f, + ), ), - ) + lineChart( - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = 1f, - maxY = 3f, + rememberLineCartesianLayer( + axisValueOverrider = AxisValueOverrider.fixed( + minY = 1f, + maxY = 3f, + ), ), ), - model = model1 + model2, + model = model2, startAxis = rememberStartAxis(), ) } diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/Previews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/Previews.kt index 68ee890e0..075b669b6 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/Previews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/Previews.kt @@ -34,10 +34,11 @@ import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.chart.line.lineSpec +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.component.lineComponent import com.patrykandpatrick.vico.compose.component.shape.shader.fromComponent import com.patrykandpatrick.vico.compose.component.shape.shader.verticalGradient @@ -47,13 +48,15 @@ import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf import com.patrykandpatrick.vico.core.axis.horizontal.createHorizontalAxis import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis import com.patrykandpatrick.vico.core.axis.vertical.createVerticalAxis -import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider import com.patrykandpatrick.vico.core.component.shape.DashedShape import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes.pillShape import com.patrykandpatrick.vico.core.component.shape.Shapes.rectShape import com.patrykandpatrick.vico.core.component.shape.shader.DynamicShaders -import com.patrykandpatrick.vico.core.entry.entryModelOf import com.patrykandpatrick.vico.sample.utils.VicoTheme private val chartModifier = Modifier.height(100.dp) @@ -64,15 +67,17 @@ public fun ColumnChartCard(): Unit = VicoTheme { val colors = MaterialTheme.colors SampleCard { - Chart( + CartesianChartHost( modifier = chartModifier, - chart = columnChart( - columns = listOf( - lineComponent( - colors.primary, - thickness = 8.dp, - shape = RoundedCornerShape(4.dp), - dynamicShader = verticalGradient(arrayOf(colors.primary, colors.secondary)), + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + listOf( + lineComponent( + color = colors.primary, + thickness = 8.dp, + shape = RoundedCornerShape(4.dp), + dynamicShader = verticalGradient(arrayOf(colors.primary, colors.secondary)), + ), ), ), ), @@ -98,7 +103,7 @@ public fun ColumnChartCard(): Unit = VicoTheme { 1.dp.value, ) }, - model = @Suppress("MagicNumber") (entryModelOf(1, 2, 3, 2)), + model = CartesianChartModel(ColumnCartesianLayerModel.build { series(1, 2, 3, 2) }), ) } } @@ -109,27 +114,29 @@ public fun LineChartCard(): Unit = VicoTheme { val colors = MaterialTheme.colors SampleCard { - Chart( + CartesianChartHost( modifier = Modifier.height(100.dp), - chart = lineChart( - lines = listOf( - lineSpec( - point = null, - lineColor = colors.primary, - lineBackgroundShader = DynamicShaders.fromComponent( - componentSize = 4.dp, - component = shapeComponent(shape = pillShape, color = colors.primary).apply { - setMargins(0.5.dp.value) - }, + chart = rememberCartesianChart( + rememberLineCartesianLayer( + listOf( + lineSpec( + point = null, + lineColor = colors.primary, + lineBackgroundShader = DynamicShaders.fromComponent( + componentSize = 4.dp, + component = shapeComponent(shape = pillShape, color = colors.primary) + .apply { setMargins(0.5.dp.value) }, + ), ), ), + axisValueOverrider = AxisValueOverrider.fixed(minX = 0f, maxY = 3f), ), - axisValuesOverrider = AxisValuesOverrider.fixed( - minX = 0f, - maxY = 3f, - ), ), - model = entryModelOf(-1 to 0, 0 to 0, 1 to 1, 2 to 2, 3 to 0, 4 to 2, 5 to 1), + model = CartesianChartModel( + LineCartesianLayerModel.build { + series(x = listOf(-1, 0, 1, 2, 3, 4, 5), y = listOf(0, 0, 1, 2, 0, 2, 1)) + }, + ), startAxis = createVerticalAxis { label = textComponent( color = colors.onSurface, diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/StackedColumnChartsWithNegativeValuesPreviews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/StackedColumnChartsWithNegativeValuesPreviews.kt index e893f7acd..84a3e6c67 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/StackedColumnChartsWithNegativeValuesPreviews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/StackedColumnChartsWithNegativeValuesPreviews.kt @@ -26,22 +26,25 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.component.lineComponent import com.patrykandpatrick.vico.core.axis.AxisItemPlacer -import com.patrykandpatrick.vico.core.chart.column.ColumnChart.MergeMode.Stack -import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayer +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.text.textComponent -import com.patrykandpatrick.vico.core.entry.entriesOf -import com.patrykandpatrick.vico.core.entry.entryModelOf import com.patrykandpatrick.vico.sample.showcase.rememberMarker -private val model = entryModelOf( - entriesOf(2f, -1f, -4f, 2f, 1f, -5f, -2f, -3f), - entriesOf(3f, -2f, 2f, -1f, 2f, -3f, -4f, -1f), - entriesOf(1f, -2f, 2f, 1f, -1f, 4f, 4f, -2f), +private val model = CartesianChartModel( + ColumnCartesianLayerModel.build { + series(2, -1, -4, 2, 1, -5, -2, -3) + series(3, -2, 2, -1, 2, -3, -4, -1) + series(1, -2, 2, 1, -1, 4, 4, -2) + }, ) private val columns: List @@ -57,15 +60,11 @@ private val columns: List public fun StackedColumnChartWithNegativeValues() { val marker = rememberMarker() Surface { - Chart( + CartesianChartHost( modifier = Modifier.height(250.dp), - chart = columnChart( - columns = columns, - persistentMarkers = mapOf( - 2f to marker, - 3f to marker, - ), - mergeMode = Stack, + chart = rememberCartesianChart( + rememberColumnCartesianLayer(columns = columns, mergeMode = ColumnCartesianLayer.MergeMode.Stacked), + persistentMarkers = mapOf(2f to marker, 3f to marker), ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }), @@ -78,11 +77,13 @@ public fun StackedColumnChartWithNegativeValues() { @Composable public fun StackedColumnChartWithNegativeValuesAndDataLabels() { Surface { - Chart( - chart = columnChart( - columns = columns, - dataLabel = textComponent(), - mergeMode = Stack, + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + columns = columns, + dataLabel = textComponent(), + mergeMode = ColumnCartesianLayer.MergeMode.Stacked, + ), ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 8) }), @@ -95,14 +96,13 @@ public fun StackedColumnChartWithNegativeValuesAndDataLabels() { @Composable public fun StackedColumnChartWithNegativeValuesAndAxisValuesOverridden() { Surface { - Chart( - chart = columnChart( - columns = columns, - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = 1f, - maxY = 4f, + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + columns = columns, + axisValueOverrider = AxisValueOverrider.fixed(minY = 1f, maxY = 4f), + mergeMode = ColumnCartesianLayer.MergeMode.Stacked, ), - mergeMode = Stack, ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 4) }), @@ -115,14 +115,13 @@ public fun StackedColumnChartWithNegativeValuesAndAxisValuesOverridden() { @Composable public fun StackedColumnChartWithNegativeValuesAndAxisValuesOverridden2() { Surface { - Chart( - chart = columnChart( - columns = columns, - axisValuesOverrider = AxisValuesOverrider.fixed( - minY = -2f, - maxY = 0f, + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + columns = columns, + axisValueOverrider = AxisValueOverrider.fixed(minY = -2f, maxY = 0f), + mergeMode = ColumnCartesianLayer.MergeMode.Stacked, ), - mergeMode = Stack, ), model = model, startAxis = rememberStartAxis(itemPlacer = remember { AxisItemPlacer.Vertical.default(maxItemCount = 3) }), diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ThresholdLinePreviews.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ThresholdLinePreviews.kt index f4c25ac82..065be0afe 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ThresholdLinePreviews.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/ThresholdLinePreviews.kt @@ -29,8 +29,9 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.chart.scroll.rememberChartScrollSpec import com.patrykandpatrick.vico.compose.component.lineComponent import com.patrykandpatrick.vico.compose.component.shape.shader.toDynamicShader @@ -38,12 +39,13 @@ 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.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine import com.patrykandpatrick.vico.core.component.shape.Shapes import com.patrykandpatrick.vico.core.component.shape.shader.ComponentShader -import com.patrykandpatrick.vico.core.entry.entryModelOf -private val model = entryModelOf(1, 2, 3, 4) +private val model = CartesianChartModel(ColumnCartesianLayerModel.build { series(1, 2, 3, 4) }) public val Color.Companion.DimmedGray: Color get() = Color(0xFFAAAAAA) @@ -57,8 +59,8 @@ private fun ProvidePreviewChartStyle(content: @Composable () -> Unit) { axisTickColor = Color.DimmedGray, axisGuidelineColor = Color.DimmedGray, ), - columnChart = LocalChartStyle.current.columnChart.copy( - columns = LocalChartStyle.current.columnChart.columns.map { + columnLayer = LocalChartStyle.current.columnLayer.copy( + columns = LocalChartStyle.current.columnLayer.columns.map { lineComponent( color = Color.DimmedGray, thickness = it.thicknessDp.dp, @@ -83,17 +85,18 @@ private fun ProvidePreviewChartStyle(content: @Composable () -> Unit) { @Composable public fun ThresholdLine() { ProvidePreviewChartStyle { - Chart( + CartesianChartHost( modifier = Modifier, - chart = columnChart().apply { - addDecoration( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + decorations = listOf( ThresholdLine( thresholdValue = 2f, lineComponent = shapeComponent(color = Color.Black), labelComponent = textComponent(Color.Black, padding = dimensionsOf(horizontal = 8.dp)), ), - ) - }, + ), + ), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -106,10 +109,11 @@ public fun ThresholdLine() { @Composable public fun ThresholdLineWithCustomText() { ProvidePreviewChartStyle { - Chart( + CartesianChartHost( modifier = Modifier, - chart = columnChart().apply { - addDecoration( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + decorations = listOf( ThresholdLine( thresholdValue = 2f, thresholdLabel = "Threshold line 1 ๐Ÿ“", @@ -131,8 +135,6 @@ public fun ThresholdLineWithCustomText() { ), labelVerticalPosition = ThresholdLine.LabelVerticalPosition.Bottom, ), - ) - addDecoration( ThresholdLine( thresholdValue = 3f, thresholdLabel = "Threshold line 2 ๐Ÿ“", @@ -153,8 +155,8 @@ public fun ThresholdLineWithCustomText() { margins = dimensionsOf(horizontal = 4.dp), ), ), - ) - }, + ), + ), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -167,17 +169,18 @@ public fun ThresholdLineWithCustomText() { @Composable public fun RangedThresholdLine() { ProvidePreviewChartStyle { - Chart( + CartesianChartHost( modifier = Modifier, - chart = columnChart().apply { - addDecoration( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + decorations = listOf( ThresholdLine( thresholdRange = 2f..3f, lineComponent = shapeComponent(color = Color.Black.copy(alpha = 0.5f)), labelComponent = textComponent(color = Color.Black, padding = dimensionsOf(horizontal = 8.dp)), ), - ) - }, + ), + ), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -190,10 +193,11 @@ public fun RangedThresholdLine() { @Composable public fun RangedThresholdLineWithBrushShader() { ProvidePreviewChartStyle { - Chart( + CartesianChartHost( modifier = Modifier, - chart = columnChart().apply { - addDecoration( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + decorations = listOf( ThresholdLine( thresholdRange = 2f..3f, lineComponent = shapeComponent( @@ -207,8 +211,8 @@ public fun RangedThresholdLineWithBrushShader() { ), labelComponent = textComponent(color = Color.Black, padding = dimensionsOf(horizontal = 8.dp)), ), - ) - }, + ), + ), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -221,10 +225,11 @@ public fun RangedThresholdLineWithBrushShader() { @Composable public fun RangedThresholdLineWithComponentShader() { ProvidePreviewChartStyle { - Chart( + CartesianChartHost( modifier = Modifier, - chart = columnChart().apply { - addDecoration( + chart = rememberCartesianChart( + rememberColumnCartesianLayer(), + decorations = listOf( ThresholdLine( thresholdRange = 2f..3f, lineComponent = shapeComponent( @@ -238,8 +243,8 @@ public fun RangedThresholdLineWithComponentShader() { ), labelComponent = textComponent(color = Color.Black, padding = dimensionsOf(horizontal = 8.dp)), ), - ) - }, + ), + ), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/column/ColumnCharts.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/column/ColumnCharts.kt index 6e3015af3..e396ec9bd 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/column/ColumnCharts.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/column/ColumnCharts.kt @@ -19,29 +19,30 @@ package com.patrykandpatrick.vico.sample.previews.composables.column import androidx.compose.runtime.Composable 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.chart.scroll.rememberChartScrollSpec -import com.patrykandpatrick.vico.core.entry.ChartEntryModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel import com.patrykandpatrick.vico.core.scroll.AutoScrollCondition import com.patrykandpatrick.vico.core.scroll.InitialScroll import com.patrykandpatrick.vico.sample.previews.annotation.ChartPreview import com.patrykandpatrick.vico.sample.previews.resource.PreviewSurface -import com.patrykandpatrick.vico.sample.previews.resource.mediumEntryModel -import com.patrykandpatrick.vico.sample.previews.resource.shortEntryModel +import com.patrykandpatrick.vico.sample.previews.resource.mediumColumnModel +import com.patrykandpatrick.vico.sample.previews.resource.shortColumnModel @ChartPreview @Composable public fun DefaultColumnChart( - model: ChartEntryModel = shortEntryModel, - oldModel: ChartEntryModel? = null, + model: CartesianChartModel = shortColumnModel, + oldModel: CartesianChartModel? = null, scrollable: Boolean = true, initialScroll: InitialScroll = InitialScroll.Start, - autoScrollCondition: AutoScrollCondition = AutoScrollCondition.Never, + autoScrollCondition: AutoScrollCondition = AutoScrollCondition.Never, ) { PreviewSurface { - Chart( - chart = columnChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberColumnCartesianLayer()), model = model, oldModel = oldModel, startAxis = rememberStartAxis(), @@ -58,17 +59,17 @@ public fun DefaultColumnChart( @ChartPreview @Composable public fun DefaultColumnChartLongScrollable() { - DefaultColumnChart(model = mediumEntryModel) + DefaultColumnChart(model = mediumColumnModel) } @ChartPreview @Composable public fun DefaultColumnChartLongScrollableEnd() { - DefaultColumnChart(model = mediumEntryModel, initialScroll = InitialScroll.End) + DefaultColumnChart(model = mediumColumnModel, initialScroll = InitialScroll.End) } @ChartPreview @Composable public fun DefaultColumnChartLongNonScrollable() { - DefaultColumnChart(model = mediumEntryModel, scrollable = false) + DefaultColumnChart(model = mediumColumnModel, scrollable = false) } diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/line/LineCharts.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/line/LineCharts.kt index 77eae7c41..e300d9516 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/line/LineCharts.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/composables/line/LineCharts.kt @@ -19,26 +19,27 @@ package com.patrykandpatrick.vico.sample.previews.composables.line import androidx.compose.runtime.Composable 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.chart.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.chart.scroll.rememberChartScrollSpec -import com.patrykandpatrick.vico.core.entry.ChartEntryModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel import com.patrykandpatrick.vico.core.scroll.InitialScroll import com.patrykandpatrick.vico.sample.previews.annotation.ChartPreview import com.patrykandpatrick.vico.sample.previews.resource.PreviewSurface -import com.patrykandpatrick.vico.sample.previews.resource.mediumEntryModel -import com.patrykandpatrick.vico.sample.previews.resource.shortEntryModel +import com.patrykandpatrick.vico.sample.previews.resource.mediumLineModel +import com.patrykandpatrick.vico.sample.previews.resource.shortLineModel @ChartPreview @Composable public fun DefaultLineChart( - model: ChartEntryModel = shortEntryModel, + model: CartesianChartModel = shortLineModel, scrollable: Boolean = true, initialScroll: InitialScroll = InitialScroll.Start, ) { PreviewSurface { - Chart( - chart = lineChart(), + CartesianChartHost( + chart = rememberCartesianChart(rememberLineCartesianLayer()), model = model, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(), @@ -50,17 +51,17 @@ public fun DefaultLineChart( @ChartPreview @Composable public fun DefaultLineChartLongScrollable() { - DefaultLineChart(model = mediumEntryModel) + DefaultLineChart(model = mediumLineModel) } @ChartPreview @Composable public fun DefaultLineChartLongScrollableEnd() { - DefaultLineChart(model = mediumEntryModel, initialScroll = InitialScroll.End) + DefaultLineChart(model = mediumLineModel, initialScroll = InitialScroll.End) } @ChartPreview @Composable public fun DefaultLineChartLongNonScrollable() { - DefaultLineChart(model = mediumEntryModel, scrollable = false) + DefaultLineChart(model = mediumLineModel, scrollable = false) } diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/resource/SampleModels.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/resource/SampleModels.kt index 90134f735..b5a79e686 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/resource/SampleModels.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/previews/resource/SampleModels.kt @@ -16,9 +16,16 @@ package com.patrykandpatrick.vico.sample.previews.resource -import com.patrykandpatrick.vico.core.entry.ChartEntryModel -import com.patrykandpatrick.vico.core.entry.entryModelOf +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.composed.CartesianChartModel +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel -public val shortEntryModel: ChartEntryModel = entryModelOf(1, 2, 4, 8, 3) +public val shortColumnModel = CartesianChartModel(ColumnCartesianLayerModel.build { series(1, 2, 4, 8, 3) }) -public val mediumEntryModel: ChartEntryModel = entryModelOf(1, 2, 4, 8, 3, 10, 4, 7, 2, 6, 4, 8) +public val mediumColumnModel = + CartesianChartModel(ColumnCartesianLayerModel.build { series(1, 2, 4, 8, 3, 10, 4, 7, 2, 6, 4, 8) }) + +public val shortLineModel = CartesianChartModel(LineCartesianLayerModel.build { series(1, 2, 4, 8, 3) }) + +public val mediumLineModel = + CartesianChartModel(LineCartesianLayerModel.build { series(1, 2, 4, 8, 3, 10, 4, 7, 2, 6, 4, 8) }) diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ChartStyle.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ChartStyle.kt index ef22255b3..4fec5ade5 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ChartStyle.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ChartStyle.kt @@ -27,7 +27,7 @@ import com.patrykandpatrick.vico.compose.style.ChartStyle import com.patrykandpatrick.vico.core.DefaultAlpha import com.patrykandpatrick.vico.core.DefaultColors import com.patrykandpatrick.vico.core.DefaultDimens -import com.patrykandpatrick.vico.core.chart.line.LineChart +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayer import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes import com.patrykandpatrick.vico.core.component.shape.shader.DynamicShaders @@ -43,7 +43,7 @@ internal fun rememberChartStyle(columnChartColors: List, lineChartColors: axisGuidelineColor = Color(defaultColors.axisGuidelineColor), axisLineColor = Color(defaultColors.axisLineColor), ), - ChartStyle.ColumnChart( + ChartStyle.ColumnLayer( columnChartColors.map { columnChartColor -> LineComponent( columnChartColor.toArgb(), @@ -52,9 +52,9 @@ internal fun rememberChartStyle(columnChartColors: List, lineChartColors: ) }, ), - ChartStyle.LineChart( + ChartStyle.LineLayer( lineChartColors.map { lineChartColor -> - LineChart.LineSpec( + LineCartesianLayer.LineSpec( lineColor = lineChartColor.toArgb(), lineBackgroundShader = DynamicShaders.fromBrush( Brush.verticalGradient( diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseScreen.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseScreen.kt index 69658eec8..7bb3596b5 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseScreen.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseScreen.kt @@ -26,7 +26,6 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.NavigationBar @@ -50,14 +49,13 @@ import com.patrykandpatrick.vico.sample.showcase.charts.Chart8 import com.patrykandpatrick.vico.sample.utils.plus @Composable -@OptIn(ExperimentalMaterial3Api::class) internal fun ShowcaseScreen(viewModel: ShowcaseViewModel = viewModel()) { val composeShowcaseState = rememberLazyListState() val viewShowcaseState = rememberLazyListState() Scaffold( bottomBar = { NavigationBar { - UISystem.values().forEach { uiSystem -> + UISystem.entries.forEach { uiSystem -> NavigationBarItem( selected = viewModel.uiSystem == uiSystem, onClick = { viewModel.setUISystem(uiSystem) }, @@ -89,14 +87,14 @@ internal fun ShowcaseScreen(viewModel: ShowcaseViewModel = viewModel()) { } private fun LazyListScope.chartItems(uiSystem: UISystem, viewModel: ShowcaseViewModel) { - cardItem { Chart1(uiSystem, viewModel.customStepChartEntryModelProducer) } - cardItem { Chart2(uiSystem, viewModel.chartEntryModelProducer) } - cardItem { Chart3(uiSystem, viewModel.chartEntryModelProducer) } - cardItem { Chart4(uiSystem, viewModel.composedChartEntryModelProducer) } - cardItem { Chart5(uiSystem, viewModel.multiDataSetChartEntryModelProducer) } - cardItem { Chart6(uiSystem, viewModel.multiDataSetChartEntryModelProducer) } - cardItem { Chart7(uiSystem, viewModel.multiDataSetChartEntryModelProducer) } - cardItem { Chart8(uiSystem, viewModel.composedChartEntryModelProducer) } + cardItem { Chart1(uiSystem, viewModel.modelProducer1) } + cardItem { Chart2(uiSystem, viewModel.modelProducer2) } + cardItem { Chart3(uiSystem, viewModel.modelProducer1) } + cardItem { Chart4(uiSystem, viewModel.modelProducer3) } + cardItem { Chart5(uiSystem, viewModel.modelProducer4) } + cardItem { Chart6(uiSystem, viewModel.modelProducer4) } + cardItem { Chart7(uiSystem, viewModel.modelProducer5) } + cardItem { Chart8(uiSystem, viewModel.modelProducer3) } } private fun LazyListScope.cardItem(content: @Composable () -> Unit) { diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseViewModel.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseViewModel.kt index 48844068b..c278597a6 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseViewModel.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/ShowcaseViewModel.kt @@ -21,33 +21,21 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer -import com.patrykandpatrick.vico.core.entry.composed.ComposedChartEntryModelProducer -import com.patrykandpatrick.vico.core.util.RandomEntriesGenerator +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer +import com.patrykandpatrick.vico.core.util.RandomCartesianModelGenerator import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch internal class ShowcaseViewModel : ViewModel() { + private val generator = RandomCartesianModelGenerator() - private val generator = RandomEntriesGenerator( - xRange = 0..GENERATOR_X_RANGE_TOP, - yRange = GENERATOR_Y_RANGE_BOTTOM..GENERATOR_Y_RANGE_TOP, - ) - - private val customStepGenerator = RandomEntriesGenerator( - xRange = IntProgression.fromClosedRange(rangeStart = 0, rangeEnd = GENERATOR_X_RANGE_TOP, step = 2), - yRange = GENERATOR_Y_RANGE_BOTTOM..GENERATOR_Y_RANGE_TOP, - ) - - internal val chartEntryModelProducer: ChartEntryModelProducer = ChartEntryModelProducer() - - internal val customStepChartEntryModelProducer: ChartEntryModelProducer = ChartEntryModelProducer() - - internal val multiDataSetChartEntryModelProducer: ChartEntryModelProducer = ChartEntryModelProducer() - - internal val composedChartEntryModelProducer = ComposedChartEntryModelProducer.build() + internal val modelProducer1 = CartesianChartModelProducer.build() + internal val modelProducer2 = CartesianChartModelProducer.build() + internal val modelProducer3 = CartesianChartModelProducer.build() + internal val modelProducer4 = CartesianChartModelProducer.build() + internal val modelProducer5 = CartesianChartModelProducer.build() var uiSystem by mutableStateOf(UISystem.Compose) private set @@ -55,15 +43,18 @@ internal class ShowcaseViewModel : ViewModel() { init { viewModelScope.launch { while (currentCoroutineContext().isActive) { - val randomSeries = generator.generateRandomEntries() - val randomDataSet = List(MULTI_ENTRIES_COMBINED) { generator.generateRandomEntries() } - chartEntryModelProducer.setEntries(randomSeries) - multiDataSetChartEntryModelProducer.setEntries(randomDataSet) - customStepChartEntryModelProducer.setEntries(customStepGenerator.generateRandomEntries()) - composedChartEntryModelProducer.runTransaction { - add(randomDataSet) - add(randomSeries) + val singleSeriesColumnLayerModelPartial = generator.getRandomColumnLayerModelPartial() + val singleSeriesLineLayerModelPartial = generator.getRandomLineLayerModelPartial() + val tripleSeriesColumnLayerModelPartial = generator.getRandomColumnLayerModelPartial(seriesCount = 3) + val tripleSeriesLineLayerModelPartial = generator.getRandomLineLayerModelPartial(seriesCount = 3) + modelProducer1.tryRunTransaction { add(singleSeriesLineLayerModelPartial) } + modelProducer2.tryRunTransaction { add(singleSeriesColumnLayerModelPartial) } + modelProducer3.tryRunTransaction { + add(tripleSeriesColumnLayerModelPartial) + add(singleSeriesLineLayerModelPartial) } + modelProducer4.tryRunTransaction { add(tripleSeriesColumnLayerModelPartial) } + modelProducer5.tryRunTransaction { add(tripleSeriesLineLayerModelPartial) } delay(UPDATE_FREQUENCY) } } @@ -74,10 +65,6 @@ internal class ShowcaseViewModel : ViewModel() { } private companion object { - const val MULTI_ENTRIES_COMBINED = 3 - const val GENERATOR_X_RANGE_TOP = 96 - const val GENERATOR_Y_RANGE_BOTTOM = 2 - const val GENERATOR_Y_RANGE_TOP = 20 const val UPDATE_FREQUENCY = 2000L } } 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 34e2d997b..30d36f947 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 @@ -22,31 +22,35 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.viewinterop.AndroidViewBinding 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.chart.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.style.ProvideChartStyle import com.patrykandpatrick.vico.core.axis.Axis -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart1Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart1(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart1(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart1(chartEntryModelProducer) - UISystem.Views -> ViewChart1(chartEntryModelProducer) + UISystem.Compose -> ComposeChart1(modelProducer) + UISystem.Views -> ViewChart1(modelProducer) } } @Composable -private fun ComposeChart1(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart1(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() ProvideChartStyle(rememberChartStyle(chartColors)) { - Chart( - chart = lineChart(persistentMarkers = remember(marker) { mapOf(PERSISTENT_MARKER_X to marker) }), - chartModelProducer = chartEntryModelProducer, + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer(), + persistentMarkers = remember(marker) { mapOf(PERSISTENT_MARKER_X to marker) }, + ), + modelProducer = modelProducer, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(guideline = null), marker = marker, @@ -56,13 +60,13 @@ private fun ComposeChart1(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart1(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart1(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() AndroidViewBinding(Chart1Binding::inflate) { with(chartView) { chart?.addPersistentMarker(PERSISTENT_MARKER_X, marker) runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer (bottomAxis as Axis).guideline = null this.marker = marker } @@ -70,7 +74,7 @@ private fun ViewChart1(chartEntryModelProducer: ChartEntryModelProducer) { } private const val COLOR_1_CODE = 0xffa485e0 -private const val PERSISTENT_MARKER_X = 10f +private const val PERSISTENT_MARKER_X = 5f private val color1 = Color(COLOR_1_CODE) private val chartColors = listOf(color1) diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart2.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart2.kt index 77f63b773..ef653fe34 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart2.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart2.kt @@ -24,8 +24,9 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidViewBinding 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.component.shapeComponent import com.patrykandpatrick.vico.compose.component.textComponent import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf @@ -41,7 +42,7 @@ import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine import com.patrykandpatrick.vico.core.chart.layout.HorizontalLayout import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.core.extension.half import com.patrykandpatrick.vico.databinding.Chart2Binding import com.patrykandpatrick.vico.sample.showcase.UISystem @@ -49,28 +50,28 @@ import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart2(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart2(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart2(chartEntryModelProducer) - UISystem.Views -> ViewChart2(chartEntryModelProducer) + UISystem.Compose -> ComposeChart2(modelProducer) + UISystem.Views -> ViewChart2(modelProducer) } } @Composable -private fun ComposeChart2(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart2(modelProducer: CartesianChartModelProducer) { val thresholdLine = rememberThresholdLine() ProvideChartStyle(rememberChartStyle(chartColors)) { - val defaultColumns = currentChartStyle.columnChart.columns - Chart( - chart = columnChart( - columns = remember(defaultColumns) { - defaultColumns.map { defaultColumn -> - LineComponent(defaultColumn.color, COLUMN_WIDTH_DP, defaultColumn.shape) - } - }, + val defaultColumns = currentChartStyle.columnLayer.columns + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + remember(defaultColumns) { + defaultColumns.map { LineComponent(it.color, COLUMN_WIDTH_DP, it.shape) } + }, + ), decorations = remember(thresholdLine) { listOf(thresholdLine) }, ), - chartModelProducer = chartEntryModelProducer, + modelProducer = modelProducer, startAxis = rememberStartAxis(valueFormatter = startAxisValueFormatter, itemPlacer = startAxisItemPlacer), bottomAxis = rememberBottomAxis(itemPlacer = bottomAxisItemPlacer), marker = rememberMarker(), @@ -81,14 +82,14 @@ private fun ComposeChart2(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart2(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart2(modelProducer: CartesianChartModelProducer) { val thresholdLine = rememberThresholdLine() val marker = rememberMarker() AndroidViewBinding(Chart2Binding::inflate) { with(chartView) { chart?.addDecoration(thresholdLine) runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer with(startAxis as VerticalAxis) { itemPlacer = startAxisItemPlacer valueFormatter = startAxisValueFormatter diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart3.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart3.kt index 9f7b22257..8b06f6a05 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart3.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/showcase/charts/Chart3.kt @@ -25,39 +25,41 @@ import androidx.compose.ui.viewinterop.AndroidViewBinding import com.patrykandpatrick.vico.R 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart import com.patrykandpatrick.vico.compose.chart.edges.rememberFadingEdges import com.patrykandpatrick.vico.compose.chart.layout.fullWidth -import com.patrykandpatrick.vico.compose.chart.line.lineChart +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer 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 import com.patrykandpatrick.vico.core.chart.layout.HorizontalLayout -import com.patrykandpatrick.vico.core.chart.line.LineChart -import com.patrykandpatrick.vico.core.chart.values.AxisValuesOverrider +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayer +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.chart.values.AxisValueOverrider import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart3Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart3(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart3(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart3(chartEntryModelProducer) - UISystem.Views -> ViewChart3(chartEntryModelProducer) + UISystem.Compose -> ComposeChart3(modelProducer) + UISystem.Views -> ViewChart3(modelProducer) } } @Composable -private fun ComposeChart3(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart3(modelProducer: CartesianChartModelProducer) { ProvideChartStyle(rememberChartStyle(chartColors)) { - Chart( - chart = lineChart(axisValuesOverrider = axisValueOverrider), - chartModelProducer = chartEntryModelProducer, + CartesianChartHost( + chart = rememberCartesianChart(rememberLineCartesianLayer(axisValueOverrider = axisValueOverrider)), + modelProducer = modelProducer, startAxis = rememberStartAxis( guideline = null, horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside, @@ -89,13 +91,13 @@ private fun ComposeChart3(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart3(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart3(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() AndroidViewBinding(Chart3Binding::inflate) { with(chartView) { - (chart as LineChart).axisValuesOverrider = axisValueOverrider + (chart?.layers?.get(0) as LineCartesianLayer?)?.axisValueOverrider = axisValueOverrider runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer this.marker = marker } } @@ -108,8 +110,10 @@ private const val AXIS_VALUE_OVERRIDER_Y_FRACTION = 1.2f private val color1 = Color(COLOR_1_CODE) private val color2 = Color(COLOR_2_CODE) private val chartColors = listOf(color1, color2) -private val axisValueOverrider = - AxisValuesOverrider.adaptiveYValues(yFraction = AXIS_VALUE_OVERRIDER_Y_FRACTION, round = true) +private val axisValueOverrider = AxisValueOverrider.adaptiveYValues( + yFraction = AXIS_VALUE_OVERRIDER_Y_FRACTION, + round = true, +) private val axisTitleHorizontalPaddingValue = 8.dp private val axisTitleVerticalPaddingValue = 2.dp private val axisTitlePadding = dimensionsOf(axisTitleHorizontalPaddingValue, axisTitleVerticalPaddingValue) 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 0265dc2d8..27eab5fc3 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 @@ -23,55 +23,50 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidViewBinding import com.patrykandpatrick.vico.compose.axis.horizontal.rememberTopAxis import com.patrykandpatrick.vico.compose.axis.vertical.rememberEndAxis -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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.component.shape.roundedCornerShape import com.patrykandpatrick.vico.compose.style.ProvideChartStyle import com.patrykandpatrick.vico.compose.style.currentChartStyle import com.patrykandpatrick.vico.core.chart.DefaultPointConnector -import com.patrykandpatrick.vico.core.chart.composed.plus import com.patrykandpatrick.vico.core.chart.copy import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.composed.ComposedChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart4Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart4(uiSystem: UISystem, chartEntryModelProducer: ComposedChartEntryModelProducer) { +internal fun Chart4(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart4(chartEntryModelProducer) - UISystem.Views -> ViewChart4(chartEntryModelProducer) + UISystem.Compose -> ComposeChart4(modelProducer) + UISystem.Views -> ViewChart4(modelProducer) } } @Composable -private fun ComposeChart4(chartEntryModelProducer: ComposedChartEntryModelProducer) { +private fun ComposeChart4(modelProducer: CartesianChartModelProducer) { ProvideChartStyle(rememberChartStyle(columnChartColors, lineChartColors)) { - val defaultColumns = currentChartStyle.columnChart.columns - val defaultLines = currentChartStyle.lineChart.lines - val columnChart = columnChart( - remember(defaultColumns) { - defaultColumns.map { defaultColumn -> - LineComponent( - defaultColumn.color, - defaultColumn.thicknessDp, - Shapes.roundedCornerShape(columnCornerRadius), - ) - } - }, - ) - val lineChart = lineChart( - remember(defaultLines) { - defaultLines.map { defaultLine -> defaultLine.copy(pointConnector = pointConnector) } - }, - ) - Chart( - chart = remember(columnChart, lineChart) { columnChart + lineChart }, - chartModelProducer = chartEntryModelProducer, + val defaultColumns = currentChartStyle.columnLayer.columns + val defaultLines = currentChartStyle.lineLayer.lines + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + remember(defaultColumns) { + defaultColumns.map { + LineComponent(it.color, it.thicknessDp, Shapes.roundedCornerShape(columnCornerRadius)) + } + }, + ), + rememberLineCartesianLayer( + remember(defaultLines) { defaultLines.map { it.copy(pointConnector = pointConnector) } }, + ), + ), + modelProducer = modelProducer, topAxis = rememberTopAxis(), endAxis = rememberEndAxis(), marker = rememberMarker(), @@ -81,12 +76,12 @@ private fun ComposeChart4(chartEntryModelProducer: ComposedChartEntryModelProduc } @Composable -private fun ViewChart4(chartEntryModelProducer: ComposedChartEntryModelProducer) { +private fun ViewChart4(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() AndroidViewBinding(Chart4Binding::inflate) { with(chartView) { runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer this.marker = marker } } 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 26d0e04f4..b9261a410 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 @@ -22,56 +22,60 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.viewinterop.AndroidViewBinding 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.style.ProvideChartStyle import com.patrykandpatrick.vico.compose.style.currentChartStyle import com.patrykandpatrick.vico.core.DefaultDimens import com.patrykandpatrick.vico.core.axis.AxisItemPlacer import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis -import com.patrykandpatrick.vico.core.chart.column.ColumnChart +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayer import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart5Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart5(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart5(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart5(chartEntryModelProducer) - UISystem.Views -> ViewChart5(chartEntryModelProducer) + UISystem.Compose -> ComposeChart5(modelProducer) + UISystem.Views -> ViewChart5(modelProducer) } } @Composable -private fun ComposeChart5(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart5(modelProducer: CartesianChartModelProducer) { ProvideChartStyle(rememberChartStyle(chartColors)) { - val defaultColumns = currentChartStyle.columnChart.columns - Chart( - chart = columnChart( - columns = remember(defaultColumns) { - defaultColumns.mapIndexed { index, defaultColumn -> - val topCornerRadiusPercent = - if (index == defaultColumns.lastIndex) DefaultDimens.COLUMN_ROUNDNESS_PERCENT else 0 - val bottomCornerRadiusPercent = if (index == 0) DefaultDimens.COLUMN_ROUNDNESS_PERCENT else 0 - LineComponent( - defaultColumn.color, - defaultColumn.thicknessDp, - Shapes.roundedCornerShape( - topCornerRadiusPercent, - topCornerRadiusPercent, - bottomCornerRadiusPercent, - bottomCornerRadiusPercent, - ), - ) - } - }, - mergeMode = ColumnChart.MergeMode.Stack, + val defaultColumns = currentChartStyle.columnLayer.columns + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + columns = remember(defaultColumns) { + defaultColumns.mapIndexed { index, defaultColumn -> + val topCornerRadiusPercent = + if (index == defaultColumns.lastIndex) DefaultDimens.COLUMN_ROUNDNESS_PERCENT else 0 + val bottomCornerRadiusPercent = + if (index == 0) DefaultDimens.COLUMN_ROUNDNESS_PERCENT else 0 + LineComponent( + defaultColumn.color, + defaultColumn.thicknessDp, + Shapes.roundedCornerShape( + topCornerRadiusPercent, + topCornerRadiusPercent, + bottomCornerRadiusPercent, + bottomCornerRadiusPercent, + ), + ) + } + }, + mergeMode = ColumnCartesianLayer.MergeMode.Stacked, + ), ), - chartModelProducer = chartEntryModelProducer, + modelProducer = modelProducer, startAxis = rememberStartAxis( itemPlacer = startAxisItemPlacer, labelRotationDegrees = AXIS_LABEL_ROTATION_DEGREES, @@ -84,13 +88,12 @@ private fun ComposeChart5(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart5(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart5(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() AndroidViewBinding(Chart5Binding::inflate) { with(chartView) { - (chart as ColumnChart).mergeMode = ColumnChart.MergeMode.Stack runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer (startAxis as VerticalAxis).itemPlacer = startAxisItemPlacer this.marker = marker } 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 4d8add880..acee57868 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 @@ -24,8 +24,9 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidViewBinding 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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer import com.patrykandpatrick.vico.compose.component.shapeComponent import com.patrykandpatrick.vico.compose.component.textComponent import com.patrykandpatrick.vico.compose.dimensions.dimensionsOf @@ -34,44 +35,46 @@ import com.patrykandpatrick.vico.compose.style.currentChartStyle import com.patrykandpatrick.vico.core.axis.AxisPosition import com.patrykandpatrick.vico.core.axis.formatter.AxisValueFormatter import com.patrykandpatrick.vico.core.axis.horizontal.HorizontalAxis -import com.patrykandpatrick.vico.core.chart.column.ColumnChart +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayer import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine import com.patrykandpatrick.vico.core.component.shape.LineComponent import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart6Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart6(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart6(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart6(chartEntryModelProducer) - UISystem.Views -> ViewChart6(chartEntryModelProducer) + UISystem.Compose -> ComposeChart6(modelProducer) + UISystem.Views -> ViewChart6(modelProducer) } } @Composable -private fun ComposeChart6(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart6(modelProducer: CartesianChartModelProducer) { val thresholdLine = rememberThresholdLine() ProvideChartStyle(rememberChartStyle(chartColors)) { - val defaultColumns = currentChartStyle.columnChart.columns - Chart( - chart = columnChart( - columns = remember(defaultColumns) { - defaultColumns.map { defaultColumn -> - LineComponent( - defaultColumn.color, - defaultColumn.thicknessDp, - Shapes.cutCornerShape(topLeftPercent = COLUMN_CORNER_CUT_SIZE_PERCENT), - ) - } - }, - mergeMode = ColumnChart.MergeMode.Grouped, + val defaultColumns = currentChartStyle.columnLayer.columns + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + remember(defaultColumns) { + defaultColumns.map { defaultColumn -> + LineComponent( + defaultColumn.color, + defaultColumn.thicknessDp, + Shapes.cutCornerShape(topLeftPercent = COLUMN_CORNER_CUT_SIZE_PERCENT), + ) + } + }, + mergeMode = ColumnCartesianLayer.MergeMode.Grouped, + ), decorations = remember(thresholdLine) { listOf(thresholdLine) }, ), - chartModelProducer = chartEntryModelProducer, + modelProducer = modelProducer, startAxis = rememberStartAxis(), bottomAxis = rememberBottomAxis(valueFormatter = bottomAxisValueFormatter), marker = rememberMarker(), @@ -81,7 +84,7 @@ private fun ComposeChart6(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart6(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart6(modelProducer: CartesianChartModelProducer) { val thresholdLine = rememberThresholdLine() val decorations = remember(thresholdLine) { listOf(thresholdLine) } val marker = rememberMarker() @@ -89,7 +92,7 @@ private fun ViewChart6(chartEntryModelProducer: ChartEntryModelProducer) { with(chartView) { chart?.setDecorations(decorations) runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer (bottomAxis as? HorizontalAxis)?.valueFormatter = bottomAxisValueFormatter this.marker = marker } @@ -135,4 +138,4 @@ private val thresholdLineLabelMargins = dimensionsOf(thresholdLineLabelMarginVal private val thresholdLineColor = color4.copy(THRESHOLD_LINE_ALPHA) private val daysOfWeek = listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") private val bottomAxisValueFormatter = - AxisValueFormatter { x, _ -> daysOfWeek[x.toInt() % daysOfWeek.size] } + AxisValueFormatter { x, _, _ -> daysOfWeek[x.toInt() % daysOfWeek.size] } 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 824021971..a482e0108 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 @@ -28,8 +28,9 @@ import com.patrykandpatrick.vico.R import com.patrykandpatrick.vico.compose.axis.axisLabelComponent 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.chart.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.component.shape.roundedCornerShape import com.patrykandpatrick.vico.compose.component.shapeComponent import com.patrykandpatrick.vico.compose.component.textComponent @@ -41,31 +42,31 @@ import com.patrykandpatrick.vico.compose.style.currentChartStyle import com.patrykandpatrick.vico.core.axis.vertical.VerticalAxis import com.patrykandpatrick.vico.core.chart.copy import com.patrykandpatrick.vico.core.component.shape.Shapes -import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart7Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart7(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModelProducer) { +internal fun Chart7(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart7(chartEntryModelProducer) - UISystem.Views -> ViewChart7(chartEntryModelProducer) + UISystem.Compose -> ComposeChart7(modelProducer) + UISystem.Views -> ViewChart7(modelProducer) } } @Composable -private fun ComposeChart7(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ComposeChart7(modelProducer: CartesianChartModelProducer) { ProvideChartStyle(rememberChartStyle(chartColors)) { - val defaultLines = currentChartStyle.lineChart.lines - Chart( - chart = lineChart( - remember(defaultLines) { - defaultLines.map { defaultLine -> defaultLine.copy(lineBackgroundShader = null) } - }, + val defaultLines = currentChartStyle.lineLayer.lines + CartesianChartHost( + chart = rememberCartesianChart( + rememberLineCartesianLayer( + remember(defaultLines) { defaultLines.map { it.copy(lineBackgroundShader = null) } }, + ), ), - chartModelProducer = chartEntryModelProducer, + modelProducer = modelProducer, startAxis = rememberStartAxis( label = rememberStartAxisLabel(), horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside, @@ -79,14 +80,14 @@ private fun ComposeChart7(chartEntryModelProducer: ChartEntryModelProducer) { } @Composable -private fun ViewChart7(chartEntryModelProducer: ChartEntryModelProducer) { +private fun ViewChart7(modelProducer: CartesianChartModelProducer) { val startAxisLabel = rememberStartAxisLabel() val marker = rememberMarker() val legend = rememberLegend() AndroidViewBinding(Chart7Binding::inflate) { with(chartView) { runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer (startAxis as VerticalAxis).horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside (startAxis as VerticalAxis).label = startAxisLabel this.marker = marker @@ -115,7 +116,7 @@ private fun rememberLegend() = verticalLegend( textSize = legendItemLabelTextSize, typeface = Typeface.MONOSPACE, ), - labelText = stringResource(R.string.data_set_x, index + 1), + labelText = stringResource(R.string.series_x, index + 1), ) }, iconSize = legendItemIconSize, 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 062e631dc..c460c3091 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 @@ -17,46 +17,45 @@ package com.patrykandpatrick.vico.sample.showcase.charts 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.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.CartesianChartHost +import com.patrykandpatrick.vico.compose.chart.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.chart.column.rememberColumnCartesianLayer +import com.patrykandpatrick.vico.compose.chart.line.rememberLineCartesianLayer import com.patrykandpatrick.vico.compose.style.ProvideChartStyle import com.patrykandpatrick.vico.core.axis.Axis import com.patrykandpatrick.vico.core.axis.AxisPosition -import com.patrykandpatrick.vico.core.chart.column.ColumnChart -import com.patrykandpatrick.vico.core.chart.composed.ComposedChart -import com.patrykandpatrick.vico.core.chart.composed.plus -import com.patrykandpatrick.vico.core.chart.line.LineChart -import com.patrykandpatrick.vico.core.entry.composed.ComposedChartEntryModelProducer +import com.patrykandpatrick.vico.core.chart.column.ColumnCartesianLayer +import com.patrykandpatrick.vico.core.chart.line.LineCartesianLayer +import com.patrykandpatrick.vico.core.entry.composed.CartesianChartModelProducer import com.patrykandpatrick.vico.databinding.Chart8Binding import com.patrykandpatrick.vico.sample.showcase.UISystem import com.patrykandpatrick.vico.sample.showcase.rememberChartStyle import com.patrykandpatrick.vico.sample.showcase.rememberMarker @Composable -internal fun Chart8(uiSystem: UISystem, chartEntryModelProducer: ComposedChartEntryModelProducer) { +internal fun Chart8(uiSystem: UISystem, modelProducer: CartesianChartModelProducer) { when (uiSystem) { - UISystem.Compose -> ComposeChart8(chartEntryModelProducer) - UISystem.Views -> ViewChart8(chartEntryModelProducer) + UISystem.Compose -> ComposeChart8(modelProducer) + UISystem.Views -> ViewChart8(modelProducer) } } @Composable -private fun ComposeChart8(chartEntryModelProducer: ComposedChartEntryModelProducer) { +private fun ComposeChart8(modelProducer: CartesianChartModelProducer) { ProvideChartStyle(rememberChartStyle(columnChartColors, lineChartColors)) { - val columnChart = columnChart( - mergeMode = ColumnChart.MergeMode.Stack, - targetVerticalAxisPosition = AxisPosition.Vertical.Start, - ) - val lineChart = lineChart(targetVerticalAxisPosition = AxisPosition.Vertical.End) - Chart( - chart = remember(columnChart, lineChart) { columnChart + lineChart }, - chartModelProducer = chartEntryModelProducer, + CartesianChartHost( + chart = rememberCartesianChart( + rememberColumnCartesianLayer( + mergeMode = ColumnCartesianLayer.MergeMode.Stacked, + targetVerticalAxisPosition = AxisPosition.Vertical.Start, + ), + rememberLineCartesianLayer(targetVerticalAxisPosition = AxisPosition.Vertical.End), + ), + modelProducer = modelProducer, startAxis = rememberStartAxis(guideline = null), endAxis = rememberEndAxis(), marker = rememberMarker(), @@ -66,15 +65,14 @@ private fun ComposeChart8(chartEntryModelProducer: ComposedChartEntryModelProduc } @Composable -private fun ViewChart8(chartEntryModelProducer: ComposedChartEntryModelProducer) { +private fun ViewChart8(modelProducer: CartesianChartModelProducer) { val marker = rememberMarker() AndroidViewBinding(Chart8Binding::inflate) { with(chartView) { - ((chart as ComposedChart).charts[0] as ColumnChart).mergeMode = ColumnChart.MergeMode.Stack - ((chart as ComposedChart).charts[0] as ColumnChart).targetVerticalAxisPosition = AxisPosition.Vertical.Start - ((chart as ComposedChart).charts[1] as LineChart).targetVerticalAxisPosition = AxisPosition.Vertical.End + (chart?.layers?.get(0) as ColumnCartesianLayer).targetVerticalAxisPosition = AxisPosition.Vertical.Start + (chart?.layers?.get(1) as LineCartesianLayer).targetVerticalAxisPosition = AxisPosition.Vertical.End runInitialAnimation = false - entryProducer = chartEntryModelProducer + this.modelProducer = modelProducer (startAxis as Axis).guideline = null this.marker = marker } diff --git a/sample/src/main/res/layout/chart_1.xml b/sample/src/main/res/layout/chart_1.xml index 64d4174ad..d19263639 100644 --- a/sample/src/main/res/layout/chart_1.xml +++ b/sample/src/main/res/layout/chart_1.xml @@ -19,12 +19,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/layout/chart_2.xml b/sample/src/main/res/layout/chart_2.xml index 27dab5533..02cccd055 100644 --- a/sample/src/main/res/layout/chart_2.xml +++ b/sample/src/main/res/layout/chart_2.xml @@ -19,13 +19,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - - diff --git a/sample/src/main/res/layout/chart_4.xml b/sample/src/main/res/layout/chart_4.xml index ff8308348..021fe85d1 100644 --- a/sample/src/main/res/layout/chart_4.xml +++ b/sample/src/main/res/layout/chart_4.xml @@ -19,13 +19,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/layout/chart_5.xml b/sample/src/main/res/layout/chart_5.xml index 1aaf69d00..9f899f989 100644 --- a/sample/src/main/res/layout/chart_5.xml +++ b/sample/src/main/res/layout/chart_5.xml @@ -19,13 +19,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/layout/chart_6.xml b/sample/src/main/res/layout/chart_6.xml index 62426d299..925e53091 100644 --- a/sample/src/main/res/layout/chart_6.xml +++ b/sample/src/main/res/layout/chart_6.xml @@ -19,12 +19,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/layout/chart_7.xml b/sample/src/main/res/layout/chart_7.xml index f29e9408b..8961b7eba 100644 --- a/sample/src/main/res/layout/chart_7.xml +++ b/sample/src/main/res/layout/chart_7.xml @@ -19,12 +19,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/layout/chart_8.xml b/sample/src/main/res/layout/chart_8.xml index 79618a81d..7afc46bba 100644 --- a/sample/src/main/res/layout/chart_8.xml +++ b/sample/src/main/res/layout/chart_8.xml @@ -19,13 +19,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - diff --git a/sample/src/main/res/values/chart_5_styles.xml b/sample/src/main/res/values/chart_5_styles.xml index 35150e750..2fd5ff54a 100644 --- a/sample/src/main/res/values/chart_5_styles.xml +++ b/sample/src/main/res/values/chart_5_styles.xml @@ -60,5 +60,6 @@ @style/Chart5Column1Style @style/Chart5Column2Style @style/Chart5Column3Style + stacked diff --git a/sample/src/main/res/values/chart_8_styles.xml b/sample/src/main/res/values/chart_8_styles.xml index d93f61daf..32466e71a 100644 --- a/sample/src/main/res/values/chart_8_styles.xml +++ b/sample/src/main/res/values/chart_8_styles.xml @@ -40,6 +40,7 @@ @style/Chart8Column1Style @style/Chart8Column2Style @style/Chart8Column3Style + stacked