Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit 430afbf

Browse files
committed
Allow to create GridPlot using tuple literals
1 parent 5c38241 commit 430afbf

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

bokeh/src/main/scala/Row.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.continuum.bokeh
2+
3+
trait Row[R, V] {
4+
def toList(obj: R): List[V]
5+
}
6+
object Row {
7+
implicit def Tuple1Row[V]: Row[Tuple1[V], V] = new Row[Tuple1[V], V] {
8+
def toList(t: Tuple1[V]) = List(t._1)
9+
}
10+
implicit def Tuple2Row[V]: Row[Tuple2[V, V], V] = new Row[Tuple2[V, V], V] {
11+
def toList(t: Tuple2[V, V]) = List(t._1, t._2)
12+
}
13+
implicit def Tuple3Row[V]: Row[Tuple3[V, V, V], V] = new Row[Tuple3[V, V, V], V] {
14+
def toList(t: Tuple3[V, V, V]) = List(t._1, t._2, t._3)
15+
}
16+
implicit def Tuple4Row[V]: Row[Tuple4[V, V, V, V], V] = new Row[Tuple4[V, V, V, V], V] {
17+
def toList(t: Tuple4[V, V, V, V]) = List(t._1, t._2, t._3, t._4)
18+
}
19+
implicit def Tuple5Row[V]: Row[Tuple5[V, V, V, V, V], V] = new Row[Tuple5[V, V, V, V, V], V] {
20+
def toList(t: Tuple5[V, V, V, V, V]) = List(t._1, t._2, t._3, t._4, t._5)
21+
}
22+
implicit def Tuple6Row[V]: Row[Tuple6[V, V, V, V, V, V], V] = new Row[Tuple6[V, V, V, V, V, V], V] {
23+
def toList(t: Tuple6[V, V, V, V, V, V]) = List(t._1, t._2, t._3, t._4, t._5, t._6)
24+
}
25+
implicit def Tuple7Row[V]: Row[Tuple7[V, V, V, V, V, V, V], V] = new Row[Tuple7[V, V, V, V, V, V, V], V] {
26+
def toList(t: Tuple7[V, V, V, V, V, V, V]) = List(t._1, t._2, t._3, t._4, t._5, t._6, t._7)
27+
}
28+
implicit def Tuple8Row[V]: Row[Tuple8[V, V, V, V, V, V, V, V], V] = new Row[Tuple8[V, V, V, V, V, V, V, V], V] {
29+
def toList(t: Tuple8[V, V, V, V, V, V, V, V]) = List(t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)
30+
}
31+
implicit def Tuple9Row[V]: Row[Tuple9[V, V, V, V, V, V, V, V, V], V] = new Row[Tuple9[V, V, V, V, V, V, V, V, V], V] {
32+
def toList(t: Tuple9[V, V, V, V, V, V, V, V, V]) = List(t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8, t._9)
33+
}
34+
}

bokeh/src/main/scala/models/Plots.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ package io.continuum.bokeh
7878
}
7979
}
8080

81+
object GridPlot {
82+
def apply[R](rows: R*)(implicit r: Row[R, Plot]): GridPlot = {
83+
new GridPlot().children(rows.toList.map(r.toList(_)))
84+
}
85+
86+
def apply(row: Plot*): GridPlot = {
87+
new GridPlot().children(List(row.toList))
88+
}
89+
}
90+
8191
@model class GridPlot extends Plot {
8292
object children extends Field[List[List[Plot]]]
8393
object border_space extends Field[Int](0)

0 commit comments

Comments
 (0)