• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A graphics backend for the browser (with a Torch7 client).

gfx.js: a browser-based graphics server

Originally forked from the amazing tty.js.

The goal is to extend this project to support the creation of rich media windows, on top of the terminal windows.

The idea is simple: the server watches a directory, and monitors the creation & modification of HTML files; upong modification / creation, it creates a new window on the client side (browser), which simply render the HTML.

Clients are easy to develop: one simply needs to dump HTML into the watched directory to have it rendered by the browser.

For now, I'm focusing on one client, written in Lua, for Torch7.

Check out tty.js for reference on the original project. Note: I'm simply extending their project, not modifying any of the core structure, so it should remain compatible.

Installation

You have to have Node.js (important, Version >= 0.10.0), NPM, and Torch7 installed. With older versions of Node.js, things won't be stable. You also need libgraphicsmagick-dev to be installed:

# OS X
brew install graphicsmagick

# Ubuntu
apt-get install libgraphicsmagick1-dev
apt-get install graphicsmagick

Then simply run:

luarocks install https://raw.github.com/clementfarabet/gfx.js/master/gfx.js-scm-0.rockspec

Or, if you cloned the repo locally:

luarocks make

Execution

Once installed, you can start/stop the server like this (I'm assuming a LuaJIT-based install):

luajit -lgfx.start
luajit -lgfx.stop

And then open up a tab in your browser, at http://localhost:8000.

The browser acts as a passive graphics backend. The server monitors the creation of new resources (charts, plots, videos, ...), and lets the browser know it should render them.

The framework is very flexible: resources can be rendered by a client (luajit) with no browser open, and even no server listening/running. The resources generated will still be saved, and can be visualized later (very useful to generate resources/charts on a server with no X session).

You can optionally specify a different port as an env variable, if the default (8000) is not available:

PORT=4321 luajit -lgfx.start
PORT=4321 luajit -lgfx.stop

Also, we provide a useful PS script, which lists running servers:

luajit -lgfx.ps

On Mac OS, we also provide a shortcut to start the server in the background and automatically open the browser at the right location:

luajit -lgfx.go

Alternatively, you can do things step by step:

luajit -lgfx.start
# starts a server...
luajit
# starts a Torch session

At the prompt, you can load the gfx.js client, and render things:

gfx = require 'gfx.js'
gfx.image(image.lena())
gfx.image({
   image.lena()
   image.lena()
   image.lena()
   image.lena()
   image.lena()
   image.lena()
   image.lena()
   image.lena()
}, {zoom=0.5, legends={'Image 1', 'Image 2'}})

This will produce this output:

I've also slowly started to integrate plots from NVD3, and bind them to Torch, so that they can seamlessly be called from the Torch repl:

gfx.chart(data, {
   chart = 'line', -- or: bar, stacked, multibar, scatter
   width = 600,
   height = 450,
})

-- where data has the form:
data = {
    {
        key = 'Legend 1',
        color = '#0f0',
        values = { {x=0,y=0}, {x=1,y=1}, ... },
    },
    {
        key = 'Legend 2',
        color = '#00f',
        values = { {x=0,y=0}, {x=1,y=1}, ... },
    },
}

-- or, for a single dataset:
data = {
    key = 'Legend',
    values = { {x=0,y=0} , ... }
}

-- values can be provided in convenient ways:
values = { {x=0,y=0[,size=0]}, ... }
values = { {0,0,0}, ... }
values = torch.randn(100,2)
values = torch.randn(100,3)  -- the 3rd dimension is the optional size, only used by certain charts
values = torch.randn(100) -- in this case, y is provided, x defaults to range(0,N-1)

-- shortcuts are also provided for quick plots:
gfx.chart(torch.randn(100,2), {chart='scatter'})
gfx.chart(torch.randn(100), {chart='line'})  -- y is provided, x will be a range(1,N)
gfx.chart({ torch.randn(100), torch.randn(100) })  -- multiple datasets
gfx.chart({ {1,2,3,4,5,6,7,8,7,6,5,4,3,2,1}, torch.randn(100) })  -- multiple datasets, table format

As explained above, one can generate resources/charts/figures with no server listening. One can connect a server later on, and redraw the last resources generated. Here are a few useful commands for that:

gfx = require 'gfx.js'
ids = gfx.list(10) -- will list the last 10 figures generated (each figure has a unique ID)
print(ids[1])
-- will print something like: dom_1212817597132847893127489
gfx.redraw(ids[1]) -- will redraw this resource
gfx.redraw(10) -- will redraw the last 10 resources available (sorted by descending time)

Finally, the server gets slower as the number of resources/charts/images grows in the watched directory. It's useful to sometimes clear this cache manually:

gfx.clear()

More Repositories

1

torch-ios

Torch7 for iOS.
C
196
star
2

manifold

A package to manipulate manifolds.
Lua
141
star
3

ipam-tutorials

IPAM Tutorials on Theano/Torch
Lua
129
star
4

graphicsmagick

A simple Lua wrapper to graphicsmagick.
Lua
126
star
5

async

An async framework for Lua/Torch.
C
116
star
6

lua---nnx

An extension to Torch7's nn package.
Lua
97
star
7

lua---parallel

A (simple) parallel computing framework for Lua
Lua
92
star
8

lua---csv

A package to read and write CSV. Provides high-level database-like handlers.
Lua
47
star
9

lua---camera

A very simple camera interface (frame grabber) for Torch7.
C
34
star
10

lua---mattorch

An interface between Torch and Matlab
C
31
star
11

neuflow

Compiler toolkit for neuFlow.
Lua
26
star
12

lua---imgraph

A package to deal with graphs built on images.
C
22
star
13

lua---ffmpeg

An interface between ffmpeg and Lua/Torch
Lua
21
star
14

xLearn

A Lua-based framework for vision.
C
20
star
15

gm

GM package (for tutorial compat)
Lua
17
star
16

buffer

A buffer object for LuaJIT
Lua
15
star
17

lua---liuflow

Dense optical flow toolbox (from C.Liu)
C++
15
star
18

lua---json

A package to read/write JSON
Lua
10
star
19

thwebterm

Torch Web Terminal
JavaScript
10
star
20

videograph

This package extends imgraph, for videos...
C
9
star
21

nnop

Parameter-free Neural Network primitives for torch/nn.
Lua
9
star
22

lua---opengm

An OpenGM wrapper for Lua.
C++
8
star
23

lua---image

An image toolBox for Torch7.
Lua
7
star
24

persist

Persist: a simple persisting table for Torch (uses Redis as a data store).
Lua
5
star
25

torchinstall

A one-line install script for Torch
Shell
5
star
26

restclient

A simple Lua client for REST APIs.
Lua
5
star
27

lua---nng

A graph extension to Torch7's nn package.
Lua
4
star
28

thmap

Trivial distributed computing for Torch.
Lua
4
star
29

lua---inline-C

An Inline C package for Lua
Lua
4
star
30

operator-library

A library of fast customizable operators, in Verilog.
3
star
31

xrocks

A simple container for all our Lua rocks.
Shell
3
star
32

lua-fs-0.3

lua FS library, with torch-pkg build
C
3
star
33

lua---bitop

LuaBitOp -- from Mike Pall (repackaged for Torch7)
Lua
3
star
34

luasql

LuaSQL, fork from https://github.com/keplerproject/luasql, adapted to Torch.
C
3
star
35

lua---python

Python in Lua.
C
3
star
36

lua---sys

A sys/unix utility package for Lua
Lua
2
star
37

nnfunc

Functional API for nn.
Lua
2
star
38

lbfgs

LibLBFGS (C Lib) wrapper.
Lua
2
star
39

luaforever

LuaForever: run a script forever.
JavaScript
2
star
40

selflua

self contained lib for lua
C
1
star
41

THC

This is the raw C api from Torch7.
C
1
star
42

lua---xml

XML Interface.
C
1
star
43

rawptr

just a raw ptr (2-way) interface to share Storages in Lua
C
1
star
44

lua---debugger

Debugger for Lua
Lua
1
star
45

lua---xlua

A few functions to make life better from the Lua prompt (lua -lxlua).
Lua
1
star
46

lua---lushmat

A simple package to load lush matrices as torch Tensors.
C
1
star
47

nn2

A next version of nn.
Lua
1
star