mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-22 10:42:09 +00:00
feat: Allow to switch line/points/dottedline display (#56)
This commit is contained in:
parent
6ab36e9ade
commit
e1946e98d0
@ -24,7 +24,7 @@ publishing {
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "${group}.${artifact}"
|
||||
namespace = "$group.$artifact"
|
||||
compileSdk = 33
|
||||
buildToolsVersion = "33.0.0"
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import com.dzeio.charts.ChartViewInterface
|
||||
import com.dzeio.charts.utils.drawDottedLine
|
||||
import kotlin.math.abs
|
||||
|
||||
class LineSerie(
|
||||
@ -25,6 +26,21 @@ class LineSerie(
|
||||
strokeWidth = 5f
|
||||
}
|
||||
|
||||
/**
|
||||
* is the line dotted
|
||||
*/
|
||||
var dotted = false
|
||||
|
||||
/**
|
||||
* do we display the points?
|
||||
*/
|
||||
var displayPoints = true
|
||||
|
||||
/**
|
||||
* do we display the lines
|
||||
*/
|
||||
var displayLines = true
|
||||
|
||||
val textPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = Color.BLACK
|
||||
@ -98,12 +114,12 @@ class LineSerie(
|
||||
)
|
||||
|
||||
// draw smol point
|
||||
if (drawableSpace.contains(posX, top)) {
|
||||
if (drawableSpace.contains(posX, top) && displayPoints) {
|
||||
canvas.drawCircle(posX, top, paint.strokeWidth, paint)
|
||||
}
|
||||
|
||||
// draw line
|
||||
if (doDraw && previousPosY != null && previousPosX != null) {
|
||||
if (doDraw && previousPosY != null && previousPosX != null && displayLines) {
|
||||
var startX = previousPosX
|
||||
var startY = previousPosY
|
||||
var stopX = posX
|
||||
@ -165,7 +181,24 @@ class LineSerie(
|
||||
debugPaint.color = Color.RED
|
||||
}
|
||||
}
|
||||
canvas.drawLine(startX, startY, stopX, stopY, if (view.debug) debugPaint else linePaint)
|
||||
if (dotted) {
|
||||
canvas.drawDottedLine(
|
||||
startX,
|
||||
startY,
|
||||
stopX,
|
||||
stopY,
|
||||
32f,
|
||||
if (view.debug) debugPaint else linePaint
|
||||
)
|
||||
} else {
|
||||
canvas.drawLine(
|
||||
startX,
|
||||
startY,
|
||||
stopX,
|
||||
stopY,
|
||||
if (view.debug) debugPaint else linePaint
|
||||
)
|
||||
}
|
||||
}
|
||||
previousPosX = posX
|
||||
previousPosY = top
|
||||
|
@ -138,6 +138,23 @@ class ChartFragment : Fragment() {
|
||||
chart.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
if (args.chartType === "linechart") {
|
||||
binding.lineItem.visibility = View.VISIBLE
|
||||
|
||||
binding.lineDisplayLines.setOnCheckedChangeListener { _, isChecked ->
|
||||
chart.series.forEach { (it as LineSerie).displayLines = isChecked }
|
||||
chart.refresh()
|
||||
}
|
||||
binding.lineDisplayPoints.setOnCheckedChangeListener { _, isChecked ->
|
||||
chart.series.forEach { (it as LineSerie).displayPoints = isChecked }
|
||||
chart.refresh()
|
||||
}
|
||||
binding.lineDotted.setOnCheckedChangeListener { _, isChecked ->
|
||||
chart.series.forEach { (it as LineSerie).dotted = isChecked }
|
||||
chart.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var lastGenerated = 0
|
||||
|
@ -209,6 +209,36 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/line_item"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/line_dotted"
|
||||
android:text="Switch Dotted line"
|
||||
android:checked="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/line_display_points"
|
||||
android:text="Display points"
|
||||
android:checked="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/line_display_lines"
|
||||
android:text="Display lines"
|
||||
android:checked="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
Loading…
x
Reference in New Issue
Block a user