-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from patrick204nqh/develop
[Update] Refactor and enhance Sequence Diagram processing and export functionality
- Loading branch information
Showing
39 changed files
with
731 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module TraceViz | ||
module Builders | ||
class BaseBuilder | ||
def build | ||
raise NotImplementedError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module TraceViz | ||
module Builders | ||
module Diagram | ||
class BaseBuilder | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require "trace_viz/managers/diagram/participant_manager" | ||
require "trace_viz/models/message" | ||
require_relative "base_builder" | ||
|
||
module TraceViz | ||
module Builders | ||
module Diagram | ||
class MessageBuilder < BaseBuilder | ||
def initialize(formatter, participants) | ||
super() | ||
@formatter = formatter | ||
@participants_manager = Managers::Diagram::ParticipantsManager.new(participants) | ||
end | ||
|
||
def build(type, from, to, content) | ||
Models::Message.new(type: type, from: from, to: to, content: content) | ||
end | ||
|
||
def build_call_message(from_trace, to_trace) | ||
return if from_trace.klass == to_trace.klass | ||
|
||
build( | ||
:call, | ||
participants_manager.find(from_trace.klass), | ||
participants_manager.find(to_trace.klass), | ||
formatter.format_call, | ||
) | ||
end | ||
|
||
def build_return_message(from_trace, to_trace) | ||
return if from_trace.klass == to_trace.klass | ||
|
||
build( | ||
:return, | ||
participants_manager.find(from_trace.klass), | ||
participants_manager.find(to_trace.klass), | ||
formatter.format_return, | ||
) | ||
end | ||
|
||
def build_loop_start_message(trace) | ||
build(:loop_start, nil, nil, "#{trace.count} calls") | ||
end | ||
|
||
def build_loop_end_message | ||
build(:loop_end, nil, nil, "") | ||
end | ||
|
||
def build_activate_message(trace) | ||
build(:activate, nil, participants_manager.find(trace.klass), "") | ||
end | ||
|
||
def build_deactivate_message(trace) | ||
build(:deactivate, nil, participants_manager.find(trace.klass), "") | ||
end | ||
|
||
def build_internal_message(trace) | ||
build( | ||
:call, | ||
participants_manager.find(trace.klass), | ||
participants_manager.find(trace.klass), | ||
trace.action, | ||
) | ||
end | ||
|
||
private | ||
|
||
attr_reader :formatter, :participants_manager | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require "trace_viz/models/diagram" | ||
require "trace_viz/extractors/diagram/participant_extractor" | ||
require "trace_viz/extractors/diagram/message_extractor" | ||
require_relative "base_builder" | ||
|
||
module TraceViz | ||
module Builders | ||
module Diagram | ||
class SequenceBuilder < BaseBuilder | ||
def initialize(collector) | ||
super() | ||
@collector = collector | ||
end | ||
|
||
def build | ||
diagram = Models::Diagram.new | ||
|
||
participants = Extractors::Diagram::ParticipantExtractor.new(collector).extract | ||
messages = Extractors::Diagram::MessageExtractor.new(collector, participants).extract | ||
|
||
participants.each { |p| diagram.add_participant(p) } | ||
messages.each { |m| diagram.add_message(m) } | ||
|
||
diagram | ||
end | ||
|
||
private | ||
|
||
attr_reader :collector | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module TraceViz | ||
module Exporters | ||
class MermaidExporter < BaseExporter | ||
private | ||
|
||
def renderer_mode | ||
:sequence_diagram | ||
end | ||
|
||
def file_extension | ||
".mmd" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module TraceViz | ||
module Extractors | ||
class BaseExtractor | ||
attr_reader :collector | ||
|
||
def initialize(collector) | ||
@collector = collector | ||
end | ||
|
||
def extract | ||
raise NotImplementedError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "trace_viz/transformers/summary_transformer" | ||
require "trace_viz/extractors/diagram/processors/sequence_node_processor" | ||
require_relative "../base_extractor" | ||
|
||
module TraceViz | ||
module Extractors | ||
module Diagram | ||
class MessageExtractor < BaseExtractor | ||
def initialize(collector, participants) | ||
super(collector) | ||
|
||
@node_processor = Processors::SequenceNodeProcessor.new(participants) | ||
end | ||
|
||
def extract | ||
root = data | ||
root.children.flat_map { |child| @node_processor.process_node(child) } | ||
end | ||
|
||
private | ||
|
||
def data | ||
@data ||= Transformers::SummaryTransformer.new(collector).transform | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "trace_viz/utils/alias_generator" | ||
require "trace_viz/models/participant" | ||
require_relative "../base_extractor" | ||
|
||
module TraceViz | ||
module Extractors | ||
module Diagram | ||
class ParticipantExtractor < BaseExtractor | ||
def extract | ||
unique_names = data.map(&:klass).uniq | ||
|
||
assigned_aliases = {} | ||
|
||
unique_names.map do |raw_name| | ||
alias_name = Utils::AliasGenerator.generate( | ||
name: raw_name, | ||
assigned_aliases: assigned_aliases, | ||
) | ||
|
||
Models::Participant.new( | ||
name: raw_name.to_s, | ||
alias_name: alias_name, | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def data | ||
collector.collection | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.