Skip to main content

2.0.0-alpha.23

This release introduces new LineCartesianLayer features, improvements for persistent CartesianMarkers, API enhancements, and more.

Breaking changesAddressed
Moderate#295, #450, #482, #620, #736, #785

CartesianChart and hosts

These CartesianChartHost parameters have been moved to rememberCartesianChart:

  • marker
  • markerVisibilityListener
  • horizontalLayout
  • getXStep

The persistentMarker parameter is now a scoped ExtraStore lambda. In the following example, marker1 is linked to x = 2, and marker2 is linked to x = 3.

rememberCartesianChart(
persistentMarkers =
rememberExtraLambda(marker1, marker2) {
marker1 at 2
marker2 at 3
},
// ...
)

CartesianChartHost’s diffAnimationSpec parameter is now called animationSpec.

CartesianChartModelProducer

CartesianChartModelProducer’s suspending functions are now main-safe, meaning that they can be safely called from Dispatchers.Main coroutines. Changing the CoroutineDispatcher to, for example, Dispatchers.Default is no longer necessary.

ColumnCartesianLayer

The spacing parameter of rememberColumnCartesianLayer is now called columnCollectionSpacing. The innerSpacing parameter has been removed—the spacing of grouped columns is now set via MergeMode.Grouped, since it concerns only this MergeMode. This is shown in the following example. Note that there are now MergeMode.grouped and MergeMode.stacked functions for Jetpack Compose.

rememberColumnCartesianLayer(
mergeMode = { MergeMode.grouped(columnSpacing = /* ... */) },
// ...
)

LineCartesianLayer

LineCartesianLayer has new APIs for more granular customization.

LineCartesianLayer.LineSpec is now called LineCartesianLayer.Line. A LineCartesianLayer receives its lines via a LineCartesianLayer.LineProvider. LineCartesianLayer.LineProvider.series gives the same result as the old, list-based system. You can create your own LineCartesianLayer.LineProvider implementations for more advanced behavior.

LineCartesianLayer.Point defines a point style. It’s used in combination with LineCartesianLayer.PointProvider, an instance of which you can add to a LineCartesianLayer.Line. This facilitates point-by-point customization. You can add points only for some entries, use different point colors depending on the y value, and more. To apply points of a common style to all entries of a line, use LineCartesianLayer.PointProvider.single.

In rememberCartesianLayer, lineProvider replaces lines, and spacing is now called pointSpacing. rememberLine, which replaces rememberLineSpec, has a pointProvider parameter instead of point and pointSize parameters. LineCartesianLayer.Points are created via rememberPoint. Here’s an example of how the new APIs can be used:

rememberLineCartesianLayer(
lineProvider =
LineCartesianLayer.LineProvider.series(
rememberLine(
pointProvider =
LineCartesianLayer.PointProvider.single(
rememberPoint(component = /* ... */, size = /* ... */),
),
// ...
),
// ...
),
// ...
)

LineCartesianLayer.LineSpec.PointConnector has been moved to LineCartesianLayer.PointConnector. LineCartesianLayer.PointConnector.cubic replaces DefaultPointConnector. LineCartesianLayer.PointConnector.connect has a new signature. Instead of horizontalDimensions, use context.horizontalDimensions.

Legend

In rememberLegendItem, the label and labelText parameters have been renamed to labelComponent and label, respectively. In Legend, the availableWidth parameter of getHeight has been renamed to maxWidth. draw’s chartBounds parameter has been removed in favor of bounds.

Components

In rememberLineComponent and rememberShapeComponent, strokeWidth and dynamicShader have been renamed to strokeThicknessDp and shader, respectively, and the parameters have been reordered. The Brush-based rememberShapeComponent overload has been removed—use Brush.toDynamicShader.

The rememberLineComponent are reflected in rememberAxisLineComponent, rememberAxisTickComponent, and rememberAxisGuidelineComponent. In rememberAxisLineComponent, the brush parameter has been replaced with a shader parameter—use Brush.toDynamicShader. The deprecated rememberAxisTickComponent overload, which used androidx.compose.ui.graphics.Shape and Brush, has been removed—use androidx.compose.ui.graphics.Shape.toVicoShape() and Brush.toDynamicShader.

TextComponent

In rememberTextComponent and rememberAxisLabelComponent, ellipsize has been renamed to truncateAt, and the parameters have been reordered. This is reflected in rememberAxisLabelComponent. In the draw, getWidth, getHeight, and getBounds functions, some parameters have been renamed.

Axis

AxisItemPlacer.Horizontal is now HorizontalAxis.ItemPlacer. Analogously, AxisItemPlacer.Vertical is VerticalAxis.ItemPlacer.

The parameters of rememberStartAxis, rememberTopAxis, rememberEndAxis, and rememberBottomAxis have been reordered.

In the HorizontalAxis.ItemPlacer, getShiftExtremeTicks is now called getShiftExtremeLines. The drawBehindChart and drawAboveChart functions of Axis are now called drawUnderLayers and drawOverLayers. In BaseAxis, axisLine has been renamed to line, and Builder has been removed in favor of the constructor, which has parameters corresponding to the BaseAxis properties.

Caching

Thanks to the new CacheStore API, drawing data can be reused more effectively, improving performance. Some caching-related improvements have been made to TextComponent and the default VerticalAxis.ItemPlacer implementation, with more enhancements on the way.

In MeasureContext, extraStore is deprecated in favor of cacheStore. In MarkerCorneredShape, tickXKey and tickPositionKey, which were used with ExtraStore, are deprecated in favor of the tickX and tickPosition instance properties.

Miscellaneous

  • The default Typeface is now Typeface.DEFAULT everywhere.
  • Elevation overlays have been removed. Rather than relying on these, manually change the background colors of ShapeComponents with shadows. This gives greater flexibility.
  • In the rememberFadingEdges overload with startEdgeWidth and endEdgeWidth parameters, the default value for endEdgeWidth is now a constant, not startEdgeWidth. To apply a common width without repetition, use the overload with an edgeWidthDp parameter.
  • In CartesianDrawContext, chartBounds is now called layerBounds.
  • The ChartInsetter functions now have model parameters. There’s a corresponding type parameter.
  • In Decoration, the onDrawBehindChart and onDrawAboveChart functions are now called drawUnderLayers and drawOverLayers. The bounds parameters have been removed—use context.layerBounds instead. For greater flexibility, CartesianChart no longer clips Decoration content to the CartesianLayer area. Decorations can implement such clipping themselves.
  • CartesianLayer no longer implements Bounded—use CartesianDrawContext.layerBounds instead of bounds.