Skip to content

Commit d3cef7b

Browse files
committed
more work on Quper
1 parent 4b1302b commit d3cef7b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/scala/05-Quper.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import scala.language.implicitConversions // TODO: remove the need for this
55
// TODO: This is copied from old Scala 2 code in reqT v3; it should be migrated and improved
66
object quper {
77

8+
extension (m: Model)
9+
def toQuperSpec: QuperSpec =
10+
def mapOf(et: EntType): Map[String,Estimate] =
11+
m.atoms.collect{ case Rel(e,l,t) if e.t == et && (t/Value).nonEmpty => (e.id,Estimate((t/Value).head)) }.toMap
12+
val nonRefs = Set[EntType](Target,Barrier,Breakpoint)
13+
val refMap = m.atoms.collect{
14+
case Rel(e,l,t) if !nonRefs.contains(e.t) && (t/Value).nonEmpty =>
15+
(e.id,Estimate((t/Value).head)) }.toMap
16+
QuperSpec(mapOf(Breakpoint), mapOf(Barrier), mapOf(Target), refMap)
17+
818
trait Estimate {
919
def min: Int
1020
def max: Int
@@ -31,8 +41,7 @@ object quper {
3141
case _ => TriangleEstimate(min, value, max)
3242
}
3343
}
34-
implicit def intToEstimate(i: Int): Estimate = Estimate(i)
35-
44+
implicit def intToEstimate(i: Int): Estimate = Estimate(i) //TODO: remove this
3645

3746
case class QuperSpec(
3847
breakpoints: Map[String, Estimate],
@@ -45,7 +54,7 @@ object quper {
4554
lazy val minValue = values.map(_.value).min
4655

4756
def toSvgElem(dx: Int, dy: Int): scala.xml.Elem = {
48-
val (axisLength, imageHeight) = (600.0, 600)
57+
val (axisLength, imageHeight) = (600.0, 800)
4958
def normalize(value: Int): Double = axisLength*(value-minValue)/(maxValue-minValue)
5059
<svg width={s"${axisLength+500}"} height={s"$imageHeight"} font-family="sans-serif">
5160
{ svg.axis("", axisLength, dx, dy) }
@@ -54,9 +63,9 @@ object quper {
5463
{ barriers.map{case (b, e) =>
5564
svg.barrier(b, e.value, normalize, svg.color("barr"), dx, dy)}}
5665
{ targets.map{case (t, e) =>
57-
svg.marker("Target",t, e.value, normalize, -25, svg.color("targ"), dx, dy)}}
66+
svg.marker("Target",t, e.value, normalize, -30, svg.color("targ"), dx, dy)}}
5867
{ references.map{case (t, e) =>
59-
svg.marker("Ref",t, e.value, normalize, -25, svg.color("refe"), dx, dy)}}
68+
svg.marker("Ref",t, e.value, normalize, -20, svg.color("refe"), dx, dy)}}
6069
</svg>
6170
}
6271

0 commit comments

Comments
 (0)