From 71378d4bba645371a08e1095b2c6f67ceea8a06c Mon Sep 17 00:00:00 2001 From: zhongl Date: Thu, 5 Sep 2024 10:28:01 +0800 Subject: [PATCH 1/5] Clean code. --- build.sc | 2 +- src/garmin/Activities.scala | 1 - src/garmin/Profile.scala | 1 - src/garmin/package.scala | 2 ++ src/plotly/Listen.scala | 3 ++- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.sc b/build.sc index ac72914..d09722d 100644 --- a/build.sc +++ b/build.sc @@ -13,7 +13,7 @@ object root extends RootModule with ScalaJSModule with ScalablyTyped { } override def scalacOptions: Target[Seq[String]] = T { - super.scalacOptions() ++ Seq("-Wunused:all") + super.scalacOptions() ++ Seq("-Wunused:all", "-feature") } object test extends ScalaJSTests { diff --git a/src/garmin/Activities.scala b/src/garmin/Activities.scala index 3aabc6b..740e45d 100644 --- a/src/garmin/Activities.scala +++ b/src/garmin/Activities.scala @@ -42,5 +42,4 @@ object Activities: private val `a.inline-edit-target` = implicitly[Name].value |> Selector[Seq] private val `div.advanced-filtering` = implicitly[Name].value |> Selector[Id] - extension [A](a: A) inline def |>[B](f: A => B): B = f(a) end Activities diff --git a/src/garmin/Profile.scala b/src/garmin/Profile.scala index b0640d0..f373222 100644 --- a/src/garmin/Profile.scala +++ b/src/garmin/Profile.scala @@ -40,5 +40,4 @@ object Profile: private val `div[class^="PageContent"]` = implicitly[Name].value |> Selector[Id] private val `i[class^="icon-activity-"]` = implicitly[Name].value |> Selector[Id] - extension [A](a: A) inline def |>[B](f: A => B): B = f(a) end Profile diff --git a/src/garmin/package.scala b/src/garmin/package.scala index 9464fe1..b4ddc75 100644 --- a/src/garmin/package.scala +++ b/src/garmin/package.scala @@ -19,3 +19,5 @@ private[garmin] val Attribute = LiteralExtract[Element, String]: key => private[garmin] class LiteralExtract[A, B](f: String => A => Option[B]) extends (String => PartialFunction[A, B]): def apply(s: String) = f(s).unlift + +extension [A](a: A) private[garmin] inline def |>[B](f: A => B): B = f(a) diff --git a/src/plotly/Listen.scala b/src/plotly/Listen.scala index ebc7733..85e0e6c 100644 --- a/src/plotly/Listen.scala +++ b/src/plotly/Listen.scala @@ -1,5 +1,6 @@ package plotly +import scala.language.implicitConversions import scala.scalajs.js import scala.scalajs.js.JSConverters.* @@ -8,6 +9,7 @@ import org.scalajs.dom.HTMLElement import typings.plotlyJs.anon.PartialLayout import typings.plotlyJs.anon.PartialLayoutAxis import typings.plotlyJs.anon.PartialPlotDataAutobinx +import typings.plotlyJs.anon.PartialScatterLine import typings.plotlyJs.mod.LegendClickEvent import typings.plotlyJs.mod.PlotlyHTMLElement import typings.plotlyJs.mod.PlotMouseEvent @@ -20,7 +22,6 @@ import typings.plotlyJsDistMin.mod.relayout import typings.plotlyJsDistMin.mod.restyle import core.metrics.* -import typings.plotlyJs.anon.PartialScatterLine type Context[A] = (A, PlotlyHTMLElement) trait Listen[A, B] extends (Context[A] => Unit) From 429b5c56f666a8790f7e43b86eaa0126113fd3c3 Mon Sep 17 00:00:00 2001 From: zhongl Date: Thu, 5 Sep 2024 10:29:54 +0800 Subject: [PATCH 2/5] Bump mill. --- .mill-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mill-version b/.mill-version index 0521cad..bd0119f 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.10 +0.11.12 From d80ed210ecf98744682732b06644cb806b0ad5cb Mon Sep 17 00:00:00 2001 From: zhongl Date: Fri, 6 Sep 2024 09:45:11 +0800 Subject: [PATCH 3/5] Distance Xaxis. --- src/plotly/DataArrayFrom.scala | 12 +++++++++++- src/plotly/Layout.scala | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plotly/DataArrayFrom.scala b/src/plotly/DataArrayFrom.scala index 83b2f58..3c7eeb0 100644 --- a/src/plotly/DataArrayFrom.scala +++ b/src/plotly/DataArrayFrom.scala @@ -20,13 +20,18 @@ trait DataArrayFrom[A] extends (A => js.Array[Data]): object DataArrayFrom: given intervals(using Performance[Interval]): DataArrayFrom[Intervals] = v => + val distances = + val (_, r) = v.foldLeft(0.0 -> List.empty[Meter]): + case ((a, t), i) => (i.distance + a) -> (i.distance + a :: t) + r.map(_.round).reverse + def scatterLine[A <: Double](name: String, fy: Interval => A) = Data .PartialPlotDataAutobinx() .setName(name) .setLine(PartialScatterLine().setWidth(1)) .setY(v.map(fy).toJSArray) - .setX(v.indices.map(_ + 1.0).toJSArray) + .setX(distances.toJSArray) .setHoverinfo(yPlussignname) js.Array( @@ -50,4 +55,9 @@ object DataArrayFrom: m.filter(_.nonEmpty).map(box).toJSArray extension (d: Double) inline def round = scala.scalajs.js.Math.round(d) + extension (i: Intervals) + inline def distances = + val (_, r) = i.foldLeft(0.0 -> List.empty[Meter]): + case ((a, t), d) => (d.distance + a) -> (d.distance + a :: t) + r.map(_.round).reverse end DataArrayFrom diff --git a/src/plotly/Layout.scala b/src/plotly/Layout.scala index 442de45..056bdab 100644 --- a/src/plotly/Layout.scala +++ b/src/plotly/Layout.scala @@ -12,6 +12,7 @@ import typings.plotlyJs.plotlyJsStrings.right import typings.plotlyJs.plotlyJsStrings.y2 import core.metrics.* +import typings.plotlyJs.plotlyJsStrings.array trait Layout[A] extends (A => PartialLayout): extension (a: A) inline def layout = this(a) @@ -44,7 +45,7 @@ object Layout: .setShowlegend(true) .setColorPalette .setLegend(inside) - .setXaxis(PartialLayoutAxis().setDtick(1.0).setTitle("圈数")) + .setXaxis(PartialLayoutAxis().setTicksuffix("m").setTickmode(array)) .setYaxis(yAxis) .setYaxis2(yAxis2) end intervals From 44e9aba851f836d49d6e6406840634d65937fc35 Mon Sep 17 00:00:00 2001 From: zhongl Date: Fri, 6 Sep 2024 09:50:25 +0800 Subject: [PATCH 4/5] Clean code. --- src/plotly/DataArrayFrom.scala | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plotly/DataArrayFrom.scala b/src/plotly/DataArrayFrom.scala index 3c7eeb0..52ab6c1 100644 --- a/src/plotly/DataArrayFrom.scala +++ b/src/plotly/DataArrayFrom.scala @@ -55,9 +55,4 @@ object DataArrayFrom: m.filter(_.nonEmpty).map(box).toJSArray extension (d: Double) inline def round = scala.scalajs.js.Math.round(d) - extension (i: Intervals) - inline def distances = - val (_, r) = i.foldLeft(0.0 -> List.empty[Meter]): - case ((a, t), d) => (d.distance + a) -> (d.distance + a :: t) - r.map(_.round).reverse end DataArrayFrom From 32e28d954db5f0a491843563dfd981b4703c405a Mon Sep 17 00:00:00 2001 From: zhongl Date: Fri, 6 Sep 2024 10:14:11 +0800 Subject: [PATCH 5/5] Improve tick format. --- src/plotly/Layout.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plotly/Layout.scala b/src/plotly/Layout.scala index 056bdab..450662a 100644 --- a/src/plotly/Layout.scala +++ b/src/plotly/Layout.scala @@ -45,7 +45,7 @@ object Layout: .setShowlegend(true) .setColorPalette .setLegend(inside) - .setXaxis(PartialLayoutAxis().setTicksuffix("m").setTickmode(array)) + .setXaxis(PartialLayoutAxis().setTickformat("~s").setTicksuffix("m").setTickmode(array)) .setYaxis(yAxis) .setYaxis2(yAxis2) end intervals