Skip to content

Commit

Permalink
Add CandlestickCartesianLayer#scaleCandleWicks
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalik committed Apr 6, 2024
1 parent 4eeadce commit 5f8144a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public fun rememberCandlestickCartesianLayer(
candles: CandlestickCartesianLayer.CandleProvider = CandlestickCartesianLayer.CandleProvider.absolute(),
minCandleBodyHeight: Dp = Defaults.MIN_CANDLE_BODY_HEIGHT_DP.dp,
candleSpacing: Dp = Defaults.CANDLE_SPACING_DP.dp,
scaleCandleWicks: Boolean = false,
verticalAxisPosition: AxisPosition.Vertical? = null,
drawingModelInterpolator: DrawingModelInterpolator<
CandlestickCartesianLayerDrawingModel.CandleInfo,
Expand All @@ -42,7 +43,8 @@ public fun rememberCandlestickCartesianLayer(
remember { CandlestickCartesianLayer(candles) }.apply {
this.candles = candles
minCandleBodyHeightDp = minCandleBodyHeight.value
this.candleSpacingDp = candleSpacing.value
candleSpacingDp = candleSpacing.value
this.scaleCandleWicks = scaleCandleWicks
this.verticalAxisPosition = verticalAxisPosition
this.drawingModelInterpolator = drawingModelInterpolator
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ import com.patrykandpatrick.vico.core.common.shape.Shape
/**
* [CandlestickCartesianLayer] displays data as vertical bars. It can draw multiple columns per segment.
*
* @param candles provides the [Candle]s.
* @param minCandleBodyHeightDp TODO
* @param candleSpacingDp the horizontal padding between the edges of chart segments and the columns they contain.
* @property candles provides the [Candle]s.
* @property minCandleBodyHeightDp TODO
* @property candleSpacingDp the horizontal padding between the edges of chart segments and the columns they contain.
* segments that contain a single column only.
* @param verticalAxisPosition the position of the [VerticalAxis] with which the [ColumnCartesianLayer] should be
* @property scaleCandleWicks whether the candle wicks should be scaled based on the zoom factor.
* @property verticalAxisPosition the position of the [VerticalAxis] with which the [ColumnCartesianLayer] should be
* associated. Use this for independent [CartesianLayer] scaling.
*/
public open class CandlestickCartesianLayer(
public var candles: CandleProvider,
public var minCandleBodyHeightDp: Float = Defaults.MIN_CANDLE_BODY_HEIGHT_DP,
public var candleSpacingDp: Float = Defaults.CANDLE_SPACING_DP,
public var scaleCandleWicks: Boolean = false,
public var verticalAxisPosition: AxisPosition.Vertical? = null,
public var drawingModelInterpolator: DrawingModelInterpolator<
CandlestickCartesianLayerDrawingModel.CandleInfo,
Expand Down Expand Up @@ -165,15 +167,15 @@ public open class CandlestickCartesianLayer(
top = topWickY,
bottom = bodyTopY,
centerX = bodyCenterX,
thicknessScale = zoom,
thicknessScale = if (scaleCandleWicks) zoom else 1f,
)

candle.bottomWick.drawVertical(
context = this,
top = bodyBottomY,
bottom = bottomWickY,
centerX = bodyCenterX,
thicknessScale = zoom,
thicknessScale = if (scaleCandleWicks) zoom else 1f,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ internal fun TypedArray.getCandlestickCartesianLayer(context: Context): Candlest
R.styleable.CandlestickLayerStyle_candleSpacing,
Defaults.CANDLE_SPACING_DP,
),
scaleCandleWicks = typedArray.getBoolean(R.styleable.CandlestickLayerStyle_scaleCandleWicks, false),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions vico/views/src/main/res/values/candlestick_chart_attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<attr name="absolutelyBearishRelativelyBearishCandleStyle" format="reference" />
<attr name="minCandleBodyHeight" format="dimension" />
<attr name="candleSpacing" format="dimension" />
<attr name="scaleCandleWicks" format="boolean" />
</declare-styleable>

<declare-styleable name="CandleStyle">
Expand Down

0 comments on commit 5f8144a

Please sign in to comment.