Skip to content

Commit c096ac6

Browse files
authored
Merge pull request #7 from azriel91/feature/support-additional-css
2 parents 06b0f79 + 220ffcd commit c096ac6

File tree

13 files changed

+374
-63
lines changed

13 files changed

+374
-63
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog
22

3-
## 0.1.1 (2024-02-17)
3+
## unreleased
44

55
* Split `dot_ix` library and `dot_ix_playground` binary.
6+
* Add `InfoGraph::builder` and `InfoGraphBuilder`.
7+
* Add `NodeId::new`.
68

79

810
## 0.1.0 (2024-02-04)

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ members = [
3434
]
3535

3636
[workspace.package]
37-
version = "0.1.1"
37+
version = "0.2.0"
3838
authors = ["Azriel Hoh <[email protected]>"]
3939
edition = "2021"
4040
homepage = "https://github.com/azriel91/dot_ix"
@@ -46,10 +46,10 @@ license = "MIT OR Apache-2.0"
4646

4747
[workspace.dependencies]
4848
# dot_ix crates
49-
dot_ix_model = { version = "0.1.1", path = "crate/model" }
50-
dot_ix_rt = { version = "0.1.1", path = "crate/rt" }
51-
dot_ix_static_check_macros = { version = "0.1.1", path = "crate/static_check_macros" }
52-
dot_ix_web_components = { version = "0.1.1", path = "crate/web_components" }
49+
dot_ix_model = { version = "0.2.0", path = "crate/model" }
50+
dot_ix_rt = { version = "0.2.0", path = "crate/rt" }
51+
dot_ix_static_check_macros = { version = "0.2.0", path = "crate/static_check_macros" }
52+
dot_ix_web_components = { version = "0.2.0", path = "crate/web_components" }
5353

5454
# external crates
5555
axum = "0.7.4"
@@ -66,7 +66,7 @@ leptos_meta = { version = "0.6" }
6666
leptos_router = { version = "0.6" }
6767
log = "0.4"
6868
log4rs = { version = "1.3.0", default-features = false }
69-
serde = "1.0.196"
69+
serde = "1.0.197"
7070
tempfile = "3.10.0"
7171
tokio = "1.36.0"
7272
tower = "0.4.13"
@@ -77,5 +77,5 @@ tracing = "0.1.40"
7777
http = "1.0.0"
7878
proc-macro2 = "1.0.78"
7979
quote = "1.0.35"
80-
syn = "2.0.49"
81-
serde_yaml = "0.9.31"
80+
syn = "2.0.50"
81+
serde_yaml = "0.9.32"

crate/model/src/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ pub use self::{
1212
tailwind_key::TailwindKey,
1313
};
1414

15+
pub mod graphviz_dot_theme;
16+
1517
mod any_id;
1618
mod dot_src_and_styles;
1719
mod edge;
1820
mod edge_id;
19-
mod graphviz_dot_theme;
2021
mod id_newtype;
2122
mod node_hierarchy;
2223
mod node_id;

