Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Mar 12, 2024
1 parent 51a07dc commit ea5b456
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy val root = project
.enablePlugins(ScalaJSPlugin)
.settings(
name := "mortgage-visuals",
scalaVersion := "3.3.0",
scalaVersion := "3.4.0",
scalacOptions ++= Seq(
"-encoding",
"utf-8",
Expand All @@ -19,8 +19,8 @@ lazy val root = project
.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("example")))
},
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.4.0",
"be.doeraene" %%% "web-components-ui5" % "1.10.0",
"com.raquo" %%% "laminar" % "16.0.0"
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
"be.doeraene" %%% "web-components-ui5" % "1.21.0",
"com.raquo" %%% "laminar" % "17.0.0-M8"
)
)
55 changes: 31 additions & 24 deletions src/main/scala/example/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ case class Settings(

end stampDuty

def LTVPercent = 100 * (loanAmount / housePrice)
def LTVPercent = (100 * (loanAmount / housePrice)).floor
end Settings

def app =
val housePrice = Var(800_000.0)
val deposit = Var(50_000.0)
val durationYears = Var(25)
val rate = Var(6.0)
val rate = Var(5.0)
var optChart = Option.empty[Chart]
val combined =
Signal.combine(housePrice, deposit, durationYears, rate).map(Settings.apply)
Expand All @@ -95,41 +95,44 @@ def app =

val numberFormat = NumberFormat("en-GB")

inline def formatPound(value: Double) =
"£" + numberFormat.format(value.floor)

inline def poundValue(source: Observable[Double]) =
val nn =
source.toObservable.map(value => "£" + numberFormat.format(value.floor))
source.toObservable.map(formatPound)
span(color.maroon, child.text <-- nn)

val sliders = div(
width := "50%",
h1("Rate: ", child.text <-- rate.signal.map(y => s"$y%")),
Slider(
_.min := 2,
_.max := 15.0,
_.step := 1,
_.value := 6,
_.min := 2,
_.max := 8.0,
_.step := 1,
_.value <-- rate,
_.showTooltip := true,
_.labelInterval := 1,
_.showTickmarks := true,
_.events.onInput.map(_.target.value) --> rate
),
h1("House price: ", poundValue(housePrice.signal)),
Slider(
_.min := 100_000,
_.max := 1_200_000,
_.step := 25_000,
_.value := 400_000,
_.min := 100_000,
_.max := 1_200_000,
_.step := 25_000,
_.value <-- housePrice,
_.showTooltip := true,
_.labelInterval := 10,
_.showTickmarks := true,
_.events.onInput.map(_.target.value) --> housePrice
),
h1("Deposit: ", poundValue(deposit.signal)),
Slider(
_.min := 10_000,
_.max := 500_000,
_.step := 10_000,
_.value := 50_000,
_.min := 10_000,
_.max <-- housePrice,
_.step := 10_000,
_.value <-- deposit,
_.showTooltip := true,
_.labelInterval := 5,
_.showTickmarks := true,
Expand All @@ -143,10 +146,10 @@ def app =
)
),
Slider(
_.min := 10,
_.max := 35,
_.step := 1,
_.value := 25,
_.min := 10,
_.max := 35,
_.step := 1,
_.value <-- durationYears.signal.map(_.toDouble),
_.showTooltip := true,
_.labelInterval := 1,
_.showTickmarks := true,
Expand Down Expand Up @@ -182,12 +185,16 @@ def app =
),
combined --> { settings =>
val deposits =
50_000.to(500_000.min(settings.housePrice.toInt), 5_000)
val monthlyPayments = deposits.map(dep =>
settings.copy(deposit = dep.toDouble).monthlyPayment
)
50_000
.to(settings.housePrice.toInt, 10_000)

val monthlyPayments = deposits
.map(dep =>
settings.copy(deposit = dep.toDouble).monthlyPayment.floor
)

optChart.foreach { ch =>
ch.data.labels = js.Array(deposits.map(_.toString)*)
ch.data.labels = js.Array(deposits.map(d => formatPound(d.toDouble))*)
ch.data.datasets = js.Array(
ChartDataset(
"Monthly payments at various deposit amounts",
Expand Down

0 comments on commit ea5b456

Please sign in to comment.