Git Product home page Git Product logo

swiftvis2's Introduction

SwiftVis

This project is an updated version of SwiftVis written in Scala with better support for parallelism, support for rendering with diverse platforms, and a programming interface. I try to keep a reasonably up to date API posted on my personal site.

SwiftVis2 is still in the early stages. I am focusing on adding basic plotting capability with the programming interface currently. The graphical dataflow interface and other features will follow. Currently I also have a research student, Nick Smoker, working on making the code cross-compile for Scala.js and Scala Native so that plotting works on all available platforms.

Updates

  • 6/21/2020: Pushed an update to use JavaFX for Java 11. If you had built previously, you might need to manually delete fxrenderer/target for this to compile and run nicely. Doing a 'clean' in sbt doesn't remove some files that need to be updated.

Installation

SwiftVis2 is not yet at the point where it belongs in a Maven repository. Until SwiftVis2 is stable enough to put in a Maven repository you can use it in one of two ways.

  1. Run publishLocal in sbt and include the appropriate dependencies in your build.sbt file. Note that you probably don't need both the JavaFX and the Swing libraries. Pick whichever you are using.
  • libraryDependencies += "edu.trinity" %% "swiftvis2core" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2jvm" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2fx" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2swing" % "0.1.0-SNAPSHOT"
  1. Compile and package this project and put the JAR files in the lib directory of your sbt project.

If you want to use SwiftVis2 with Spark, you should probably use the publishLocal option, but with some modifications.

  1. Spark now supports Scala 2.12, but many versions don't do so by default. Check your version. If your Spark is using Scala 2.11 then run ++2.11.12 to set the Scala version to 2.11. You can update the last value to whatever the latest release is.
  2. Run publishLocal to publish the 2.11 version of the main SwiftVis2 library.
  3. Run spark/publishLocal to publish the Spark integration library.
  4. Add the following lines to your build.sbt. Again, you probably won't use both JavaFX and Swing so leave out the one you don't need.
  • libraryDependencies += "edu.trinity" %% "swiftvis2core" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2jvm" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2fx" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2swing" % "0.1.0-SNAPSHOT"
  • libraryDependencies += "edu.trinity" %% "swiftvis2spark" % "0.1.0-SNAPSHOT"

Note that the sbt commands can all be done at onced from the command line with sbt ++2.11.12 publishLocal spark/publishLocal.

Usage

While it is possible to build plots piece by piece, the fact that SwiftVis2 supports a lot of plotting options can make that tedious. To help with that, facade methods are added that construct frequently used structures. The following code shows how you can use two facade methods to generate a scatter plot and display it. Note that you need to do this in a class that extends JFXApp to use the FXRenderer. That isn't needed for other renderers. Based on our expereince, at this point we would recommend using the SwingRenderer over the FXRenderer. It is easier to use, faster, and produces slightly nicer output.

A sample application using JavaFX might look like the following.

import scalafx.application.JFXApp
import swiftvis2.plotting
import swiftvis2.plotting.Plot
import swiftvis2.plotting.renderer.FXRenderer

object PlotTesting extends JFXApp {
  val xPnt = 1 to 10
  val yPnt = xPnt.map(a => a * a)
  val plot = Plot.scatterPlot(xPnt, yPnt, "Quadratic", "x", "y")
  FXRenderer(plot)

  val plot2 = Plot.scatterPlot((1 to 1000).map(_ => math.random * math.random), (1 to 1000).map(_ => math.random * math.random), "Random Points", "x", "y")
  FXRenderer(plot2, 1500, 500)
}

This same example using Swing would look like the following.

import swiftvis2.plotting
import swiftvis2.plotting.Plot
import swiftvis2.plotting.renderer.SwingRenderer

object PlotTesting extends App {
  val xPnt = 1 to 10
  val yPnt = xPnt.map(a => a * a)
  val plot = Plot.scatterPlot(xPnt, yPnt, "Quadratic", "x", "y")
  SwingRenderer(plot)

  val plot2 = Plot.scatterPlot((1 to 1000).map(_ => math.random * math.random), (1 to 1000).map(_ => math.random * math.random), "Random Points", "x", "y")
  SwingRenderer(plot2, 1500, 500, true)  // The true at the end means that closing this window terminates the application.
}

Currently scatter plots, bar charts, histograms, box and whisker plots, and violin plots are the only plotting styles that are implemented. I'm building up some examples that can help you see how to do things.

If you want to use SwiftVis2 in a shell/REPL, including the spark-shell, you can specify the SwiftVis2 JAR file on the command line with the -cp option. Once in the shell you need to import a few things probably including swiftvis2.plotting._ and swiftvis2.plotting.renderer._. If you are using the FXRenderer you then run FXRenderer.startShell(). This is shown in the following example. You can then repeatedly call FXRenderer on various plots as long as you don't close the small window that comes up with startShell. If you are using the SwingRenderer, you can skip that step and just display plots. There won't be extra windows, but you need to be careful not to have your windows exit on close.

import swiftvis2.plotting
import swiftvis2.plotting.Plot
import swiftvis2.plotting.fxrenderer.FXRenderer

FXRenderer.shellStart()
val xPnt = 1 to 10
val yPnt = xPnt.map(a => a * a)
val plot = Plot.scatterPlot(xPnt, yPnt, "Quadratic", "x", "y")
FXRenderer(plot)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.