-
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.
* Stash. * React by select. * Fix pace order. * Fix GMT.
- Loading branch information
Showing
12 changed files
with
200 additions
and
112 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package core | ||
|
||
import scala.scalajs.js | ||
|
||
trait DateTimeGMT[A] extends (A => js.Date): | ||
private trait Ext extends js.Object: | ||
def toLocaleDateString(locale: String, option: js.Any): String | ||
|
||
extension (a: A) | ||
inline def ymd(locale: String) = | ||
this(a).asInstanceOf[Ext].toLocaleDateString(locale, js.undefined) | ||
|
||
end extension | ||
end DateTimeGMT | ||
|
||
object DateTimeGMT: | ||
given string: DateTimeGMT[String] = s => | ||
val d = new js.Date(s) | ||
new js.Date(d.getTime() - (d.getTimezoneOffset() * 60000)) | ||
end DateTimeGMT |
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,47 @@ | ||
package plotly | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.JSConverters.* | ||
|
||
import typings.plotlyJs.anon.PartialLayout | ||
import typings.plotlyJs.anon.PartialLegendBgcolor | ||
import typings.plotlyJs.mod.Data | ||
import typings.plotlyJs.plotlyJsBooleans.`false` | ||
|
||
trait Correlate[A]: | ||
def data(i: Int): DataArrayFrom[A] | ||
def layout(i: Int): Layout[A] | ||
object Correlate: | ||
def apply[A](using s: Correlate[A]) = s | ||
|
||
given [A, B <: Data]( | ||
using SharedAxis[A, B], | ||
Trace["mpb", A, B], | ||
Trace["bpm", A, B], | ||
Trace["spm", A, B], | ||
Trace["/km", A, B], | ||
Layout[A], | ||
ColorPalette[Common] | ||
): Correlate[A] with | ||
private val secondaries = List( | ||
Trace["bpm", A, B], | ||
Trace["spm", A, B], | ||
Trace["/km", A, B] | ||
) | ||
def layout(i: Int): Layout[A] = a => | ||
a.layout | ||
.setShowlegend(true) | ||
.setLegend(PartialLegendBgcolor().setX(1.1).setY(0.5).setItemclick(`false`).setItemdoubleclick(`false`)) | ||
.setXaxis(SharedAxis[A, B].axis) | ||
.setYaxis(Trace["mpb", A, B].y(0.color)) | ||
.setYaxis2(secondaries(i - 1).y(i.color)) | ||
|
||
def data(i: Int): DataArrayFrom[A] = a => | ||
val h = Trace["mpb", A, B].data(a) | ||
val t = secondaries.zipWithIndex.map: | ||
case (t, n) if n + 1 == i => t.data(a) | ||
case (t, _) => t.dummy(a) | ||
(h :: t).map(SharedAxis[A, B].share(a)).toJSArray | ||
end given | ||
|
||
end Correlate |
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,26 @@ | ||
package plotly | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.JSConverters.* | ||
|
||
import typings.plotlyJs.anon.PartialLayoutAxis | ||
import typings.plotlyJs.anon.PartialPlotDataAutobinx | ||
import typings.plotlyJs.mod.Data | ||
import typings.plotlyJs.plotlyJsStrings.array | ||
|
||
import core.metrics.* | ||
|
||
trait SharedAxis[A, B <: Data]: | ||
def axis: PartialLayoutAxis | ||
def share(a: A): B => B | ||
|
||
object SharedAxis: | ||
def apply[A, B <: Data](using s: SharedAxis[A, B]) = s | ||
|
||
given SharedAxis[Intervals, PartialPlotDataAutobinx] with | ||
def axis: PartialLayoutAxis = PartialLayoutAxis().setTickformat("~s").setTicksuffix("m").setTickmode(array) | ||
def share(a: Intervals): PartialPlotDataAutobinx => PartialPlotDataAutobinx = | ||
val (_, r) = a.foldLeft(0.0 -> List.empty[Meter]): | ||
case ((s, t), i) => (i.distance + s) -> (i.distance + s :: t) | ||
r.map(_.round).reverse | ||
_.setX(r.toJSArray) |
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,11 +1,12 @@ | ||
package plotly | ||
|
||
import core.DateFormat | ||
import core.DateTimeGMT | ||
import core.metrics.* | ||
|
||
trait Title[A] extends (A => String): | ||
extension (a: A) inline def title = this(a) | ||
object Title: | ||
given date(using DateFormat[String]): Title[Intervals] = oi => s"${oi.head.startTimeGMT.ymd("zh-CN")} 速心比走势" | ||
given Title[History] = _ => "速心比分布走势" | ||
given date(using DateTimeGMT[String]): Title[Intervals] = oi => | ||
s"${(oi.head.startTimeGMT).ymd("fr-CA")} 速心比走势" | ||
given Title[History] = _ => "速心比分布走势" | ||
end Title |
Oops, something went wrong.