Skip to content

Commit

Permalink
Merge pull request #36 from azriel91/feature/node-sep-and-rank-sep
Browse files Browse the repository at this point in the history
Support `nodesep` and `ranksep`
  • Loading branch information
azriel91 authored Sep 27, 2024
2 parents 3a90c45 + 1467aa3 commit 92ab186
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[advisories]
ignore = [
# `proc-macro-error` is Unmaintained.
#
# Transitive dependency of `syn_derive`.
# Pending https://github.com/Kyuuhachi/syn_derive/issues/4.
"RUSTSEC-2024-0370",
]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Support inline images ([#33]).
* Support `splines` in `GraphvizAttrs`.
* Support `nodesep` in `GraphvizAttrs`.
* Support `ranksep` in `GraphvizAttrs`.


[#33]: https://github.com/azriel91/dot_ix/issues/33
Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,36 @@ dot_ix_static_check_macros = { version = "0.8.0", path = "crate/static_check_mac
dot_ix_web_components = { version = "0.8.0", path = "crate/web_components" }

# external crates
axum = "0.7.5"
axum = "0.7.6"
console_error_panic_hook = "0.1"
console_log = "1"
cfg-if = "1"
gloo-net = "0.6.0"
indexmap = "2.4.0"
indexmap = "2.5.0"
indoc = "2.0.5"
js-sys = "0.3.70"
web-sys = "0.3.70"
leptos = { version = "0.6" }
leptos_axum = "0.6"
leptos_meta = { version = "0.6" }
leptos_router = { version = "0.6" }
leptos-use = "0.12.0"
leptos-use = "0.13.5"
log = "0.4"
log4rs = { version = "1.3.0", default-features = false }
monaco = "0.4.0"
serde = "1.0.207"
serde = "1.0.210"
tempfile = "3.12.0"
tokio = "1.39.2"
tower = "0.5.0"
tokio = "1.40.0"
tower = "0.5.1"
wasm-bindgen = "0.2.93"
tailwind-css = "0.13.0"
thiserror = "1.0.63"
thiserror = "1.0.64"
tracing = "0.1.40"
http = "1.1.0"
proc-macro2 = "1.0.86"
quote = "1.0.36"
reqwest = "0.12.5"
syn = "2.0.74"
quote = "1.0.37"
reqwest = "0.12.7"
syn = "2.0.77"
serde_yaml = "0.9.34"

[workspace.lints.rust]
Expand Down
73 changes: 73 additions & 0 deletions crate/model/src/common/graphviz_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ mod splines;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(default)]
pub struct GraphvizAttrs {
/// Minimum space between two adjacent nodes in the same rank, in
/// inches. Also controls the spacing between multiple edges between the
/// same pair of nodes.
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// See [`nodesep`].
///
/// [`nodesep`]: https://graphviz.org/docs/attrs/nodesep/
pub nodesep: f64,
/// The desired separation between nodes of different ranks, in inches. See
/// [`ranksep`].
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// This does not support the `equally` string (yet). I'm not sure if it is
/// used.
///
/// [`ranksep`]: https://graphviz.org/docs/attrs/ranksep/
pub ranksep: f64,
/// How to render edge lines. See [`splines`].
///
/// [`splines`]: https://graphviz.org/docs/attrs/splines/
Expand Down Expand Up @@ -55,6 +75,34 @@ impl GraphvizAttrs {
Self::default()
}

/// Sets the minimum space between two adjacent nodes in the same rank, in
/// inches. Also controls the spacing between multiple edges between the
/// same pair of nodes.
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// See [`nodesep`].
///
/// [`nodesep`]: https://graphviz.org/docs/attrs/nodesep/
pub fn with_nodesep(mut self, nodesep: f64) -> Self {
self.nodesep = nodesep;
self
}

/// Sets the desired separation between nodes of different ranks, in inches.
/// See [`ranksep`].
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// This does not support the `equally` string (yet). I'm not sure if it is
/// used.
///
/// [`ranksep`]: https://graphviz.org/docs/attrs/ranksep/
pub fn with_ranksep(mut self, ranksep: f64) -> Self {
self.ranksep = ranksep;
self
}

/// Sets how to render edge lines. See [`splines`].
///
/// [`splines`]: https://graphviz.org/docs/attrs/splines/
Expand Down Expand Up @@ -111,6 +159,29 @@ impl GraphvizAttrs {
self
}

/// Returns the minimum space between two adjacent nodes in the same rank,
/// in inches. Also controls the spacing between multiple edges between
/// the same pair of nodes.
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// See [`nodesep`].
///
/// [`nodesep`]: https://graphviz.org/docs/attrs/nodesep/
pub fn nodesep(&self) -> f64 {
self.nodesep
}

/// Returns the desired separation between nodes of different ranks, in
/// inches. See [`ranksep`].
///
/// Defaults to `0.25`. Minimum `0.02`.
///
/// [`ranksep`]: https://graphviz.org/docs/attrs/ranksep/
pub fn ranksep(&self) -> f64 {
self.ranksep
}

/// Returns how to render edge lines. See [`splines`].
///
/// [`splines`]: https://graphviz.org/docs/attrs/splines/
Expand Down Expand Up @@ -164,6 +235,8 @@ impl GraphvizAttrs {
impl Default for GraphvizAttrs {
fn default() -> Self {
Self {
nodesep: 0.25,
ranksep: 0.25,
splines: Splines::default(),
edge_constraint_default: true,
edge_constraints: EdgeConstraints::default(),
Expand Down
2 changes: 1 addition & 1 deletion crate/model/src/common/id_newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ macro_rules! id_newtype {
/// compile time checks and returns a `const` value.
///
#[doc = concat!("[`", stringify!($macro_name), "!`]: dot_ix_static_check_macros::profile")]
pub fn new(s: &'static str) -> Result<Self, $ty_err_name> {
pub fn new(s: &'static str) -> Result<Self, $ty_err_name<'static>> {
Self::try_from(s)
}

Expand Down
7 changes: 4 additions & 3 deletions crate/rt/src/into_graphviz_dot_src/info_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ fn graph_attrs(
GraphDir::Vertical => "TB",
};

let nodesep = graphviz_attrs.nodesep();
let ranksep = graphviz_attrs.ranksep();
let splines = graphviz_attrs.splines();
let splines = match splines {
Splines::Unset => Cow::Borrowed(""),
Expand All @@ -250,9 +252,8 @@ fn graph_attrs(
compound = true
graph [
margin = 0.1
penwidth = 0
nodesep = 0.0
ranksep = 0.02
nodesep = {nodesep}
ranksep = {ranksep}
bgcolor = "transparent"
fontname = "helvetica"
packmode = "{pack_mode}"
Expand Down
6 changes: 5 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ yanked = "warn"
# A list of advisory IDs to ignore. Note that ignored advisories will still
# output a note when they are encountered.
ignore = [
#"RUSTSEC-0000-0000",
# `proc-macro-error` is Unmaintained.
#
# Transitive dependency of `syn_derive`.
# Pending https://github.com/Kyuuhachi/syn_derive/issues/4.
"RUSTSEC-2024-0370",
]

# If this is true, then cargo deny will use the git executable to fetch advisory database.
Expand Down
2 changes: 1 addition & 1 deletion playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ reqwest = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, optional = true }
tower = { workspace = true, optional = true }
tower-http = { version = "0.5", features = ["fs"], optional = true }
tower-http = { version = "0.6", features = ["fs"], optional = true }
tracing = { workspace = true, optional = true }
http = { workspace = true }
serde_yaml = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ use_field_init_shorthand = true
format_code_in_doc_comments = true
wrap_comments = true
edition = "2021"
version = "Two"
style_edition = "2021"

0 comments on commit 92ab186

Please sign in to comment.