Sha256: 87856f3eadf2b035201226dcbd5a943c69cd386a6487c036f7c5114aa92ca574

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

# hyper-vis

A Opal Ruby wraper for (Vis.js)[visjs.org] with a Ruby-Hyperloop Component.
Currently supports the complete API for:
- Vis Dataset
- Vis Dataview
- Vis Network

### Installation
for a rails app:
```
gem 'hyper-vis'
```
and `bundle update`
hyper-vis depends on `hyper-component` from (ruby-hyperloop)[http://ruby-hyperloop.org]

### Usage

vis.js is automatically imported. If you use webpacker, you may need to cancel the import in your config/intializers/hyperloop.rb
```
  config.cancel_import 'vis/source/vis.js'
```
stylesheets are includes in 'vis/source/vis.css', images are there too.

#### The Vis part
```
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
dom_node = Vis::Network.test_container
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
xy = net.canvas_to_dom({x: 10, y: 10})
```
#### The Component part
The Component takes care about all the things necessary to make Vis.js play nice with React.
The Component also provides a helper to access the document.
Vis::Network can be used within the render_with_dom_node.
```
class MyVisNetworkComponent
  include Hyperloop::Vis::Network::Mixin

  render_with_dom_node do |dom_node, data, options|

    net = Vis::Network.new(dom_node, data, options)

    canvas = document.JS.querySelector('canvas')
  end
end

class AOuterComponent < Hyperloop::Component
  render do
    received_data = []

    options = { manipulation: {
        edit_node: proc { |node_data, callback| received_data << node_data }
      }}

    data = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
    
    DIV { MyVisNetworkComponent(data: data, otions: options)}
  end
end
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyper-vis-1.0.0.lap26 README.md