Skip to content

Commit

Permalink
Add LineFill and AreaFill to LineCartesianLayer, and make `Dyna…
Browse files Browse the repository at this point in the history
…micShader`-related updates

Co-authored-by: Patryk Goworowski <[email protected]>
  • Loading branch information
patrickmichalik and Gowsky committed Jul 28, 2024
1 parent 95f815d commit a557e02
Show file tree
Hide file tree
Showing 25 changed files with 708 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLa
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState
import com.patrykandpatrick.vico.compose.common.data.rememberExtraLambda
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.core.cartesian.axis.BaseAxis
import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.databinding.Chart1Binding
import com.patrykandpatrick.vico.sample.showcase.UIFramework
import com.patrykandpatrick.vico.sample.showcase.rememberMarker
Expand Down Expand Up @@ -69,7 +68,7 @@ private fun ComposeChart1(modelProducer: CartesianChartModelProducer, modifier:
rememberCartesianChart(
rememberLineCartesianLayer(
LineCartesianLayer.LineProvider.series(
rememberLine(DynamicShader.color(Color(0xffa485e0)))
rememberLine(remember { LineCartesianLayer.LineFill.single(fill(Color(0xffa485e0))) })
)
),
startAxis = rememberStartAxis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import com.patrykandpatrick.vico.compose.cartesian.rememberFadingEdges
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout
import com.patrykandpatrick.vico.core.cartesian.axis.VerticalAxis
import com.patrykandpatrick.vico.core.cartesian.data.AxisValueOverrider
Expand All @@ -46,7 +46,6 @@ import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.cartesian.marker.DefaultCartesianMarker
import com.patrykandpatrick.vico.core.common.Dimensions
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shape.Shape
import com.patrykandpatrick.vico.databinding.Chart3Binding
import com.patrykandpatrick.vico.sample.showcase.Defaults
Expand Down Expand Up @@ -86,7 +85,9 @@ private fun ComposeChart3(modelProducer: CartesianChartModelProducer, modifier:
rememberCartesianChart(
rememberLineCartesianLayer(
lineProvider =
LineCartesianLayer.LineProvider.series(rememberLine(DynamicShader.color(lineColor))),
LineCartesianLayer.LineProvider.series(
rememberLine(remember { LineCartesianLayer.LineFill.single(fill(lineColor)) })
),
axisValueOverrider = axisValueOverrider,
),
startAxis =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLa
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.compose.common.shape.rounded
import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.data.columnSeries
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shape.Shape
import com.patrykandpatrick.vico.databinding.Chart4Binding
import com.patrykandpatrick.vico.sample.showcase.Defaults
Expand Down Expand Up @@ -100,7 +99,7 @@ private fun ComposeChart4(modelProducer: CartesianChartModelProducer, modifier:
rememberLineCartesianLayer(
LineCartesianLayer.LineProvider.series(
rememberLine(
shader = DynamicShader.color(lineColor),
fill = remember { LineCartesianLayer.LineFill.single(fill(lineColor)) },
pointConnector = remember { LineCartesianLayer.PointConnector.cubic(curvature = 0f) },
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.rememberLegendItem
import com.patrykandpatrick.vico.compose.common.rememberVerticalLegend
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.shape.rounded
import com.patrykandpatrick.vico.compose.common.vicoTheme
import com.patrykandpatrick.vico.core.cartesian.CartesianDrawContext
Expand All @@ -48,7 +48,6 @@ import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.common.Dimensions
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shape.Shape
import com.patrykandpatrick.vico.databinding.Chart7Binding
import com.patrykandpatrick.vico.sample.showcase.Defaults
Expand Down Expand Up @@ -99,7 +98,10 @@ private fun ComposeChart7(modelProducer: CartesianChartModelProducer, modifier:
rememberLineCartesianLayer(
LineCartesianLayer.LineProvider.series(
chartColors.map { color ->
rememberLine(shader = DynamicShader.color(color), backgroundShader = null)
rememberLine(
fill = remember { LineCartesianLayer.LineFill.single(fill(color)) },
areaFill = null,
)
}
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLa
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.core.cartesian.axis.AxisPosition
import com.patrykandpatrick.vico.core.cartesian.axis.BaseAxis
import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.data.columnSeries
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.ColumnCartesianLayer
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shape.Shape
import com.patrykandpatrick.vico.databinding.Chart8Binding
import com.patrykandpatrick.vico.sample.showcase.Defaults
Expand Down Expand Up @@ -104,7 +103,9 @@ private fun ComposeChart8(modelProducer: CartesianChartModelProducer, modifier:
),
rememberLineCartesianLayer(
lineProvider =
LineCartesianLayer.LineProvider.series(rememberLine(DynamicShader.color(color4))),
LineCartesianLayer.LineProvider.series(
rememberLine(remember { LineCartesianLayer.LineFill.single(fill(color4)) })
),
verticalAxisPosition = AxisPosition.Vertical.End,
),
startAxis = rememberStartAxis(guideline = null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLa
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
import com.patrykandpatrick.vico.compose.common.component.shapeComponent
import com.patrykandpatrick.vico.compose.common.fill
import com.patrykandpatrick.vico.compose.common.of
import com.patrykandpatrick.vico.compose.common.shader.color
import com.patrykandpatrick.vico.compose.common.shader.component
import com.patrykandpatrick.vico.compose.common.shader.verticalGradient
import com.patrykandpatrick.vico.compose.common.shape.dashed
Expand All @@ -52,9 +53,10 @@ import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer
import com.patrykandpatrick.vico.core.common.Dimensions
import com.patrykandpatrick.vico.core.common.Fill
import com.patrykandpatrick.vico.core.common.component.ShapeComponent
import com.patrykandpatrick.vico.core.common.shader.ComponentShader
import com.patrykandpatrick.vico.core.common.shader.DynamicShader
import com.patrykandpatrick.vico.core.common.shader.TopBottomShader
import com.patrykandpatrick.vico.core.common.shape.Shape
import com.patrykandpatrick.vico.databinding.Chart9Binding
import com.patrykandpatrick.vico.sample.showcase.Defaults
Expand Down Expand Up @@ -99,38 +101,48 @@ private fun ComposeChart9(modelProducer: CartesianChartModelProducer, modifier:
lineProvider =
LineCartesianLayer.LineProvider.series(
rememberLine(
shader =
TopBottomShader(DynamicShader.color(colors[0]), DynamicShader.color(colors[1])),
backgroundShader =
TopBottomShader(
DynamicShader.compose(
DynamicShader.component(
componentSize = 6.dp,
component =
rememberShapeComponent(
color = colors[0],
shape = Shape.Pill,
margins = Dimensions.of(1.dp),
),
),
DynamicShader.verticalGradient(arrayOf(Color.Black, Color.Transparent)),
PorterDuff.Mode.DST_IN,
),
DynamicShader.compose(
DynamicShader.component(
componentSize = 5.dp,
component =
rememberShapeComponent(
color = colors[1],
shape = Shape.Rectangle,
margins = Dimensions.of(horizontal = 2.dp),
),
checkeredArrangement = false,
),
DynamicShader.verticalGradient(arrayOf(Color.Transparent, Color.Black)),
PorterDuff.Mode.DST_IN,
),
),
fill =
remember(colors) {
LineCartesianLayer.LineFill.double(fill(colors[0]), fill(colors[1]))
},
areaFill =
remember(colors) {
LineCartesianLayer.AreaFill.double(
topFill =
fill(
DynamicShader.compose(
DynamicShader.component(
component =
shapeComponent(
color = colors[0],
shape = Shape.Pill,
margins = Dimensions.of(1.dp),
),
componentSize = 6.dp,
),
DynamicShader.verticalGradient(arrayOf(Color.Black, Color.Transparent)),
PorterDuff.Mode.DST_IN,
)
),
bottomFill =
fill(
DynamicShader.compose(
DynamicShader.component(
component =
shapeComponent(
color = colors[1],
shape = Shape.Rectangle,
margins = Dimensions.of(horizontal = 2.dp),
),
componentSize = 5.dp,
checkeredArrangement = false,
),
DynamicShader.verticalGradient(arrayOf(Color.Transparent, Color.Black)),
PorterDuff.Mode.DST_IN,
)
),
)
},
)
)
),
Expand Down Expand Up @@ -190,37 +202,52 @@ private fun ViewChart9(modelProducer: CartesianChartModelProducer, modifier: Mod
lineProvider =
LineCartesianLayer.LineProvider.series(
LineCartesianLayer.Line(
shader =
TopBottomShader(DynamicShader.color(colors[0]), DynamicShader.color(colors[1])),
backgroundShader =
TopBottomShader(
DynamicShader.compose(
DynamicShader.component(
componentSize = 6.dp,
component =
ShapeComponent(
color = colors[0].toArgb(),
shape = Shape.Pill,
margins = Dimensions.of(1.dp),
fill =
LineCartesianLayer.LineFill.double(
topFill = Fill(colors[0].toArgb()),
bottomFill = Fill(colors[1].toArgb()),
),
areaFill =
LineCartesianLayer.AreaFill.double(
topFill =
Fill(
DynamicShader.compose(
ComponentShader(
component =
ShapeComponent(
color = colors[0].toArgb(),
shape = Shape.Pill,
margins = Dimensions(allDp = 1f),
),
componentSizeDp = 6f,
),
DynamicShader.verticalGradient(
android.graphics.Color.BLACK,
android.graphics.Color.TRANSPARENT,
),
PorterDuff.Mode.DST_IN,
)
),
DynamicShader.verticalGradient(arrayOf(Color.Black, Color.Transparent)),
PorterDuff.Mode.DST_IN,
),
DynamicShader.compose(
DynamicShader.component(
componentSize = 5.dp,
component =
ShapeComponent(
color = colors[1].toArgb(),
shape = Shape.Rectangle,
margins = Dimensions.of(horizontal = 2.dp),
bottomFill =
Fill(
DynamicShader.compose(
ComponentShader(
component =
ShapeComponent(
color = colors[1].toArgb(),
shape = Shape.Rectangle,
margins = Dimensions(horizontalDp = 2f, verticalDp = 0f),
),
componentSizeDp = 5f,
checkeredArrangement = false,
),
DynamicShader.verticalGradient(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.BLACK,
),
checkeredArrangement = false,
PorterDuff.Mode.DST_IN,
)
),
DynamicShader.verticalGradient(arrayOf(Color.Transparent, Color.Black)),
PorterDuff.Mode.DST_IN,
),
),
)
)
Expand Down
Loading

0 comments on commit a557e02

Please sign in to comment.