Sha256: 531b596d6fb9630a4638e47fb9b86581105b1a82e271e517cd38d66b638ea6b6
Contents?: true
Size: 1.82 KB
Versions: 6
Compression:
Stored size: 1.82 KB
Contents
module Gush class Graph attr_reader :workflow, :filename, :path, :start, :end_node def initialize(workflow, options = {}) @workflow = workflow @filename = options.fetch(:filename, "graph.png") @path = options.fetch(:path, Pathname.new(Dir.tmpdir).join(filename)) end def viz GraphViz.new(:G, graph_options) do |graph| set_node_options!(graph) set_edge_options!(graph) @start = graph.start(shape: 'diamond', fillcolor: '#CFF09E') @end_node = graph.end(shape: 'diamond', fillcolor: '#F56991') workflow.jobs.each do |job| add_job(graph, job) end graph.output(png: path) end end def path @path.to_s end private def add_job(graph, job) name = job.class.to_s graph.add_nodes(job.name, label: name) if job.incoming.empty? graph.add_edges(start, job.name) end if job.outgoing.empty? graph.add_edges(job.name, end_node) else job.outgoing.each do |id| outgoing_job = workflow.find_job(id) graph.add_edges(job.name, outgoing_job.name) end end end def set_node_options!(graph) node_options.each do |key, value| graph.node[key] = value end end def set_edge_options!(graph) edge_options.each do |key, value| graph.edge[key] = value end end def graph_options { type: :digraph, dpi: 200, compound: true, rankdir: "LR", center: true } end def node_options { shape: "ellipse", style: "filled", color: "#555555", fillcolor: "white" } end def edge_options { dir: "forward", penwidth: 1, color: "#555555" } end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
gush-2.0.2 | lib/gush/graph.rb |
gush-2.0.1 | lib/gush/graph.rb |
gush-2.0.0 | lib/gush/graph.rb |
gush-1.1.1 | lib/gush/graph.rb |
gush-1.1.0 | lib/gush/graph.rb |
gush-1.0.0 | lib/gush/graph.rb |