Skip to content

Commit

Permalink
指标支持扩展、细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Jan 13, 2022
1 parent bae2934 commit 827a726
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import android.view.View
import android.view.ViewGroup
import com.github.wangyiqian.stockchart.IStockChart
import com.github.wangyiqian.stockchart.StockChart
import com.github.wangyiqian.stockchart.entities.FLAG_EMPTY
import com.github.wangyiqian.stockchart.entities.GestureEvent
import com.github.wangyiqian.stockchart.entities.containFlag
import com.github.wangyiqian.stockchart.listener.OnKEntitiesChangedListener

/**
Expand Down Expand Up @@ -246,4 +248,20 @@ abstract class BaseChildChart<C : BaseChildChartConfig> @JvmOverloads constructo
override fun getConfig() = chartConfig

override fun onTap(event: GestureEvent) {}

override fun isRise(idx: Int) =
if (getKEntities()[idx].getClosePrice() == getKEntities()[idx].getOpenPrice()) {
if (idx - 1 in getKEntities().indices) {
val preKEntity = getKEntities()[idx - 1]
if (!preKEntity.containFlag(FLAG_EMPTY)) {
getKEntities()[idx].getClosePrice() >= preKEntity.getClosePrice()
} else {
true
}
} else {
true
}
} else {
getKEntities()[idx].getClosePrice() > getKEntities()[idx].getOpenPrice()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ interface IChildChart {
*/
fun onTap(event: GestureEvent)

/**
* 涨跌判断
*/
fun isRise(idx: Int): Boolean

fun getHighlightValue(highlightX: Float, highlightY: Float, highlightValue: FloatArray) {
highlightValue[0] = highlightX
highlightValue[1] = highlightY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,22 +838,6 @@ open class KChart(
}
}

private fun isRise(idx: Int) =
if (getKEntities()[idx].getClosePrice() == getKEntities()[idx].getOpenPrice()) {
if (idx - 1 in getKEntities().indices) {
val preKEntity = getKEntities()[idx - 1]
if (!preKEntity.containFlag(FLAG_EMPTY)) {
getKEntities()[idx].getClosePrice() >= preKEntity.getClosePrice()
} else {
true
}
} else {
true
}
} else {
getKEntities()[idx].getClosePrice() > getKEntities()[idx].getOpenPrice()
}

private fun drawLineKChart(canvas: Canvas) {
lineKChartLinePaint.strokeWidth = chartConfig.lineChartStrokeWidth
lineKChartLinePaint.color = chartConfig.lineChartColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.graphics.Canvas
import android.graphics.Paint
import com.github.wangyiqian.stockchart.IStockChart
import com.github.wangyiqian.stockchart.childchart.base.BaseChildChart
import kotlin.math.abs

/**
* @author wangyiqian E-mail: [email protected]
Expand Down Expand Up @@ -59,8 +60,15 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) :
}
}
}
result[0] = yMin
result[1] = yMax

if (abs(yMin - yMax) > 0.0001) {
result[0] = yMin
result[1] = yMax
} else { // 约等于0
var delta = 2
result[0] = yMin - delta
result[1] = yMax + delta
}
}

override fun preDrawBackground(canvas: Canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.graphics.Canvas
import android.graphics.Paint
import com.github.wangyiqian.stockchart.IStockChart
import com.github.wangyiqian.stockchart.childchart.base.BaseChildChart
import kotlin.math.abs

/**
* MACD指标图
Expand Down Expand Up @@ -63,8 +64,16 @@ class MacdChart(
}
}
}
result[0] = yMin
result[1] = yMax

if (abs(yMin - yMax) > 0.0001) {
result[0] = yMin
result[1] = yMax
} else { // 约等于0
var delta = 2
result[0] = yMin - delta
result[1] = yMax + delta
}

}

override fun preDrawBackground(canvas: Canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ class VolumeChart(
}
}

private fun isRise(idx: Int) =
if (getKEntities()[idx].getClosePrice() == getKEntities()[idx].getOpenPrice()) {
if (idx - 1 in getKEntities().indices) {
val preKEntity = getKEntities()[idx - 1]
if (!preKEntity.containFlag(FLAG_EMPTY)) {
getKEntities()[idx].getClosePrice() >= preKEntity.getClosePrice()
} else {
true
}
} else {
true
}
} else {
getKEntities()[idx].getClosePrice() > getKEntities()[idx].getOpenPrice()
}

override fun preDrawHighlight(canvas: Canvas) {}

override fun drawHighlight(canvas: Canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.github.wangyiqian.stockchart.entities.IKEntity
* @author wangyiqian E-mail: [email protected]
* @version 创建时间: 2021/2/18
*/
sealed class Index(
open abstract class Index(
var param: String,
var startText: String,
var startTextColor: Int,
Expand Down

0 comments on commit 827a726

Please sign in to comment.