-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
449 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package core | ||
|
||
enum Gauge: | ||
case MeterPerBeat | ||
case BeatPerMinute | ||
case StepPerMinute | ||
case Pace | ||
|
||
def label: String = this match | ||
case MeterPerBeat => "mpb" | ||
case BeatPerMinute => "bpm" | ||
case StepPerMinute => "spm" | ||
case Pace => "/km" | ||
end Gauge | ||
object Gauge: | ||
type MeterPerBeat = MeterPerBeat.type | ||
type BeatPerMinute = BeatPerMinute.type | ||
type StepPerMinute = StepPerMinute.type | ||
type Pace = Pace.type | ||
|
||
trait Distance | ||
trait Duration | ||
trait Timestamp | ||
trait Box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package core | ||
|
||
opaque type Read[T, A, B] = A => B | ||
object Read: | ||
def apply[T, A, B](a: A)(using r: Read[T, A, B]): B = r(a) | ||
|
||
def apply[T, A, B](f: A => B): Read[T, A, B] = f |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package garmin.read | ||
|
||
import scala.scalajs.js | ||
|
||
import core.* | ||
|
||
given Read[Gauge.BeatPerMinute, js.Dynamic, Double] = Read: a => | ||
a.averageHR.asInstanceOf[Double].round | ||
|
||
given Read[Gauge.StepPerMinute, js.Dynamic, Double] = Read: a => | ||
a.averageRunCadence.asInstanceOf[Double].round | ||
|
||
given Read[Distance, js.Dynamic, Double] = Read: a => | ||
a.distance.asInstanceOf[Double] | ||
|
||
given Read[Duration, js.Dynamic, Double] = Read: a => | ||
a.duration.asInstanceOf[Double] | ||
|
||
given Read[Timestamp, js.Dynamic, String] = Read: a => | ||
a.startTimeGMT.asInstanceOf[String] | ||
|
||
given [A](using | ||
Read[Distance, A, Double], | ||
Read[Duration, A, Double], | ||
Read[Gauge.BeatPerMinute, A, Double] | ||
): Read[Gauge.MeterPerBeat, A, Double] = Read: a => | ||
val speed = Read[Distance, A, Double](a) / Read[Duration, A, Double](a) | ||
val hr = Read[Gauge.BeatPerMinute, A, Double](a) | ||
speed * 60 / hr | ||
end given | ||
|
||
given [A](using | ||
Read[Distance, A, Double], | ||
Read[Duration, A, Double] | ||
): Read[Gauge.Pace, A, js.Date] = Read: a => | ||
inline val minute = 60 | ||
inline val hour = (60 * minute) | ||
inline def spm = Read[Duration, A, Double](a) / Read[Distance, A, Double](a) | ||
inline def spkm = Math.round(spm * 1000).intValue | ||
new js.Date(0, 0, 0, spkm / hour, spkm / minute, spkm % minute) | ||
end given | ||
|
||
extension (d: Double) private inline def round = js.Math.round(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package plotly | ||
|
||
import scala.scalajs.js | ||
|
||
import typings.plotlyJs.anon.PartialLayoutAxis | ||
import typings.plotlyJs.plotlyJsStrings.array | ||
import typings.plotlyJs.plotlyJsStrings.reversed | ||
import typings.plotlyJs.plotlyJsStrings.right | ||
import typings.plotlyJs.plotlyJsStrings.y2 | ||
|
||
import core.* | ||
|
||
opaque type Axis[T] = List[PartialLayoutAxis] | ||
object Axis: | ||
|
||
def apply[T](using a: Axis[T]): List[PartialLayoutAxis] = a | ||
|
||
given [A]: Axis[EmptyTuple] = Nil | ||
given [H, T <: Tuple](using h: Axis[H], t: Axis[T]): Axis[H *: T] = h ::: t | ||
|
||
given Axis[Gauge.MeterPerBeat] = PartialLayoutAxis() | ||
.setOverlaying(y2) | ||
.setTickformat(".2f") | ||
.setTickmodeSync | ||
:: Nil | ||
|
||
given Axis[Gauge.BeatPerMinute] = PartialLayoutAxis() | ||
.setSide(right) | ||
:: Nil | ||
|
||
given Axis[Gauge.StepPerMinute] = PartialLayoutAxis() | ||
.setSide(right) | ||
:: Nil | ||
|
||
given Axis[Gauge.Pace] = PartialLayoutAxis() | ||
.setSide(right) | ||
.setTickformat("%M:%S") | ||
.setAutorange(reversed) | ||
:: Nil | ||
|
||
given Axis[Distance] = PartialLayoutAxis() | ||
.setTickformat("~s") | ||
.setTicksuffix("m") | ||
.setTickmode(array) | ||
:: Nil | ||
|
||
given (using ColorPalette): Axis[Box] = PartialLayoutAxis() | ||
.setTickformat(".2f") | ||
.setColorIndex(0) | ||
:: Nil | ||
|
||
extension (a: PartialLayoutAxis) | ||
private inline def setTickmodeSync: PartialLayoutAxis = | ||
a.asInstanceOf[js.Dynamic].tickmode = "sync" | ||
a | ||
|
||
end Axis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
package plotly | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.JSConverters.* | ||
import scala.language.implicitConversions | ||
|
||
import typings.plotlyJs.anon.PartialLayout | ||
import typings.plotlyJs.anon.PartialLayoutAxis | ||
|
||
trait ColorPalette[A]: | ||
def list: List[String] | ||
extension (i: Int) inline def color = list(i % list.length) | ||
extension (a: PartialLayout) inline def setColorPalette = a.setColorway(list.toJSArray) | ||
end ColorPalette | ||
import convs.given | ||
|
||
final class ColorPalette(list: List[String]): | ||
extension (a: PartialLayoutAxis) inline def setColorIndex(i: Int) = a.setColor(list(i % list.length)) | ||
extension (a: PartialLayout) inline def setColorPalette = a.setColorway(list) | ||
|
||
object ColorPalette: | ||
given ColorPalette[Common] with | ||
val list: List[String] = List( | ||
"#1f77b4", | ||
"#ff7f0e", | ||
"#2ca02c", | ||
"#d62728", | ||
"#9467bd", | ||
"#8c564b", | ||
"#e377c2", | ||
"#7f7f7f", | ||
"#bcbd22", | ||
"#17becf" | ||
given ColorPalette = ColorPalette: | ||
List( | ||
"#1f77b4", | ||
"#ff7f0e", | ||
"#2ca02c", | ||
"#d62728", | ||
"#9467bd", | ||
"#8c564b", | ||
"#e377c2", | ||
"#7f7f7f", | ||
"#bcbd22", | ||
"#17becf" | ||
) | ||
end given | ||
end ColorPalette |
Oops, something went wrong.