Skip to content

Commit

Permalink
Move CartesianChart-related XML attributes to a separate styleable …
Browse files Browse the repository at this point in the history
…resource
  • Loading branch information
Gowsky committed Nov 18, 2024
1 parent f2ca824 commit a60f4b8
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 125 deletions.
8 changes: 1 addition & 7 deletions sample/src/main/res/layout/chart_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart1BottomAxisStyle"
app:layers="line"
app:lineLayerStyle="@style/Chart1LineLayerStyle"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showBottomAxis="true"
app:showStartAxis="true"
app:chartStyle="@style/Chart1CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
5 changes: 1 addition & 4 deletions sample/src/main/res/layout/chart_10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart10BottomAxisStyle"
app:layers="candlestick"
app:showBottomAxis="true"
app:showStartAxis="true" />
app:chartStyle="@style/Chart10CartesianChartStyle" />
</FrameLayout>
6 changes: 1 addition & 5 deletions sample/src/main/res/layout/chart_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart2BottomAxisStyle"
app:columnLayerStyle="@style/Chart2ColumnLayerStyle"
app:layers="column"
app:showBottomAxis="true"
app:showStartAxis="true" />
app:chartStyle="@style/Chart2CartesianChartStyle" />
</FrameLayout>
9 changes: 1 addition & 8 deletions sample/src/main/res/layout/chart_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart3BottomAxisStyle"
app:fadingEdgeVisibilityInterpolator="androidx.interpolator.view.animation.FastOutSlowInInterpolator"
app:fadingEdgeWidth="32dp"
app:layers="line"
app:lineLayerStyle="@style/Chart3LineLayerStyle"
app:showBottomAxis="true"
app:showStartAxis="true"
app:startAxisStyle="@style/Chart3StartAxisStyle"
app:chartStyle="@style/Chart3CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
9 changes: 1 addition & 8 deletions sample/src/main/res/layout/chart_4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart4BottomAxisStyle"
app:columnLayerStyle="@style/Chart4ColumnLayerStyle"
app:layers="line|column"
app:lineLayerStyle="@style/Chart4LineLayerStyle"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showEndAxis="true"
app:showTopAxis="true"
app:chartStyle="@style/Chart4CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
9 changes: 1 addition & 8 deletions sample/src/main/res/layout/chart_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart5BottomAxisStyle"
app:columnLayerStyle="@style/Chart5ColumnLayerStyle"
app:layers="column"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showBottomAxis="true"
app:showStartAxis="true"
app:startAxisStyle="@style/Chart5AxisStyle"
app:chartStyle="@style/Chart5CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
9 changes: 1 addition & 8 deletions sample/src/main/res/layout/chart_6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart6BottomAxisStyle"
app:columnLayerStyle="@style/Chart6ColumnLayerStyle"
app:layers="column"
app:previewColumnSeriesCount="3"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showBottomAxis="true"
app:showStartAxis="true"
app:chartStyle="@style/Chart6CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
8 changes: 1 addition & 7 deletions sample/src/main/res/layout/chart_7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart7BottomAxisStyle"
app:layers="line"
app:lineLayerStyle="@style/Chart7LineLayerStyle"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showBottomAxis="true"
app:showStartAxis="true"
app:chartStyle="@style/Chart7CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
12 changes: 1 addition & 11 deletions sample/src/main/res/layout/chart_8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
android:id="@+id/chart_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bottomAxisStyle="@style/Chart8BottomAxisStyle"
app:columnLayerStyle="@style/Chart8ColumnLayerStyle"
app:endAxisStyle="@style/Chart8VerticalAxisStyle"
app:layers="line|column"
app:lineLayerStyle="@style/Chart8LineLayerStyle"
app:scalableEndLayerPadding="16dp"
app:scalableStartLayerPadding="16dp"
app:showBottomAxis="true"
app:showEndAxis="true"
app:showStartAxis="true"
app:startAxisStyle="@style/Chart8VerticalAxisStyle"
app:chartStyle="@style/Chart8CartesianChartStyle"
app:zoomEnabled="false" />
</FrameLayout>
10 changes: 1 addition & 9 deletions sample/src/main/res/layout/chart_9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,5 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Chart9ThemeOverlay"
app:bottomAxisStyle="@style/Chart9BottomAxisStyle"
app:layers="line"
app:lineLayerStyle="@style/Chart9LineLayerStyle"
app:previewMaxX="8"
app:previewMaxY="10"
app:previewMinY="-7"
app:showBottomAxis="true"
app:showStartAxis="true"
app:startAxisStyle="@style/Chart9StartAxisStyle" />
app:chartStyle="@style/Chart9CartesianChartStyle" />
</FrameLayout>
7 changes: 7 additions & 0 deletions sample/src/main/res/values/chart_10_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
<item name="horizontalAxisLabelSpacing">3</item>
<item name="showGuidelines">false</item>
</style>

