2.0.0-alpha.23
This release introduces new LineCartesianLayer features, improvements for persistent CartesianMarkers, API
enhancements, and more.
| Breaking changes | Addressed |
|---|---|
| Moderate | #295, #450, #482, #620, #736, #785 |
CartesianChart and hosts
- Compose
- Views
These CartesianChartHost parameters have been moved to rememberCartesianChart:
markermarkerVisibilityListenerhorizontalLayoutgetXStep
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.
These CartesianChartView properties have been moved to CartesianChart:
markermarkerVisibilityListenerhorizontalLayoutgetXStep
For simplicity, the addDecoration, setDecorations, and removeDecoration functions have been replaced with
a decorations property.
Similarly, the addPersistentMarker, setPersistentMarkers, and removePersistentMarker functions have been
replaced with a persistentMarkers property. This is a scoped ExtraStore lambda. In the following example,
marker1 is linked to x = 2, and marker2 is linked to x = 3.
cartesianChartView.chart?.persistentMarkers = {
marker1 at 2
marker2 at 3
}
The list-based CartesianChart constructor has been deprecated in favor of the vararg one.
The setDiffAnimationDuration and setDiffAnimationInterpolator functions of CartesianChartView are now
called setAnimationDuration and setAnimationInterpolator.
Some XML attributes have been renamed:
| Attribute set | Old attribute name | New attribute name |
|---|---|---|
AxisStyle (previously Axis) | showAxisLine | showLine |
AxisStyle (previously Axis) | axisLineStyle | lineStyle |
AxisStyle (previously Axis) | showGuideline | showGuidelines |
AxisStyle (previously Axis) | axisGuidelineStyle | guidelineStyle |
AxisStyle (previously Axis) | axisTickStyle | tickStyle |
AxisStyle (previously Axis) | axisLabelStyle | labelStyle |
AxisStyle (previously Axis) | axisTickLength | tickLength |
AxisStyle (previously Axis) | axisLabelBackground | labelBackground |
LineComponentStyle (previously LineComponent) | strokeWidth | strokeThickness |
ColumnCartesianLayerStyle | column* | column*Style |
ColumnCartesianLayerStyle | columnOuterSpacing | columnCollectionSpacing |
ColumnCartesianLayerStyle | columnInnerSpacing | groupedColumnSpacing |
LineCartesianLayerStyle | line*Spec | line*Style |
LineCartesianLayerStyle | spacing | pointSpacing |
LineStyle (previously LineSpec) | lineThickness | thickness |
LineStyle (previously LineSpec) | cubicStrength | curvature |
ComponentStyle | strokeWidth | strokeThickness |
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
- Compose
- Views
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 = /* ... */) },
// ...
)
The spacingDp property of ColumnCartesianLayer is now called columnCollectionSpacingDp. The
innerSpacingDp property 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. (The corresponding XML
attribute remains available but has a new name, as described above.)
mergeMode = MergeMode.Grouped(columnSpacingDp = /* ... */)
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.
- Compose
- Views
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 = /* ... */),
),
// ...
),
// ...
),
// ...
)
There haven’t been any significant changes on the XML front, but keep in mind the new attribute names, listed above. We cover programmatic customization below.
In LineCartesianLayer, lineProvider replaces lines, and spacingDp is now called pointSpacingDp.
LineCartesianLayer.Line has a pointProvider property instead of point and pointSizeDp properties. Here’s
an example of how the new APIs can be used:
lineProvider =
LineCartesianLayer.LineProvider.series(
LineCartesianLayer.Line(
pointProvider =
LineCartesianLayer.PointProvider.single(
LineCartesianLayer.Point(...),
),
// ...
),
// ...
)
Since with LineCartesianLayer.LineProvider, the XML-based LineCartesianLayer.Lines can’t be easily
retrieved, a LineCartesianLayer.Line.copy function isn’t provided. LineCartesianLayer.Lines should be
created either entirely via XML or entirely programmatically.
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
- Compose
- Views
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.
In LegendItem, the label and labelText properties 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
- Compose
- Views
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.
In LineComponent and ShapeComponent, strokeWidthDp and dynamicShader have been renamed to
strokeThicknessDp and shader, respectively, and the constructor parameters have been reordered.
TextComponent
- Compose
- Views
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.
In TextComponent, ellipsize has been renamed to truncateAt, and build has been removed in favor of the
constructor, which has parameters corresponding to the TextComponent properties. 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.
- Compose
- Views
The parameters of rememberStartAxis, rememberTopAxis, rememberEndAxis, and rememberBottomAxis have been
reordered.
HorizontalAxis.Builder and HorizontalAxis.build have been replaced with HorizontalAxis.top and
HorizontalAxis.bottom. Analogously, HorizontalAxis.Builder and HorizontalAxis.build have been replaced
with VerticalAxis.start and VerticalAxis.end. These functions have parameters corresponding to the
HorizontalAxis and VerticalAxis properties.
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
- Compose
- Views
- The default
Typefaceis nowTypeface.DEFAULTeverywhere. - 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
rememberFadingEdgesoverload withstartEdgeWidthandendEdgeWidthparameters, the default value forendEdgeWidthis now a constant, notstartEdgeWidth. To apply a common width without repetition, use the overload with anedgeWidthDpparameter. - In
CartesianDrawContext,chartBoundsis now calledlayerBounds. - The
ChartInsetterfunctions now havemodelparameters. There’s a corresponding type parameter. - In
Decoration, theonDrawBehindChartandonDrawAboveChartfunctions are now calleddrawUnderLayersanddrawOverLayers. Theboundsparameters have been removed—usecontext.layerBoundsinstead. For greater flexibility,CartesianChartno longer clipsDecorationcontent to theCartesianLayerarea.Decorations can implement such clipping themselves. CartesianLayerno longer implementsBounded—useCartesianDrawContext.layerBoundsinstead ofbounds.
- The default
Typefaceis nowTypeface.DEFAULTeverywhere. - 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
FadingEdgesconstructor overload withstartEdgeWidthDpandendEdgeWidthDpparameters, the default value forendEdgeWidthDpis now a constant, notstartEdgeWidthDp. To apply a common width without repetition, use the overload with anedgeWidthDpparameter. - In
CartesianDrawContext,chartBoundsis now calledlayerBounds. - The
ChartInsetterfunctions now havemodelparameters. There’s a corresponding type parameter. - In
Decoration, theonDrawBehindChartandonDrawAboveChartfunctions are now calleddrawUnderLayersanddrawOverLayers. Theboundsparameters have been removed—usecontext.layerBoundsinstead. For greater flexibility,CartesianChartno longer clipsDecorationcontent to theCartesianLayerarea.Decorations can implement such clipping themselves. CartesianLayerno longer implementsBounded—useCartesianDrawContext.layerBoundsinstead ofbounds.