v0.9.1
This commit is contained in:
1 parent
271ad2a492
commit
61d4e54b72
6 files changed
+179
-44
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
kotlin version: 2.0.21
|
||||||
|
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
|
||||||
|
1. Kotlin compile daemon is ready
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ Up / CH+ – next channel, down / CH- – previous · digits – channel number
|
|||||||
|
|
||||||
**Programme grid** (also *Programme guide* on the start screen): channels down, time across, a "now" line and the details of the highlighted programme on top. Up/down – channel, left/right – programme, CH+/CH- – a page, OK – details with record / watch, RED – record or cancel, GREEN – back to now, BACK – close. Some Sony remotes keep the GUIDE key for the TV's own guide – the right arrow always works.
|
**Programme grid** (also *Programme guide* on the start screen): channels down, time across, a "now" line and the details of the highlighted programme on top. Up/down – channel, left/right – programme, CH+/CH- – a page, OK – details with record / watch, RED – record or cancel, GREEN – back to now, BACK – close. Some Sony remotes keep the GUIDE key for the TV's own guide – the right arrow always works.
|
||||||
|
|
||||||
The tuner card (top right, optional) shows the adapter, frequency, lock, three small charts – signal/SNR, server CPU (whole host and the simply-dvb process, needs simply-dvb 0.1.13+) and the stream bitrate actually received by the TV (multiplex bitrate below) – plus modulation/FEC, BER and error counters.
|
The tuner card (top right, optional) shows the adapter, frequency, lock, three small charts – signal/SNR, server CPU (whole host and the simply-dvb process, needs simply-dvb 0.1.13+) and the stream bitrate actually received by the TV (multiplex bitrate below) – plus modulation/FEC, BER and error counters. The charts cover the last 3 minutes: signal/SNR and CPU come from the statistics history simply-dvb keeps in memory (every 2 s, 15 minutes; simply-dvb 0.1.18+), the received bitrate is measured by the TV while it plays – so a chart is full as soon as the card opens.
|
||||||
|
|
||||||
**Smooth video:** *Tunnelled video playback* (*Settings*, on by default) lets the TV's own video pipeline decode and sync the picture – the same path the built-in tuner uses. If a channel shows no picture with it, switch it off. The tuner card's white line shows what the TV does with the stream: resolution, frames shown per second, dropped frames (red), buffer and decoder; the last line shows simply-dvb's driver timing (time of a signal statistics read and the longest pause in the stream).
|
**Smooth video:** *Tunnelled video playback* (*Settings*, on by default) lets the TV's own video pipeline decode and sync the picture – the same path the built-in tuner uses. If a channel shows no picture with it, switch it off. The tuner card's white line shows what the TV does with the stream: resolution, frames shown per second, dropped frames (red), buffer and decoder; the last line shows simply-dvb's driver timing (time of a signal statistics read and the longest pause in the stream).
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ Góra / CH+ – następny kanał, dół / CH- – poprzedni · cyfry – numer k
|
|||||||
|
|
||||||
**Siatka programu** (także *Program TV* na ekranie startowym): kanały w pionie, czas w poziomie, linia „teraz” i szczegóły zaznaczonej audycji u góry. Góra/dół – kanał, lewo/prawo – audycja, CH+/CH- – strona, OK – szczegóły z nagrywaniem / oglądaniem, CZERWONY – nagraj lub anuluj, ZIELONY – powrót do „teraz”, WSTECZ – zamknij. Niektóre piloty Sony zostawiają przycisk GUIDE dla przewodnika telewizora – strzałka w prawo działa zawsze.
|
**Siatka programu** (także *Program TV* na ekranie startowym): kanały w pionie, czas w poziomie, linia „teraz” i szczegóły zaznaczonej audycji u góry. Góra/dół – kanał, lewo/prawo – audycja, CH+/CH- – strona, OK – szczegóły z nagrywaniem / oglądaniem, CZERWONY – nagraj lub anuluj, ZIELONY – powrót do „teraz”, WSTECZ – zamknij. Niektóre piloty Sony zostawiają przycisk GUIDE dla przewodnika telewizora – strzałka w prawo działa zawsze.
|
||||||
|
|
||||||
Karta tunera (prawy górny róg, opcjonalna) pokazuje adapter, częstotliwość, synchronizację, trzy małe wykresy – sygnał/SNR, CPU serwera (cały host i proces simply-dvb, wymaga simply-dvb 0.1.13+) oraz przepływność strumienia faktycznie odbieranego przez telewizor (pod spodem przepływność multipleksu) – a także modulację/FEC, BER i liczniki błędów.
|
Karta tunera (prawy górny róg, opcjonalna) pokazuje adapter, częstotliwość, synchronizację, trzy małe wykresy – sygnał/SNR, CPU serwera (cały host i proces simply-dvb, wymaga simply-dvb 0.1.13+) oraz przepływność strumienia faktycznie odbieranego przez telewizor (pod spodem przepływność multipleksu) – a także modulację/FEC, BER i liczniki błędów. Wykresy obejmują ostatnie 3 minuty: sygnał/SNR i CPU pochodzą z historii statystyk, którą simply-dvb trzyma w pamięci (co 2 s, 15 minut; simply-dvb 0.1.18+), a przepływność odbieraną mierzy telewizor podczas odtwarzania – wykres jest więc pełny od razu po otwarciu karty.
|
||||||
|
|
||||||
**Płynny obraz:** *Tunelowanie wideo* (*Ustawienia*, domyślnie włączone) przekazuje dekodowanie i synchronizację obrazu do toru wideo telewizora – tego samego, którego używa wbudowany tuner. Jeśli na jakimś kanale nie ma wtedy obrazu, wyłącz je. Biała linia na karcie tunera pokazuje, co telewizor robi ze strumieniem: rozdzielczość, wyświetlane klatki na sekundę, gubione klatki (na czerwono), bufor i dekoder; ostatnia linia to czasy sterownika w simply-dvb (odczyt statystyk sygnału i najdłuższa przerwa w strumieniu).
|
**Płynny obraz:** *Tunelowanie wideo* (*Ustawienia*, domyślnie włączone) przekazuje dekodowanie i synchronizację obrazu do toru wideo telewizora – tego samego, którego używa wbudowany tuner. Jeśli na jakimś kanale nie ma wtedy obrazu, wyłącz je. Biała linia na karcie tunera pokazuje, co telewizor robi ze strumieniem: rozdzielczość, wyświetlane klatki na sekundę, gubione klatki (na czerwono), bufor i dekoder; ostatnia linia to czasy sterownika w simply-dvb (odczyt statystyk sygnału i najdłuższa przerwa w strumieniu).
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ android {
|
|||||||
applicationId = "io.simplytv"
|
applicationId = "io.simplytv"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 10
|
versionCode = 11
|
||||||
versionName = "0.9.0"
|
versionName = "0.9.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -67,6 +67,29 @@ class LiveActivity : Activity() {
|
|||||||
private lateinit var spark: SparkView
|
private lateinit var spark: SparkView
|
||||||
private lateinit var cpuSpark: SparkView
|
private lateinit var cpuSpark: SparkView
|
||||||
private lateinit var rateSpark: SparkView
|
private lateinit var rateSpark: SparkView
|
||||||
|
|
||||||
|
/** Server statistics history already shown (unix s), 0: ask for the last minutes. */
|
||||||
|
private var histSince = 0L
|
||||||
|
/** Tuner + multiplex the signal chart belongs to; another one starts a fresh chart. */
|
||||||
|
private var histKey: String? = null
|
||||||
|
/** Received bitrate, measured here every 2 s while playing (no network). */
|
||||||
|
private var rateLast: Float? = null
|
||||||
|
private var rateBytes = -1L
|
||||||
|
private var rateAt = 0L
|
||||||
|
private val rateTick = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
val b = meter.total()
|
||||||
|
if (rateBytes >= 0 && now > rateAt) {
|
||||||
|
val v = ((b - rateBytes) * 8000.0 / (now - rateAt)).toFloat()
|
||||||
|
rateLast = v
|
||||||
|
rateSpark.add(now / 1000, v)
|
||||||
|
}
|
||||||
|
rateBytes = b
|
||||||
|
rateAt = now
|
||||||
|
main.postDelayed(this, 2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
private val meter = ByteMeter()
|
private val meter = ByteMeter()
|
||||||
private var channels: List<HChannel> = emptyList()
|
private var channels: List<HChannel> = emptyList()
|
||||||
private var events: Map<Long, List<HEvent>> = emptyMap()
|
private var events: Map<Long, List<HEvent>> = emptyMap()
|
||||||
@@ -506,7 +529,7 @@ class LiveActivity : Activity() {
|
|||||||
private fun showCard(seconds: Int = 8) {
|
private fun showCard(seconds: Int = 8) {
|
||||||
cardUntil = System.currentTimeMillis() + seconds * 1000L
|
cardUntil = System.currentTimeMillis() + seconds * 1000L
|
||||||
if (card.visibility != View.VISIBLE) {
|
if (card.visibility != View.VISIBLE) {
|
||||||
spark.clear()
|
// charts keep their data; the next poll adds what the server saw meanwhile
|
||||||
findViewById<TextView>(R.id.t_name).text = getString(R.string.loading)
|
findViewById<TextView>(R.id.t_name).text = getString(R.string.loading)
|
||||||
findViewById<TextView>(R.id.t_stream).text = ""
|
findViewById<TextView>(R.id.t_stream).text = ""
|
||||||
card.visibility = View.VISIBLE
|
card.visibility = View.VISIBLE
|
||||||
@@ -530,19 +553,74 @@ class LiveActivity : Activity() {
|
|||||||
}
|
}
|
||||||
io.execute {
|
io.execute {
|
||||||
val t = try {
|
val t = try {
|
||||||
Server.getJson(this, "/api/status/inputs?channel=${ch.id}").optJSONArray("entries")?.optJSONObject(0)
|
val since = if (histSince > 0) histSince else System.currentTimeMillis() / 1000 - 300
|
||||||
|
Server.getJson(this, "/api/status/inputs?channel=${ch.id}&since=$since").optJSONArray("entries")?.optJSONObject(0)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
main.post {
|
main.post {
|
||||||
val rate = meter.rate()
|
val rate = rateLast?.toDouble()
|
||||||
if (t != null) renderCard(t, rate) else renderRate(rate, null)
|
if (t != null) {
|
||||||
|
addHistory(t)
|
||||||
|
renderCard(t, rate)
|
||||||
|
} else {
|
||||||
|
renderRate(rate, null)
|
||||||
|
}
|
||||||
renderVideo()
|
renderVideo()
|
||||||
main.postDelayed({ pollCard() }, 1000)
|
main.postDelayed({ pollCard() }, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the server's statistics samples (every 2 s, kept 15 min) to the charts: signal /
|
||||||
|
* SNR and server CPU show the last minutes as soon as the card opens.
|
||||||
|
*/
|
||||||
|
private fun addHistory(t: JSONObject) {
|
||||||
|
val key = t.optString("input") + "|" + t.optString("stream")
|
||||||
|
if (key != histKey) {
|
||||||
|
if (histKey != null) {
|
||||||
|
// another tuner or multiplex: its own history, from the start
|
||||||
|
spark.clear()
|
||||||
|
histKey = key
|
||||||
|
histSince = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
histKey = key
|
||||||
|
}
|
||||||
|
if (!t.has("history")) {
|
||||||
|
// server older than 0.1.18: no history, chart the live values
|
||||||
|
val now = System.currentTimeMillis() / 1000
|
||||||
|
spark.add(now, num(t, "snr_db")?.toFloat(), num(t, "strength_pct")?.toFloat())
|
||||||
|
cpuSpark.add(now, num(t, "server_cpu")?.toFloat(), num(t, "server_proc_cpu")?.toFloat())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var newest = histSince
|
||||||
|
t.optJSONArray("history")?.let { h ->
|
||||||
|
for (i in 0 until h.length()) {
|
||||||
|
val r = h.optJSONArray(i) ?: continue
|
||||||
|
val ts = r.optLong(0)
|
||||||
|
val sig = if (r.isNull(1)) null else r.optDouble(1).toFloat()
|
||||||
|
val snr = if (r.isNull(2)) null else r.optDouble(2).toFloat()
|
||||||
|
spark.add(ts, snr, sig)
|
||||||
|
newest = maxOf(newest, ts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.optJSONArray("host_history")?.let { h ->
|
||||||
|
for (i in 0 until h.length()) {
|
||||||
|
val r = h.optJSONArray(i) ?: continue
|
||||||
|
val ts = r.optLong(0)
|
||||||
|
cpuSpark.add(
|
||||||
|
ts,
|
||||||
|
if (r.isNull(1)) null else r.optDouble(1).toFloat(),
|
||||||
|
if (r.isNull(2)) null else r.optDouble(2).toFloat(),
|
||||||
|
)
|
||||||
|
newest = maxOf(newest, ts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
histSince = newest
|
||||||
|
}
|
||||||
|
|
||||||
private fun num(o: JSONObject, k: String): Double? = if (o.isNull(k) || !o.has(k)) null else o.optDouble(k).takeIf { !it.isNaN() }
|
private fun num(o: JSONObject, k: String): Double? = if (o.isNull(k) || !o.has(k)) null else o.optDouble(k).takeIf { !it.isNaN() }
|
||||||
|
|
||||||
private fun mbit(bps: Double) = if (bps >= 1e6) "%.1f Mb/s".format(Locale.ROOT, bps / 1e6) else "%.0f kb/s".format(Locale.ROOT, bps / 1e3)
|
private fun mbit(bps: Double) = if (bps >= 1e6) "%.1f Mb/s".format(Locale.ROOT, bps / 1e6) else "%.0f kb/s".format(Locale.ROOT, bps / 1e3)
|
||||||
@@ -579,7 +657,6 @@ class LiveActivity : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderRate(rate: Double?, mux: Long?) {
|
private fun renderRate(rate: Double?, mux: Long?) {
|
||||||
if (rate != null) rateSpark.push(rate.toFloat())
|
|
||||||
findViewById<TextView>(R.id.t_rate).text = rate?.let { mbit(it) } ?: "–"
|
findViewById<TextView>(R.id.t_rate).text = rate?.let { mbit(it) } ?: "–"
|
||||||
findViewById<TextView>(R.id.t_rate_sub).text = mux?.takeIf { it > 0 }?.let { "MUX " + mbit(it.toDouble()) } ?: ""
|
findViewById<TextView>(R.id.t_rate_sub).text = mux?.takeIf { it > 0 }?.let { "MUX " + mbit(it.toDouble()) } ?: ""
|
||||||
}
|
}
|
||||||
@@ -596,12 +673,10 @@ class LiveActivity : Activity() {
|
|||||||
findViewById<TextView>(R.id.t_stream).text = t.optString("stream")
|
findViewById<TextView>(R.id.t_stream).text = t.optString("stream")
|
||||||
findViewById<TextView>(R.id.t_signal).text =
|
findViewById<TextView>(R.id.t_signal).text =
|
||||||
(sig?.let { "%.0f%%".format(Locale.ROOT, it) } ?: "–") + " " + (snr?.let { "%.0fdB".format(Locale.ROOT, it) } ?: "")
|
(sig?.let { "%.0f%%".format(Locale.ROOT, it) } ?: "–") + " " + (snr?.let { "%.0fdB".format(Locale.ROOT, it) } ?: "")
|
||||||
spark.add(snr?.toFloat(), sig?.toFloat())
|
|
||||||
// server load
|
// server load
|
||||||
val cpu = num(t, "server_cpu")
|
val cpu = num(t, "server_cpu")
|
||||||
val proc = num(t, "server_proc_cpu")
|
val proc = num(t, "server_proc_cpu")
|
||||||
val temp = num(t, "server_temp")
|
val temp = num(t, "server_temp")
|
||||||
cpuSpark.push(cpu?.toFloat(), proc?.toFloat())
|
|
||||||
findViewById<TextView>(R.id.t_cpu).text = cpu?.let { "%.0f%%".format(Locale.ROOT, it) } ?: "–"
|
findViewById<TextView>(R.id.t_cpu).text = cpu?.let { "%.0f%%".format(Locale.ROOT, it) } ?: "–"
|
||||||
findViewById<TextView>(R.id.t_cpu_sub).text = listOfNotNull(
|
findViewById<TextView>(R.id.t_cpu_sub).text = listOfNotNull(
|
||||||
proc?.let { "dvb %.1f%%".format(Locale.ROOT, it) },
|
proc?.let { "dvb %.1f%%".format(Locale.ROOT, it) },
|
||||||
@@ -838,8 +913,16 @@ class LiveActivity : Activity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
rateBytes = -1
|
||||||
|
main.removeCallbacks(rateTick)
|
||||||
|
main.post(rateTick)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
|
main.removeCallbacks(rateTick)
|
||||||
player.stop()
|
player.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,26 +9,36 @@ import android.util.AttributeSet
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tiny line chart for the tuner card. Each series has its own colour and scale
|
* Tiny time-based line chart for the tuner card: points carry their own time (unix seconds)
|
||||||
* (`max` > 0: fixed 0..max, `max` = 0: scaled to the largest visible value).
|
* and the chart shows the last [window] seconds, so history loaded from the server and
|
||||||
* By default: SNR (0–35 dB) and signal (0–100 %).
|
* points added live line up, and sparse or missing samples stay where they belong in time.
|
||||||
|
* Each series has its own colour and scale (`max` > 0: fixed 0..max, `max` = 0: scaled to
|
||||||
|
* the largest visible value). By default: SNR (0–35 dB) and signal (0–100 %).
|
||||||
*/
|
*/
|
||||||
class SparkView(ctx: Context, attrs: AttributeSet? = null) : View(ctx, attrs) {
|
class SparkView(ctx: Context, attrs: AttributeSet? = null) : View(ctx, attrs) {
|
||||||
private class Series(val paint: Paint, val max: Float, val fill: Boolean) {
|
private class Series(val paint: Paint, val max: Float, val fill: Boolean)
|
||||||
val v = ArrayList<Float>()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val keep = 90
|
private class Point(val t: Long, val v: FloatArray)
|
||||||
|
|
||||||
|
/** Visible time range, seconds. */
|
||||||
|
var window = 180L
|
||||||
|
|
||||||
|
/** A gap longer than this (seconds) breaks the line. */
|
||||||
|
var maxGap = 15L
|
||||||
|
|
||||||
|
private val points = ArrayList<Point>()
|
||||||
private var series = listOf(
|
private var series = listOf(
|
||||||
Series(stroke("#7aa7ff", 3f), 35f, false),
|
Series(stroke("#7aa7ff", 3f), 35f, false),
|
||||||
Series(stroke("#bdd293", 2f).apply { alpha = 170 }, 100f, false),
|
Series(stroke("#bdd293", 2f).apply { alpha = 170 }, 100f, false),
|
||||||
)
|
)
|
||||||
private val pGrid = Paint().apply { color = Color.parseColor("#22ffffff"); strokeWidth = 1f }
|
private val pGrid = Paint().apply { color = Color.parseColor("#22ffffff"); strokeWidth = 1f }
|
||||||
|
private val pFill = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
||||||
|
|
||||||
private fun stroke(c: String, w: Float) = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
private fun stroke(c: String, w: Float) = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
color = Color.parseColor(c)
|
color = Color.parseColor(c)
|
||||||
strokeWidth = w
|
strokeWidth = w
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
|
strokeJoin = Paint.Join.ROUND
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Replaces the series: (colour, max, filled area). */
|
/** Replaces the series: (colour, max, filled area). */
|
||||||
@@ -38,49 +48,87 @@ class SparkView(ctx: Context, attrs: AttributeSet? = null) : View(ctx, attrs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
series.forEach { it.v.clear() }
|
points.clear()
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One value per series (null draws 0). */
|
/** Newest point's time, or 0. */
|
||||||
fun push(vararg values: Float?) {
|
fun lastTime(): Long = points.lastOrNull()?.t ?: 0
|
||||||
series.forEachIndexed { i, s ->
|
|
||||||
s.v.add(values.getOrNull(i) ?: 0f)
|
/** Adds a point at unix time `t` (seconds); one value per series, null draws 0. */
|
||||||
while (s.v.size > keep) s.v.removeAt(0)
|
fun add(t: Long, vararg values: Float?) {
|
||||||
|
if (points.isNotEmpty() && t <= points.last().t) {
|
||||||
|
if (t == points.last().t) return
|
||||||
|
// out of order (history after live points): insert in place
|
||||||
|
val i = points.indexOfFirst { it.t >= t }
|
||||||
|
if (i >= 0 && points[i].t == t) return
|
||||||
|
points.add(if (i < 0) points.size else i, Point(t, FloatArray(series.size) { values.getOrNull(it) ?: 0f }))
|
||||||
|
} else {
|
||||||
|
points.add(Point(t, FloatArray(series.size) { values.getOrNull(it) ?: 0f }))
|
||||||
}
|
}
|
||||||
|
val cut = points.last().t - window - maxGap
|
||||||
|
while (points.isNotEmpty() && points.first().t < cut) points.removeAt(0)
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compatibility: SNR (dB) and signal (%). */
|
|
||||||
fun add(snrDb: Float?, signalPct: Float?) = push(snrDb, signalPct)
|
|
||||||
|
|
||||||
override fun onDraw(c: Canvas) {
|
override fun onDraw(c: Canvas) {
|
||||||
val w = width.toFloat()
|
val w = width.toFloat()
|
||||||
val h = height.toFloat()
|
val h = height.toFloat()
|
||||||
for (i in 1..3) c.drawLine(0f, h * i / 4, w, h * i / 4, pGrid)
|
for (i in 1..3) c.drawLine(0f, h * i / 4, w, h * i / 4, pGrid)
|
||||||
for (s in series.asReversed()) line(c, s, w, h)
|
if (points.size < 2) return
|
||||||
|
val now = System.currentTimeMillis() / 1000
|
||||||
|
val end = maxOf(now, points.last().t)
|
||||||
|
for (si in series.indices.reversed()) line(c, si, w, h, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun line(c: Canvas, s: Series, w: Float, h: Float) {
|
private fun line(c: Canvas, si: Int, w: Float, h: Float, end: Long) {
|
||||||
val v = s.v
|
val s = series[si]
|
||||||
if (v.size < 2) return
|
val from = end - window
|
||||||
val top = if (s.max > 0) s.max else (v.maxOrNull() ?: 0f).coerceAtLeast(1e-6f) * 1.15f
|
val visible = points.filter { it.t >= from - maxGap }
|
||||||
val step = w / (keep - 1)
|
if (visible.size < 2) return
|
||||||
val x0 = w - (v.size - 1) * step
|
val top = if (s.max > 0) s.max else (visible.maxOfOrNull { it.v[si] } ?: 0f).coerceAtLeast(1e-6f) * 1.15f
|
||||||
|
fun x(t: Long) = w - (end - t).toFloat() / window * w
|
||||||
|
fun y(v: Float) = h - 2 - (v / top).coerceIn(0f, 1f) * (h - 4)
|
||||||
val path = Path()
|
val path = Path()
|
||||||
v.forEachIndexed { i, y ->
|
val area = Path()
|
||||||
val px = x0 + i * step
|
var open = false
|
||||||
val py = h - 2 - (y / top).coerceIn(0f, 1f) * (h - 4)
|
var startX = 0f
|
||||||
if (i == 0) path.moveTo(px, py) else path.lineTo(px, py)
|
var lastX = 0f
|
||||||
|
var prevT = 0L
|
||||||
|
for (p in visible) {
|
||||||
|
val px = x(p.t)
|
||||||
|
val py = y(p.v[si])
|
||||||
|
if (!open || p.t - prevT > maxGap) {
|
||||||
|
if (open && s.fill) closeArea(area, lastX, startX, h)
|
||||||
|
path.moveTo(px, py)
|
||||||
|
if (s.fill) area.moveTo(px, py)
|
||||||
|
startX = px
|
||||||
|
open = true
|
||||||
|
} else {
|
||||||
|
path.lineTo(px, py)
|
||||||
|
if (s.fill) area.lineTo(px, py)
|
||||||
|
}
|
||||||
|
lastX = px
|
||||||
|
prevT = p.t
|
||||||
}
|
}
|
||||||
if (s.fill) {
|
if (s.fill) {
|
||||||
val area = Path(path)
|
closeArea(area, lastX, startX, h)
|
||||||
area.lineTo(w, h)
|
pFill.color = s.paint.color
|
||||||
area.lineTo(x0, h)
|
pFill.alpha = 45
|
||||||
area.close()
|
c.save()
|
||||||
val p = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = s.paint.color; alpha = 45; style = Paint.Style.FILL }
|
c.clipRect(0f, 0f, w, h)
|
||||||
c.drawPath(area, p)
|
c.drawPath(area, pFill)
|
||||||
|
c.restore()
|
||||||
}
|
}
|
||||||
|
c.save()
|
||||||
|
c.clipRect(0f, 0f, w, h)
|
||||||
c.drawPath(path, s.paint)
|
c.drawPath(path, s.paint)
|
||||||
|
c.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeArea(area: Path, lastX: Float, startX: Float, h: Float) {
|
||||||
|
area.lineTo(lastX, h)
|
||||||
|
area.lineTo(startX, h)
|
||||||
|
area.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user