rbbt-rest 1.7.17 → 1.7.18
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/lib/rbbt/rest/common/cache.rb +1 -0
- data/lib/rbbt/rest/entity.rb +69 -2
- data/lib/rbbt/rest/entity/render.rb +21 -3
- data/lib/rbbt/rest/main.rb +11 -11
- data/lib/rbbt/rest/workflow.rb +1 -1
- data/share/views/compass/app.sass +1 -0
- data/share/views/compass/layout.sass +5 -3
- data/share/views/compass/misc.sass +17 -1
- data/share/views/entity/Default.haml +1 -1
- data/share/views/form.haml +6 -6
- data/share/views/layout/header.haml +3 -3
- data/share/views/layout/top_menu.haml +1 -1
- data/share/views/partials/form.haml +1 -1
- data/share/views/public/js/rbbt.aes_plots.js +381 -0
- data/share/views/public/js/rbbt.aesthetics.js +14 -2
- data/share/views/public/js/rbbt.basic.js +36 -30
- data/share/views/public/js/rbbt.entity.basic.js +77 -0
- data/share/views/public/js/rbbt.entity_list.js +107 -47
- data/share/views/public/js/rbbt.exception.js +1 -1
- data/share/views/public/js/rbbt.knowledge_base.js +1 -1
- data/share/views/public/js/rbbt.plots.js +32 -20
- data/share/views/public/plugins/cytoscapejs/LICENSE +19 -0
- data/share/views/public/plugins/cytoscapejs/cytoscape.js +21248 -19688
- data/share/views/public/plugins/cytoscapejs/cytoscape.js.map +1 -0
- data/share/views/public/plugins/cytoscapejs/cytoscape.min.js +57 -0
- data/share/views/public/plugins/cytoscapejs/cytoscape.min.js.map +1 -0
- data/share/views/tasks.haml +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb820762ab31ca47b731784cc93f6826d057a79
|
4
|
+
data.tar.gz: e01a21750686b96449e811c9f42d2f01aaa8b00b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c411823107dd3b10a869354bcaee32c0e227cf4165e641c3936a19a0825f2f4b5c3c2a8b8c74369731511ff1d540ff259e8eda6666dd5512985e032f698f62
|
7
|
+
data.tar.gz: 88ecd5856f8550634fc58a134bb522025fe2e26a596350bdbec4eb373a533dad804f4ff004449ef08c9e8397f88da55ca60777aa6a244bd330cb1b8dd11b6c49
|
data/lib/rbbt/rest/entity.rb
CHANGED
@@ -460,8 +460,29 @@ module Sinatra
|
|
460
460
|
|
461
461
|
entity = setup_entity(entity_type, entity, @clean_params)
|
462
462
|
|
463
|
-
|
464
|
-
|
463
|
+
begin
|
464
|
+
res = entity.send(property,*args)
|
465
|
+
rescue
|
466
|
+
if entity.respond_to?(:format) and entity.base_type.respond_to?(:default_format) and entity.format != entity.base_type.default_format
|
467
|
+
entity = entity.to(:default)
|
468
|
+
Log.warn "Error computing property #{property} for #{entity}. Automatically changing entity format to default"
|
469
|
+
retry
|
470
|
+
else
|
471
|
+
raise $!
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
case res
|
476
|
+
when String
|
477
|
+
content_type "application/json"
|
478
|
+
halt 200, '"' + res + '"'
|
479
|
+
when Fixnum
|
480
|
+
content_type :text
|
481
|
+
halt 200, res.to_s
|
482
|
+
else
|
483
|
+
content_type "application/json"
|
484
|
+
halt 200, res.to_json
|
485
|
+
end
|
465
486
|
end
|
466
487
|
|
467
488
|
get '/entity_list_property/:property/:entity_type/:list_id' do
|
@@ -498,6 +519,52 @@ module Sinatra
|
|
498
519
|
halt 200, list.send(property, *args).to_json
|
499
520
|
end
|
500
521
|
|
522
|
+
post '/entity_list_property/:property/:entity_type' do
|
523
|
+
entity_type = consume_parameter :entity_type
|
524
|
+
property = consume_parameter :property
|
525
|
+
list = consume_parameter :list
|
526
|
+
info = consume_parameter :info
|
527
|
+
args = consume_parameter :args
|
528
|
+
|
529
|
+
info = (info.nil? or info.empty?) ? {} : JSON.parse(info)
|
530
|
+
entity_type = Entity::REST.restore_element(entity_type)
|
531
|
+
list = Misc.prepare_entity(list.split(/[,|]/), entity_type, info)
|
532
|
+
list.extend AnnotatedArray
|
533
|
+
|
534
|
+
args = (args.nil? or args.empty?) ? nil : begin JSON.parse(args) rescue args end
|
535
|
+
case args
|
536
|
+
when Hash
|
537
|
+
args = [args]
|
538
|
+
when String
|
539
|
+
args = args.split(/[,\|]/)
|
540
|
+
end
|
541
|
+
|
542
|
+
begin
|
543
|
+
res = list.send(property,*args)
|
544
|
+
rescue
|
545
|
+
if list.respond_to?(:format) and list.base_type.respond_to?(:default_format) and list.format != list.base_type.default_format
|
546
|
+
list = list.to(:default)
|
547
|
+
Log.warn "Error computing property #{property} for list. Automatically changing list format to default"
|
548
|
+
retry
|
549
|
+
else
|
550
|
+
raise $!
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
case res
|
555
|
+
when String
|
556
|
+
content_type "application/json"
|
557
|
+
halt 200, '"' + res + '"'
|
558
|
+
when Fixnum
|
559
|
+
content_type :text
|
560
|
+
halt 200, res.to_s
|
561
|
+
else
|
562
|
+
content_type "application/json"
|
563
|
+
halt 200, res.to_json
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
|
501
568
|
|
502
569
|
#{{{{{{{{{{{{{{
|
503
570
|
#{{{ FAVOURITES
|
@@ -39,6 +39,9 @@ module EntityRESTHelpers
|
|
39
39
|
params = {} if params.nil?
|
40
40
|
locals = {:entity => entity}.merge(params)
|
41
41
|
|
42
|
+
name = entity.respond_to?(:name)? entity.name : entity
|
43
|
+
@title = "#{name} [#{$title}]"
|
44
|
+
|
42
45
|
layout_file = layout ? locate_template("layout") : nil
|
43
46
|
|
44
47
|
render(template_file, locals, layout_file, "Entity: #{ entity }")
|
@@ -49,9 +52,12 @@ module EntityRESTHelpers
|
|
49
52
|
|
50
53
|
locals = params.merge({:entity => entity})
|
51
54
|
|
55
|
+
name = entity.respond_to?(:name)? entity.name : entity
|
56
|
+
@title = "#{action} #{name} [#{$title}]"
|
57
|
+
|
52
58
|
layout_file = layout ? locate_template("layout") : nil
|
53
59
|
|
54
|
-
render(template_file, locals, layout_file, "
|
60
|
+
render(template_file, locals, layout_file, "Action #{ action }: #{ entity }")
|
55
61
|
end
|
56
62
|
|
57
63
|
def entity_list_render(list, id)
|
@@ -59,6 +65,9 @@ module EntityRESTHelpers
|
|
59
65
|
|
60
66
|
locals = {:list => list, :list_id => id}
|
61
67
|
|
68
|
+
name = id
|
69
|
+
@title = "#{name} [#{$title}]"
|
70
|
+
|
62
71
|
layout_file = layout ? locate_template("layout") : nil
|
63
72
|
|
64
73
|
render(template_file, locals, layout_file, "Entity list: #{ id }")
|
@@ -69,9 +78,12 @@ module EntityRESTHelpers
|
|
69
78
|
|
70
79
|
locals = params.merge({:list => list, :list_id => id})
|
71
80
|
|
81
|
+
name = id
|
82
|
+
@title = "#{action} #{name} [#{$title}]"
|
83
|
+
|
72
84
|
layout_file = layout ? locate_template("layout") : nil
|
73
85
|
|
74
|
-
render(template_file, locals, layout_file, "
|
86
|
+
render(template_file, locals, layout_file, "Action #{ action } for list: #{ id }")
|
75
87
|
end
|
76
88
|
|
77
89
|
def entity_map_render(map_id, type, column)
|
@@ -80,6 +92,9 @@ module EntityRESTHelpers
|
|
80
92
|
map = Entity::Map.load_map(type, column, map_id, user)
|
81
93
|
locals = {:map => map, :map_id => map_id}
|
82
94
|
|
95
|
+
name = map_id
|
96
|
+
@title = "#{name} [#{$title}]"
|
97
|
+
|
83
98
|
layout_file = layout ? locate_template("layout") : nil
|
84
99
|
|
85
100
|
render(template_file, locals, layout_file, "Entity map: #{ map_id }")
|
@@ -90,9 +105,12 @@ module EntityRESTHelpers
|
|
90
105
|
|
91
106
|
locals = params.merge({:map => map, :map_id => id})
|
92
107
|
|
108
|
+
name = id
|
109
|
+
@title = "#{action} #{name} [#{$title}]"
|
110
|
+
|
93
111
|
layout_file = layout ? locate_template("layout") : nil
|
94
112
|
|
95
|
-
render(template_file, locals, layout_file, "
|
113
|
+
render(template_file, locals, layout_file, "Action #{ action } for map: #{ id }")
|
96
114
|
end
|
97
115
|
|
98
116
|
|
data/lib/rbbt/rest/main.rb
CHANGED
@@ -69,12 +69,11 @@ module Sinatra
|
|
69
69
|
before do
|
70
70
|
method = request.request_method
|
71
71
|
method_color = case method
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
72
|
+
when "GET"
|
73
|
+
:cyan
|
74
|
+
when "POST"
|
75
|
+
:yellow
|
76
|
+
end
|
78
77
|
|
79
78
|
Log.medium{ "#{Log.color method_color, method} #{Log.color(:blue, request.ip)}: " << request.path_info.gsub('/', Log.color(:blue, "/")) << ". Params: " << Log.color(:blue, Misc.fingerprint(params))}
|
80
79
|
process_common_parameters
|
@@ -88,12 +87,13 @@ module Sinatra
|
|
88
87
|
|
89
88
|
after do
|
90
89
|
method = request.request_method
|
90
|
+
|
91
91
|
method_color = case method
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
when "GET"
|
93
|
+
:cyan
|
94
|
+
when "POST"
|
95
|
+
:green
|
96
|
+
end
|
97
97
|
|
98
98
|
status = response.status.to_s
|
99
99
|
case status.to_i
|
data/lib/rbbt/rest/workflow.rb
CHANGED
@@ -45,6 +45,8 @@ body
|
|
45
45
|
overflow: auto
|
46
46
|
|
47
47
|
@media #{$only-large}
|
48
|
+
#top_menu > .item.title
|
49
|
+
margin-left: 32px
|
48
50
|
#top_menu > .favourite
|
49
51
|
white-space: nowrap
|
50
52
|
|
@@ -145,9 +147,9 @@ body
|
|
145
147
|
|
146
148
|
#content
|
147
149
|
margin-top: 2em
|
148
|
-
margin-left:
|
149
|
-
margin-right:
|
150
|
-
width: calc(100% - 2 *
|
150
|
+
margin-left: 16px !important
|
151
|
+
margin-right: 16px !important
|
152
|
+
width: calc(100% - 2 * 16px)
|
151
153
|
padding: 0px
|
152
154
|
|
153
155
|
.entity_card, .entity_list_card
|
@@ -54,8 +54,11 @@ table, table.responsive
|
|
54
54
|
.table_column_selector
|
55
55
|
span.field
|
56
56
|
font-size: 1.2em
|
57
|
-
width:
|
57
|
+
width: 15em
|
58
58
|
display: inline-block
|
59
|
+
overflow: hidden
|
60
|
+
text-overflow: ellipsis
|
61
|
+
margin-right: 2em
|
59
62
|
|
60
63
|
.figure
|
61
64
|
margin-bottom: 1em
|
@@ -207,3 +210,16 @@ td
|
|
207
210
|
span.choice
|
208
211
|
padding: 0.5em
|
209
212
|
cursor: pointer
|
213
|
+
|
214
|
+
ul.tasks
|
215
|
+
li
|
216
|
+
a
|
217
|
+
margin-right: 1em
|
218
|
+
overflow: hidden
|
219
|
+
text-overflow: ellipsis
|
220
|
+
|
221
|
+
.modal
|
222
|
+
.error.message
|
223
|
+
ul.stacktrace
|
224
|
+
li > span
|
225
|
+
margin-left: 0.5em
|
@@ -11,7 +11,7 @@
|
|
11
11
|
- if entity.respond_to? :genes
|
12
12
|
- genes = entity.genes
|
13
13
|
- list_container = ListContainer.new
|
14
|
-
- list_container.add "
|
14
|
+
- list_container.add "#{name} #{entity.base_type} genes", genes
|
15
15
|
- entity_card.list_container = list_container
|
16
16
|
|
17
17
|
- entity_card.action_controller = default_action_controller entity
|
data/share/views/form.haml
CHANGED
@@ -14,18 +14,18 @@
|
|
14
14
|
:markdown
|
15
15
|
#{task_info[:description]}
|
16
16
|
|
17
|
-
.form.action_parameters
|
17
|
+
.form.action_parameters.ui.segment
|
18
18
|
= partial_render('partials/form', :id => id, :action => action, :method => 'post',
|
19
19
|
:enctype => "multipart/form-data", :info => task_info, :klass => 'workflow_task')
|
20
20
|
|
21
21
|
- if workflow.libdir.examples[task.to_s].exists?
|
22
22
|
.examples
|
23
|
-
|
24
|
-
Click below to load example data:
|
25
|
-
|
26
23
|
:javascript
|
27
24
|
example_inputs = [];
|
28
|
-
|
25
|
+
|
26
|
+
Click to load example data:
|
27
|
+
|
28
|
+
%ul.ui.buttons
|
29
29
|
- workflow.libdir.examples[task.to_s].glob('*').each do |example_dir|
|
30
30
|
- name = File.basename(example_dir)
|
31
31
|
- task_info = workflow.task_info task
|
@@ -33,7 +33,7 @@
|
|
33
33
|
- inputs.each{ |k,v| v.replace Open.read(v) if String === v and File.exists? v }
|
34
34
|
:javascript
|
35
35
|
example_inputs["#{ name }"] = #{inputs.to_json}
|
36
|
-
%li
|
36
|
+
%li.ui.button
|
37
37
|
%a.load_example(href="#" task=task name=name)= name
|
38
38
|
|
39
39
|
:javascript
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
%link{:rel => "icon", :type => "image/gif", :href => "/favicon.gif"}/
|
6
6
|
|
7
|
-
%title= $title
|
7
|
+
%title= @title || $title
|
8
8
|
|
9
9
|
// Semantic-ui
|
10
10
|
|
@@ -62,10 +62,10 @@
|
|
62
62
|
- %w(dom_update fragment actions table list map reveal).each do |file|
|
63
63
|
- record_js "/js-find/rbbt/#{ file }"
|
64
64
|
|
65
|
-
- %w(rbbt rbbt.basic rbbt.exception rbbt.job rbbt.page rbbt.entity rbbt.entity_list rbbt.entity_map rbbt.views rbbt.favourites rbbt.modal).each do |file|
|
65
|
+
- %w(rbbt rbbt.basic rbbt.exception rbbt.job rbbt.page rbbt.entity.basic rbbt.entity rbbt.entity_list rbbt.entity_map rbbt.views rbbt.favourites rbbt.modal).each do |file|
|
66
66
|
- record_js "/js-find/#{ file }"
|
67
67
|
|
68
|
-
- %w(rbbt.knowledge_base rbbt.aesthetics rbbt.plots).each do |file|
|
68
|
+
- %w(rbbt.knowledge_base rbbt.aesthetics rbbt.plots rbbt.aes_plots).each do |file|
|
69
69
|
- record_js "/js-find/#{ file }"
|
70
70
|
|
71
71
|
- record_js "/js-find/app"
|
@@ -27,7 +27,7 @@
|
|
27
27
|
%div(class="field #{types[input]} #{input} #{hide ? 'hide' : ''}")
|
28
28
|
- input_options = options[input]
|
29
29
|
- input_options = input_options.dup unless input_options.nil?
|
30
|
-
|
30
|
+
!~ form_input(input, types[input], defaults[input], values[input], descriptions[input], input_id, input_options)
|
31
31
|
|
32
32
|
|
33
33
|
.input.field.submit
|
@@ -0,0 +1,381 @@
|
|
1
|
+
rbbt.plots.aes = {}
|
2
|
+
|
3
|
+
rbbt.plots.aes.get_properties = function(list, rules){
|
4
|
+
if (undefined === rules) rules == []
|
5
|
+
if (undefined === list.properties) list.properties = {}
|
6
|
+
var promises = []
|
7
|
+
forArray(rules, function(rule){
|
8
|
+
var name = rule.name
|
9
|
+
var extract = rule.extract
|
10
|
+
|
11
|
+
if (rule.entity_type && rule.entity_type != list.type) return
|
12
|
+
|
13
|
+
if (rule.info){
|
14
|
+
var property = rule.property
|
15
|
+
var deferred = m.deferred()
|
16
|
+
var entry = rule.info
|
17
|
+
if (undefined === name) name = entry
|
18
|
+
|
19
|
+
var value = list.info[entry]
|
20
|
+
if (undefined === value && entry == 'type') value = list.type
|
21
|
+
if (undefined === value && entry == 'code') value = list.codes
|
22
|
+
|
23
|
+
deferred.resolve(value)
|
24
|
+
promise = deferred.promise
|
25
|
+
}
|
26
|
+
|
27
|
+
if (rule.value){
|
28
|
+
var property = rule.property
|
29
|
+
var deferred = m.deferred()
|
30
|
+
deferred.resolve(rule.value)
|
31
|
+
promise = deferred.promise
|
32
|
+
}
|
33
|
+
|
34
|
+
if (rule.property){
|
35
|
+
var property = rule.property
|
36
|
+
var args = rule.args
|
37
|
+
if (undefined === name) name = property
|
38
|
+
promise = rbbt.entity_array.property(list.codes, list.type, list.info, property, args)
|
39
|
+
if (extract){ promise = promise.then(function(res){ return res.map(extract)}) }
|
40
|
+
}
|
41
|
+
|
42
|
+
if (rule.workflow){
|
43
|
+
var workflow = rule.workflow
|
44
|
+
var task = rule.task
|
45
|
+
var args = rule.args
|
46
|
+
if (undefined === name) name = task
|
47
|
+
promise = rbbt.job(workflow, task, args, true)
|
48
|
+
if (extract){ promise = promise.then(function(res){ return list.codes.map(function(code){return extract.call(null, res, code)}) } )}
|
49
|
+
}
|
50
|
+
|
51
|
+
if (rule.parents || rule.children){
|
52
|
+
var kb_type
|
53
|
+
var database
|
54
|
+
if (rule.parents){
|
55
|
+
kb_type = 'parent'
|
56
|
+
var database = rule.parents
|
57
|
+
if (undefined === name) name = database
|
58
|
+
|
59
|
+
promise = rbbt.entity_array.parents(list.codes, list.type, database)
|
60
|
+
}else{
|
61
|
+
kb_type = 'children'
|
62
|
+
var database = rule.children
|
63
|
+
if (undefined === name) name = database
|
64
|
+
|
65
|
+
promise = rbbt.entity_array.children(list.codes, list.type, database)
|
66
|
+
}
|
67
|
+
|
68
|
+
if (rule.field){
|
69
|
+
promise = m.sync([promise,rbbt.knowledge_base.database_info(database)]).then(function(res){
|
70
|
+
var data = res[0]
|
71
|
+
var db_info = res[1]
|
72
|
+
var fields = db_info.fields
|
73
|
+
var field_pos = fields.indexOf(rule.field)
|
74
|
+
|
75
|
+
if (field_pos < 0){
|
76
|
+
var msg = "Field not found: " + rule.field + ". Options: " + fields.join(", ")
|
77
|
+
throw new Error(msg)
|
78
|
+
}
|
79
|
+
|
80
|
+
var matches = {}
|
81
|
+
forHash(data, function(key, values){
|
82
|
+
var source = values[0]
|
83
|
+
var target = values[1]
|
84
|
+
if (matches[source] === undefined) matches[source] = {}
|
85
|
+
matches[source][target] = values[field_pos+2]
|
86
|
+
})
|
87
|
+
return matches
|
88
|
+
})
|
89
|
+
}else{
|
90
|
+
promise = promise.then(function(data){
|
91
|
+
var matches = {}
|
92
|
+
forHash(data, function(key, values){
|
93
|
+
var source = values[0]
|
94
|
+
var target = values[1]
|
95
|
+
if (matches[source] === undefined) matches[source] = {}
|
96
|
+
matches[source][target] = values.slice(2)
|
97
|
+
})
|
98
|
+
return matches
|
99
|
+
})
|
100
|
+
}
|
101
|
+
|
102
|
+
if (extract){
|
103
|
+
promise = promise.then(function(matches){
|
104
|
+
return list.codes.map(function(e){
|
105
|
+
return extract.call(null, matches, e)
|
106
|
+
})
|
107
|
+
})
|
108
|
+
}
|
109
|
+
else{
|
110
|
+
promise = promise.then(function(matches){
|
111
|
+
return list.codes.map(function(e){ return matches[e] })
|
112
|
+
})
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
promises.push(promise.then(function(res){list.properties[name] = res}))
|
117
|
+
})
|
118
|
+
|
119
|
+
return m.sync(promises)
|
120
|
+
}
|
121
|
+
|
122
|
+
rbbt.plots.aes.set_aes = function(list, aes_rules){
|
123
|
+
if (undefined === list.aes) list.aes = {}
|
124
|
+
forArray(aes_rules, function(rule){
|
125
|
+
|
126
|
+
if (rule.entity_type && rule.entity_type != list.type) return
|
127
|
+
|
128
|
+
|
129
|
+
var name = rule.name
|
130
|
+
var aes = rule.aes
|
131
|
+
var mapper = rule.mapper
|
132
|
+
var mapper_obj = rule.mapper_obj
|
133
|
+
var property = list.properties[name]
|
134
|
+
|
135
|
+
if (rule.value){
|
136
|
+
list.aes[aes] = rule.value
|
137
|
+
return
|
138
|
+
}
|
139
|
+
|
140
|
+
if (undefined === property && list.info[name]) property = list.info[name]
|
141
|
+
if (undefined === property && name == 'type') property = list.type
|
142
|
+
if (undefined === property && name == 'code') property = list.codes
|
143
|
+
if (undefined === property) return
|
144
|
+
|
145
|
+
list.aes[aes] = aes_module.map_aesthetic(property, mapper, mapper_obj)
|
146
|
+
})
|
147
|
+
}
|
148
|
+
|
149
|
+
rbbt.plots.aes.update_aes = function(graph_model){
|
150
|
+
var data_promises = []
|
151
|
+
forHash(graph_model.entities, function(type, list){
|
152
|
+
data_promises.push(
|
153
|
+
|
154
|
+
rbbt.plots.aes.get_properties(list, graph_model.rules).
|
155
|
+
then(function(){
|
156
|
+
rbbt.plots.aes.set_aes(list, graph_model.aes_rules)
|
157
|
+
})
|
158
|
+
|
159
|
+
)
|
160
|
+
})
|
161
|
+
|
162
|
+
forHash(graph_model.associations, function(db, list){
|
163
|
+
data_promises.push(
|
164
|
+
|
165
|
+
rbbt.plots.aes.get_properties(list, graph_model.edge_rules).
|
166
|
+
then(function(){
|
167
|
+
rbbt.plots.aes.set_aes(list, graph_model.edge_aes_rules)
|
168
|
+
})
|
169
|
+
|
170
|
+
)
|
171
|
+
})
|
172
|
+
return m.sync(data_promises)
|
173
|
+
}
|
174
|
+
|
175
|
+
//{{{ SUBSET
|
176
|
+
rbbt.plots.aes.subset = function(db,source,target){
|
177
|
+
var promise = rbbt.entity_array.subset(db,source,target)
|
178
|
+
var db_info = KB.database_info(db)
|
179
|
+
return m.sync([promise,db_info]).then(function(d){
|
180
|
+
var associations = d[0]
|
181
|
+
var info = d[1]
|
182
|
+
var fields = ['source', 'target'].concat(info.fields)
|
183
|
+
|
184
|
+
var edges = {}
|
185
|
+
edges.codes = []
|
186
|
+
edges.database = db
|
187
|
+
edges.source_type = info.source
|
188
|
+
edges.target_type = info.target
|
189
|
+
edges.source_info = info.source_entity_options
|
190
|
+
edges.target_info = info.target_entity_options
|
191
|
+
edges.info = {}
|
192
|
+
edges.info.database = db
|
193
|
+
edges.properties = {}
|
194
|
+
edges.aes = {}
|
195
|
+
|
196
|
+
for (i in fields)
|
197
|
+
edges.info[fields[i]] = []
|
198
|
+
|
199
|
+
forHash(associations, function(code, values){
|
200
|
+
edges.codes.push(code)
|
201
|
+
for(i in values){
|
202
|
+
var field = fields[i]
|
203
|
+
var value = values[i]
|
204
|
+
edges.info[field].push(value)
|
205
|
+
}
|
206
|
+
})
|
207
|
+
|
208
|
+
edges.aes['source'] = edges.info['source']
|
209
|
+
edges.aes['target'] = edges.info['target']
|
210
|
+
edges.aes['database'] = db
|
211
|
+
|
212
|
+
return edges
|
213
|
+
})
|
214
|
+
}
|
215
|
+
|
216
|
+
//{{{ CONSOLIDATION
|
217
|
+
|
218
|
+
rbbt.plots.aes.consolidate_list = function(list){
|
219
|
+
var nodes = []
|
220
|
+
|
221
|
+
var codes = list.codes
|
222
|
+
var info = list.info
|
223
|
+
var aes = list.aes
|
224
|
+
var properties = list.properties
|
225
|
+
|
226
|
+
for (i in codes){
|
227
|
+
var node = {}
|
228
|
+
node.code = codes[i]
|
229
|
+
forHash(aes, function(name, values){
|
230
|
+
var value
|
231
|
+
if (typeof values == 'object') value = values[i]
|
232
|
+
else value = values
|
233
|
+
node[name] = value
|
234
|
+
})
|
235
|
+
nodes.push(node)
|
236
|
+
}
|
237
|
+
|
238
|
+
return nodes
|
239
|
+
}
|
240
|
+
|
241
|
+
rbbt.plots.aes.consolidate_associations = function(list, database){
|
242
|
+
var edges = []
|
243
|
+
forHash(list,function(code, values){
|
244
|
+
var edge = {}
|
245
|
+
var source_code = values[0]
|
246
|
+
var target_code = values[1]
|
247
|
+
|
248
|
+
edge.source = source_code
|
249
|
+
edge.target = target_code
|
250
|
+
edge.database = database
|
251
|
+
|
252
|
+
edges.push(edge)
|
253
|
+
})
|
254
|
+
|
255
|
+
return edges
|
256
|
+
}
|
257
|
+
|
258
|
+
rbbt.plots.aes.consolidate_associations = function(list){
|
259
|
+
var nodes = []
|
260
|
+
|
261
|
+
var codes = list.codes
|
262
|
+
var info = list.info
|
263
|
+
var aes = list.aes
|
264
|
+
var properties = list.properties
|
265
|
+
var values = list.properties
|
266
|
+
|
267
|
+
for (i in codes){
|
268
|
+
var node = {}
|
269
|
+
node.code = codes[i]
|
270
|
+
forHash(aes, function(name, values){
|
271
|
+
var value
|
272
|
+
if (typeof values == 'object') value = values[i]
|
273
|
+
else value = values
|
274
|
+
node[name] = value
|
275
|
+
})
|
276
|
+
nodes.push(node)
|
277
|
+
}
|
278
|
+
|
279
|
+
return nodes
|
280
|
+
}
|
281
|
+
|
282
|
+
rbbt.plots.aes.consolidate = function(graph_model){
|
283
|
+
var model = {}
|
284
|
+
|
285
|
+
var nodes = []
|
286
|
+
|
287
|
+
forHash(graph_model.entities, function(type, list){
|
288
|
+
var list_nodes = rbbt.plots.aes.consolidate_list(list)
|
289
|
+
for (i in list_nodes) nodes.push(list_nodes[i])
|
290
|
+
})
|
291
|
+
|
292
|
+
var edges = []
|
293
|
+
forHash(graph_model.associations, function(database, list){
|
294
|
+
var list_edges = rbbt.plots.aes.consolidate_associations(list,database)
|
295
|
+
for (i in list_edges) edges.push(list_edges[i])
|
296
|
+
})
|
297
|
+
|
298
|
+
model.nodes = nodes
|
299
|
+
model.edges = edges
|
300
|
+
|
301
|
+
return model
|
302
|
+
}
|
303
|
+
|
304
|
+
//}}} CONSOLIDATION
|
305
|
+
|
306
|
+
|
307
|
+
rbbt.plots.aes.build_d3 = function(graph_model){
|
308
|
+
|
309
|
+
var model = rbbt.plots.aes.consolidate(graph_model)
|
310
|
+
|
311
|
+
var node_index = {}
|
312
|
+
for (i=0; i< model.nodes.length; i++) node_index[model.nodes[i].code] = i
|
313
|
+
|
314
|
+
for (i=0; i< model.edges.length; i++){
|
315
|
+
var edge = model.edges[i]
|
316
|
+
edge.source = node_index[edge.source]
|
317
|
+
edge.target = node_index[edge.target]
|
318
|
+
}
|
319
|
+
|
320
|
+
model.links = model.edges
|
321
|
+
model.edges = undefined
|
322
|
+
model.node_index = node_index
|
323
|
+
|
324
|
+
return model
|
325
|
+
}
|
326
|
+
|
327
|
+
rbbt.plots.aes.build_cytoscape = function(graph_model){
|
328
|
+
var model = rbbt.plots.aes.consolidate(graph_model)
|
329
|
+
|
330
|
+
var dataSchema = {nodes: [], edges:[]}
|
331
|
+
|
332
|
+
var node_vars = {}
|
333
|
+
for (i in model.nodes){
|
334
|
+
for (p in model.nodes[i]){
|
335
|
+
if (undefined !== model.nodes[i][p])
|
336
|
+
node_vars[p] = typeof model.nodes[i][p]
|
337
|
+
}
|
338
|
+
}
|
339
|
+
for (p in node_vars){
|
340
|
+
dataSchema.nodes.push({name: p, type: node_vars[p]})
|
341
|
+
}
|
342
|
+
|
343
|
+
node_vars = {}
|
344
|
+
for (i in model.edges){
|
345
|
+
for (p in model.edges[i]){
|
346
|
+
if (undefined !== model.edges[i][p])
|
347
|
+
node_vars[p] = typeof model.edges[i][p]
|
348
|
+
}
|
349
|
+
}
|
350
|
+
for (p in node_vars){
|
351
|
+
dataSchema.edges.push({name: p, type: node_vars[p]})
|
352
|
+
}
|
353
|
+
|
354
|
+
var cy_model = {}
|
355
|
+
cy_model.dataSchema = dataSchema
|
356
|
+
cy_model.data = model
|
357
|
+
|
358
|
+
return cy_model
|
359
|
+
}
|
360
|
+
|
361
|
+
rbbt.plots.aes.build_cytoscapejs = function(graph_model){
|
362
|
+
var model = rbbt.plots.aes.consolidate(graph_model)
|
363
|
+
|
364
|
+
var nodes = []
|
365
|
+
forArray(model.nodes, function(node){
|
366
|
+
nodes.push({data: node})
|
367
|
+
})
|
368
|
+
|
369
|
+
console.log(model.edges)
|
370
|
+
var edges = []
|
371
|
+
forArray(model.edges, function(edge){
|
372
|
+
edges.push({data: edge})
|
373
|
+
})
|
374
|
+
|
375
|
+
var cy_model = {}
|
376
|
+
cy_model.elements = {nodes: nodes, edges: edges}
|
377
|
+
|
378
|
+
console.log(cy_model)
|
379
|
+
return cy_model
|
380
|
+
}
|
381
|
+
|