Skip to content

Commit

Permalink
Merge pull request #27 from azriel91/feature/interactive-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 authored Aug 4, 2024
2 parents 0e5c3c1 + 6f52d38 commit 81ce8a8
Show file tree
Hide file tree
Showing 20 changed files with 1,557 additions and 655 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Reimplement playground for better responsive layout.
* Take in `svg_extra` elements and insert into generated SVG.
* Allow cluster edge ports to work correctly.
* Take in `tags` which only include tag names.
* Take in `tag_items` for nodes and edges instead of tags per node.
* Support theming nodes based on tag focus.

[monaco]: https://github.com/microsoft/monaco-editor
[rust-monaco]: https://github.com/siku2/rust-monaco
Expand Down
12 changes: 10 additions & 2 deletions crate/model/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use self::{
edge::Edge,
edge_descs::EdgeDescs,
edge_id::{EdgeId, EdgeIdInvalidFmt},
edge_tags_set::EdgeTagsSet,
edges::Edges,
graphviz_attrs::GraphvizAttrs,
graphviz_dot_theme::GraphvizDotTheme,
Expand All @@ -13,8 +14,11 @@ pub use self::{
node_hierarchy::NodeHierarchy,
node_id::{NodeId, NodeIdInvalidFmt},
node_names::NodeNames,
node_tags::NodeTags,
node_tags_set::NodeTagsSet,
tag_id::{TagId, TagIdInvalidFmt},
tag_items::TagItems,
tag_names::TagNames,
tag_styles::TagStyles,
};

pub mod graphviz_attrs;
Expand All @@ -25,12 +29,16 @@ mod dot_src_and_styles;
mod edge;
mod edge_descs;
mod edge_id;
mod edge_tags_set;
mod edges;
mod id_newtype;
mod node_descs;
mod node_emojis;
mod node_hierarchy;
mod node_id;
mod node_names;
mod node_tags;
mod node_tags_set;
mod tag_id;
mod tag_items;
mod tag_names;
mod tag_styles;
54 changes: 54 additions & 0 deletions crate/model/src/common/edge_tags_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::ops::{Deref, DerefMut};

use indexmap::{IndexMap, IndexSet};
use serde::{Deserialize, Serialize};

use crate::common::{EdgeId, TagId};

/// Tags associated with each edge. `IndexMap<EdgeId, IndexSet<TagId>>` newtype.
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct EdgeTagsSet(IndexMap<EdgeId, IndexSet<TagId>>);

impl EdgeTagsSet {
/// Returns a new `EdgeTags` map.
pub fn new() -> Self {
Self::default()
}

/// Returns a new `EdgeTags` map with the given preallocated
/// capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self(IndexMap::with_capacity(capacity))
}

/// Returns the underlying map.
pub fn into_inner(self) -> IndexMap<EdgeId, IndexSet<TagId>> {
self.0
}
}

