The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or click here to continue anyway

Wisp is Scala Plotting | Quantifind

Check out Wisp on Github

At Quantifind we've been pushing all of our services into Scala - big heavy ETL pipelines, realtime processing we'll be talking about at Scala Days, and all of the data science and exploration we do on a daily basis.

Everyone coding these technologies wants to visualize something: analysing running times in line plots, using scatter plots with regression lines during modeling, histograms, pie charts, bubble charts during cluster analysis, and so much more. We did an informal survey around how people have been doing this visualization and there was a huge variety: R, matplotlib and gnuplot in python, Keynote, Numbers, Excel, D3.js, and Highcharts. We found that none of the Java or Scala based tools were beautiful enough to show off, or flexible and powerful enough to fit within their development cycle.

So, we built Wisp, a Scala library that offers the interactivity necessary for iterative development, and visualizes using modern browser technologies to capitalize on their power and beauty. We chose Highcharts as our original visualization library because of its comprehensive API, and we are building out other implementations (such as vega, a grammar for D3).

 

Quickstart

Download from Sonatype by adding this to your sbt definitions:

"com.quantifind" %% "wisp" % "0.0.1"

try it out from the scala console

scala> import com.quantifind.charts.Highcharts._ import com.quantifind.charts.Highcharts._ scala> help serving resources from: file:/Users/austin/IdeaProjects/wisp/index-1421703480614.html 2015-01-19 13:38:00.854:INFO:oejs.Server:jetty-8.1.13.v20130916 2015-01-19 13:38:00.909:INFO:oejs.AbstractConnector:Started SocketConnector@0.0.0.0:64782 Server started: http://192.168.1.244:64782/index-1421703480614.html Available Plot Types: Takes an Iterable, an Iterable of pairs, a pair of Iterables, or an Iterable and a Function area areaspline bar column line pie scatter spline regression Stylistic changes: hold plots the next plot on top of the existing plot unhold plots the next plot in a new chart title(String) add a title to the most recent plot xAxis(String) adds a label to the x-axis yAxis(String) adds a label to y-axis legend(Iterable[String]) adds a legend to the most recent plot stack(["normal", "percent"]) stacks bars, columns, and lines relative to each other Server Controls: undo undoes the most recent action redo the opposite of undo delete wipes the most recent chart from the page deleteAll wipes all plots from the page scala>

Highcharts

The Highcharts implementation attempts to closely follow the Highcharts API. We make some concessions to support alternative default values and to accommodate the differences between javascript and scala while preserving simplicity (such as 22-field case classes). To create or modify Highchart objects, you should import com.quantifind.charts.highcharts._ for the types and com.quantifind.charts.highcharts.Highchart._ for implicit conversions. You can then instantiate an object like so:

Highchart(Seq(Series(Seq(Data(1, 2)))), chart = Chart(zoomType = Zoom.xy), yAxis = None)

The current repl API supports the original series types from Highcharts v3.0.6 and we are slowly updating to v4.0.4. You can pass any highchart object to plot, or use methods defined by the Highcharts plot type (recommended), which consume both data and functions: area, areaspline, bar, column, line, pie, scatter, spline. By means of example:

import com.quantifind.charts.Highcharts._ areaspline(List(1, 2, 3, 4, 5), List(4, 1, 3, 2, 6))

pie(Seq(4, 4, 5, 9))

You can pass in

  1. Iterable[Numeric]
  2. Iterable[(Numeric, Numeric)]
  3. (Iterable[Numeric], Iterable[Numeric])
  4. (Iterable[Numeric], Numeric => Numeric)
  5. (Numeric => Numeric, Iterable[Numeric])

To any of these functions. All of the following produce the same graph:

line((0 until 5).map(x => x -> x*x)) line(Seq(0, 1, 4, 9, 16)) line(List(0, 1, 2, 3, 4), Set(0, 1, 9, 16, 4).toSeq,sorted) def f(x: Int): Int = scala.math.pow(x, 2).toInt line(0 to 4, f _)

We are developing further support for more customized plots. For example, linear-regression:

You can then make stylistic changes to your plot. You can add a title, xAxis, yAxis, legend, as well as hold and unhold plots, which causes plots to layer on top-of each other, and change the plots to be stacked, where appropriate:

import com.quantifind.charts.Highcharts._ bar((0 until 20).map(_ % 8)) hold bar((0 until 20).map(_ % 4)) stack() title("Stacked Bars") xAxis("Quantity") yAxis("Price") legend(List("Blue", "Black"))

Looking Forward

We welcome any feedback or contributions through our wisp github repository. We are working to stay up-to-date with all the great advancements from the Highcharts team and supporting new visualization technologies.

Continue reading on quantifind.com