Refactoring
This commit is contained in:
@ -142,10 +142,22 @@ impl From<(Vec<GraphMapNodes>, Rc<translator::Translator>)> for GraphMapNodesTy
|
||||
|
||||
impl GraphMapNodesTy {
|
||||
pub fn generate<'a>(
|
||||
&self
|
||||
self
|
||||
) -> Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a>
|
||||
{
|
||||
todo!()
|
||||
let mut accumulator:
|
||||
Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a> =
|
||||
super::format_helpers::graph_map_nodes_ty_from::format_hide(
|
||||
Rc::clone(&self.translator)
|
||||
);
|
||||
for f in self.functions {
|
||||
accumulator = Box::new(move |i, n| {
|
||||
(accumulator)(i, n)
|
||||
+ &f(i, n)
|
||||
})
|
||||
}
|
||||
|
||||
accumulator
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,6 +167,7 @@ impl GraphMapNodesTy {
|
||||
/// Helper structure that specifies what information to display for edges
|
||||
#[derive(Clone)]
|
||||
pub enum GraphMapEdges {
|
||||
String { string: String },
|
||||
Hide,
|
||||
Products,
|
||||
MaskProducts { mask: RSset },
|
||||
@ -176,7 +189,8 @@ type GraphMapEdgesFnTy = dyn Fn(petgraph::prelude::EdgeIndex, &RSlabel) -> Strin
|
||||
/// Helper structure that holds a formatting function from node as RSsystem to
|
||||
/// string
|
||||
pub struct GraphMapEdgesTy {
|
||||
function: Box<GraphMapEdgesFnTy>
|
||||
function: Vec<Box<GraphMapEdgesFnTy>>,
|
||||
translator: Rc<translator::Translator>
|
||||
}
|
||||
|
||||
impl GraphMapEdgesTy {
|
||||
@ -194,6 +208,9 @@ impl GraphMapEdgesTy {
|
||||
// borrow to the struct, also translator needs to be in box, a reference
|
||||
// is not enough
|
||||
match f {
|
||||
String { string } => {
|
||||
format_string(translator, string)
|
||||
}
|
||||
Hide => {
|
||||
format_hide(translator)
|
||||
},
|
||||
@ -249,7 +266,7 @@ impl GraphMapEdgesTy {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Formatting Nodes & Edges
|
||||
// Color Nodes & Edges
|
||||
// -----------------------------------------------------------------------------
|
||||
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};
|
||||
|
||||
|
||||
@ -561,7 +561,7 @@ pub fn bisimilar(
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn generate_node_pringting_fn<'a>(
|
||||
fn generate_node_printing_fn<'a>(
|
||||
node_display: &[NodeDisplay],
|
||||
graph: &graph::RSgraph,
|
||||
translator: Rc<Translator>,
|
||||
@ -594,13 +594,15 @@ fn generate_node_pringting_fn<'a>(
|
||||
}
|
||||
).collect::<Vec<_>>();
|
||||
|
||||
let gmnt = graph::GraphMapNodesTy::from((node_display, Rc::clone(&translator)));
|
||||
let gmnt = graph::GraphMapNodesTy::from(
|
||||
(node_display, Rc::clone(&translator))
|
||||
);
|
||||
|
||||
gmnt.generate()
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn generate_edge_pringting_fn<'a>(
|
||||
fn generate_edge_printing_fn<'a>(
|
||||
edge_display: &'a Vec<EdgeDisplay>,
|
||||
translator: Rc<Translator>,
|
||||
) -> Box<dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a> {
|
||||
@ -707,10 +709,10 @@ pub fn dot(
|
||||
// this is awful but rust is not a functional language so its all
|
||||
// fine...
|
||||
let modified_graph = graph.map(
|
||||
generate_node_pringting_fn(&node_display,
|
||||
generate_node_printing_fn(&node_display,
|
||||
graph,
|
||||
Rc::clone(&rc_translator)),
|
||||
generate_edge_pringting_fn(&edge_display,
|
||||
generate_edge_printing_fn(&edge_display,
|
||||
Rc::clone(&rc_translator)),
|
||||
);
|
||||
|
||||
@ -751,10 +753,10 @@ pub fn graphml(
|
||||
|
||||
// map each value to the corresponding value we want to display
|
||||
let modified_graph = graph.map(
|
||||
generate_node_pringting_fn(&node_display,
|
||||
generate_node_printing_fn(&node_display,
|
||||
graph,
|
||||
Rc::clone(&rc_translator)),
|
||||
generate_edge_pringting_fn(&edge_display,
|
||||
generate_edge_printing_fn(&edge_display,
|
||||
rc_translator),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user