Skip to content

Commit

Permalink
增加一个高级用法配置extMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Jun 17, 2022
1 parent f52daf6 commit 7522222
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 37 deletions.
134 changes: 100 additions & 34 deletions lib/src/main/java/com/github/wangyiqian/stockchart/StockChartConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.github.wangyiqian.stockchart

import android.graphics.DashPathEffect
import android.graphics.Matrix
import android.graphics.PathEffect
import androidx.annotation.ColorInt
import com.github.wangyiqian.stockchart.childchart.base.*
Expand All @@ -27,126 +27,185 @@ import com.github.wangyiqian.stockchart.listener.OnLoadMoreListener
*/
class StockChartConfig {

// K线数据
/**
* K线数据
*/
var kEntities = mutableListOf<IKEntity>()
set(value) {
setKEntities(value, 0, kEntities.size - 1)
}

// 初始显示区域的起始坐标
/**
* 初始显示区域的起始坐标
*/
var showStartIndex = 0

// 初始显示区域的结束坐标
/**
* 初始显示区域的结束坐标
*/
var showEndIndex = 0

// 是否支持滑动
/**
* 是否支持滑动
*/
var scrollAble =
DEFAULT_SCROLL_ABLE

// 是否支持"滑过头回弹"效果
/**
* 是否支持"滑过头回弹"效果
*/
var overScrollAble =
DEFAULT_OVER_SCROLL_ABLE

// "滑过头回弹"最大距离
/**
* "滑过头回弹"最大距离
*/
var overScrollDistance =
DEFAULT_OVER_SCROLL_DISTANCE

// "滑过头回弹"过程中触发加载更多需要的距离
/**
* "滑过头回弹"过程中触发加载更多需要的距离
*/
var overScrollOnLoadMoreDistance =
DEFAULT_OVER_SCROLL_ON_LOAD_MORE_DISTANCE

// 是否支持双指缩放
/**
* 是否支持双指缩放
*/
var scaleAble =
DEFAULT_SCALE_ABLE

// 是否需要"平滑的"滑动。如果false,滑动时一个下标对应的内容要么全显示,要么不显示。
var scrollSmoothly =
DEFAULT_SCROLL_SMOOTHLY
/**
* 是否需要"平滑的"滑动。如果false,滑动时一个下标对应的内容要么全显示,要么不显示。
*/
var scrollSmoothly = DEFAULT_SCROLL_SMOOTHLY

// 超出滑动限制范围时拖动的"摩擦力"
/**
* 超出滑动限制范围时拖动的"摩擦力"
*/
var frictionScrollExceedLimit =
DEFAULT_FRICTION_SCROLL_EXCEED_LIMIT

// 双指缩放最大缩放比例
/**
* 双指缩放最大缩放比例
*/
var scaleFactorMax =
DEFAULT_SCALE_FACTOR_MAX
set(value) {
check(value >= 1f) { "The factor of max must not be less than 1.0 " }
field = value
}

// 双指缩放最小缩放比例
/**
* 双指缩放最小缩放比例
*/
var scaleFactorMin =
DEFAULT_SCALE_FACTOR_MIN
set(value) {
check(value <= 1f) { "The factor of max must not be greater than 1.0 " }
field = value
}

// 是否支持长按高亮横线
/**
* 是否支持长按高亮横线
*/
var showHighlightHorizontalLine =
DEFAULT_SHOW_HIGHLIGHT_HORIZONTAL_LINE

// 长按高亮横线宽度
/**
* 长按高亮横线宽度
*/
var highlightHorizontalLineWidth =
DEFAULT_HIGHLIGHT_HORIZONTAL_LINE_WIDTH

// 长按高亮横线颜色
/**
* 长按高亮横线颜色
*/
var highlightHorizontalLineColor =
DEFAULT_HIGHLIGHT_HORIZONTAL_LINE_COLOR

// 是否支持长按高亮竖线
/**
* 是否支持长按高亮竖线
*/
var showHighlightVerticalLine =
DEFAULT_SHOW_HIGHLIGHT_VERTICAL_LINE

// 长按高亮竖线宽度
/**
* 长按高亮竖线宽度
*/
var highlightVerticalLineWidth =
DEFAULT_HIGHLIGHT_VERTICAL_LINE_WIDTH

// 长按高亮竖线颜色
/**
* 长按高亮竖线颜色
*/
var highlightVerticalLineColor =
DEFAULT_HIGHLIGHT_VERTICAL_LINE_COLOR

// 涨色值
/**
* 涨色值
*/
var riseColor: Int =
DEFAULT_RISE_COLOR

// 跌色值
/**
* 跌色值
*/
var downColor: Int =
DEFAULT_DOWN_COLOR

// 背景色
/**
* 背景色
*/
@ColorInt
var backgroundColor = DEFAULT_BACKGROUND_COUNT

// 背景网格横线数
/**
* 背景网格横线数
*/
var gridHorizontalLineCount = DEFAULT_GRID_HORIZONTAL_LINE_COUNT

// 背景网格竖线数
/**
* 背景网格竖线数
*/
var gridVerticalLineCount = DEFAULT_GRID_VERTICAL_LINE_COUNT

// 背景网格线条色
/**
* 背景网格线条色
*/
@ColorInt
var gridLineColor = DEFAULT_GRID_LINE_COLOR

// 背景网格线条宽度
/**
* 背景网格线条宽度
*/
var gridLineStrokeWidth = DEFAULT_GRID_LINE_STROKE_WIDTH

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

// 背景网格横线第一条线的顶部偏移量
/**
* 背景网格横线第一条线的顶部偏移量
*/
var horizontalGridLineTopOffsetCalculator: ((StockChart) -> Float)? = null

// 背景网格横线左侧偏移量
/**
* 背景网格横线左侧偏移量
*/
var horizontalGridLineLeftOffsetCalculator: ((StockChart) -> Float)? = null

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

var valueTendToZero = DEFAULT_VALUE_TEND_TO_ZERO

// 加载更多监听
/**
* 加载更多监听
*/
var onLoadMoreListener: OnLoadMoreListener? = null
set(value) {
field?.apply { removeOnLoadMoreListener(this) }
Expand All @@ -155,14 +214,21 @@ class StockChartConfig {

}

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

/**
* 高级用法,每个子图最终绘制追加一个Matrix
*/
var extMatrix: Matrix? = null

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

private var onLoadMoreListeners = mutableSetOf<OnLoadMoreListener>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ internal class ChildChartMatrixHelper<O : BaseChildChartConfig>(

val chartDisplayArea = chart.getChartMainDisplayArea()


tmp2FloatArray[0] = chartDisplayArea.left
tmp2FloatArray[1] = 0f
// 反算出会被移动到显示区域的第一个逻辑坐标值(数据下标)
Expand Down Expand Up @@ -275,6 +274,9 @@ internal class ChildChartMatrixHelper<O : BaseChildChartConfig>(
postConcat(stockChart.getScrollMatrix())
postConcat(fixXMatrix)
postConcat(fixYMatrix)
stockChart.getConfig().extMatrix?.also {
postConcat(it)
}
}
}

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.5'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.1.5'
}

0 comments on commit 7522222

Please sign in to comment.