Class: DecisionAgent::Dmn::GraphSvgGenerator
- Inherits:
-
Object
- Object
- DecisionAgent::Dmn::GraphSvgGenerator
- Defined in:
- lib/decision_agent/dmn/visualizer.rb
Overview
Generates SVG for decision graphs
Constant Summary collapse
- NODE_WIDTH =
180- NODE_HEIGHT =
70- HORIZONTAL_SPACING =
100- VERTICAL_SPACING =
120
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(decision_graph) ⇒ GraphSvgGenerator
constructor
A new instance of GraphSvgGenerator.
Constructor Details
#initialize(decision_graph) ⇒ GraphSvgGenerator
253 254 255 256 |
# File 'lib/decision_agent/dmn/visualizer.rb', line 253 def initialize(decision_graph) @graph = decision_graph @positions = {} end |
Instance Method Details
#generate ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/decision_agent/dmn/visualizer.rb', line 258 def generate calculate_graph_layout width = (@positions.values.map { |p| p[:x] }.max || 0) + NODE_WIDTH + 40 height = (@positions.values.map { |p| p[:y] }.max || 0) + NODE_HEIGHT + 40 svg = [ %(<svg xmlns="http://www.w3.org/2000/svg" width="#{width}" height="#{height}" viewBox="0 0 #{width} #{height}">), "<defs>", %( <marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">), %( <polygon points="0 0, 10 3, 0 6" fill="#666" />), " </marker>", "</defs>", "<g>" ] # Draw edges svg.concat(generate_edges) # Draw nodes svg.concat(generate_nodes) svg << "</g>" svg << "</svg>" svg.join("\n") end |