Skip to content

Commit

Permalink
改用距离做速心比X轴 (#14)
Browse files Browse the repository at this point in the history
* Clean code.

* Bump mill.

* Distance Xaxis.

* Clean code.

* Improve tick format.
  • Loading branch information
zhongl authored Sep 6, 2024
1 parent d0e8317 commit 5525a40
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.10
0.11.12
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/garmin/Activities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/garmin/Profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/garmin/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 6 additions & 1 deletion src/plotly/DataArrayFrom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/plotly/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/plotly/Listen.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package plotly

import scala.language.implicitConversions
import scala.scalajs.js
import scala.scalajs.js.JSConverters.*

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5525a40

Please sign in to comment.