mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Switch to graphviz gem [SCI-5596]
This commit is contained in:
parent
0ba6eec73c
commit
f7c865974d
4 changed files with 36 additions and 26 deletions
2
Gemfile
2
Gemfile
|
@ -97,7 +97,7 @@ gem 'rufus-scheduler', '~> 3.5'
|
|||
|
||||
gem 'discard', '~> 1.0'
|
||||
|
||||
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
|
||||
gem 'graphviz'
|
||||
gem 'tinymce-rails', '~> 4.9.10' # Rich text editor - SEE BELOW
|
||||
# Any time you update tinymce-rails Gem, also update the cache_suffix parameter
|
||||
# in sitewide/tiny_mce.js - to prevent browsers from loading old, cached .js
|
||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -295,6 +295,8 @@ GEM
|
|||
gherkin (5.1.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
graphviz (1.2.1)
|
||||
process-pipeline
|
||||
hammerjs-rails (2.0.8)
|
||||
hashdiff (1.0.1)
|
||||
hashie (4.1.0)
|
||||
|
@ -416,6 +418,12 @@ GEM
|
|||
activerecord (>= 5.2)
|
||||
activesupport (>= 5.2)
|
||||
polyglot (0.3.5)
|
||||
process-group (1.2.3)
|
||||
process-terminal (~> 0.2.0)
|
||||
process-pipeline (1.0.2)
|
||||
process-group
|
||||
process-terminal (0.2.0)
|
||||
ffi
|
||||
pry (0.13.1)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
|
@ -529,8 +537,6 @@ GEM
|
|||
activesupport (>= 4.2.0)
|
||||
rack (>= 1.1)
|
||||
rubocop (>= 0.82.0)
|
||||
ruby-graphviz (1.2.5)
|
||||
rexml
|
||||
ruby-progressbar (1.11.0)
|
||||
ruby-vips (2.0.17)
|
||||
ffi (~> 1.9)
|
||||
|
@ -656,6 +662,7 @@ DEPENDENCIES
|
|||
faker
|
||||
fastimage
|
||||
figaro
|
||||
graphviz
|
||||
hammerjs-rails
|
||||
httparty (~> 0.17.3)
|
||||
i18n-js (~> 3.6)
|
||||
|
@ -702,7 +709,6 @@ DEPENDENCIES
|
|||
rubocop (= 0.83.0)
|
||||
rubocop-performance
|
||||
rubocop-rails
|
||||
ruby-graphviz (~> 1.2)
|
||||
rubyzip
|
||||
rufus-scheduler (~> 3.5)
|
||||
sanitize (~> 5.2)
|
||||
|
|
|
@ -10,7 +10,6 @@ class User < ApplicationRecord
|
|||
include InputSanitizeHelper
|
||||
include ActiveStorageConcerns
|
||||
|
||||
acts_as_token_authenticatable
|
||||
devise :invitable, :confirmable, :database_authenticatable, :registerable,
|
||||
:async, :recoverable, :rememberable, :trackable, :validatable,
|
||||
:timeoutable, :omniauthable, :lockable,
|
||||
|
|
|
@ -9,9 +9,7 @@ module Experiments
|
|||
|
||||
def initialize(experiment:)
|
||||
@exp = experiment
|
||||
graph_params = {
|
||||
type: :digraph,
|
||||
use: :neato,
|
||||
@graph_params = {
|
||||
inputscale: 3,
|
||||
size: '2,2',
|
||||
pad: '0.4',
|
||||
|
@ -22,15 +20,20 @@ module Experiments
|
|||
bgcolor: Constants::COLOR_CONCRETE,
|
||||
mode: 'ipsep'
|
||||
}
|
||||
@graph = GraphViz.new(:G, graph_params)
|
||||
@graph.node[color: Constants::COLOR_VOLCANO,
|
||||
style: :filled,
|
||||
fontcolor: Constants::COLOR_VOLCANO,
|
||||
shape: 'circle',
|
||||
fontname: 'Arial',
|
||||
fontsize: '16.0']
|
||||
@node_params = {
|
||||
color: Constants::COLOR_VOLCANO,
|
||||
style: :filled,
|
||||
fontcolor: Constants::COLOR_VOLCANO,
|
||||
shape: 'circle',
|
||||
fontname: 'Arial',
|
||||
fontsize: '16.0'
|
||||
}
|
||||
@edge_params = {
|
||||
color: Constants::COLOR_VOLCANO,
|
||||
penwidth: '3.0'
|
||||
}
|
||||
|
||||
@graph.edge[color: Constants::COLOR_VOLCANO, penwidth: '3.0']
|
||||
@graph = Graphviz::Graph.new('G', @graph_params)
|
||||
@errors = []
|
||||
end
|
||||
|
||||
|
@ -48,18 +51,18 @@ module Experiments
|
|||
|
||||
def draw_diagram
|
||||
# Draw grouped modules
|
||||
subg = {}
|
||||
@exp.my_module_groups.each_with_index do |group, gindex|
|
||||
subgraph_id = "cluster-#{gindex}"
|
||||
subg[subgraph_id] = @graph.subgraph
|
||||
nodes = {}
|
||||
|
||||
group.my_modules.workflow_ordered.each_with_index do |my_module, index|
|
||||
# draw nodes
|
||||
node = subg[subgraph_id].add_nodes(
|
||||
node = @graph.add_node(
|
||||
"#{subgraph_id}-#{index}",
|
||||
label: '',
|
||||
pos: "#{my_module.x / 10},-#{my_module.y / 10}!"
|
||||
@node_params.merge(
|
||||
label: '',
|
||||
pos: "#{my_module.x / 10},-#{my_module.y / 10}!"
|
||||
)
|
||||
)
|
||||
nodes[my_module.id] = node
|
||||
end
|
||||
|
@ -69,17 +72,19 @@ module Experiments
|
|||
m.outputs.each do |output|
|
||||
parent_node = nodes[m.id]
|
||||
child_node = nodes[output.input_id]
|
||||
subg[subgraph_id].add_edges(parent_node, child_node)
|
||||
parent_node.connect(child_node, @edge_params)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Draw orphan nodes
|
||||
@exp.my_modules.without_group.each do |my_module|
|
||||
@graph.subgraph.add_nodes(
|
||||
@graph.add_node(
|
||||
"Orphan-#{my_module.id}",
|
||||
label: '',
|
||||
pos: "#{my_module.x / 10},-#{my_module.y / 10}!"
|
||||
@node_params.merge(
|
||||
label: '',
|
||||
pos: "#{my_module.x / 10},-#{my_module.y / 10}!"
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -87,7 +92,7 @@ module Experiments
|
|||
def save_file
|
||||
file = Tempfile.open(%w(wimg .png), Rails.root.join('tmp'))
|
||||
begin
|
||||
@graph.output(png: file.path)
|
||||
Graphviz.output(@graph, path: file.path, format: 'png', dot: 'neato')
|
||||
file.rewind
|
||||
@exp.workflowimg.attach(io: file, filename: File.basename(file.path))
|
||||
ensure
|
||||
|
|
Loading…
Reference in a new issue