Skip to content

Commit

Permalink
Replace CartesianChartView.setModel with property
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowsky committed Nov 11, 2024
1 parent 21df82c commit 02986ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0

private val ranges = MutableCartesianChartRanges()

private var _model: CartesianChartModel? = null

override var model: CartesianChartModel?
get() = _model
set(value) {
setModel(value)
}

override val measuringContext: MutableCartesianMeasuringContext =
MutableCartesianMeasuringContext(
canvasBounds = canvasBounds,
Expand Down Expand Up @@ -206,28 +214,22 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
} else {
RandomCartesianModelGenerator.defaultY.endInclusive
}
setModel(
model =
RandomCartesianModelGenerator.getRandomModel(
typedArray.getInt(R.styleable.CartesianChartView_previewColumnSeriesCount, 1),
typedArray.getInt(R.styleable.CartesianChartView_previewLineSeriesCount, 1),
minX..maxX,
minY..maxY,
)
)
}
}
}

/** Sets the [CartesianChartModel]. */
public fun setModel(model: CartesianChartModel) {
setModel(model = model, updateRanges = true)
}

override fun shouldShowPlaceholder(): Boolean = model == null

private fun setModel(model: CartesianChartModel?, updateRanges: Boolean) {
val oldModel = this.model
this.model = model
private fun setModel(model: CartesianChartModel?, updateRanges: Boolean = true) {
val oldModel = this._model
this._model = model
updatePlaceholderVisibility()
tryInvalidate(chart, model, updateRanges)
if (model != null && oldModel?.id != model.id && isInEditMode.not()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
)

/** Houses the chart data. */
public var model: Model? = null
protected set
public abstract var model: Model?

protected val animator: ValueAnimator =
ValueAnimator.ofFloat(Animation.range.start, Animation.range.endInclusive).apply {
Expand Down

0 comments on commit 02986ec

Please sign in to comment.