diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/MatrixHelper.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/MatrixHelper.kt index 3ab5613..0d85d14 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/MatrixHelper.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/MatrixHelper.kt @@ -175,7 +175,7 @@ internal class MatrixHelper(private val stockChart: IStockChart) { val limitRight = tmp4FloatArray[2] // 显示区域 - val displayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() + val mainDisplayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() // 当前拖动的距离 val dragDistanceX = -distanceX @@ -184,25 +184,25 @@ internal class MatrixHelper(private val stockChart: IStockChart) { var dx = 0f if (dragDistanceX > 0) { // 手指往右拖 - if (limitLeft + dragDistanceX > displayArea.left) { + if (limitLeft + dragDistanceX > mainDisplayArea.left) { var dragDistanceXLeft = dragDistanceX // 需要拖动的距离 - if (limitLeft < displayArea.left) { // 处理未超出边界部分 - dx += displayArea.left - limitLeft + if (limitLeft < mainDisplayArea.left) { // 处理未超出边界部分 + dx += mainDisplayArea.left - limitLeft dragDistanceXLeft -= dx } if (stockChart.getConfig().overScrollAble && dragDistanceXLeft > 0) { // 超出边界部分,处理回弹区 - if (limitLeft - displayArea.left >= stockChart.getConfig().overScrollOnLoadMoreDistance) { + if (limitLeft - mainDisplayArea.left >= stockChart.getConfig().overScrollOnLoadMoreDistance) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnLeftLoadMore() } } dragDistanceXLeft *= stockChart.getConfig().frictionScrollExceedLimit // 加阻力 - if (limitLeft + dragDistanceXLeft > displayArea.left + stockChart.getConfig().overScrollDistance) { // 超出极限 + if (limitLeft + dragDistanceXLeft > mainDisplayArea.left + stockChart.getConfig().overScrollDistance) { // 超出极限 dragDistanceXLeft = - displayArea.left + stockChart.getConfig().overScrollDistance - limitLeft + mainDisplayArea.left + stockChart.getConfig().overScrollDistance - limitLeft } dx += dragDistanceXLeft } else { @@ -218,25 +218,25 @@ internal class MatrixHelper(private val stockChart: IStockChart) { } else { // 手指往左拖 - if (limitRight + dragDistanceX < displayArea.right) { + if (limitRight + dragDistanceX < mainDisplayArea.right) { var dragDistanceXLeft = dragDistanceX // 需要拖动的距离 - if (limitRight > displayArea.right) { // 未超出边界部分 - dx += displayArea.right - limitRight + if (limitRight > mainDisplayArea.right) { // 未超出边界部分 + dx += mainDisplayArea.right - limitRight dragDistanceXLeft -= dx } if (stockChart.getConfig().overScrollAble && dragDistanceXLeft < 0) { // 超出边界部分,处理回弹区 - if (displayArea.right - limitRight >= stockChart.getConfig().overScrollOnLoadMoreDistance) { + if (mainDisplayArea.right - limitRight >= stockChart.getConfig().overScrollOnLoadMoreDistance) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnRightLoadMore() } } dragDistanceXLeft *= stockChart.getConfig().frictionScrollExceedLimit // 加阻力 - if (limitRight + dragDistanceXLeft < displayArea.right - stockChart.getConfig().overScrollDistance) { // 超出极限 + if (limitRight + dragDistanceXLeft < mainDisplayArea.right - stockChart.getConfig().overScrollDistance) { // 超出极限 dragDistanceXLeft = - displayArea.right - stockChart.getConfig().overScrollDistance - limitRight + mainDisplayArea.right - stockChart.getConfig().overScrollDistance - limitRight } dx += dragDistanceXLeft } else { @@ -290,9 +290,9 @@ internal class MatrixHelper(private val stockChart: IStockChart) { val limitRight = tmp4FloatArray[2] // 显示区域 - val displayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() + val mainDisplayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() - if (limitRight < displayArea.right || limitLeft > displayArea.left) { + if (limitRight < mainDisplayArea.right || limitLeft > mainDisplayArea.left) { // 边界外不能开始fling return } @@ -300,8 +300,8 @@ internal class MatrixHelper(private val stockChart: IStockChart) { computeScrollCurrX = 0 // 计算出x能惯性滑动的限制位置 - val minX = -abs(limitRight - displayArea.right) - val maxX = abs(limitLeft - displayArea.left) + val minX = -abs(limitRight - mainDisplayArea.right) + val maxX = abs(limitLeft - mainDisplayArea.left) if (velocityX < 0 && maxX != 0f || velocityX > 0 && minX != 0f) { @@ -340,14 +340,14 @@ internal class MatrixHelper(private val stockChart: IStockChart) { stockChart.getChildCharts()[0].mapPointsValue2Real(tmp4FloatArray) val limitLeft = tmp4FloatArray[0] val limitRight = tmp4FloatArray[2] - val displayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() + val mainDisplayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() if (stockChart.getConfig().overScrollAble) { - if (limitLeft - displayArea.left >= stockChart.getConfig().overScrollOnLoadMoreDistance) { + if (limitLeft - mainDisplayArea.left >= stockChart.getConfig().overScrollOnLoadMoreDistance) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnLeftLoadMore() } - } else if (displayArea.right - limitRight >= stockChart.getConfig().overScrollOnLoadMoreDistance) { + } else if (mainDisplayArea.right - limitRight >= stockChart.getConfig().overScrollOnLoadMoreDistance) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnRightLoadMore() @@ -356,12 +356,12 @@ internal class MatrixHelper(private val stockChart: IStockChart) { enableTriggerOnLoadMoreNextTime = true } } else { - if (limitLeft.toInt() >= displayArea.left.toInt()) { + if (limitLeft.toInt() >= mainDisplayArea.left.toInt()) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnLeftLoadMore() } - } else if (limitRight.toInt() <= displayArea.right.toInt()) { + } else if (limitRight.toInt() <= mainDisplayArea.right.toInt()) { if (enableTriggerOnLoadMoreNextTime) { enableTriggerOnLoadMoreNextTime = false stockChart.dispatchOnRightLoadMore() @@ -394,13 +394,13 @@ internal class MatrixHelper(private val stockChart: IStockChart) { val limitRight = tmp4FloatArray[2] // 显示区域 - val displayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() + val mainDisplayArea = stockChart.getChildCharts()[0].getChartMainDisplayArea() var dx = 0 - if (limitLeft > displayArea.left) { // 左边界滑过头 - dx = (displayArea.left - limitLeft).toInt() - } else if (limitRight < displayArea.right) { // 右边界滑过头 - dx = (displayArea.right - limitRight).toInt() + if (limitLeft > mainDisplayArea.left) { // 左边界滑过头 + dx = (mainDisplayArea.left - limitLeft).toInt() + } else if (limitRight < mainDisplayArea.right) { // 右边界滑过头 + dx = (mainDisplayArea.right - limitRight).toInt() } if (dx != 0) { // 需要回弹 diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/StockChartConfig.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/StockChartConfig.kt index da507a0..d803227 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/StockChartConfig.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/StockChartConfig.kt @@ -203,6 +203,16 @@ class StockChartConfig { var valueTendToZero = DEFAULT_VALUE_TEND_TO_ZERO + /** + * 主数据显示区域的左内间距 + */ + var chartMainDisplayAreaPaddingLeft: Float = 0f + + /** + * 主数据显示区域的右内间距 + */ + var chartMainDisplayAreaPaddingRight: Float = 0f + /** * 加载更多监听 */ diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/BaseChildChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/BaseChildChart.kt index 6b4e8c8..a68788b 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/BaseChildChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/BaseChildChart.kt @@ -108,8 +108,8 @@ abstract class BaseChildChart @JvmOverloads constructo } chartMainDisplayArea.apply { - left = chartDisplayArea.left - right = chartDisplayArea.right + left = chartDisplayArea.left + stockChart.getConfig().chartMainDisplayAreaPaddingLeft + right = chartDisplayArea.right - stockChart.getConfig().chartMainDisplayAreaPaddingRight top = chartDisplayArea.top + chartConfig.chartMainDisplayAreaPaddingTop bottom = chartDisplayArea.bottom - chartConfig.chartMainDisplayAreaPaddingBottom } diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/ChildChartMatrixHelper.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/ChildChartMatrixHelper.kt index 23012e7..540c091 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/ChildChartMatrixHelper.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/base/ChildChartMatrixHelper.kt @@ -66,7 +66,7 @@ internal class ChildChartMatrixHelper( private fun prepareCoordinateMatrix() { coordinateMatrix.reset() - val chartDisplayArea = chart.getChartMainDisplayArea() + val chartMainDisplayArea = chart.getChartMainDisplayArea() chart.getXValueRange( stockChart.getConfig().showStartIndex, @@ -89,36 +89,36 @@ internal class ChildChartMatrixHelper( if (yValueRangeLen == 0f) { // 非正常情况,y轴逻辑区间无法算出(所有值相等),之前处于原始逻辑坐标,将需要显示的逻辑区域移动到显示区域左边垂直居中位置 coordinateMatrix.postTranslate( - chartDisplayArea.left - xValueRangeFrom, - (chartDisplayArea.bottom - chartDisplayArea.top) / 2 + chartMainDisplayArea.left - xValueRangeFrom, + (chartMainDisplayArea.bottom - chartMainDisplayArea.top) / 2 ) } else { // 正常情况,之前处于原始逻辑坐标,将需要显示的逻辑区域移动到显示区域左上角 coordinateMatrix.postTranslate( - chartDisplayArea.left - xValueRangeFrom, - chartDisplayArea.top - yValueRangeFrom + chartMainDisplayArea.left - xValueRangeFrom, + chartMainDisplayArea.top - yValueRangeFrom ) } - val sx = (chartDisplayArea.right - chartDisplayArea.left) / xValueRangeLen + val sx = (chartMainDisplayArea.right - chartMainDisplayArea.left) / xValueRangeLen val sy = if (yValueRangeLen == 0f) { // 非正常情况,y轴逻辑区间无法算出(所有值相等),直接保持原状不缩放 1f } else { // 正常情况,y按照区间比缩放即可 - (chartDisplayArea.bottom - chartDisplayArea.top) / yValueRangeLen + (chartMainDisplayArea.bottom - chartMainDisplayArea.top) / yValueRangeLen } // 缩放使得需要显示的内容刚好撑满显示区域,再向上翻转,使得y内容翻转在显示区域上方 coordinateMatrix.postScale( sx, -sy, - chartDisplayArea.left, - chartDisplayArea.top + chartMainDisplayArea.left, + chartMainDisplayArea.top ) // 正常情况,下移一个显示区域 - coordinateMatrix.postTranslate(0f, chartDisplayArea.bottom - chartDisplayArea.top) + coordinateMatrix.postTranslate(0f, chartMainDisplayArea.bottom - chartMainDisplayArea.top) } /** @@ -131,9 +131,9 @@ internal class ChildChartMatrixHelper( // "一格一格"地滑 - val chartDisplayArea = chart.getChartMainDisplayArea() + val mainChartDisplayArea = chart.getChartMainDisplayArea() - tmp2FloatArray[0] = chartDisplayArea.left + tmp2FloatArray[0] = mainChartDisplayArea.left tmp2FloatArray[1] = 0f // 反算出会被移动到显示区域的第一个逻辑坐标值(数据下标) tmpMatrix.apply { @@ -168,7 +168,7 @@ internal class ChildChartMatrixHelper( val lengthOfOneIndex = second - first if (lengthOfOneIndex != 0f) { - val unalignedDis = (first - chartDisplayArea.left) % lengthOfOneIndex + val unalignedDis = (first - mainChartDisplayArea.left) % lengthOfOneIndex val dx = when { // 右移 @@ -203,11 +203,11 @@ internal class ChildChartMatrixHelper( private fun setFixYMatrix() { fixYMatrix.reset() - val chartDisplayArea = chart.getChartMainDisplayArea() + val mainChartDisplayArea = chart.getChartMainDisplayArea() - tmp4FloatArray[0] = chartDisplayArea.left + tmp4FloatArray[0] = mainChartDisplayArea.left tmp4FloatArray[1] = 0f - tmp4FloatArray[2] = chartDisplayArea.right + tmp4FloatArray[2] = mainChartDisplayArea.right tmp4FloatArray[3] = 0f // 反算出哪个下标(逻辑坐标)范围会被移动到显示区域 tmpMatrix.apply { @@ -258,10 +258,10 @@ internal class ChildChartMatrixHelper( if (yMin != yMax) { // 先贴顶 - fixYMatrix.postTranslate(0f, chartDisplayArea.top - yMin) - val sy = (chartDisplayArea.bottom - chartDisplayArea.top) / (yMax - yMin) + fixYMatrix.postTranslate(0f, mainChartDisplayArea.top - yMin) + val sy = (mainChartDisplayArea.bottom - mainChartDisplayArea.top) / (yMax - yMin) // 再缩放 - fixYMatrix.postScale(1f, sy, 0f, chartDisplayArea.top) + fixYMatrix.postScale(1f, sy, 0f, mainChartDisplayArea.top) } } diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt index ea6a156..59f7b6f 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt @@ -310,6 +310,14 @@ open class KChart( highlightHorizontalLineRight -= bgWidth } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight horizontal line canvas.drawLine( highlightHorizontalLineLeft, @@ -318,6 +326,9 @@ open class KChart( highlight.y, highlightHorizontalLinePaint ) + + canvas.restoreToCount(saveCount) + } } @@ -419,6 +430,14 @@ open class KChart( highlightHorizontalLineBottom -= bgHeight } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight vertical line canvas.drawLine( x, @@ -427,6 +446,8 @@ open class KChart( highlightHorizontalLineBottom, highlightVerticalLinePaint ) + + canvas.restoreToCount(saveCount) } } } @@ -435,6 +456,13 @@ open class KChart( override fun drawAddition(canvas: Canvas) {} private fun drawCostPriceLine(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) chartConfig.costPrice?.let { costPriceLinePaint.color = chartConfig.costPriceLineColor costPriceLinePaint.strokeWidth = chartConfig.costPriceLineWidth @@ -449,9 +477,18 @@ open class KChart( costPriceLinePaint ) } + canvas.restoreToCount(saveCount) } private fun drawHighestAndLowestLabel(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + chartConfig.kChartType.highestAndLowestLabelConfig?.let { config -> highestAndLowestLabelPaint.textSize = config.labelTextSize highestAndLowestLabelPaint.strokeWidth = config.lineStrokeWidth @@ -503,6 +540,7 @@ open class KChart( doDrawHighestAndLowestLabel(canvas, config, it, minPrice) } } + canvas.restoreToCount(saveCount) } private fun doDrawHighestAndLowestLabel( @@ -540,6 +578,13 @@ open class KChart( if (chartConfig.index == null) { return } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) indexPaint.strokeWidth = chartConfig.indexStrokeWidth indexList?.forEachIndexed { lineIdx, pointList -> chartConfig.indexColors?.let { indexColors -> @@ -574,6 +619,7 @@ open class KChart( } } } + canvas.restoreToCount(saveCount) // draw index text chartConfig.index?.let { index -> @@ -607,7 +653,7 @@ open class KChart( val text = index.textFormatter.invoke(lineIdx, value) val textWidth = indexTextPaint.measureText(text) - if(left + textWidth > getChartDisplayArea().width()){ + if (left + textWidth > getChartDisplayArea().width()) { // 需要换行 isFirstLine = false left = index.textMarginLeft @@ -615,7 +661,7 @@ open class KChart( drawnIndexTextHeight += textHeight } - if(isFirstLine){ + if (isFirstLine) { drawnIndexTextHeight = textHeight + index.textMarginTop } @@ -634,6 +680,14 @@ open class KChart( } private fun drawMountainKChart(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + mountainKChartPaint.strokeWidth = chartConfig.mountainChartStrokeWidth mountainKChartPaint.color = chartConfig.mountainChartColor @@ -715,6 +769,7 @@ open class KChart( ) preIdx = idx } + canvas.restoreToCount(saveCount) } private fun needDrawAvgPriceLine() = @@ -723,6 +778,14 @@ open class KChart( private fun drawAvgPriceLine(canvas: Canvas) { if (needDrawAvgPriceLine()) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + avgPriceLinePaint.strokeWidth = chartConfig.avgLineStrokeWidth avgPriceLinePaint.color = chartConfig.avgLineColor var preAvgIdx = -1 @@ -752,10 +815,19 @@ open class KChart( ) preAvgIdx = idx } + canvas.restoreToCount(saveCount) } } private fun drawBarKChart(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + barKChartPaint.strokeWidth = chartConfig.barChartLineStrokeWidth val barWidth = 1 * (1 - chartConfig.barSpaceRatio) val spaceWidth = 1 * chartConfig.barSpaceRatio @@ -786,9 +858,18 @@ open class KChart( } left += barWidth + spaceWidth } + canvas.restoreToCount(saveCount) } private fun drawHollowKChart(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + hollowKChartPaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth val barWidth = 1 * (1 - chartConfig.barSpaceRatio) val spaceWidth = 1 * chartConfig.barSpaceRatio @@ -827,9 +908,18 @@ open class KChart( } left += barWidth + spaceWidth } + canvas.restoreToCount(saveCount) } private fun drawCandleKChart(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + candleKChartPaint.strokeWidth = chartConfig.candleChartLineStrokeWidth val barWidth = 1 * (1 - chartConfig.barSpaceRatio) @@ -857,9 +947,18 @@ open class KChart( } left += barWidth + spaceWidth } + + canvas.restoreToCount(saveCount) } private fun drawLineKChart(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) lineKChartLinePaint.strokeWidth = chartConfig.lineChartStrokeWidth lineKChartLinePaint.color = chartConfig.lineChartColor var preIdx = -1 @@ -888,6 +987,7 @@ open class KChart( ) preIdx = idx } + canvas.restoreToCount(saveCount) } private fun drawLabels(canvas: Canvas) { diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kdjchart/KdjChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kdjchart/KdjChart.kt index aecfd59..351e5f8 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kdjchart/KdjChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kdjchart/KdjChart.kt @@ -148,6 +148,13 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : } private fun doDrawLine(canvas: Canvas, valueList: List?) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) valueList?.forEachIndexed { valueIdx, value -> if (valueIdx == 0) { return@forEachIndexed @@ -165,6 +172,7 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : } } } + canvas.restoreToCount(saveCount) } override fun preDrawHighlight(canvas: Canvas) { @@ -266,6 +274,14 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : highlightHorizontalLineRight -= bgWidth } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight horizontal line canvas.drawLine( highlightHorizontalLineLeft, @@ -274,6 +290,9 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : highlight.y, highlightHorizontalLinePaint ) + + canvas.restoreToCount(saveCount) + } } @@ -290,6 +309,14 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : mapPointsValue2Real(tmp2FloatArray) val x = tmp2FloatArray[0] + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight vertical line canvas.drawLine( x, @@ -298,6 +325,9 @@ class KdjChart(stockChart: IStockChart, chartConfig: KdjChartConfig) : getChartDisplayArea().bottom, highlightVerticalLinePaint ) + + canvas.restoreToCount(saveCount) + } } } diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/macdchart/MacdChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/macdchart/MacdChart.kt index f6ccec8..93c6272 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/macdchart/MacdChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/macdchart/MacdChart.kt @@ -90,29 +90,7 @@ class MacdChart( val deaIdx = 1 val macdIdx = 2 - // draw macd bar - val barWidth = 1 * (1 - chartConfig.barSpaceRatio) - val spaceWidth = 1 * chartConfig.barSpaceRatio - var barLeft = spaceWidth / 2 - indexList?.get(macdIdx).let { valueList -> - valueList?.forEach { value -> - value?.let { - barPaint.color = - if (it >= 0f) stockChart.getConfig().riseColor else stockChart.getConfig().downColor - - tmpRectF.left = barLeft - tmpRectF.top = it - tmpRectF.right = barLeft + barWidth - tmpRectF.bottom = 0f - - mapRectValue2Real(tmpRectF) - - canvas.drawRect(tmpRectF, barPaint) - } - - barLeft += barWidth + spaceWidth - } - } + drawMacdBar(canvas, macdIdx) // draw dif line linePaint.strokeWidth = chartConfig.difLineStrokeWidth @@ -170,7 +148,50 @@ class MacdChart( } } + private fun drawMacdBar(canvas: Canvas, macdIdx: Int){ + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + + // draw macd bar + val barWidth = 1 * (1 - chartConfig.barSpaceRatio) + val spaceWidth = 1 * chartConfig.barSpaceRatio + var barLeft = spaceWidth / 2 + indexList?.get(macdIdx).let { valueList -> + valueList?.forEach { value -> + value?.let { + barPaint.color = + if (it >= 0f) stockChart.getConfig().riseColor else stockChart.getConfig().downColor + + tmpRectF.left = barLeft + tmpRectF.top = it + tmpRectF.right = barLeft + barWidth + tmpRectF.bottom = 0f + + mapRectValue2Real(tmpRectF) + + canvas.drawRect(tmpRectF, barPaint) + } + + barLeft += barWidth + spaceWidth + } + } + canvas.restoreToCount(saveCount) + } + private fun doDrawLine(canvas: Canvas, valueList: List?) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + valueList?.forEachIndexed { valueIdx, value -> if (valueIdx == 0) { return@forEachIndexed @@ -188,6 +209,7 @@ class MacdChart( } } } + canvas.restoreToCount(saveCount) } override fun preDrawHighlight(canvas: Canvas) { @@ -289,6 +311,14 @@ class MacdChart( highlightHorizontalLineRight -= bgWidth } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight horizontal line canvas.drawLine( highlightHorizontalLineLeft, @@ -297,6 +327,8 @@ class MacdChart( highlight.y, highlightHorizontalLinePaint ) + + canvas.restoreToCount(saveCount) } } @@ -313,6 +345,14 @@ class MacdChart( mapPointsValue2Real(tmp2FloatArray) val x = tmp2FloatArray[0] + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight vertical line canvas.drawLine( x, @@ -321,6 +361,8 @@ class MacdChart( getChartDisplayArea().bottom, highlightVerticalLinePaint ) + + canvas.restoreToCount(saveCount) } } } diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/timebar/TimeBar.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/timebar/TimeBar.kt index 26224ee..110eb22 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/timebar/TimeBar.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/timebar/TimeBar.kt @@ -90,7 +90,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : private fun drawLabelOfDayType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -112,7 +112,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -178,7 +178,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < getChartDisplayArea().left || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < getChartMainDisplayArea().left || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return } @@ -190,7 +190,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : private fun drawLabelOfWeekType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 70f) @@ -213,7 +213,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -228,7 +228,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfMonthType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 100f) @@ -250,7 +250,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -265,7 +265,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfQuarterType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -289,7 +289,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -303,7 +303,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfYearType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 30f) @@ -327,7 +327,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -341,7 +341,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfFiveYearsType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -365,7 +365,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -379,7 +379,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfAllType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 40f) @@ -398,7 +398,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : val labelWidth = labelPaint.measureText(label) val labelHalfWidth = labelWidth / 2 - var x = getChartDisplayArea().left + var x = getChartMainDisplayArea().left val y = getChartDisplayArea().top + getChartDisplayArea().height() / 2 + (tmpFontMetrics.bottom - tmpFontMetrics.top) / 2 - tmpFontMetrics.bottom @@ -407,7 +407,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -422,7 +422,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfYTDType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 30f) @@ -446,7 +446,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -460,7 +460,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfOneMinuteType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -482,7 +482,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -497,7 +497,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfFiveMinutesType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -519,7 +519,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -534,7 +534,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : } private fun drawLabelOfSixtyMinutesType(canvas: Canvas) { - var lastDrawRight = getChartDisplayArea().left + var lastDrawRight = getChartMainDisplayArea().left var lastDrawLabel = "" val labelMinSpace = DimensionUtil.dp2px(context, 50f) @@ -556,7 +556,7 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : tmp2FloatArray[1] = 0f mapPointsValue2Real(tmp2FloatArray) val centerRealX = tmp2FloatArray[0] - if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartDisplayArea().right) { + if (centerRealX - labelHalfWidth < lastDrawRight + labelMinSpace || centerRealX + labelHalfWidth > getChartMainDisplayArea().right) { return@forEachIndexed } @@ -598,10 +598,10 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : val centerRealX = tmp2FloatArray[0] var x = centerRealX - labelHalfWidth - if (x + labelWidth > getChartDisplayArea().right - labelMinSpace) x = - getChartDisplayArea().right - labelMinSpace - labelWidth - if (x < getChartDisplayArea().left + labelMinSpace) x = - getChartDisplayArea().left + labelMinSpace + if (x + labelWidth > getChartMainDisplayArea().right - labelMinSpace) x = + getChartMainDisplayArea().right - labelMinSpace - labelWidth + if (x < getChartMainDisplayArea().left + labelMinSpace) x = + getChartMainDisplayArea().left + labelMinSpace val y = getChartDisplayArea().top + getChartDisplayArea().height() / 2 + (tmpFontMetrics.bottom - tmpFontMetrics.top) / 2 - tmpFontMetrics.bottom canvas.drawText(label, x, y, labelPaint) @@ -634,11 +634,11 @@ class TimeBar(stockChart: IStockChart, chartConfig: TimeBarConfig) : val bgPadding = 10f var x = centerRealX - labelHalfWidth - if (x - bgPadding < getChartDisplayArea().left) { - x = getChartDisplayArea().left + bgPadding + if (x - bgPadding < getChartMainDisplayArea().left) { + x = getChartMainDisplayArea().left + bgPadding } - if (x + labelWidth + bgPadding > getChartDisplayArea().right) { - x = getChartDisplayArea().right - labelWidth - bgPadding + if (x + labelWidth + bgPadding > getChartMainDisplayArea().right) { + x = getChartMainDisplayArea().right - labelWidth - bgPadding } val y = getChartDisplayArea().top + getChartDisplayArea().height() / 2 + (tmpFontMetrics.bottom - tmpFontMetrics.top) / 2 - tmpFontMetrics.bottom diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/volumechart/VolumeChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/volumechart/VolumeChart.kt index 1dc0e13..cc29445 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/volumechart/VolumeChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/volumechart/VolumeChart.kt @@ -69,6 +69,13 @@ class VolumeChart( } private fun drawVolumeChart(canvas: Canvas, isHollow: Boolean) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) volumePaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth val barWidth = 1 * (1 - chartConfig.barSpaceRatio) val spaceWidth = 1 * chartConfig.barSpaceRatio @@ -98,13 +105,13 @@ class VolumeChart( left += barWidth + spaceWidth } + canvas.restoreToCount(saveCount) } override fun preDrawHighlight(canvas: Canvas) {} override fun drawHighlight(canvas: Canvas) { getHighlight()?.let { highlight -> - if (stockChart.getConfig().showHighlightHorizontalLine) { if (highlight.y >= getChartDisplayArea().top && highlight.y <= getChartDisplayArea().bottom) { @@ -198,6 +205,14 @@ class VolumeChart( highlightHorizontalLineRight -= bgWidth } + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight horizontal line canvas.drawLine( highlightHorizontalLineLeft, @@ -206,6 +221,8 @@ class VolumeChart( highlight.y, highlightHorizontalLinePaint ) + + canvas.restoreToCount(saveCount) } } @@ -222,6 +239,14 @@ class VolumeChart( mapPointsValue2Real(tmp2FloatArray) val x = tmp2FloatArray[0] + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + // highlight vertical line canvas.drawLine( x, @@ -230,6 +255,8 @@ class VolumeChart( getChartDisplayArea().bottom, highlightVerticalLinePaint ) + + canvas.restoreToCount(saveCount) } } } diff --git a/samples/build.gradle b/samples/build.gradle index ae1a1da..11e8c5b 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -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.9' + implementation project(':lib') +// implementation 'com.github.wangyiqian:StockChart:1.1.9' } \ No newline at end of file diff --git a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/custom/CustomChart.kt b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/custom/CustomChart.kt index 912816e..849f25b 100644 --- a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/custom/CustomChart.kt +++ b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/custom/CustomChart.kt @@ -75,7 +75,7 @@ class CustomChart( if (!chartConfig.bigLabel.isNullOrEmpty()) { bigLabelPaint.getFontMetrics(tmpFontMetrics) val x = - (getChartDisplayArea().left + getChartDisplayArea().right) / 2 - bigLabelPaint.measureText( + (getChartMainDisplayArea().left + getChartMainDisplayArea().right) / 2 - bigLabelPaint.measureText( chartConfig.bigLabel ) / 2 val y = @@ -88,6 +88,13 @@ class CustomChart( } override fun drawData(canvas: Canvas) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) getKEntities().forEachIndexed { index, kEntity -> if (!kEntity.containFlag(FLAG_EMPTY)) { tmp2FloatArray[0] = index + 0.5f @@ -96,6 +103,7 @@ class CustomChart( canvas.drawCircle(tmp2FloatArray[0], tmp2FloatArray[1], 10f, pointPaint) } } + canvas.restoreToCount(saveCount) } override fun preDrawHighlight(canvas: Canvas) { @@ -103,7 +111,14 @@ class CustomChart( override fun drawHighlight(canvas: Canvas) { getHighlight()?.let { highlight -> - if (highlight.x >= getChartDisplayArea().left && highlight.x <= getChartDisplayArea().right) { + val saveCount = canvas.saveLayer( + getChartMainDisplayArea().left, + getChartDisplayArea().top, + getChartMainDisplayArea().right, + getChartDisplayArea().bottom, + null + ) + if (highlight.x >= getChartMainDisplayArea().left && highlight.x <= getChartMainDisplayArea().right) { val idx = highlight.getIdx() @@ -124,6 +139,7 @@ class CustomChart( ) } } + canvas.restoreToCount(saveCount) } } diff --git a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample3/activechart/ActiveChart.kt b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample3/activechart/ActiveChart.kt index c261116..705dadc 100644 --- a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample3/activechart/ActiveChart.kt +++ b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample3/activechart/ActiveChart.kt @@ -191,9 +191,9 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : tmp2FloatArray[1] = it mapPointsValue2Real(tmp2FloatArray) canvas.drawLine( - getChartDisplayArea().left, + getChartMainDisplayArea().left, tmp2FloatArray[1], - getChartDisplayArea().right, + getChartMainDisplayArea().right, tmp2FloatArray[1], preCloseLinePaint ) @@ -209,7 +209,7 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : if (chartConfig.fixTimeLeft != null) { chartConfig.fixTimeLeft?.let { text -> - val textX = getChartDisplayArea().left + chartConfig.timeTextMarginH + val textX = getChartMainDisplayArea().left + chartConfig.timeTextMarginH canvas.drawText(text, textX, textY, timeTextPaint) } } else { @@ -217,7 +217,7 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : val kEntity = getKEntities()[idx] tmpDate.time = kEntity.getTime() val text = timeTextFormat.format(tmpDate) - val textX = getChartDisplayArea().left + chartConfig.timeTextMarginH + val textX = getChartMainDisplayArea().left + chartConfig.timeTextMarginH canvas.drawText(text, textX, textY, timeTextPaint) } } @@ -225,7 +225,7 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : if (chartConfig.fixTimeRight != null) { chartConfig.fixTimeRight?.let { text -> val textWidth = timeTextPaint.measureText(text) - val textX = getChartDisplayArea().right - chartConfig.timeTextMarginH - textWidth + val textX = getChartMainDisplayArea().right - chartConfig.timeTextMarginH - textWidth canvas.drawText(text, textX, textY, timeTextPaint) } } else { @@ -234,7 +234,7 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : tmpDate.time = kEntity.getTime() val text = timeTextFormat.format(tmpDate) val textWidth = timeTextPaint.measureText(text) - val textX = getChartDisplayArea().right - chartConfig.timeTextMarginH - textWidth + val textX = getChartMainDisplayArea().right - chartConfig.timeTextMarginH - textWidth canvas.drawText(text, textX, textY, timeTextPaint) } } @@ -518,7 +518,7 @@ class ActiveChart(stockChart: IStockChart, chartConfig: ActiveChartConfig) : ) { activeRect.apply { left = - if (cx + rectWidth > getChartDisplayArea().right) cx - rectWidth else cx + if (cx + rectWidth > getChartMainDisplayArea().right) cx - rectWidth else cx right = left + rectWidth val initLineLength = getChartDisplayArea().height() * 2 / 5 if (isAbove) {