aboutsummaryrefslogtreecommitdiff
path: root/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Distribution.scala
blob: caeac337fd5152124201f082fbc93e082b268b89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package vfd.dashboard.ui.instruments

import org.scalajs.dom.html
import vfd.dashboard.Environment

class Distribution(implicit env: Environment) extends SvgInstrument[(Double, Double, Double, Double)] {
  import SvgInstrument._
  
  val initial = (0.0, 0.0, 0.0, 0.0)
  
  lazy val element = svgObject("distribution")
  lazy val position = part("position")
  lazy val moveable = Seq(position)

  private final val Radius = 50 //px
  
  protected def update(value: (Double, Double, Double, Double)) = {
    val sum = value._1 + value._2 + value._3 + value._4
    val i = (value._1 - value._3) / sum
    val j = (value._2 - value._4) / sum
    val x = math.sqrt(2) / 2 * (i - j)
    val y = math.sqrt(2) / 2 * (-i - j)
    translate(position, (x * Radius).toInt, (y * Radius).toInt)
  }
  
}