crate/model/src/common/graphviz_dot_theme.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
pub use graph_style::GraphStyle;
2+
3+
mod graph_style;
4+
15
#[derive(Clone, Debug, PartialEq)]
26
pub struct GraphvizDotTheme {
7+
/// Style of graph to render.
8+
pub graph_style: GraphStyle,
9+
10+
/// The colour to use for graph edges.
311
pub edge_color: &'static str,
412

513
// Node attributes:
@@ -44,6 +52,86 @@ pub struct GraphvizDotTheme {
4452
}
4553

4654
impl GraphvizDotTheme {
55+
pub fn with_graph_style(mut self, graph_style: GraphStyle) -> Self {
56+
self.graph_style = graph_style;
57+
self
58+
}
59+
60+
pub fn with_edge_color(mut self, edge_color: &'static str) -> Self {
61+
self.edge_color = edge_color;
62+
self
63+
}
64+
65+
pub fn with_node_text_color(mut self, node_text_color: &'static str) -> Self {
66+
self.node_text_color = node_text_color;
67+
self
68+
}
69+
70+
pub fn with_node_width(mut self, node_width: f64) -> Self {
71+
self.node_width = node_width;
72+
self
73+
}
74+
75+
pub fn with_node_height(mut self, node_height: f64) -> Self {
76+
self.node_height = node_height;
77+
self
78+
}
79+
80+
pub fn with_node_margin_x(mut self, node_margin_x: f64) -> Self {
81+
self.node_margin_x = node_margin_x;
82+
self
83+
}
84+
85+
pub fn with_node_margin_y(mut self, node_margin_y: f64) -> Self {
86+
self.node_margin_y = node_margin_y;
87+
self
88+
}
89+
90+
pub fn with_plain_text_color(mut self, plain_text_color: &'static str) -> Self {
91+
self.plain_text_color = plain_text_color;
92+
self
93+
}
94+
95+
pub fn with_emoji_point_size(mut self, emoji_point_size: u32) -> Self {
96+
self.emoji_point_size = emoji_point_size;
97+
self
98+
}
99+
100+
pub fn with_node_point_size(mut self, node_point_size: u32) -> Self {
101+
self.node_point_size = node_point_size;
102+
self
103+
}
104+
105+
pub fn with_tag_width(mut self, tag_width: f64) -> Self {
106+
self.tag_width = tag_width;
107+
self
108+
}
109+
110+
pub fn with_tag_height(mut self, tag_height: f64) -> Self {
111+
self.tag_height = tag_height;
112+
self
113+
}
114+
115+
pub fn with_tag_margin_x(mut self, tag_margin_x: f64) -> Self {
116+
self.tag_margin_x = tag_margin_x;
117+
self
118+
}
119+
120+
pub fn with_tag_margin_y(mut self, tag_margin_y: f64) -> Self {
121+
self.tag_margin_y = tag_margin_y;
122+
self
123+
}
124+
125+
pub fn with_tag_point_size(mut self, tag_point_size: u32) -> Self {
126+
self.tag_point_size = tag_point_size;
127+
self
128+
}
129+
130+
pub fn with_tag_classes(mut self, tag_classes: &'static str) -> Self {
131+
self.tag_classes = tag_classes;
132+
self
133+
}
134+
47135
pub fn edge_color(&self) -> &str {
48136
self.edge_color
49137
}
@@ -108,6 +196,7 @@ impl GraphvizDotTheme {
108196
impl Default for GraphvizDotTheme {
109197
fn default() -> Self {
110198
Self {
199+
graph_style: GraphStyle::default(),
111200
edge_color: "#333333",
112201
node_text_color: "#111111",
113202
node_width: 0.3,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// The style of graph to render.
4+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
5+
pub enum GraphStyle {
6+
/// A rectangle is rendered for each node, with labels within them.
7+
#[default]
8+
Boxes,
9+
/// A circle is rendered for each node, with labels next to them.
10+
Circle,
11+
}

crate/model/src/common/tailwind_classes.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ impl TailwindClasses {
4747
[&>path]:focus:outline-lime-600 \
4848
[&>path]:focus:outline-dashed \
4949
[&>path]:focus:rounded-xl \
50+
[&>ellipse]:fill-slate-300 \
51+
[&>ellipse]:stroke-1 \
52+
[&>ellipse]:stroke-slate-600 \
53+
[&>ellipse]:hover:fill-slate-200 \
54+
[&>ellipse]:hover:stroke-slate-600 \
55+
[&>ellipse]:hover:stroke-2 \
56+
[&>ellipse]:focus:fill-lime-200 \
57+
[&>ellipse]:focus:outline-1 \
58+
[&>ellipse]:focus:outline-lime-600 \
59+
[&>ellipse]:focus:outline-dashed \
60+
[&>ellipse]:focus:rounded-xl \
5061
cursor-pointer \
5162
"
5263
.trim()

crate/model/src/info_graph.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,82 @@
1-
use indexmap::{IndexMap, IndexSet};
1+
pub use indexmap::{IndexMap, IndexSet};
2+
23
use serde::{Deserialize, Serialize};
34

45
use crate::common::{EdgeId, NodeHierarchy, NodeId, TagId, TailwindClasses};
56

6-
pub use self::{graph_dir::GraphDir, node_info::NodeInfo, tag::Tag};
7+
pub use self::{
8+
graph_dir::GraphDir, info_graph_builder::InfoGraphBuilder, node_info::NodeInfo, tag::Tag,
9+
};
710

811
mod graph_dir;
12+
mod info_graph_builder;
913
mod node_info;
1014
mod tag;
1115

1216
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1317
#[serde(default)]
1418
pub struct InfoGraph {
1519
/// Direction of the graph, `vertical` or `horizontal`.
16-
direction: GraphDir,
20+
pub(crate) direction: GraphDir,
1721
/// Nested nodes.
18-
hierarchy: NodeHierarchy,
22+
pub(crate) hierarchy: NodeHierarchy,
1923
/// Logical / ordering dependencies.
20-
edges: IndexMap<EdgeId, [NodeId; 2]>,
24+
pub(crate) edges: IndexMap<EdgeId, [NodeId; 2]>,
2125
/// List of nodes and basic node info.
22-
node_infos: IndexMap<NodeId, NodeInfo>,
26+
pub(crate) node_infos: IndexMap<NodeId, NodeInfo>,
2327
/// Tags associated with each node.
24-
node_tags: IndexMap<NodeId, IndexSet<TagId>>,
28+
pub(crate) node_tags: IndexMap<NodeId, IndexSet<TagId>>,
2529
/// Tags to associate with nodes.
26-
tags: IndexMap<TagId, Tag>,
30+
pub(crate) tags: IndexMap<TagId, Tag>,
2731
/// Tailwind classes to add to nodes with the given tag.
28-
tailwind_classes: TailwindClasses,
32+
pub(crate) tailwind_classes: TailwindClasses,
33+
/// Additional CSS to add in the spreadsheet.
34+
pub(crate) css: String,
2935
}
3036

3137
impl InfoGraph {
38+
/// Returns a builder to instantiate an `InfoGraph`.
39+
pub fn builder() -> InfoGraphBuilder {
40+
InfoGraphBuilder::default()
41+
}
42+
43+
/// Returns the direction of the graph, `vertical` or `horizontal`.
3244
pub fn direction(&self) -> GraphDir {
3345
self.direction
3446
}
3547

48+
/// Returns the nested nodes.
3649
pub fn hierarchy(&self) -> &NodeHierarchy {
3750
&self.hierarchy
3851
}
3952

53+
/// Returns the logical / ordering dependencies.
4054
pub fn edges(&self) -> &IndexMap<EdgeId, [NodeId; 2]> {
4155
&self.edges
4256
}
4357

58+
/// Returns the list of nodes and basic node info.
4459
pub fn node_infos(&self) -> &IndexMap<NodeId, NodeInfo> {
4560
&self.node_infos
4661
}
4762

63+
/// Returns the tags associated with each node.
4864
pub fn node_tags(&self) -> &IndexMap<NodeId, IndexSet<TagId>> {
4965
&self.node_tags
5066
}
5167

68+
/// Returns the tags to associate with nodes.
5269
pub fn tags(&self) -> &IndexMap<TagId, Tag> {
5370
&self.tags
5471
}
5572

73+
/// Returns the tailwind classes to add to nodes with the given tag.
5674
pub fn tailwind_classes(&self) -> &TailwindClasses {
5775
&self.tailwind_classes
5876
}
77+
78+
/// Returns the additional CSS to add in the spreadsheet.
79+
pub fn css(&self) -> &str {
80+
&self.css
81+
}
5982
}

0 commit comments

Comments
 (0)