In [ ]:
%libraryDependencies += "com.scalatags" %% "scalatags" % "0.4.1"

In [ ]:
%libraryDependencies += "io.continuum.bokeh" %% "bokeh" % "0.2"

In [ ]:
%libraryDependencies += "org.jfree" % "jfreechart" % "1.0.19"

In [ ]:
%update

In [ ]:
<div style="color: red">XXX</div>

In [ ]:
import scalatags.Text.all._

In [ ]:
div(style:="color: red", "XXX")

In [ ]:
implicit val HTMLTypedTag = org.refptr.iscala.display.HTMLDisplay[scalatags.Text.TypedTag[String]](_.toString)

In [ ]:
div(style:="color: red", "XXX")

In [ ]:
<table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
  </tr>
  <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
  </tr>
</table>

In [ ]:
org.refptr.iscala.display.Math("""F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx""")

In [ ]:
org.refptr.iscala.display.Latex("""
\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0 
\end{eqnarray}
""")

In [ ]:
org.refptr.iscala.display.ImageURL("http://scala-lang.org/resources/img/smooth-spiral.png", 100, 200)

In [ ]:
org.refptr.iscala.display.YouTubeVideo("1j_HxD4iLn8")

In [ ]:
Nil

In [ ]:
implicit val PlainNil = org.refptr.iscala.display.PlainDisplay[Nil.type](_ => "Nil")

In [ ]:
Nil

In [ ]:
implicit val PlainNil = org.refptr.iscala.display.PlainDisplay[Nil.type](_ => "NIL")

In [ ]:
Nil

In [ ]:
import io.continuum.bokeh._

In [ ]:
val resources = Resources.CDN

In [ ]:
implicit val HTMLPlot = org.refptr.iscala.display.HTMLDisplay[Plot, xml.NodeSeq] { plot =>
    val context = new PlotContext().children(plot :: Nil)
    val writer = new HTMLFileWriter(context :: Nil, Some(resources))
    writer.renderPlots(writer.specs())
}

In [ ]:
(resources.styles ++ resources.scripts): xml.NodeSeq

In [ ]:
import Tools._
import math.{Pi=>pi,sin}

val x = -2*pi to 2*pi by 0.1
val y = x.map(sin)

val source = new ColumnDataSource().addColumn('x, x).addColumn('y, y)

val xdr = new DataRange1d().sources(source.columns('x) :: Nil)
val ydr = new DataRange1d().sources(source.columns('y) :: Nil)

val plot = new Plot().x_range(xdr).y_range(ydr).tools(Pan|WheelZoom)

val xaxis = new LinearAxis().plot(plot).location(Location.Below)
val yaxis = new LinearAxis().plot(plot).location(Location.Left)
plot.below <<= (xaxis :: _)
plot.left <<= (yaxis :: _)

val circle = new Circle().x('x).y('y).size(5).fill_color(Color.Red).line_color(Color.Black)
val glyph = new Glyph().data_source(source).glyph(circle)

plot.renderers := List(xaxis, yaxis, glyph)

In [ ]:
plot

In [ ]:
import org.jfree.data.xy.{XYSeries,XYSeriesCollection}
import org.jfree.chart.ChartFactory
import math.{Pi=>pi,sin}

val x = -2*pi to 2*pi by 0.1
val y = x.map(sin)

val series = new XYSeries("sin(x)")
(x zip y).foreach { case (x, y) => series.add(x, y) }

val dataset = new XYSeriesCollection()
dataset.addSeries(series)

val chart = ChartFactory.createXYLineChart("y = sin(x)", "x", "y", dataset)
chart.createBufferedImage(500, 300)

In [ ]: