Skip to content

Commit 3669dfd

Browse files
mtsrjakobhellermann
authored andcommitted
Use existing html_escape & minor style changes
1 parent 45b8fef commit 3669dfd

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

src/dot.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ pub fn font_tag(text: &str, color: &str, size: u8) -> String {
1919
)
2020
}
2121

22-
fn html_escape(input: &str) -> String {
23-
input.replace('<', "&lt;").replace('>', "&gt;")
22+
pub fn html_escape(input: &str) -> String {
23+
input
24+
.replace("&", "&amp;")
25+
.replace("\"", "&quot;")
26+
.replace('<', "&lt;")
27+
.replace('>', "&gt;")
2428
}
2529

2630
impl DotGraph {

src/render_graph.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
use std::borrow::Cow;
2-
31
use crate::{
4-
dot::{font_tag, DotGraph},
2+
dot::{font_tag, html_escape, DotGraph},
53
utils,
64
};
75
use bevy::render::render_graph::{Edge, NodeId, RenderGraph};
86
use itertools::{EitherOrBoth, Itertools};
97

10-
/// Escape tags in such a way that it is suitable for inclusion in a
11-
/// Graphviz HTML label.
12-
pub fn escape_html<'a, S>(s: S) -> Cow<'a, str>
13-
where
14-
S: Into<Cow<'a, str>>,
15-
{
16-
s.into()
17-
.replace("&", "&amp;")
18-
.replace("\"", "&quot;")
19-
.replace("<", "&lt;")
20-
.replace(">", "&gt;")
21-
.into()
22-
}
23-
248
pub fn render_graph_dot(graph: &RenderGraph) -> String {
259
let options = [("rankdir", "LR"), ("ranksep", "1.0")];
2610
let mut dot = DotGraph::new("RenderGraph", &options);
@@ -47,9 +31,9 @@ pub fn render_graph_dot(graph: &RenderGraph) -> String {
4731
.map(|(index, slot)| {
4832
format!(
4933
"<TD PORT=\"{}\">{}: {}</TD>",
50-
escape_html(format!("{}", index)),
51-
escape_html(slot.info.name.clone()),
52-
escape_html(format!("{:?}", slot.info.resource_type))
34+
html_escape(&format!("{}", index)),
35+
html_escape(&slot.info.name),
36+
html_escape(&format!("{:?}", slot.info.resource_type))
5337
)
5438
})
5539
.collect::<Vec<_>>();
@@ -60,10 +44,10 @@ pub fn render_graph_dot(graph: &RenderGraph) -> String {
6044
.enumerate()
6145
.map(|(index, slot)| {
6246
format!(
63-
"<TD PORT=\"{}\">{}: {:?}</TD>",
64-
escape_html(format!("{}", index)),
65-
escape_html(slot.info.name.clone()),
66-
escape_html(format!("{:?}", slot.info.resource_type))
47+
"<TD PORT=\"{}\">{}: {}</TD>",
48+
html_escape(&format!("{}", index)),
49+
html_escape(&slot.info.name),
50+
html_escape(&format!("{:?}", slot.info.resource_type))
6751
)
6852
})
6953
.collect::<Vec<_>>();
@@ -83,9 +67,9 @@ pub fn render_graph_dot(graph: &RenderGraph) -> String {
8367
.collect::<String>();
8468

8569
let label = format!(
86-
"<<TABLE><TR><TD PORT=\"title\" BORDER=\"0\" COLSPAN=\"2\">{}<BR/>{}</TD></TR>{}</TABLE>>",
87-
escape_html(name),
88-
font_tag(&escape_html(&type_name), "red", 10),
70+
"<<TABLE STYLE=\"rounded\"><TR><TD PORT=\"title\" BORDER=\"0\" COLSPAN=\"2\">{}<BR/>{}</TD></TR>{}</TABLE>>",
71+
html_escape(name),
72+
font_tag(&type_name, "red", 10),
8973
slots,
9074
);
9175

@@ -101,9 +85,6 @@ pub fn render_graph_dot(graph: &RenderGraph) -> String {
10185
output_node,
10286
output_index,
10387
} => {
104-
let input = graph.get_node_state(*input_node).unwrap();
105-
let input_slot = &input.input_slots.iter().nth(*input_index).unwrap().info;
106-
10788
dot.add_edge(
10889
&node_id(output_node),
10990
Some(&format!("{}:e", output_index)),
@@ -121,7 +102,7 @@ pub fn render_graph_dot(graph: &RenderGraph) -> String {
121102
Some("title:e"),
122103
&node_id(input_node),
123104
Some("title:w"),
124-
&[("style", "dashed")],
105+
&[],
125106
);
126107
}
127108
}

0 commit comments

Comments
 (0)