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 347cba5 commit c01565d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const val DEFAULT_GRID_HORIZONTAL_LINE_COUNT = 0
const val DEFAULT_GRID_VERTICAL_LINE_COUNT = 0
val DEFAULT_GRID_LINE_COLOR = Color.parseColor("#676767")
const val DEFAULT_GRID_LINE_STROKE_WIDTH = 1f
const val DEFAULT_HORIZONTAL_GRID_LINE_LEFT_OFFSET = 0f
const val DEFAULT_VALUE_TEND_TO_ZERO = 0.0001f

// K线图
Expand Down
11 changes: 9 additions & 2 deletions lib/src/main/java/com/github/wangyiqian/stockchart/StockChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,20 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
private fun drawBackgroundGrid(canvas: Canvas) {
backgroundGridPaint.color = config.gridLineColor
backgroundGridPaint.strokeWidth = config.gridLineStrokeWidth
backgroundGridPaint.pathEffect = config.gridLinePathEffect

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

for (i in 1..config.gridHorizontalLineCount) {
canvas.drawLine(0f, top, width.toFloat(), top, backgroundGridPaint)
canvas.drawLine(
config.horizontalGridLineLeftOffset,
top,
width.toFloat(),
top,
backgroundGridPaint
)
top += space

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package com.github.wangyiqian.stockchart

import android.graphics.DashPathEffect
import android.graphics.PathEffect
import androidx.annotation.ColorInt
import com.github.wangyiqian.stockchart.childchart.base.*
import com.github.wangyiqian.stockchart.entities.IKEntity
Expand Down Expand Up @@ -130,6 +132,15 @@ class StockChartConfig {
// 背景网格线条宽度
var gridLineStrokeWidth = DEFAULT_GRID_LINE_STROKE_WIDTH

// 背景网格线条虚线配置
var gridLinePathEffect: PathEffect? = null

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

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

var valueTendToZero = DEFAULT_VALUE_TEND_TO_ZERO

// 加载更多监听
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.1'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.1.1'
}

0 comments on commit c01565d

Please sign in to comment.