Class: Aidp::Planning::Generators::GanttGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/planning/generators/gantt_generator.rb

Overview

Generates Mermaid Gantt charts with critical path analysis Visualizes project timeline, dependencies, and milestones

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ GanttGenerator

Returns a new instance of GanttGenerator.



11
12
13
# File 'lib/aidp/planning/generators/gantt_generator.rb', line 11

def initialize(config: nil)
  @config = config || Aidp::Config.waterfall_config
end

Instance Method Details

#format_mermaid(tasks, critical_path) ⇒ String

Format as Mermaid gantt syntax

Parameters:

  • gantt_data (Hash)

    Gantt chart data

Returns:

  • (String)

    Mermaid formatted chart



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/aidp/planning/generators/gantt_generator.rb', line 43

def format_mermaid(tasks, critical_path)
  Aidp.log_debug("gantt_generator", "format_mermaid")

  output = ["gantt"]
  output << "    title Project Timeline"
  output << "    dateFormat YYYY-MM-DD"
  output << "    section Planning"

  current_section = nil

  tasks.each do |task|
    if task[:phase] != current_section
      current_section = task[:phase]
      output << "    section #{current_section}"
    end

    status = critical_path.include?(task[:id]) ? "crit" : ""
    duration = task[:duration] || 1

    # Mermaid gantt task format: TaskName :status, id, start, duration
    if task[:dependencies].empty?
      output << "    #{task[:name]} :#{status}, #{task[:id]}, #{duration}d"
    else
      after_task = task[:dependencies].first.tr(" ", "_")
      output << "    #{task[:name]} :#{status}, #{task[:id]}, after #{after_task}, #{duration}d"
    end
  end

  output.join("\n")
end

#generate(wbs:, task_list: nil) ⇒ Hash

Generate Gantt chart from WBS and task list

Parameters:

  • wbs (Hash)

    Work breakdown structure

  • task_list (Array<Hash>) (defaults to: nil)

    Optional detailed task list

Returns:

  • (Hash)

    Gantt chart data and Mermaid syntax



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aidp/planning/generators/gantt_generator.rb', line 19

def generate(wbs:, task_list: nil)
  Aidp.log_debug("gantt_generator", "generate", phase_count: wbs[:phases].size)

  tasks = extract_tasks_from_wbs(wbs)
  calculate_durations(tasks)
  critical_path = calculate_critical_path(tasks)

  Aidp.log_debug("gantt_generator", "calculated", task_count: tasks.size, critical_path_length: critical_path.size)

  {
    tasks: tasks,
    critical_path: critical_path,
    mermaid: format_mermaid(tasks, critical_path),
    metadata: {
      generated_at: Time.now.iso8601,
      total_tasks: tasks.size,
      critical_path_length: critical_path.size
    }
  }
end