Class: SportsManager::SolutionDrawer::Mermaid::Graph
- Defined in:
- lib/sports_manager/solution_drawer/mermaid/graph.rb
Constant Summary collapse
- FIELDS =
%i[ subgraphs class_definitions subgraph_colorscheme ].freeze
- TEMPLATE =
<<~GRAPH.chomp graph LR %<class_definitions>s %<subgraph_colorscheme>s %<subgraphs>s GRAPH
- SUBGRAPH =
<<~GRAPH.chomp subgraph %<name>s direction LR %<nodes>s end GRAPH
- STYLE =
<<~GRAPH.chomp classDef %<class_definition>s GRAPH
- DEFAULT_STYLE_CONFIGURATIONS =
TODO: move to class and make dynamic based on input
{ class_definitions: [ 'court0 fill:#a9f9a9', 'court1 fill:#4ff7de', 'court_default fill:#aff7de' ], subgraph_colorscheme: [ 'COURT_0:::court0', 'COURT_1:::court1', 'COURT:::court_default', 'COURT_0 --- COURT_1 --- COURT' ] }.freeze
Instance Attribute Summary collapse
-
#configurations ⇒ Object
readonly
Returns the value of attribute configurations.
Class Method Summary collapse
Instance Method Summary collapse
- #add_class_definitions(class_definitions) ⇒ Object
- #add_configurations(configurations) ⇒ Object
- #add_subgraph_colorscheme(subgraph_colorscheme) ⇒ Object
- #add_subgraphs(subgraphs) ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
55 56 57 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 55 def initialize @configurations = {} end |
Instance Attribute Details
#configurations ⇒ Object (readonly)
Returns the value of attribute configurations.
7 8 9 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 7 def configurations @configurations end |
Class Method Details
.draw(configurations = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 49 def self.draw(configurations = {}) new .add_configurations(configurations) .draw end |
Instance Method Details
#add_class_definitions(class_definitions) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 80 def add_class_definitions(class_definitions) configurations[:class_definitions] = class_definitions .map { |class_definition| format(STYLE, class_definition: class_definition) } .join("\n") self end |
#add_configurations(configurations) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 63 def add_configurations(configurations) DEFAULT_STYLE_CONFIGURATIONS .merge(configurations) .slice(*FIELDS) .each { |field, value| public_send("add_#{field}", value) } self end |
#add_subgraph_colorscheme(subgraph_colorscheme) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 88 def add_subgraph_colorscheme(subgraph_colorscheme) nodes = subgraph_colorscheme.join("\n ") colorscheme = format(SUBGRAPH, name: 'colorscheme', nodes: nodes) configurations[:subgraph_colorscheme] = colorscheme self end |
#add_subgraphs(subgraphs) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/sports_manager/solution_drawer/mermaid/graph.rb', line 72 def add_subgraphs(subgraphs) configurations[:subgraphs] = subgraphs .map { |(name, nodes)| build_subgraph(name, nodes) } .join("\n") self end |