Atom Packages Directory

a package directory for a text editor of the 21st Century

Proto Repl Charts

Install with:
    apm install proto-repl-charts
  

proto-repl-charts package

API Docs

Proto REPL Charts is an Atom plugin that extends Proto REPL and allows you to display tables and graphs of results from executed Clojure Code.

Execute this in Proto REPL:

Clojure (proto-repl-charts.charts/line-chart "Trigonometry" {"sin" (map #(Math/sin %) (range 0.0 6.0 0.2)) "cos" (map #(Math/cos %) (range 0.0 6.0 0.2))})

… and display this:

A screenshot of Proto REPL Charts showing a graph with sine and cosine

Installation

  1. Install Proto REPL.
  2. apm install proto-repl-charts or go to your Atom settings, select “+ Install” and search for “proto-repl-charts”.

Usage

Proto REPL Charts are invoked from Clojure code run in Proto REPL. A very small Clojure library, proto-repl-charts, defines a namespace prc with functions for displaying different charts.

1. Add proto-repl-charts as a dependency in your Clojure project.

(Not necessary for self hosted REPL. The dependency is already available.)

Add Clojars Project to your dependencies in your project.clj file.

(Proto REPL comes with a default Clojure project. If you bring open a new Atom window for and start a REPL it will already have proto-repl-charts dependency loaded and available.)

2. Start the REPL in Proto REPL and wait for it to come up.

3. Execute one of the functions in the proto-repl-charts.<chart-type-ns> namespace. See the examples below.

The chart functions are all of the form (proto-repl-charts.<chart-type-ns>/<function-name> <tab-name> <series-map> <[options]>)

Displaying a Line Chart

Clojure (let [input-values (range 0.0 6.0 0.5)] (proto-repl-charts.charts/line-chart "Trigonometry" {"sin" (map #(Math/sin %) input-values) "cos" (map #(Math/cos %) input-values)} {:labels input-values}))

line chart

Displaying a Bar Chart

Clojure (proto-repl-charts.charts/bar-chart "GDP_By_Year" {"2013" [16768 9469 4919 3731] "2014" [17418 10380 4616 3859]} {:labels ["US" "China" "Japan" "Germany"]})

bar chart

Displaying a Scatter Chart

Clojure (let [tlr (java.util.concurrent.ThreadLocalRandom/current)] (proto-repl-charts.charts/scatter-chart "Randoms" {:gaussian (repeatedly 200 #(.nextGaussian tlr)) :uniform (repeatedly 200 #(.nextDouble tlr))}))

scatter chart

Displaying a Custom Chart

Displays a custom chart in a tab with the given name. C3 is the charting library used. The chart config will be converted from Clojure to a JavaScript object and passed to C3. It can be any configuration data C3 supports. See C3 examples for more.

```Clojure (proto-repl-charts.charts/custom-chart “Custom”

      :groups [["data1" "data2"]]}}) ```

custom chart

Displaying a Table

Proto REPL Charts can display a table of data that can be sorted by individual columns. The row data can either be a sequence of sequences or a sequence of maps.

```Clojure (proto-repl-charts.table/table “Users” [{:name “Jane” :age 24 :favorite-color :blue}

{:name “Peter” :age 32 :favorite-color :green}]) ```

table from maps

Displaying a Graph

Graphs of networks of nodes and edges can be displayed using the proto-repl-charts.graph/graph function.

See Graphs for details.

map graph

Drawing on a Canvas

Proto REPL Charts supports building more complex visualizations by drawing on an HTML canvas embedded within Atom using the proto-repl-charts.canvas/draw function.

See Canvas for details.

Canvas Dragon Curve

Keywords: clojure, lisp, repl, interactive, graph, chart, visual Suggest keywords
Fork me on GitHub