From f7c865974da5a04ab2da7de5aaca6c0d8efe8f1d Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 25 Mar 2021 17:42:57 +0100 Subject: [PATCH] Switch to graphviz gem [SCI-5596] --- Gemfile | 2 +- Gemfile.lock | 12 +++-- app/models/user.rb | 1 - .../generate_workflow_image_service.rb | 47 ++++++++++--------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index 94e51f529..0c6fe59d3 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 4f665e982..43a3f6eaa 100644 --- a/Gemfile.lock +++ b/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) diff --git a/app/models/user.rb b/app/models/user.rb index b0d149ff9..44fea297f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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, diff --git a/app/services/experiments/generate_workflow_image_service.rb b/app/services/experiments/generate_workflow_image_service.rb index b8c5ddb1f..47f83019e 100644 --- a/app/services/experiments/generate_workflow_image_service.rb +++ b/app/services/experiments/generate_workflow_image_service.rb @@ -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