From 5525a40b1ca5b10e253b61e4ac0613f39837e8f2 Mon Sep 17 00:00:00 2001 From: Lunfu Zhong Date: Fri, 6 Sep 2024 10:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E8=B7=9D=E7=A6=BB=E5=81=9A?= =?UTF-8?q?=E9=80=9F=E5=BF=83=E6=AF=94X=E8=BD=B4=20(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Clean code. * Bump mill. * Distance Xaxis. * Clean code. * Improve tick format. --- .mill-version | 2 +- build.sc | 2 +- src/garmin/Activities.scala | 1 - src/garmin/Profile.scala | 1 - src/garmin/package.scala | 2 ++ src/plotly/DataArrayFrom.scala | 7 ++++++- src/plotly/Layout.scala | 3 ++- src/plotly/Listen.scala | 3 ++- 8 files changed, 14 insertions(+), 7 deletions(-) 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 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/DataArrayFrom.scala b/src/plotly/DataArrayFrom.scala index 83b2f58..52ab6c1 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( diff --git a/src/plotly/Layout.scala b/src/plotly/Layout.scala index 442de45..450662a 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().setTickformat("~s").setTicksuffix("m").setTickmode(array)) .setYaxis(yAxis) .setYaxis2(yAxis2) end intervals 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)