<style name="Chart10CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart10BottomAxisStyle</item>
<item name="layers">candlestick</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
</style>
</resources>
10 changes: 10 additions & 0 deletions sample/src/main/res/values/chart_1_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<resources>
<color name="chart_1_color_1">#a485e0</color>

<style name="Chart1CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart1BottomAxisStyle</item>
<item name="layers">line</item>
<item name="lineLayerStyle">@style/Chart1LineLayerStyle</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
</style>

<style name="Chart1BottomAxisStyle">
<item name="horizontalAxisItemPlacer">segmented</item>
<item name="showGuidelines">false</item>
Expand Down
8 changes: 8 additions & 0 deletions sample/src/main/res/values/chart_2_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<resources>
<color name="chart_2_color_1">#ff5500</color>

<style name="Chart2CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart2BottomAxisStyle</item>
<item name="columnLayerStyle">@style/Chart2ColumnLayerStyle</item>
<item name="layers">column</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
</style>

<style name="Chart2BottomAxisStyle">
<item name="addExtremeHorizontalAxisLabelPadding">true</item>
<item name="horizontalAxisLabelSpacing">3</item>
Expand Down
11 changes: 11 additions & 0 deletions sample/src/main/res/values/chart_3_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
<color name="chart_3_color_1">#ffbb00</color>
<color name="chart_3_color_2">#9db591</color>

<style name="Chart3CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart3BottomAxisStyle</item>
<item name="fadingEdgeVisibilityInterpolator">androidx.interpolator.view.animation.FastOutSlowInInterpolator</item>
<item name="fadingEdgeWidth">32dp</item>
<item name="layers">line</item>
<item name="lineLayerStyle">@style/Chart3LineLayerStyle</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
<item name="startAxisStyle">@style/Chart3StartAxisStyle</item>
</style>

<style name="Chart3AxisStyle">
<item name="showTitle">true</item>
</style>
Expand Down
11 changes: 11 additions & 0 deletions sample/src/main/res/values/chart_4_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
<color name="chart_4_color_3">#f094bb</color>
<color name="chart_4_color_4">#fdc8c4</color>

<style name="Chart4CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart4BottomAxisStyle</item>
<item name="columnLayerStyle">@style/Chart4ColumnLayerStyle</item>
<item name="layers">line|column</item>
<item name="lineLayerStyle">@style/Chart4LineLayerStyle</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showEndAxis">true</item>
<item name="showTopAxis">true</item>
</style>

<style name="Chart4BottomAxisStyle">
<item name="horizontalAxisItemPlacer">segmented</item>
</style>
Expand Down
11 changes: 11 additions & 0 deletions sample/src/main/res/values/chart_5_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
<color name="chart_5_color_2">#3490de</color>
<color name="chart_5_color_3">#73e8dc</color>

<style name="Chart5CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart5BottomAxisStyle</item>
<item name="columnLayerStyle">@style/Chart5ColumnLayerStyle</item>
<item name="layers">column</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
<item name="startAxisStyle">@style/Chart5AxisStyle</item>
</style>

<style name="Chart5Column1ShapeStyle">
<item name="topStartCornerSize">0dp</item>
<item name="topEndCornerSize">0dp</item>
Expand Down
11 changes: 11 additions & 0 deletions sample/src/main/res/values/chart_6_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
<color name="chart_6_color_2">#5e836a</color>
<color name="chart_6_color_3">#a5ba8e</color>

<style name="Chart6CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart6BottomAxisStyle</item>
<item name="columnLayerStyle">@style/Chart6ColumnLayerStyle</item>
<item name="layers">column</item>
<item name="previewColumnSeriesCount">3</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
</style>

<style name="Chart6BottomAxisStyle">
<item name="horizontalAxisItemPlacer">segmented</item>
</style>
Expand Down
10 changes: 10 additions & 0 deletions sample/src/main/res/values/chart_7_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
<color name="chart_7_color_2">#91b1fd</color>
<color name="chart_7_color_3">#8fdaff</color>

