Skip to content

Commit

Permalink
Merge pull request #84 from zHaytam/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
zHaytam authored Mar 24, 2021
2 parents de5c31a + efd551a commit d923bb4
Show file tree
Hide file tree
Showing 164 changed files with 5,350 additions and 1,823 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,5 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.vscode/symbols.json
.vscode/settings.json
9 changes: 9 additions & 0 deletions Blazor.Diagrams.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CEEAE4C2-CE68-4FC3-9E0F-D4781B91F7F4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Diagrams.Core.Tests", "tests\Blazor.Diagrams.Core.Tests\Blazor.Diagrams.Core.Tests.csproj", "{36B4DCCD-45AB-4338-9224-DDAF386A23A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -55,6 +59,10 @@ Global
{CB3A42B6-3C87-4ECB-B60C-D98275AB1FB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB3A42B6-3C87-4ECB-B60C-D98275AB1FB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB3A42B6-3C87-4ECB-B60C-D98275AB1FB6}.Release|Any CPU.Build.0 = Release|Any CPU
{36B4DCCD-45AB-4338-9224-DDAF386A23A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36B4DCCD-45AB-4338-9224-DDAF386A23A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36B4DCCD-45AB-4338-9224-DDAF386A23A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36B4DCCD-45AB-4338-9224-DDAF386A23A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -66,6 +74,7 @@ Global
{1CBCC8E6-111C-4364-9882-50881E4CC8B4} = {DA819127-3EF6-4EB9-A2DA-BC056B284A50}
{B9EE910B-8FE7-490C-B20C-CEC27A2890D6} = {DA819127-3EF6-4EB9-A2DA-BC056B284A50}
{CB3A42B6-3C87-4ECB-B60C-D98275AB1FB6} = {EE32E278-A887-454E-987D-FFE9E37169FE}
{36B4DCCD-45AB-4338-9224-DDAF386A23A3} = {CEEAE4C2-CE68-4FC3-9E0F-D4781B91F7F4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {969540A2-8162-4063-A4E3-B488F69BD582}
Expand Down
130 changes: 130 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,136 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Diagrams (2.0.0) - 2021-03-24

## Added

- `GroupUngrouped` event (not the greatest name 😄)
- Touch events `TouchStart`, `TouchMove` and `TouchEnd`
- Mobile support
- Dragging new links from ports
- Selecting models
- Panning
- Dragging movables
- `RemoveGroup` method to delete a group and all its children
- Pressing DEL on a selected group will now remove it
- Ability for links to be segmentable (by setting `Segmentable` to `true`)
- Clicking a segmentable link will add a new vertex in that position
- Vertices are movable models, which mean you can drag them to reposition them
- Double clicking a vertex will delete it
- Link routers
- Routers are functions that take into account a link's vertices, and decide whether to add more points along the path
- They are specified using `Options.Links.DefaultRouter` or by setting `Router` in links
- There are currently two routers, `Routers.Normal` and `Routers.Orthogonal`
- You can provide your own router by simply respecting the delegate `Router`
- Link path generators
- Path generators are functions that takes as input a link's route, and return a list of generated SVG paths (strings), as well as the position and angle of the source/target markers
- They are specified using `Options.Links.DefaultPathGenerator` or by setting `PathGenerator` in links
- There are currently two generators, `PathGenerators.Straight` and `PathGenerators.Smooth`
- You can provide your own generator by simply respecting the delegate `PathGenerator`
- On-the-fly link markers
- A link can either have a `SourceMarker` or `TargetMarker`
- Link markers are SVG Paths with a known width (to calculate angle and where to cut the links)
- Static markers are available (e.g. `LinkMarker.Arrow`) as well as utility methods to create known shapes
- `MouseClick` event, which only fires if the model (or canvas) in question didn't move, as opposed to MouseUp
- `data-X-id` HTML attributes to nodes, ports and links
- Abstract `BaseLinkModel`, `LinkModel` now inherits from it
- All the parts of the library now refer to `BaseLinkModel` instead of `LinkModel` (e.g. PortModel.Links)
- `Color`, `SelectedColor` and `Width` properties to `LinkModel`
- Link labels
- Can have custom models, using `RegisterModelComponent`
- Due to the limitation of SVGs in Blazor, labels aren't interactive and must be created using `MarkupString`
- They can have a specified distance
- A number between 0 and 1: Position relative to the link's length
- A positive number, greater than 1: Position away from the start
- A negative number, less than 0: Position away from the end
- They can have an offset (Point)
- Link snapping
- While the user is dragging a link, it will try to find the closest port it can attach the link to
- Options (in `DiagramOptions.Links`): `EnableSnapping` and `SnappingRadius`
- `GetBounds` extension method on `IEnumerable<NodeModel>`
- Expose `Padding` property in `GroupModel`
- `Factory` option to `Options.Links`
- This is a delegate (`BaseLinkModel LinkFactory(DiagramManager diagram, PortModel sourcePort)`) to let you control how links are created
- `Groups` (of type `DiagramGroupOptions`) option to `DiagramOptions`
- `Enabled` option controls whether users are allow to group nodes together or not
- `KeyboardShortcut` (`Func<KeyboardEventArgs, bool>`) controls what keys need to be pressed to trigger the behavior
- `Factory` lets you control how groups are created
- `GetRelativePoint` method to `Diagram`
- This method gives the relative mouse point on the canvas
- `SelectionBoxWidget`
- If used, holding SHIFT and clicking then dragging will show a selection box that selects all models intersecting with it
- Minified versions of all assets
- Observe document body mutations to update canvas container
- Ability to add/remove children after the group is created
- `Diagram` now also inherits `Model`
- Ability to suspend refreshes in `Diagram` by setting `Diagram.SuspendRefresh` to `true`
- As the name suggests, this will stop the method `Refresh` from triggering the event `Changed`, which tries to re-render the UI
- `Batch(Action action)` in `Diagram`.
- This is just a helper method that suspends refreshes, runs the action and then refreshes
- This is now used internally in node/link layers to only trigger 1 UI re-render
- Add `FillColor` parameter to `NavigatorWidget`
- Ability to create links between two nodes directly, without needing ports
- This depends on the shape of the nodes, which can be defined by providing a `ShapeDefiner` in `NodeModel`'s constructor
- The default shape definer is `Shapes.Rectangle`
- Currently, there is only the Rectangle and Ellipse (including Circle) shapes, others will be added later
- This also works for groups, since groups are nodes
- Unit tests

## Changed

- Renamed `DiagramManager` to `Diagram`
- Remove need to specify `Name` in diagram's `CascadingValue`
- Separate Nodes/Links from DiagramManager, they are now layers (`Diagram.Nodes` and `Diagram.Links`)
- - Adding/Removing nodes or links is now done inside these layers (e.g. `Diagram.Nodes.Add`)
- Added/Removed events are now inside these layers, not in the diagram (e.g. `Diagram.Links.Added`)
- `LinkAttached` event removed (`TargetPortChanged` is the alternative)
- It is now mandatory to add nodes to diagram before creating groups
- `SelectionChanged` event only contains the model now, use `Selected` property
- Removed `SelectedModels` in favor of `GetSelectedModels()`, this is because we don't hold a list of selected models anymore (unnecessary)
- Renamed `DiagramSubManager` to `Behavior`, it makes more sense
- `RegisterBehavior` now takes as an argument the behavior instance to add. No need to use `Activator.CreateInstance` for something like this, as it just slows things down
- Removed `LinkType` enum
- Removed `DefaultLinkType` link option
- Removed `DefaultLinkModel` link option
- Removed `GetNodesRect` method from DiagramManager (use `GetBounds`)
- Removed diagram dependency from `GroupModel` (was only using `GetNodesRect`)
- Renamed `GetRelativePoint` to `GetRelativeMousePoint`
- This method gives the relative mouse point inside the diagram, taking into account the current pan & zoom
- `Widgets` are inside the `DiagramCanvas` now
- This change is necessary so that widgets with absolute position have their relative parent be the canvas
- Renamed `Navigator` widget to `NavigatorWidget`
- Allow empty groups
- Compare received JS sizes (width and height) with precision of 0.0001
- In most cases, sizes retrieved from JS (especially with a zoom <> 1) can't be compared accurately (e.g. `80` and `79.9999975`). We fix this by comparing with a tolerance.
- Update ports dimensions only if Initialized is false
- This avoids useless re-renders/JS calls when node is re-visible
- `NodeModel.Ports` is now a `IReadOnlyList<PortModel>`
- `BaseLinkModelExtensions` is now obsolete
- Moved everything in `Blazor.Diagrams.Core.Models.Core` to `Blazor.Diagrams.Core.Geometry`
- This includes `Point`, `Size` and `Rectangle`
- This is to better structure things in the project, the new `Geometry` namespace will contain many other things related to it
- Only render links when ports/nodes are initialized (position and/or size received)
- This will avoid the weird flicker where links show at (0, 0) then move to the correct position

## Fixed

- Remove links when groups are removed
- Issue where links are clickable outside the visible stroke
- `pointer-events` is now set to `visiblePainted` instead of `all`
- `MouseUp` event bubbles up from `PortModel` to `NodeModel`
- `Size` not taking into account zoom when nodes become visible again
- Only allow link creation using left mouse button
- JS errors in razor pages without a diagram
- CustomNodeWidget was movable from text input
- All users who create custom nodes with HTML inputs should use `x:stopPropagation` on `mousedown`, `mousemove` and `mouseup` to prevent the node from being movable through inputs.
- Deleted nodes from groups would still show them
- `NavigatorWidget` not handling negative node positions
- Panning with right click. It is now disallowed
- PortRender not taking into account its parent's `RenderLayer`
- Ports on SVG nodes will now render as `<g>` elements
- Useless refreshes when diagram `Container` values didn't change

## Diagrams [1.5.2] - 2021-01-18

## Fixed
Expand Down
Binary file added DBDesigner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 35 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,62 @@
# Blazor.Diagrams

Blazor.Diagrams is a fully customizable and extensible all-purpose diagrams library for Blazor (both Server Side and WASM). It was inspired by the popular React library [react-diagrams](https://github.com/projectstorm/react-diagrams).
![](ZBD.png)

Blazor.Diagrams can be used to make advanced diagrams with a custom design. Even the behavior of the library is "hackable" and can be changed to suit your needs. It is very code/OOP oriented, representing a diagram (using models) is seperate from rendering. This has a lot of benefits, for example if you want to (de)serialize diagrams or make an engine that runs at runtime (visual programming).
Z.Blazor.Diagrams is a fully customizable and extensible all-purpose diagrams library for Blazor (both Server Side and WASM). It was first inspired by the popular React library [react-diagrams](https://github.com/projectstorm/react-diagrams), but then evolved into something much bigger. ZBD can be used to make advanced diagrams with a custom design. Even the behavior of the library is "hackable" and can be changed to suit your needs.

This library aims to provide most of its features using C#/Blazor while minimizing Javascript.

| NuGet Package | Version | Download |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Z.Blazor.Diagrams.Core | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.Core.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Core) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.Core.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Core) |
| Z.Blazor.Diagrams | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams) |
| Z.Blazor.Diagrams.Algorithms | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.Algorithms.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Algorithms) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.Algorithms.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Algorithms) |
| NuGet Package | Version | Download |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Z.Blazor.Diagrams.Core | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.Core.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Core) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.Core.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Core) |
| Z.Blazor.Diagrams | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams) |
| Z.Blazor.Diagrams.Algorithms | [![NuGet](https://img.shields.io/nuget/v/Z.Blazor.Diagrams.Algorithms.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Algorithms) | [![Nuget](https://img.shields.io/nuget/dt/Z.Blazor.Diagrams.Algorithms.svg)](https://www.nuget.org/packages/Z.Blazor.Diagrams.Algorithms) |

| Badges | |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| JavaScript | ![GitHub file size in bytes](https://img.shields.io/github/size/zHaytam/Blazor.Diagrams/src/Blazor.Diagrams/wwwroot/script.min.js) |
| JavaScript | ![GitHub file size in bytes](https://img.shields.io/github/size/zHaytam/Blazor.Diagrams/src/Blazor.Diagrams/wwwroot/script.min.js) |
| CSS | ![GitHub file size in bytes](https://img.shields.io/github/size/zHaytam/Blazor.Diagrams/src/Blazor.Diagrams/wwwroot/style.css) |
| Activity | [![GitHub](https://img.shields.io/github/last-commit/zHaytam/Blazor.Diagrams/develop)](https://github.com/zHaytam/Blazor.Diagrams) |
| License | [![GitHub](https://img.shields.io/github/license/zHaytam/Blazor.Diagrams.svg)](https://github.com/zHaytam/Blazor.Diagrams) |

## Getting Started
## Mindset/Goals

You can get started very easily & quickly using:
- **Be multi purpose and useful for most diagramming use cases**. ZBD started as a diagramming library for specific use cases, but it is now expanding to be more generic and more useful.
- **Performance** is very important, especially in WebAssembly.
- **Separate the data layer (models) and the UI layer (widgets)**. Representing diagrams as a model has a lot of benefits, and the separation makes things easier, such as saving snapshots or mutating models, regardless of how/where it's gonna be rendered.
- **Be fully customizable, either in how things look or how things behave**. All of the UI can be customized by either providing Blazor components or using CSS. All of the default behaviors are customizable by replacing them with your own custom behaviors.
- **Avoid JavaScript**. 95% of ZBD is made using C#/Blazor, JS is only used when absolutely necessary (e.g. bounds and observers). JS interop calls are costly, in the future, we strive to have most of them batched and/or replaced.

- [Documentation](https://blazor-diagrams.zhaytam.com/)
- [Quick Start](https://blazor-diagrams.zhaytam.com/quickstart)
- [Demos](https://blazor-diagrams.zhaytam.com/demos/simple)

## Functionalities
## Features

- Panning/Zooming
- Ports & Links (no free links for now)
- Multi selection / deletion
- Locking mechanism
- Custom nodes/links
- Multi purpose
- Touch support
- SVG layer for links/nodes and HTML layer for nodes for maximum customizability
- Replaceable behaviors (e.g. link dragging, model deletion, ...)
- Zoom to fit (all nodes or selected ones only)
- Customizable Diagram Overview/Preview/Navigator (on the bottom right by default)
- Links between nodes directly or node ports
- Link routers, path generators, markers and labels
- Panning, Zooming and Zooming to fit a set of nodes
- Multi selection, deletion and region selection
- Groups as first class citizen, with all the features of nodes
- Custom nodes, links and groups
- Replaceable ("Hackable") behaviors (e.g. link dragging, model deletion, etc..)
- Customizable Diagram overview/navigator for large diagrams
- Snap to Grid
- Grouping: [CTRL + ALT + G] to (un)group
- Groups with ports/links and nested groups (**experimental**)
- Virtualization: only draw nodes that are visible to the users
- Virtualization, only draw nodes that are visible to the users
- Locking mechanism (read-only)
- Algorithms

## Preview

```html
<CascadingValue Name="DiagramManager" Value="diagramManager">
<DiagramCanvas>
<Widgets>
<Navigator Width="300" Height="200" DefaultStyle="true"></Navigator>
</Widgets>
</DiagramCanvas>
</CascadingValue>
```
## Getting Started

![](https://i.imgur.com/WZYL2PW.png)
You can get started very easily & quickly using:

- [Documentation](https://blazor-diagrams.zhaytam.com/)
- [Quick Start](https://blazor-diagrams.zhaytam.com/quickstart)
- [Demos](https://blazor-diagrams.zhaytam.com/demos/simple)

### Sample project

Repository: https://github.com/zHaytam/Blazor.DatabaseDesigner

![](https://i.imgur.com/yFXZ0JN.png)

## Roadmap

- [x] Better way to handle/render groups
- [ ] Pluggable history (undo/redo)
- [ ] Auto layout

### Thinking about
Repository: https://github.com/Blazor-Diagrams/Blazor.DatabaseDesigner

- [ ] Razor-oriented diagram creation
- [ ] Send to front/back (limited since there are 2 layers)
- [ ] Free links, no need for ports (useful in simple diagram scenarios, like a flowchart)
- [ ] A set of common shapes (depends on the above feature)
![](DBDesigner.png)

## Feedback

If you find a bug or you want to see a functionality in this library, feel free to open an issue in the repository!
Of course, PRs are very welcome.
If you find a bug or you want to see a functionality in this library, feel free to open an issue. All kinds of contributions are welcome!
Binary file added ZBD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d923bb4

Please sign in to comment.