2.0.0-beta.1
This release includes bug fixes and API enhancements.
Breaking changes | Addressed |
---|---|
Moderate | #856, #865 |
The views
module’s minimum SDK version has been raised to 21, as Appcompat now requires this. Since compose
already
had such a minimum SDK version, and core
is intended for use with compose
or views
, the minimum SDK version of
core
has been raised to the same value.
Some APIs have been renamed, moved, or removed in favor of others:
- Compose
- Views
2.0.0-alpha.28 | 2.0.0-beta.1 |
---|---|
cartesian.HorizontalInsets | common.HorizontalInsets |
cartesian.Insets | common.Insets |
ChartInsetter | CartesianLayerInsetter |
Dimensions.of | dimensions |
Shape.Pill | CorneredShape.Pill |
Shape.cut | CorneredShape.cut |
Shape.dashed | dashedShape |
Shape.markerCornered | markerCorneredShape |
Shape.rounded | CorneredShape.rounded |
rememberBottomAxis | HorizontalAxis.rememberBottom |
rememberCandle | CandlestickCartesianLayer.Candle constructor |
rememberEndAxis | VerticalAxis.rememberEnd |
rememberHorizontalBox | HorizontalBox constructor |
rememberHorizontalLine | HorizontalLine constructor |
rememberLine | LineCartesianLayer.rememberLine |
rememberPoint | LineCartesianLayer.point |
rememberShadow | shadow |
rememberStartAxis | VerticalAxis.rememberStart |
rememberTopAxis | HorizontalAxis.rememberTop |
All deprecated APIs have been removed.
2.0.0-alpha.28 | 2.0.0-beta.1 |
---|---|
BaseChartView | ChartView |
cartesian.HorizontalInsets | common.HorizontalInsets |
cartesian.Insets | common.Insets |
ChartInsetter | CartesianLayerInsetter |
ComponentShader | DynamicShader.component |
Shape.Pill | CorneredShape.Pill |
Shape.cut | CorneredShape.cut |
Shape.rounded | CorneredShape.rounded |
All deprecated APIs have been removed. This includes the deprecated XML attributes:
View or attribute set | Deprecated attribute | New attribute |
---|---|---|
AxisStyle | maxVerticalAxisItemCount | verticalAxisItemCount |
CartesianChartView | chartHorizontalScrollingEnabled | scrollEnabled |
CartesianChartView | chartZoomEnabled | zoomEnabled |
ShapeStyle | dashGapLength | gapLength |
TextComponentStyle | labelColor | android:color |
AxisValueOverrider
is now called CartesianLayerRangeProvider
, and the axisValueOverrider
parameters and properties
have been renamed to rangeProvider
.
AxisValueOverrider.adaptiveYValues
has been removed due to being overly specific for a built-in factory function
(primarily in terms of rounding). Migrate by creating a suitable CartesianLayerRangeProvider
implementation. For
example, the following sets the maximum y value to the default multiplied by 1.5 and rounded to the nearest whole
number:
object : CartesianLayerRangeProvider {
override fun getMaxY(minY: Double, maxY: Double, extraStore: ExtraStore) =
ceil(1.5 * maxY)
}
ChartValues
is now called CartesianChartRanges
. In CartesianMeasuringContext
, ranges
replaces chartValues
.
Unlike ChartValues
, CartesianChartRanges
has no model
property—use the new CartesianMeasuringContext.model
property instead.
CartesianValueFormatter.format
has a new signature—use context.ranges
and context.model
instead of chartValues
.
Also, empty HorizontalAxis
and VerticalAxis
labels are no longer permitted—an exception occurs when such a label is
detected. As described in the wiki, you should use
HorizontalAxis.ItemPlacer
and VerticalAxis.ItemPlacer
to customize for what x and y values labels and lines are
displayed. Utilizing empty strings instead could produce undesirable results, including unexpected label truncation.
HorizontalLayout
and HorizontalAxis.ItemPlacer.default
have been replaced by three new APIs:
CartesianLayerPadding
, which lets you add scalable and unscalableCartesianLayer
paddingHorizontalAxis.ItemPlacer.aligned
, which is used by default and places items asHorizontalAxis.ItemPlacer.default
did withHorizontalLayout.FullWidth
HorizontalAxis.ItemPlacer.segmented
, which places items asHorizontalAxis.ItemPlacer.default
did withHorizontalLayout.Segmented
- Compose
- Views
Instantiate CartesianLayerPadding
via the cartesianLayerPadding
function.
The horizontalLayout
parameter of rememberCartesianChart
has been replaced by a layerPadding
parameter.
Similarly, in CartesianMeasuringContext
, the horizontalLayout
property has been replaced by a layerPadding
property.
In CartesianChart
and CartesianMeasuringContext
, the horizontalLayout
properties have been replaced by
layerPadding
properties. Also, the following changes have been made to the XML attributes:
CartesianChartView
:- The
*ContentPadding
attributes have been renamed to*LayerPadding
. - The
horizontalLayout
attribute has been removed.
- The
AxisStyle
:- There’s a new
horizontalAxisItemPlacer
attribute, whose value can bealigned
orsegmented
. - The
shiftExtremeHorizontalAxisTicks
attribute has been renamed toshiftExtremeHorizontalAxisLines
.
- There’s a new
How to migrate to the new APIs depends on what HorizontalLayout
you have applied. Start by removing the code that
applies the HorizontalLayout
(if such code is present). Then, add the appropriate amount of CartesianLayer
padding:
- Case A:
- Determine the greatest of the following, depending on what
CartesianLayer
s yourCartesianChart
has:CandlestickCartesianLayer.candleSpacingDp
(default: 4),ColumnCartesianLayer.columnCollectionSpacingDp
(default: 32), andLineCartesianLayer.pointSpacingDp
(default: 32). - Let p be half of the value from step 1.
- Using the
CartesianLayerPadding
APIs, apply p dp of scalable padding on either end.
- Determine the greatest of the following, depending on what
- Case B: Use
CartesianLayerPadding
to apply the same amount of padding as previously. - Case C: Do nothing.
If there are HorizontalAxis
instances, do the following for each one:
- Case A: Use
HorizontalAxis.ItemPlacer.segmented()
. - Case B: Do nothing.
- Case C: Modify the
HorizontalAxis.ItemPlacer
for compatibility with the API changes. - Case D: Use
HorizontalAxis.ItemPlacer.segmented
. IfshiftExtremeTicks
was set tofalse
, setshiftExtremeLines
tofalse
. - Case E: There’s no longer built-in spacing and offset customization for the segmented style. This is because the two
aren’t entirely compatible. In particular, with the segmented style, there’s no reasonable way to reflect spacing and
offset customization in tick and guideline positioning—which is why previously, with
HorizontalLayout.Segmented
, it affected only labels. Generally, the only instance in which this setup produced a desirable result was when no ticks or guidelines were present, and in such cases, you can migrate as described below. In the unlikely event that you’re settingoffset
to a value other than 0 orspacing
to a value other than 1, and yourHorizontalAxis
does have ticks or guidelines, migrate by creating a suitableHorizontalAxis.ItemPlacer
implementation. (You can do so easily by copying and modifying theSegmentedHorizontalAxisItemPlacer
definition. Also copy this code, whichSegmentedHorizontalAxisItemPlacer
uses. All that’s required is updating the calls toCartesianDrawingContext.getLabelValues
, which hasoffset
andspacing
parameters.) - Case F: Use
HorizontalAxis.ItemPlacer.aligned
, using the same arguments as previously. Note thatshiftExtremeTicks
is now calledshiftExtremeLines
, and the default value ofaddExtremeLabelPadding
is nowtrue
.
- Compose
- Views
An issue where a LineCartesianLayer
-related IllegalArgumentException
could occur in composable previews has
been addressed. The root cause is a bug in the preview renderer—we’ve worked around it.
A bug where the values of the HorizontalAxis
-specific XML attributes were incorrectly retrieved, leading to a
HorizontalAxis.ItemPlacer
-related OutOfMemoryError
, has been resolved.