<style name="Chart7CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart7BottomAxisStyle</item>
<item name="layers">line</item>
<item name="lineLayerStyle">@style/Chart7LineLayerStyle</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
</style>

<style name="Chart7BottomAxisStyle">
<item name="horizontalAxisItemPlacer">segmented</item>
</style>
Expand Down
14 changes: 14 additions & 0 deletions sample/src/main/res/values/chart_8_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
<color name="chart_8_color_3">#f09b7d</color>
<color name="chart_8_color_4">#ffc3a1</color>

<style name="Chart8CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart8BottomAxisStyle</item>
<item name="columnLayerStyle">@style/Chart8ColumnLayerStyle</item>
<item name="endAxisStyle">@style/Chart8VerticalAxisStyle</item>
<item name="layers">line|column</item>
<item name="lineLayerStyle">@style/Chart8LineLayerStyle</item>
<item name="scalableEndLayerPadding">16dp</item>
<item name="scalableStartLayerPadding">16dp</item>
<item name="showBottomAxis">true</item>
<item name="showEndAxis">true</item>
<item name="showStartAxis">true</item>
<item name="startAxisStyle">@style/Chart8VerticalAxisStyle</item>
</style>

<style name="Chart8BottomAxisStyle">
<item name="horizontalAxisItemPlacer">segmented</item>
</style>
Expand Down
12 changes: 12 additions & 0 deletions sample/src/main/res/values/chart_9_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
<color name="chart_9_color_positive">#FF3716FF</color>
<color name="chart_9_color_negative">#FFFF166A</color>

<style name="Chart9CartesianChartStyle">
<item name="bottomAxisStyle">@style/Chart9BottomAxisStyle</item>
<item name="layers">line</item>
<item name="lineLayerStyle">@style/Chart9LineLayerStyle</item>
<item name="previewMaxX">8</item>
<item name="previewMaxY">10</item>
<item name="previewMinY">-7</item>
<item name="showBottomAxis">true</item>
<item name="showStartAxis">true</item>
<item name="startAxisStyle">@style/Chart9StartAxisStyle</item>
</style>

<style name="Chart9Line1Style">
<item name="positiveColor">?colorPrimary</item>
<item name="negativeColor">?colorSecondary</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
have been initialized yet. Such calls can be ignored, as `Context.isLtr` will be read at
`MutableMeasuringContext` instantiation. */
@Suppress("UNNECESSARY_SAFE_CALL")
measuringContext?.isLtr = layoutDirection == View.LAYOUT_DIRECTION_LTR
measuringContext?.isLtr = layoutDirection == LAYOUT_DIRECTION_LTR
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.patrykandpatrick.vico.views.common.defaultColors

internal fun TypedArray.getColumnCartesianLayer(
context: Context,
@StyleableRes resourceId: Int = R.styleable.CartesianChartView_columnLayerStyle,
@StyleableRes resourceId: Int = R.styleable.CartesianChartStyle_columnLayerStyle,
@StyleableRes styleableResourceId: IntArray = R.styleable.ColumnCartesianLayerStyle,
): ColumnCartesianLayer =
getNestedTypedArray(context, resourceId, styleableResourceId).run {
Expand Down Expand Up @@ -120,7 +120,7 @@ internal fun TypedArray.getColumnCartesianLayer(

internal fun TypedArray.getLineCartesianLayer(
context: Context,
@StyleableRes resourceId: Int = R.styleable.CartesianChartView_lineLayerStyle,
@StyleableRes resourceId: Int = R.styleable.CartesianChartStyle_lineLayerStyle,
@StyleableRes styleableResourceId: IntArray = R.styleable.LineCartesianLayerStyle,
): LineCartesianLayer =
getNestedTypedArray(context, resourceId, styleableResourceId).run {
Expand Down Expand Up @@ -170,7 +170,7 @@ internal fun TypedArray.getCandlestickCartesianLayer(context: Context): Candlest
val bearishColor = context.defaultColors.bearishCandleColor.toInt()
return getNestedTypedArray(
context,
R.styleable.CartesianChartView_candlestickLayerStyle,
R.styleable.CartesianChartStyle_candlestickLayerStyle,
R.styleable.CandlestickCartesianLayerStyle,
)
.use { typedArray ->
Expand Down
Loading

0 comments on commit a60f4b8

Please sign in to comment.