Skip to content

Commit

Permalink
优化所有K线点值一直的显示问题、优化山峰图阴影
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Dec 13, 2021
1 parent c25325b commit afdc094
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal class ChildChartMatrixHelper<O : BaseChildChartConfig>(
// 非正常情况,y轴逻辑区间无法算出(所有值相等),之前处于原始逻辑坐标,将需要显示的逻辑区域移动到显示区域左边垂直居中位置
coordinateMatrix.postTranslate(
chartDisplayArea.left - xValueRangeFrom,
(chartDisplayArea.bottom - chartDisplayArea.top) / 2 - yValueRangeFrom
(chartDisplayArea.bottom - chartDisplayArea.top) / 2
)
} else {
// 正常情况,之前处于原始逻辑坐标,将需要显示的逻辑区域移动到显示区域左上角
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.github.wangyiqian.stockchart.childchart.base.BaseChildChart
import com.github.wangyiqian.stockchart.entities.EmptyKEntity
import com.github.wangyiqian.stockchart.entities.KEntityOfLineStarter
import com.github.wangyiqian.stockchart.index.Index
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

Expand Down Expand Up @@ -153,8 +154,17 @@ open class KChart(
}
}

result[0] = yMin
result[1] = yMax
if (abs(yMin - yMax) > 0.0001) {
result[0] = yMin
result[1] = yMax
} else { // 约等于0
var delta = abs(chartConfig.costPrice ?: 0f - yMin) * 2
if (delta == yMin) {
delta = abs(yMin / 2f)
}
result[0] = yMin - delta
result[1] = yMax + delta
}
}

override fun preDrawBackground(canvas: Canvas) {}
Expand Down Expand Up @@ -593,11 +603,16 @@ open class KChart(
mountainGradientKChartPaint.shader = mountainLinearGradient
tmpPath.reset()

tmp2FloatArray[1] = getChartDisplayArea().bottom
mapPointsReal2Value(tmp2FloatArray)
val yMinValue = tmp2FloatArray[1]

var preIdx = -1
for (idx in getKEntities().indices) {
if (getKEntities()[idx] is EmptyKEntity || getKEntities()[idx] is KEntityOfLineStarter) {
if (preIdx != -1) {
tmpPath.lineTo(preIdx + 0.5f, 0f)
tmpPath.lineTo(preIdx + 1f, getKEntities()[preIdx].getClosePrice())
tmpPath.lineTo(preIdx + 1f, yMinValue)
mapPathValue2Real(tmpPath)
canvas.drawPath(tmpPath, mountainGradientKChartPaint)
tmpPath.reset()
Expand All @@ -610,7 +625,11 @@ open class KChart(
if (preIdx == -1) {
preIdx = idx
tmpPath.reset()
tmpPath.moveTo(preIdx + 0.5f, 0f)
tmpPath.moveTo(preIdx.toFloat(), yMinValue)
tmpPath.lineTo(preIdx.toFloat(), getKEntities()[preIdx].getClosePrice())
tmpPath.lineTo(preIdx + 0.5f, getKEntities()[preIdx].getClosePrice())


} else {
preIdx = idx
}
Expand All @@ -619,7 +638,8 @@ open class KChart(
}

if (preIdx != -1) {
tmpPath.lineTo(preIdx + 0.5f, 0f)
tmpPath.lineTo(preIdx + 1f, getKEntities()[preIdx].getClosePrice())
tmpPath.lineTo(preIdx + 1f, yMinValue)
mapPathValue2Real(tmpPath)
canvas.drawPath(tmpPath, mountainGradientKChartPaint)
tmpPath.reset()
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.0.11'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.0.11'
}

0 comments on commit afdc094

Please sign in to comment.