Skip to content

Commit 81ce8a8

Browse files
authored
Merge pull request #27 from azriel91/feature/interactive-tags
2 parents 0e5c3c1 + 6f52d38 commit 81ce8a8

File tree

20 files changed

+1557
-655
lines changed

20 files changed

+1557
-655
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* Reimplement playground for better responsive layout.
1212
* Take in `svg_extra` elements and insert into generated SVG.
1313
* Allow cluster edge ports to work correctly.
14+
* Take in `tags` which only include tag names.
15+
* Take in `tag_items` for nodes and edges instead of tags per node.
16+
* Support theming nodes based on tag focus.
1417

1518
[monaco]: https://github.com/microsoft/monaco-editor
1619
[rust-monaco]: https://github.com/siku2/rust-monaco

crate/model/src/common.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use self::{
55
edge::Edge,
66
edge_descs::EdgeDescs,
77
edge_id::{EdgeId, EdgeIdInvalidFmt},
8+
edge_tags_set::EdgeTagsSet,
89
edges::Edges,
910
graphviz_attrs::GraphvizAttrs,
1011
graphviz_dot_theme::GraphvizDotTheme,
@@ -13,8 +14,11 @@ pub use self::{
1314
node_hierarchy::NodeHierarchy,
1415
node_id::{NodeId, NodeIdInvalidFmt},
1516
node_names::NodeNames,
16-
node_tags::NodeTags,
17+
node_tags_set::NodeTagsSet,
1718
tag_id::{TagId, TagIdInvalidFmt},
19+
tag_items::TagItems,
20+
tag_names::TagNames,
21+
tag_styles::TagStyles,
1822
};
1923

2024
pub mod graphviz_attrs;
@@ -25,12 +29,16 @@ mod dot_src_and_styles;
2529
mod edge;
2630
mod edge_descs;
2731
mod edge_id;
32+
mod edge_tags_set;
2833
mod edges;
2934
mod id_newtype;
3035
mod node_descs;
3136
mod node_emojis;
3237
mod node_hierarchy;
3338
mod node_id;
3439
mod node_names;
35-
mod node_tags;
40+
mod node_tags_set;
3641
mod tag_id;
42+
mod tag_items;
43+
mod tag_names;
44+
mod tag_styles;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
use indexmap::{IndexMap, IndexSet};
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::common::{EdgeId, TagId};
7+
8+
/// Tags associated with each edge. `IndexMap<EdgeId, IndexSet<TagId>>` newtype.
9+
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
10+
pub struct EdgeTagsSet(IndexMap<EdgeId, IndexSet<TagId>>);
11+
12+
impl EdgeTagsSet {
13+
/// Returns a new `EdgeTags` map.
14+
pub fn new() -> Self {
15+
Self::default()
16+
}
17+
18+
/// Returns a new `EdgeTags` map with the given preallocated
19+
/// capacity.
20+
pub fn with_capacity(capacity: usize) -> Self {
21+
Self(IndexMap::with_capacity(capacity))
22+
}
23+
24+
/// Returns the underlying map.
25+
pub fn into_inner(self) -> IndexMap<EdgeId, IndexSet<TagId>> {
26+
self.0
27+
}
28+
}
29+
30+
impl Deref for EdgeTagsSet {
31+
type Target = IndexMap<EdgeId, IndexSet<TagId>>;
32+
33+
fn deref(&self) -> &Self::Target {
34+
&self.0
35+
}
36+
}
37+
38+
impl DerefMut for EdgeTagsSet {
39+
fn deref_mut(&mut self) -> &mut Self::Target {
40+
&mut self.0
41+
}
42+
}
43+
44+
impl From<IndexMap<EdgeId, IndexSet<TagId>>> for EdgeTagsSet {
45+
fn from(inner: IndexMap<EdgeId, IndexSet<TagId>>) -> Self {
46+
Self(inner)
47+
}
48+
}
49+
50+
impl FromIterator<(EdgeId, IndexSet<TagId>)> for EdgeTagsSet {
51+
fn from_iter<I: IntoIterator<Item = (EdgeId, IndexSet<TagId>)>>(iter: I) -> Self {
52+
Self(IndexMap::from_iter(iter))
53+
}
54+
}

crate/model/src/common/node_tags.rs renamed to crate/model/src/common/node_tags_set.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::common::{NodeId, TagId};
77

88
/// Tags associated with each node. `IndexMap<NodeId, IndexSet<TagId>>` newtype.
99
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
10-
pub struct NodeTags(IndexMap<NodeId, IndexSet<TagId>>);
10+
pub struct NodeTagsSet(IndexMap<NodeId, IndexSet<TagId>>);
1111

12-
impl NodeTags {
12+
impl NodeTagsSet {
1313
/// Returns a new `NodeTags` map.
1414
pub fn new() -> Self {
1515
Self::default()
@@ -27,27 +27,27 @@ impl NodeTags {
2727
}
2828
}
2929

30-
impl Deref for NodeTags {
30+
impl Deref for NodeTagsSet {
3131
type Target = IndexMap<NodeId, IndexSet<TagId>>;
3232

3333
fn deref(&self) -> &Self::Target {
3434
&self.0
3535
}
3636
}
3737

38-
impl DerefMut for NodeTags {
38+
impl DerefMut for NodeTagsSet {
3939
fn deref_mut(&mut self) -> &mut Self::Target {
4040
&mut self.0
4141
}
4242
}
4343

44-
impl From<IndexMap<NodeId, IndexSet<TagId>>> for NodeTags {
44+
impl From<IndexMap<NodeId, IndexSet<TagId>>> for NodeTagsSet {
4545
fn from(inner: IndexMap<NodeId, IndexSet<TagId>>) -> Self {
4646
Self(inner)
4747
}
4848
}
4949

50-
impl FromIterator<(NodeId, IndexSet<TagId>)> for NodeTags {
50+
impl FromIterator<(NodeId, IndexSet<TagId>)> for NodeTagsSet {
5151
fn from_iter<I: IntoIterator<Item = (NodeId, IndexSet<TagId>)>>(iter: I) -> Self {
5252
Self(IndexMap::from_iter(iter))
5353
}

crate/model/src/common/tag_items.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
use indexmap::IndexMap;
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::common::{AnyId, TagId};
7+
8+
/// Each tag and the items associated with it. `IndexMap<TagId, Vec<AnyId>>`
9+
/// newtype.
10+
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
11+
pub struct TagItems(IndexMap<TagId, Vec<AnyId>>);
12+
13+
impl TagItems {
14+
/// Returns a new `TagItems` map.
15+
pub fn new() -> Self {
16+
Self::default()
17+
}
18+
19+
/// Returns a new `TagItems` map with the given preallocated
20+
/// capacity.
21+
pub fn with_capacity(capacity: usize) -> Self {
22+
Self(IndexMap::with_capacity(capacity))
23+
}
24+
25+
/// Returns the underlying map.
26+
pub fn into_inner(self) -> IndexMap<TagId, Vec<AnyId>> {
27+
self.0
28+
}
29+
}
30+
31+
impl Deref for TagItems {
32+
type Target = IndexMap<TagId, Vec<AnyId>>;
33+
34+
fn deref(&self) -> &Self::Target {
35+
&self.0
36+
}
37+
}
38+
39+
impl DerefMut for TagItems {
40+
fn deref_mut(&mut self) -> &mut Self::Target {
41+
&mut self.0
42+
}
43+
}
44+
45+
impl From<IndexMap<TagId, Vec<AnyId>>> for TagItems {
46+
fn from(inner: IndexMap<TagId, Vec<AnyId>>) -> Self {
47+
Self(inner)
48+
}
49+
}
50+
51+
impl FromIterator<(TagId, Vec<AnyId>)> for TagItems {
52+
fn from_iter<I: IntoIterator<Item = (TagId, Vec<AnyId>)>>(iter: I) -> Self {
53+
Self(IndexMap::from_iter(iter))
54+
}
55+
}

crate/model/src/common/tag_names.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
use indexmap::IndexMap;
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::common::TagId;
7+
8+
/// Each tag and its name. `IndexMap<TagId, String>` newtype.
9+
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
10+
pub struct TagNames(IndexMap<TagId, String>);
11+
12+
impl TagNames {
13+
/// Returns a new `TagNames` map.
14+
pub fn new() -> Self {
15+
Self::default()
16+
}
17+
18+
/// Returns a new `TagNames` map with the given preallocated
19+
/// capacity.
20+
pub fn with_capacity(capacity: usize) -> Self {
21+
Self(IndexMap::with_capacity(capacity))
22+
}
23+
24+
/// Returns the underlying map.
25+
pub fn into_inner(self) -> IndexMap<TagId, String> {
26+
self.0
27+
}
28+
}
29+
30+
impl Deref for TagNames {
31+
type Target = IndexMap<TagId, String>;
32+
33+
fn deref(&self) -> &Self::Target {
34+
&self.0
35+
}
36+
}
37+
38+
impl DerefMut for TagNames {
39+
fn deref_mut(&mut self) -> &mut Self::Target {
40+
&mut self.0
41+
}
42+
}
43+
44+
impl From<IndexMap<TagId, String>> for TagNames {
45+
fn from(inner: IndexMap<TagId, String>) -> Self {
46+
Self(inner)
47+
}
48+
}
49+
50+
impl FromIterator<(TagId, String)> for TagNames {
51+
fn from_iter<I: IntoIterator<Item = (TagId, String)>>(iter: I) -> Self {
52+
Self(IndexMap::from_iter(iter))
53+
}
54+
}

crate/model/src/common/tag_styles.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
use indexmap::IndexMap;
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::{common::TagId, theme::ThemeStyles};
7+
8+
/// Each tag and styles for the items associated with it. `IndexMap<TagId,
9+
/// ThemeStyles>` newtype.
10+
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
11+
pub struct TagStyles(IndexMap<TagId, ThemeStyles>);
12+
13+
impl TagStyles {
14+
/// Returns a new `TagStyles` map.
15+
pub fn new() -> Self {
16+
Self::default()
17+
}
18+
19+
/// Returns a new `TagStyles` map with the given preallocated
20+
/// capacity.
21+
pub fn with_capacity(capacity: usize) -> Self {
22+
Self(IndexMap::with_capacity(capacity))
23+
}
24+
25+
/// Returns the underlying map.
26+
pub fn into_inner(self) -> IndexMap<TagId, ThemeStyles> {
27+
self.0
28+
}
29+
}
30+
31+
impl Deref for TagStyles {
32+
type Target = IndexMap<TagId, ThemeStyles>;
33+
34+
fn deref(&self) -> &Self::Target {
35+
&self.0
36+
}
37+
}
38+
39+
impl DerefMut for TagStyles {
40+
fn deref_mut(&mut self) -> &mut Self::Target {
41+
&mut self.0
42+
}
43+
}
44+
45+
impl From<IndexMap<TagId, ThemeStyles>> for TagStyles {
46+
fn from(inner: IndexMap<TagId, ThemeStyles>) -> Self {
47+
Self(inner)
48+
}
49+
}
50+
51+
impl FromIterator<(TagId, ThemeStyles)> for TagStyles {
52+
fn from_iter<I: IntoIterator<Item = (TagId, ThemeStyles)>>(iter: I) -> Self {
53+
Self(IndexMap::from_iter(iter))
54+
}
55+
}

0 commit comments

Comments
 (0)