Skip to content

Commit

Permalink
增加背景网格线配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Jun 2, 2022
1 parent 4aded24 commit 8f47b89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
backgroundGridPaint.pathEffect = config.gridLinePathEffect

if (config.gridHorizontalLineCount > 0) {
val space = height.toFloat() / (config.gridHorizontalLineCount + 1)
val space = config.horizontalGridLineSpaceCalculator?.invoke(this)
?: height.toFloat() / (config.gridHorizontalLineCount + 1)
var top = config.horizontalGridLineTopOffset ?: space

for (i in 1..config.gridHorizontalLineCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,33 @@ class StockChartConfig {
// 背景网格线条虚线配置
var gridLinePathEffect: PathEffect? = null

// 背景网格第一条线的顶部偏移量,默认是高度按照网格线数量平均分后的距离
// 背景网格横线第一条线的顶部偏移量
var horizontalGridLineTopOffset: Float? = null

// 背景网格左侧偏移量
// 背景网格横线左侧偏移量
var horizontalGridLineLeftOffset: Float = DEFAULT_HORIZONTAL_GRID_LINE_LEFT_OFFSET

// 背景网格横线间距
var horizontalGridLineSpaceCalculator: ((StockChart) -> Float)? = null

var valueTendToZero = DEFAULT_VALUE_TEND_TO_ZERO

// 加载更多监听
var onLoadMoreListener: OnLoadMoreListener? = null
set(value) {
field?.apply { removeOnLoadMoreListener(this) }
value?.apply { addOnLoadMoreListener(this)}
field = value
set(value) {
field?.apply { removeOnLoadMoreListener(this) }
value?.apply { addOnLoadMoreListener(this) }
field = value

}
}

// 手势监听
var onGestureListener: OnGestureListener? = null
set(value) {
field?.apply { removeOnGestureListener(this) }
value?.apply { addOnGestureListener(this) }
field = value
}
set(value) {
field?.apply { removeOnGestureListener(this) }
value?.apply { addOnGestureListener(this) }
field = value
}

val childChartFactories = mutableListOf<AbsChildChartFactory<*>>()

Expand Down Expand Up @@ -241,7 +244,7 @@ class StockChartConfig {
*/
fun insertKEntities(index: Int, kEntities: List<IKEntity>) {
check(index in this.kEntities.indices) { "Index $index out of bounds for length ${kEntities.size}" }
if(index <= showEndIndex) {
if (index <= showEndIndex) {
showEndIndex += kEntities.size
showStartIndex += kEntities.size
}
Expand All @@ -252,11 +255,11 @@ class StockChartConfig {
/**
* 删除一个K线数据点
*/
fun removeKEntity(index: Int){
fun removeKEntity(index: Int) {
check(index in this.kEntities.indices) { "Index $index out of bounds for length ${kEntities.size}" }
if(index <= showEndIndex){
showEndIndex --
showStartIndex --
if (index <= showEndIndex) {
showEndIndex--
showStartIndex--
}
this.kEntities.removeAt(index)
modifyKEntitiesFlag = true
Expand Down Expand Up @@ -286,14 +289,14 @@ class StockChartConfig {
/**
* 添加手势监听
*/
fun addOnGestureListener(listener: OnGestureListener){
fun addOnGestureListener(listener: OnGestureListener) {
onGestureListeners.add(listener)
}

/**
* 移除手势监听
*/
fun removeOnGestureListener(listener: OnGestureListener){
fun removeOnGestureListener(listener: OnGestureListener) {
onGestureListeners.remove(listener)
}

Expand Down
4 changes: 2 additions & 2 deletions samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android:flexbox:2.0.1'

// implementation project(':lib')
implementation 'com.github.wangyiqian:StockChart:1.1.2'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.1.2'
}

0 comments on commit 8f47b89

Please sign in to comment.