From eadbd462c5ce2e912c021a37d8dd69ee6034a594 Mon Sep 17 00:00:00 2001 From: wangyiqian Date: Wed, 15 Dec 2021 21:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A4=BA=E4=BE=8B=E6=88=90?= =?UTF-8?q?=E4=BA=A4=E9=87=8F=E5=9B=BE=E7=A9=BA=E5=BF=83=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stockchart/childchart/kchart/KChart.kt | 89 +++++++------------ .../childchart/volumechart/VolumeChart.kt | 2 +- samples/build.gradle | 4 +- .../sample/sample2/Sample2Activity.kt | 4 + 4 files changed, 37 insertions(+), 62 deletions(-) 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 17a8bdb..dfcaeac 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 @@ -753,54 +753,32 @@ open class KChart( hollowKChartPaint.color = if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) stockChart.getConfig().riseColor else stockChart.getConfig().downColor - if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) { // 空心阳线 - tmp24FloatArray[0] = left - tmp24FloatArray[1] = kEntity.getOpenPrice() - tmp24FloatArray[2] = left - tmp24FloatArray[3] = kEntity.getClosePrice() - - tmp24FloatArray[4] = left - tmp24FloatArray[5] = kEntity.getOpenPrice() - tmp24FloatArray[6] = left + barWidth - tmp24FloatArray[7] = kEntity.getOpenPrice() - - tmp24FloatArray[8] = left + barWidth - tmp24FloatArray[9] = kEntity.getOpenPrice() - tmp24FloatArray[10] = left + barWidth - tmp24FloatArray[11] = kEntity.getClosePrice() - - tmp24FloatArray[12] = left - tmp24FloatArray[13] = kEntity.getClosePrice() - tmp24FloatArray[14] = left + barWidth - tmp24FloatArray[15] = kEntity.getClosePrice() - - tmp24FloatArray[16] = left + barWidth / 2 - tmp24FloatArray[17] = kEntity.getHighPrice() - tmp24FloatArray[18] = left + barWidth / 2 - tmp24FloatArray[19] = max(kEntity.getOpenPrice(), kEntity.getClosePrice()) - - tmp24FloatArray[20] = left + barWidth / 2 - tmp24FloatArray[21] = kEntity.getLowPrice() - tmp24FloatArray[22] = left + barWidth / 2 - tmp24FloatArray[23] = min(kEntity.getOpenPrice(), kEntity.getClosePrice()) - - mapPointsValue2Real(tmp24FloatArray) - canvas.drawLines(tmp24FloatArray, hollowKChartPaint) - } else { // 实心阴线 - tmp4FloatArray[0] = left + barWidth / 2 - tmp4FloatArray[1] = kEntity.getHighPrice() - tmp4FloatArray[2] = left + barWidth / 2 - tmp4FloatArray[3] = kEntity.getLowPrice() - mapPointsValue2Real(tmp4FloatArray) - canvas.drawLines(tmp4FloatArray, hollowKChartPaint) - tmpRectF.left = left - tmpRectF.top = kEntity.getOpenPrice() - tmpRectF.right = left + barWidth - tmpRectF.bottom = kEntity.getClosePrice() - mapRectValue2Real(tmpRectF) - canvas.drawRect(tmpRectF, hollowKChartPaint) - } + tmp4FloatArray[0] = left + barWidth / 2 + tmp4FloatArray[1] = kEntity.getHighPrice() + tmp4FloatArray[2] = tmp4FloatArray[0] + tmp4FloatArray[3] = max(kEntity.getOpenPrice(), kEntity.getClosePrice()) + mapPointsValue2Real(tmp4FloatArray) + canvas.drawLines(tmp4FloatArray, hollowKChartPaint) + + tmp4FloatArray[0] = left + barWidth / 2 + tmp4FloatArray[1] = kEntity.getLowPrice() + tmp4FloatArray[2] = tmp4FloatArray[0] + tmp4FloatArray[3] = min(kEntity.getOpenPrice(), kEntity.getClosePrice()) + mapPointsValue2Real(tmp4FloatArray) + canvas.drawLines(tmp4FloatArray, hollowKChartPaint) + tmpRectF.left = left + tmpRectF.top = kEntity.getOpenPrice() + tmpRectF.right = left + barWidth + tmpRectF.bottom = kEntity.getClosePrice() + mapRectValue2Real(tmpRectF) + hollowKChartPaint.style = if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) { + // 空心阳线 + Paint.Style.STROKE + } else { + Paint.Style.FILL + } + canvas.drawRect(tmpRectF, hollowKChartPaint) } left += barWidth + spaceWidth } @@ -808,6 +786,7 @@ open class KChart( private fun drawCandleKChart(canvas: Canvas) { candleKChartPaint.strokeWidth = chartConfig.candleChartLineStrokeWidth + val barWidth = 1 * (1 - chartConfig.barSpaceRatio) val spaceWidth = 1 * chartConfig.barSpaceRatio var left = spaceWidth / 2f @@ -818,7 +797,7 @@ open class KChart( candleKChartPaint.color = candleKChartPaint.color tmp4FloatArray[0] = left + barWidth / 2 tmp4FloatArray[1] = kEntity.getHighPrice() - tmp4FloatArray[2] = left + barWidth / 2 + tmp4FloatArray[2] = tmp4FloatArray[0] tmp4FloatArray[3] = kEntity.getLowPrice() mapPointsValue2Real(tmp4FloatArray) canvas.drawLines(tmp4FloatArray, candleKChartPaint) @@ -827,17 +806,9 @@ open class KChart( tmpRectF.right = left + barWidth tmpRectF.bottom = kEntity.getClosePrice() mapRectValue2Real(tmpRectF) - if (tmpRectF.height() == 0f) { - canvas.drawLine( - tmpRectF.left, - tmpRectF.top, - tmpRectF.right, - tmpRectF.bottom, - candleKChartPaint - ) - } else { - canvas.drawRect(tmpRectF, candleKChartPaint) - } + candleKChartPaint.style = + if (tmpRectF.height() == 0f) Paint.Style.STROKE else Paint.Style.FILL + canvas.drawRect(tmpRectF, candleKChartPaint) } left += barWidth + spaceWidth } 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 aa96a4e..b7300e7 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,7 @@ class VolumeChart( } private fun drawVolumeChart(canvas: Canvas, isHollow: Boolean) { + volumePaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth val barWidth = 1 * (1 - chartConfig.barSpaceRatio) val spaceWidth = 1 * chartConfig.barSpaceRatio var left = spaceWidth / 2f @@ -92,7 +93,6 @@ class VolumeChart( } volumePaint.color = if (isRise) stockChart.getConfig().riseColor else stockChart.getConfig().downColor - volumePaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth if (kEntity.getClosePrice() >= kEntity.getOpenPrice() && isHollow) { // 空心 volumePaint.style = Paint.Style.STROKE } else { diff --git a/samples/build.gradle b/samples/build.gradle index cab367b..fdeb397 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.0.13' + implementation project(':lib') +// implementation 'com.github.wangyiqian:StockChart:1.0.13' } \ No newline at end of file diff --git a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/Sample2Activity.kt b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/Sample2Activity.kt index bbb3820..fa9ba96 100644 --- a/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/Sample2Activity.kt +++ b/samples/src/main/java/com/github/wangyiqian/stockchart/sample/sample2/Sample2Activity.kt @@ -299,6 +299,10 @@ class Sample2Activity : AppCompatActivity() { Util.formatVolume(volume = volume.toLong()) } ) + + // 柱子空心时的线条宽度 + hollowChartLineStrokeWidth = DimensionUtil.dp2px(this@Sample2Activity, 1f).toFloat() + } }