impl Deref for EdgeTagsSet {
type Target = IndexMap<EdgeId, IndexSet<TagId>>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for EdgeTagsSet {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<IndexMap<EdgeId, IndexSet<TagId>>> for EdgeTagsSet {
fn from(inner: IndexMap<EdgeId, IndexSet<TagId>>) -> Self {
Self(inner)
}
}

impl FromIterator<(EdgeId, IndexSet<TagId>)> for EdgeTagsSet {
fn from_iter<I: IntoIterator<Item = (EdgeId, IndexSet<TagId>)>>(iter: I) -> Self {
Self(IndexMap::from_iter(iter))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::common::{NodeId, TagId};

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

impl NodeTags {
impl NodeTagsSet {
/// Returns a new `NodeTags` map.
pub fn new() -> Self {
Self::default()
Expand All @@ -27,27 +27,27 @@ impl NodeTags {
}
}

impl Deref for NodeTags {
impl Deref for NodeTagsSet {
type Target = IndexMap<NodeId, IndexSet<TagId>>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for NodeTags {
impl DerefMut for NodeTagsSet {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<IndexMap<NodeId, IndexSet<TagId>>> for NodeTags {
impl From<IndexMap<NodeId, IndexSet<TagId>>> for NodeTagsSet {
fn from(inner: IndexMap<NodeId, IndexSet<TagId>>) -> Self {
Self(inner)
}
}

impl FromIterator<(NodeId, IndexSet<TagId>)> for NodeTags {
impl FromIterator<(NodeId, IndexSet<TagId>)> for NodeTagsSet {
fn from_iter<I: IntoIterator<Item = (NodeId, IndexSet<TagId>)>>(iter: I) -> Self {
Self(IndexMap::from_iter(iter))
}
Expand Down
55 changes: 55 additions & 0 deletions crate/model/src/common/tag_items.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::ops::{Deref, DerefMut};

use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::common::{AnyId, TagId};

/// Each tag and the items associated with it. `IndexMap<TagId, Vec<AnyId>>`
/// newtype.
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct TagItems(IndexMap<TagId, Vec<AnyId>>);

impl TagItems {
/// Returns a new `TagItems` map.
pub fn new() -> Self {
Self::default()
}

/// Returns a new `TagItems` map with the given preallocated
/// capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self(IndexMap::with_capacity(capacity))
}

/// Returns the underlying map.
pub fn into_inner(self) -> IndexMap<TagId, Vec<AnyId>> {
self.0
}
}

impl Deref for TagItems {
type Target = IndexMap<TagId, Vec<AnyId>>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for TagItems {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<IndexMap<TagId, Vec<AnyId>>> for TagItems {
fn from(inner: IndexMap<TagId, Vec<AnyId>>) -> Self {
Self(inner)
}
}

impl FromIterator<(TagId, Vec<AnyId>)> for TagItems {
fn from_iter<I: IntoIterator<Item = (TagId, Vec<AnyId>)>>(iter: I) -> Self {
Self(IndexMap::from_iter(iter))
}
}
54 changes: 54 additions & 0 deletions crate/model/src/common/tag_names.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::ops::{Deref, DerefMut};

use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::common::TagId;

/// Each tag and its name. `IndexMap<TagId, String>` newtype.
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct TagNames(IndexMap<TagId, String>);

impl TagNames {
/// Returns a new `TagNames` map.
pub fn new() -> Self {
Self::default()
}

/// Returns a new `TagNames` map with the given preallocated
/// capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self(IndexMap::with_capacity(capacity))
}

/// Returns the underlying map.
pub fn into_inner(self) -> IndexMap<TagId, String> {
self.0
}
}

impl Deref for TagNames {
type Target = IndexMap<TagId, String>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for TagNames {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<IndexMap<TagId, String>> for TagNames {
fn from(inner: IndexMap<TagId, String>) -> Self {
Self(inner)
}
}

impl FromIterator<(TagId, String)> for TagNames {
fn from_iter<I: IntoIterator<Item = (TagId, String)>>(iter: I) -> Self {
Self(IndexMap::from_iter(iter))
}
}
55 changes: 55 additions & 0 deletions crate/model/src/common/tag_styles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::ops::{Deref, DerefMut};

use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::{common::TagId, theme::ThemeStyles};

/// Each tag and styles for the items associated with it. `IndexMap<TagId,
/// ThemeStyles>` newtype.
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct TagStyles(IndexMap<TagId, ThemeStyles>);

impl TagStyles {
/// Returns a new `TagStyles` map.
pub fn new() -> Self {
Self::default()
}

/// Returns a new `TagStyles` map with the given preallocated
/// capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self(IndexMap::with_capacity(capacity))
}

/// Returns the underlying map.
pub fn into_inner(self) -> IndexMap<TagId, ThemeStyles> {
self.0
}
}

impl Deref for TagStyles {
type Target = IndexMap<TagId, ThemeStyles>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for TagStyles {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<IndexMap<TagId, ThemeStyles>> for TagStyles {
fn from(inner: IndexMap<TagId, ThemeStyles>) -> Self {
Self(inner)
}
}

impl FromIterator<(TagId, ThemeStyles)> for TagStyles {
fn from_iter<I: IntoIterator<Item = (TagId, ThemeStyles)>>(iter: I) -> Self {
Self(IndexMap::from_iter(iter))
}
}
Loading

0 comments on commit 81ce8a8

Please sign in to comment.