hyper-vis 1.0.0.lap34 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +154 -23
- data/hyper-vis.gemspec +5 -5
- data/lib/hyper-vis.rb +7 -0
- data/lib/hyperloop/vis/graph2d/component.rb +16 -0
- data/lib/hyperloop/vis/graph2d/mixin.rb +89 -0
- data/lib/hyperloop/vis/graph3d/component.rb +15 -0
- data/lib/hyperloop/vis/graph3d/mixin.rb +79 -0
- data/lib/hyperloop/vis/network/mixin.rb +1 -1
- data/lib/hyperloop/vis/timeline/component.rb +16 -0
- data/lib/hyperloop/vis/timeline/mixin.rb +89 -0
- data/lib/hyperloop/vis/version.rb +1 -1
- data/lib/vis.rb +4 -1
- data/lib/vis/data_common.rb +46 -0
- data/lib/vis/data_set.rb +6 -1
- data/lib/vis/graph2d.rb +145 -0
- data/lib/vis/graph3d.rb +135 -0
- data/lib/vis/network.rb +187 -8
- data/lib/vis/railtie.rb +7 -0
- data/lib/vis/timeline.rb +338 -0
- data/lib/vis/utilities.rb +7 -199
- data/spec/test_app/Gemfile +2 -4
- data/spec/test_app/app/assets/stylesheets/application.css +2 -1
- data/spec/test_app/db/schema.rb +28 -0
- data/spec/vis_graph2d_component_spec.rb +89 -0
- data/spec/vis_graph2d_spec.rb +304 -0
- data/spec/vis_graph3d_component_spec.rb +124 -0
- data/spec/vis_graph3d_spec.rb +247 -0
- data/spec/vis_timeline_component_spec.rb +89 -0
- data/spec/vis_timeline_spec.rb +425 -0
- metadata +37 -13
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hyperloop
|
2
|
+
module Vis
|
3
|
+
module Timeline
|
4
|
+
class Component
|
5
|
+
include Hyperloop::Vis::Timeline::Mixin
|
6
|
+
def self.inherited(base)
|
7
|
+
base.class_eval do
|
8
|
+
param items: nil
|
9
|
+
param groups: nil
|
10
|
+
param options: nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'react/component'
|
2
|
+
|
3
|
+
module Hyperloop
|
4
|
+
module Vis
|
5
|
+
module Timeline
|
6
|
+
module Mixin
|
7
|
+
def self.included(base)
|
8
|
+
base.include(Hyperloop::Component::Mixin)
|
9
|
+
base.class_eval do
|
10
|
+
param items: nil
|
11
|
+
param groups: nil
|
12
|
+
param options: nil
|
13
|
+
|
14
|
+
def _set_dom_node(dom_node)
|
15
|
+
@_dom_node = dom_node
|
16
|
+
end
|
17
|
+
|
18
|
+
def items
|
19
|
+
@_items
|
20
|
+
end
|
21
|
+
|
22
|
+
def groups
|
23
|
+
@_groups
|
24
|
+
end
|
25
|
+
|
26
|
+
def document
|
27
|
+
`window.document`
|
28
|
+
end
|
29
|
+
|
30
|
+
def options
|
31
|
+
@_options
|
32
|
+
end
|
33
|
+
|
34
|
+
def automatic_refresh
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.automatic_refresh(value)
|
39
|
+
define_method(:automatic_refresh) do
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.render_with_dom_node(tag = 'DIV', &block)
|
45
|
+
render do
|
46
|
+
@_vis_render_block = block
|
47
|
+
@_items = params.items
|
48
|
+
@_groups = params.groups
|
49
|
+
@_options = params.options
|
50
|
+
send(tag, ref: method(:_set_dom_node).to_proc)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def should_component_update?
|
55
|
+
`false`
|
56
|
+
end
|
57
|
+
|
58
|
+
after_mount do
|
59
|
+
if @_dom_node && @_vis_render_block
|
60
|
+
instance_exec(@_dom_node, @_items, @_groups, @_options, &@_vis_render_block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
before_receive_props do |new_props|
|
65
|
+
if automatic_refresh && @_dom_node && @_vis_render_block
|
66
|
+
changed = false
|
67
|
+
if new_props[:items] != @_items
|
68
|
+
@_items = new_props[:items]
|
69
|
+
changed = true
|
70
|
+
end
|
71
|
+
if new_props[:groups] != @_groups
|
72
|
+
@_items = new_props[:groups]
|
73
|
+
changed = true
|
74
|
+
end
|
75
|
+
if new_props[:options] != @_options
|
76
|
+
@_options = new_props[:options]
|
77
|
+
changed = true
|
78
|
+
end
|
79
|
+
if changed
|
80
|
+
instance_exec(@_dom_node, @_items, @_groups, @_options, &@_vis_render_block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/vis.rb
CHANGED
data/lib/vis/data_common.rb
CHANGED
@@ -19,5 +19,51 @@ module Vis
|
|
19
19
|
def get_ids(options)
|
20
20
|
@native.JS.getIds(options_to_native(options))
|
21
21
|
end
|
22
|
+
|
23
|
+
# events
|
24
|
+
|
25
|
+
def off(event, event_handler_id)
|
26
|
+
event = lower_camelize(event)
|
27
|
+
handler = @event_handlers[event][event_handler_id]
|
28
|
+
`self["native"].off(event, handler)`
|
29
|
+
@event_handlers[event].delete(event_handler_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def on(event, &block)
|
33
|
+
event = lower_camelize(event)
|
34
|
+
@event_handlers[event] = {} unless @event_handlers[event]
|
35
|
+
event_handler_id = `Math.random().toString(36).substring(6)`
|
36
|
+
handler = %x{
|
37
|
+
function(event, properties, sender_id) {
|
38
|
+
return block.$call(Opal.Hash.$new(event),Opal.Hash.$new(properties), sender_id);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
@event_handlers[event][event_handler_id] = handler
|
42
|
+
`self["native"].on(event, handler);`
|
43
|
+
event_handler_id
|
44
|
+
end
|
45
|
+
|
46
|
+
# options
|
47
|
+
|
48
|
+
def options_to_native(options)
|
49
|
+
return unless options
|
50
|
+
new_opts = {}.merge!(options)
|
51
|
+
|
52
|
+
if new_opts.has_key?(:filter)
|
53
|
+
block = new_opts[:filter]
|
54
|
+
if `typeof block === "function"`
|
55
|
+
unless new_opts[:filter].JS[:hyper_wrapped]
|
56
|
+
new_opts[:filter] = %x{
|
57
|
+
function(item) {
|
58
|
+
return #{block.call(`Opal.Hash.$new(item)`)};
|
59
|
+
}
|
60
|
+
}
|
61
|
+
new_opts[:filter].JS[:hyper_wrapped] = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
lower_camelize_hash(new_opts).to_n
|
67
|
+
end
|
22
68
|
end
|
23
69
|
end
|
data/lib/vis/data_set.rb
CHANGED
@@ -11,6 +11,12 @@ module Vis
|
|
11
11
|
|
12
12
|
attr_reader :event_handlers
|
13
13
|
|
14
|
+
def self.wrap(native)
|
15
|
+
instance = allocate
|
16
|
+
instance.instance_variable_set(:@native, native)
|
17
|
+
instance
|
18
|
+
end
|
19
|
+
|
14
20
|
def initialize(*args)
|
15
21
|
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
|
16
22
|
hash_array = []
|
@@ -86,6 +92,5 @@ module Vis
|
|
86
92
|
end
|
87
93
|
`self["native"].update.apply(self["native"], Opal.to_a(args))`
|
88
94
|
end
|
89
|
-
|
90
95
|
end
|
91
96
|
end
|
data/lib/vis/graph2d.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
module Vis
|
2
|
+
class Graph2d
|
3
|
+
include Native
|
4
|
+
include Vis::Utilities
|
5
|
+
|
6
|
+
aliases_native %i[
|
7
|
+
addCustomTime
|
8
|
+
destroy
|
9
|
+
fit
|
10
|
+
getCurrentTime
|
11
|
+
getCustomTime
|
12
|
+
isGroupVisible
|
13
|
+
redraw
|
14
|
+
removeCustomTime
|
15
|
+
setCurrentTime
|
16
|
+
setCustomTime
|
17
|
+
setWindow
|
18
|
+
]
|
19
|
+
|
20
|
+
def initialize(native_container, item_dataset, group_dataset = nil, options = {})
|
21
|
+
native_item_data = item_dataset.to_n
|
22
|
+
if group_dataset.is_a?(Hash) && options == {}
|
23
|
+
options = group_dataset
|
24
|
+
group_dataset = nil
|
25
|
+
end
|
26
|
+
native_options = options_to_native(options)
|
27
|
+
@event_handlers = {}
|
28
|
+
if group_dataset.nil?
|
29
|
+
@native = `new vis.Graph2d(native_container, native_item_data, native_options)`
|
30
|
+
else
|
31
|
+
native_group_data = group_dataset.to_n
|
32
|
+
@native = `new vis.Graph2d(native_container, native_item_data, native_group_data, native_options)`
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def off(event, event_handler_id)
|
37
|
+
event = lower_camelize(event)
|
38
|
+
handler = @event_handlers[event][event_handler_id]
|
39
|
+
`self["native"].off(event, handler)`
|
40
|
+
@event_handlers[event].delete(event_handler_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
EVENTS_NO_PARAM = %i[currentTimeTick changed]
|
44
|
+
|
45
|
+
def on(event, &block)
|
46
|
+
event = lower_camelize(event)
|
47
|
+
@event_handlers[event] = {} unless @event_handlers[event]
|
48
|
+
event_handler_id = `Math.random().toString(36).substring(6)`
|
49
|
+
handler = if EVENTS_NO_PARAM.include?(event)
|
50
|
+
`function() { block.$call(); }`
|
51
|
+
else
|
52
|
+
`function(event_info) { block.$call(Opal.Hash.$new(event_info)); }`
|
53
|
+
end
|
54
|
+
@event_handlers[event][event_handler_id] = handler
|
55
|
+
`self["native"].on(event, handler)`
|
56
|
+
event_handler_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_groups(dataset)
|
60
|
+
@native.JS.setGroups(dataset.to_n)
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_items(dataset)
|
64
|
+
@native.JS.setItems(dataset.to_n)
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_options(options)
|
68
|
+
@native.JS.setOptions(options_to_native(options))
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_data_range
|
72
|
+
res = @native.JS.getDataRange()
|
73
|
+
`Opal.Hash.$new(res)`
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_event_properties(event)
|
77
|
+
res = @native.JS.getEventProperties(event.to_n)
|
78
|
+
`Opal.Hash.$new(res)`
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_legend(group_id, icon_width, icon_height)
|
82
|
+
res = @native.JS.getLegend(group_id, icon_width, icon_height)
|
83
|
+
`Opal.Hash.$new(res)`
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_window
|
87
|
+
res = @native.JS.getWindow()
|
88
|
+
`Opal.Hash.$new(res)`
|
89
|
+
end
|
90
|
+
|
91
|
+
def move_to(time, options = {})
|
92
|
+
@native.JS.moveTo(time, options_to_native(options))
|
93
|
+
end
|
94
|
+
|
95
|
+
def options_to_native(options)
|
96
|
+
return unless options
|
97
|
+
# options must be duplicated, so callbacks dont get wrapped twice
|
98
|
+
new_opts = {}.merge!(options)
|
99
|
+
|
100
|
+
if new_opts.has_key?(:configure)
|
101
|
+
block = new_opts[:configure]
|
102
|
+
if `typeof block === "function"`
|
103
|
+
unless new_opts[:configure].JS[:hyper_wrapped]
|
104
|
+
new_opts[:configure] = %x{
|
105
|
+
function(option, path) {
|
106
|
+
return block.$call(option, path);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
new_opts[:configure].JS[:hyper_wrapped] = true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
if new_opts.has_key?(:draw_points)
|
115
|
+
block = new_opts[:draw_points]
|
116
|
+
if `typeof block === "function"`
|
117
|
+
unless new_opts[:draw_points].JS[:hyper_wrapped]
|
118
|
+
new_opts[:draw_points] = %x{
|
119
|
+
function(item, group) {
|
120
|
+
return block.$call(Opal.Hash.$new(item), Opal.Hash.$new(group));
|
121
|
+
}
|
122
|
+
}
|
123
|
+
new_opts[:draw_points].JS[:hyper_wrapped] = true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if new_opts.has_key?(:moment)
|
129
|
+
block = new_opts[:moment]
|
130
|
+
if `typeof block === "function"`
|
131
|
+
unless new_opts[:moment].JS[:hyper_wrapped]
|
132
|
+
new_opts[:moment] = %x{
|
133
|
+
function(native_date) {
|
134
|
+
return block.$call(native_date);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
new_opts[:moment].JS[:hyper_wrapped] = true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
lower_camelize_hash(new_opts).to_n
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/lib/vis/graph3d.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
module Vis
|
2
|
+
class Graph3d
|
3
|
+
include Native
|
4
|
+
include Vis::Utilities
|
5
|
+
|
6
|
+
aliases_native %i[
|
7
|
+
animationStart
|
8
|
+
animationStop
|
9
|
+
redraw
|
10
|
+
setSize
|
11
|
+
]
|
12
|
+
|
13
|
+
def initialize(native_container, dataset, options = {})
|
14
|
+
native_options = options_to_native(options)
|
15
|
+
native_data = dataset.to_n
|
16
|
+
@event_handlers = {}
|
17
|
+
@native = `new vis.Graph3d(native_container, native_data, native_options)`
|
18
|
+
end
|
19
|
+
|
20
|
+
def off(event, event_handler_id)
|
21
|
+
event = lower_camelize(event)
|
22
|
+
handler = @event_handlers[event][event_handler_id]
|
23
|
+
`self["native"].off(event, handler)`
|
24
|
+
@event_handlers[event].delete(event_handler_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(event, &block)
|
28
|
+
event = lower_camelize(event)
|
29
|
+
@event_handlers[event] = {} unless @event_handlers[event]
|
30
|
+
event_handler_id = `Math.random().toString(36).substring(6)`
|
31
|
+
handler = `function(event_info) { block.$call(Opal.Hash.$new(event_info)); }`
|
32
|
+
@event_handlers[event][event_handler_id] = handler
|
33
|
+
`self["native"].on(event, handler)`
|
34
|
+
event_handler_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_data(dataset)
|
38
|
+
native_data = dataset.to_n
|
39
|
+
@native.JS.setData(native_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_options(options)
|
43
|
+
native_options = options_to_native(options)
|
44
|
+
@native.JS.setOptions(native_options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_camera_position
|
48
|
+
res = @native.JS.getCameraPosition()
|
49
|
+
`Opal.Hash.$new(res)`
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_camera_position(dis_hor_ver)
|
53
|
+
res = @native.JS.setCameraPosition(dis_hor_ver.to_n)
|
54
|
+
`Opal.Hash.$new(res)`
|
55
|
+
end
|
56
|
+
|
57
|
+
def options_to_native(options)
|
58
|
+
return unless options
|
59
|
+
# options must be duplicated, so callbacks dont get wrapped twice
|
60
|
+
new_opts = {}.merge!(options)
|
61
|
+
|
62
|
+
if new_opts.has_key?(:onclick)
|
63
|
+
block = new_opts[:onclick]
|
64
|
+
if `typeof block === "function"`
|
65
|
+
unless new_opts[:onclick].JS[:hyper_wrapped]
|
66
|
+
new_opts[:onclick] = %x{
|
67
|
+
function(point) {
|
68
|
+
return #{block.call(`Opal.Hash.$new(point)`)};
|
69
|
+
}
|
70
|
+
}
|
71
|
+
new_opts[:onclick].JS[:hyper_wrapped] = true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
if new_opts.has_key?(:tooltip)
|
77
|
+
block = new_opts[:tooltip]
|
78
|
+
if `typeof block === "function"`
|
79
|
+
unless new_opts[:tooltip].JS[:hyper_wrapped]
|
80
|
+
new_opts[:tooltip] = %x{
|
81
|
+
function(item) {
|
82
|
+
return #{block.call(`Opal.Hash.$new(item)`)};
|
83
|
+
}
|
84
|
+
}
|
85
|
+
new_opts[:tooltip].JS[:hyper_wrapped] = true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if new_opts.has_key?(:x_value_label)
|
91
|
+
block = new_opts[:x_value_label]
|
92
|
+
if `typeof block === "function"`
|
93
|
+
unless new_opts[:x_value_label].JS[:hyper_wrapped]
|
94
|
+
new_opts[:x_value_label] = %x{
|
95
|
+
function(value) {
|
96
|
+
return #{block.call(value)};
|
97
|
+
}
|
98
|
+
}
|
99
|
+
new_opts[:x_value_label].JS[:hyper_wrapped] = true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
if new_opts.has_key?(:y_value_label)
|
105
|
+
block = new_opts[:y_value_label]
|
106
|
+
if `typeof block === "function"`
|
107
|
+
unless new_opts[:y_value_label].JS[:hyper_wrapped]
|
108
|
+
new_opts[:y_value_label] = %x{
|
109
|
+
function(value) {
|
110
|
+
return #{block.call(value)};
|
111
|
+
}
|
112
|
+
}
|
113
|
+
new_opts[:y_value_label].JS[:hyper_wrapped] = true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if new_opts.has_key?(:z_value_label)
|
119
|
+
block = new_opts[:z_value_label]
|
120
|
+
if `typeof block === "function"`
|
121
|
+
unless new_opts[:z_value_label].JS[:hyper_wrapped]
|
122
|
+
new_opts[:z_value_label] = %x{
|
123
|
+
function(value) {
|
124
|
+
return #{block.call(value)};
|
125
|
+
}
|
126
|
+
}
|
127
|
+
new_opts[:z_value_label].JS[:hyper_wrapped] = true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
lower_camelize_hash(new_opts).to_n
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|