Skip to content

Commit

Permalink
Distance Xaxis.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl committed Sep 6, 2024
1 parent 429b5c5 commit d80ed21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 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 All @@ -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
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().setTicksuffix("m").setTickmode(array))
.setYaxis(yAxis)
.setYaxis2(yAxis2)
end intervals
Expand Down

0 comments on commit d80ed21

Please sign in to comment.