Skip to content

Commit fd75232

Browse files
authored
Merge pull request #56 from zHaytam/develop
Version 1.3.0
2 parents b504799 + 44ccd19 commit fd75232

32 files changed

+377
-153
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Diagrams [1.3.0] - 2020-11-29
8+
9+
### Added
10+
- Abstract `MovableModel`, which inherits from `SelectableModel` and represents models that can be move with the mouse (e.g. nodes and groups).
11+
- Groups widget customization using `RegisterModelComponent`.
12+
- `SizeChanged` event on `NodeModel`.
13+
14+
### Changed
15+
- `SelectableModel` is now abstract.
16+
- Groups:
17+
- Renamed model `Group` to `GroupModel`.
18+
- Rendered as a single entity (HTML div) with padding.
19+
- Movable and Selectable.
20+
- Selecting a node inside a group doesn't select the others anymore.
21+
- **[BREAKING]** Renamed `DiagramManager.ChangePan` to `UpdatePan`.
22+
- **[BREAKING]** Renamed `DiagramManager.ChangeZoom` to `SetZoom`.
23+
24+
### Fixed
25+
- `ZoomToFit` wasn't unhiding hidden nodes.
26+
727
## Diagrams [1.2.0] - 2020-11-08
828
### Added
929
- `DefaultLinkModel` in `DiagramLinkOptions` ([@joezearing](https://github.com/joezearing)).

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ You can get started very easily & quickly using:
5757

5858
![](https://i.imgur.com/k4UThmh.png)
5959

60+
6061
### Sample project
6162

6263
Repository: https://github.com/zHaytam/Blazor.DatabaseDesigner
@@ -65,7 +66,7 @@ Repository: https://github.com/zHaytam/Blazor.DatabaseDesigner
6566

6667
## Roadmap
6768

68-
- [ ] Better way to handle/render groups
69+
- [x] Better way to handle/render groups
6970
- [ ] Pluggable history (undo/redo)
7071
- [ ] Auto layout
7172

samples/SharedDemo/Demos/DynamicInsertions.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ namespace SharedDemo.Demos
1010
public class DynamicInsertionsComponent : ComponentBase
1111
{
1212
private static readonly Random _random = new Random();
13-
protected readonly DiagramManager diagramManager = new DiagramManager();
13+
protected readonly DiagramManager diagramManager = new DiagramManager(new DiagramOptions
14+
{
15+
GroupingEnabled = true
16+
});
1417

1518
protected override void OnInitialized()
1619
{

samples/SharedDemo/Demos/Grouping.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
base.OnInitialized();
1010

1111
LayoutData.Title = "Grouping";
12-
LayoutData.Info = "You can group nodes using CTRL+G and ungroup using CTRL+SHIFT+G.<br>" +
13-
"Whenever you select a node that belongs to a group, every other node in the group is also selected.";
12+
LayoutData.Info = "You can (un)group nodes using CTRL+ALT+G.<br>" +
13+
"Currently, the library doesn't handle nested groups yet nor ports.";
1414
LayoutData.DataChanged();
1515
}
1616
}

samples/SharedDemo/Demos/Grouping.razor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ protected override void OnInitialized()
1717
base.OnInitialized();
1818

1919
var node1 = NewNode(50, 50);
20-
var node2 = NewNode(300, 300);
20+
var node2 = NewNode(250, 250);
21+
var node3 = NewNode(450, 100);
22+
2123
diagramManager.AddLink(node1.GetPort(PortAlignment.Right), node2.GetPort(PortAlignment.Left));
22-
diagramManager.AddNode(node1);
23-
diagramManager.AddNode(node2);
24-
diagramManager.AddNode(NewNode(300, 50));
24+
diagramManager.AddLink(node2.GetPort(PortAlignment.Right), node3.GetPort(PortAlignment.Left));
25+
diagramManager.Group(node1, node2);
26+
diagramManager.AddNode(node3);
2527
}
2628

2729
private NodeModel NewNode(double x, double y)

src/Blazor.Diagrams.Core/Blazor.Diagrams.Core.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<PackageLicenseExpression>MIT</PackageLicenseExpression>
88
<Authors>zHaytam</Authors>
99
<Description>A fully customizable and extensible all-purpose diagrams library for Blazor</Description>
10-
<AssemblyVersion>1.2.0</AssemblyVersion>
11-
<FileVersion>1.2.0</FileVersion>
10+
<AssemblyVersion>1.3.0</AssemblyVersion>
11+
<FileVersion>1.3.0</FileVersion>
1212
<RepositoryUrl>https://github.com/zHaytam/Blazor.Diagrams</RepositoryUrl>
13-
<Version>1.2.0</Version>
13+
<Version>1.3.0</Version>
1414
<PackageId>Z.Blazor.Diagrams.Core</PackageId>
1515
<PackageTags>blazor diagrams diagramming svg drag</PackageTags>
1616
<Product>Z.Blazor.Diagrams.Core</Product>

src/Blazor.Diagrams.Core/Default/DragNodeSubManager.cs renamed to src/Blazor.Diagrams.Core/Default/DragMovablesSubManager.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
using Blazor.Diagrams.Core.Extensions;
2-
using Blazor.Diagrams.Core.Models;
3-
using Blazor.Diagrams.Core.Models.Base;
1+
using Blazor.Diagrams.Core.Models.Base;
42
using Blazor.Diagrams.Core.Models.Core;
53
using Microsoft.AspNetCore.Components.Web;
64
using System;
75
using System.Linq;
86

97
namespace Blazor.Diagrams.Core.Default
108
{
11-
public class DragNodeSubManager : DiagramSubManager
9+
public class DragMovablesSubManager : DiagramSubManager
1210
{
1311
private Point[]? _initialPositions;
1412
private double? _lastClientX;
1513
private double? _lastClientY;
1614

17-
public DragNodeSubManager(DiagramManager diagramManager) : base(diagramManager)
15+
public DragMovablesSubManager(DiagramManager diagramManager) : base(diagramManager)
1816
{
1917
DiagramManager.MouseDown += DiagramManager_MouseDown;
2018
DiagramManager.MouseMove += DiagramManager_MouseMove;
@@ -23,13 +21,13 @@ public DragNodeSubManager(DiagramManager diagramManager) : base(diagramManager)
2321

2422
private void DiagramManager_MouseDown(Model model, MouseEventArgs e)
2523
{
26-
if (!(model is NodeModel))
24+
if (!(model is MovableModel))
2725
return;
2826

2927
// Don't link this linq
3028
_initialPositions = DiagramManager.SelectedModels
31-
.Where(m => m is NodeModel)
32-
.Select(m => (m as NodeModel).Position)
29+
.Where(m => m is MovableModel)
30+
.Select(m => (m as MovableModel)!.Position)
3331
.ToArray();
3432

3533
_lastClientX = e.ClientX;
@@ -47,14 +45,13 @@ private void DiagramManager_MouseMove(Model model, MouseEventArgs e)
4745

4846
foreach (var sm in DiagramManager.SelectedModels)
4947
{
50-
if (!(sm is NodeModel node) || node.Locked)
48+
if (!(sm is MovableModel node) || node.Locked)
5149
continue;
5250

5351
var initialPosition = _initialPositions[i];
5452
var ndx = ApplyGridSize(deltaX + initialPosition.X);
5553
var ndy = ApplyGridSize(deltaY + initialPosition.Y);
5654
node.SetPosition(ndx, ndy);
57-
node.RefreshAll();
5855
i++;
5956
}
6057
}

src/Blazor.Diagrams.Core/Default/GroupingSubManager.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Blazor.Diagrams.Core.Models;
2-
using Blazor.Diagrams.Core.Models.Base;
32
using Microsoft.AspNetCore.Components.Web;
43
using System;
54
using System.Linq;
@@ -11,34 +10,6 @@ public class GroupingSubManager : DiagramSubManager
1110
public GroupingSubManager(DiagramManager diagramManager) : base(diagramManager)
1211
{
1312
DiagramManager.KeyDown += DiagramManager_KeyDown;
14-
DiagramManager.SelectionChanged += DiagramManager_SelectionChanged;
15-
}
16-
17-
private void DiagramManager_SelectionChanged(SelectableModel model, bool selected)
18-
{
19-
if (!DiagramManager.Options.GroupingEnabled)
20-
return;
21-
22-
if (!(model is NodeModel node))
23-
return;
24-
25-
if (node.Group == null)
26-
return;
27-
28-
foreach (var n in node.Group.Nodes)
29-
{
30-
if (n == node || n.Selected == selected)
31-
continue;
32-
33-
if (selected)
34-
{
35-
DiagramManager.SelectModel(n, false);
36-
}
37-
else
38-
{
39-
DiagramManager.UnselectModel(n);
40-
}
41-
}
4213
}
4314

4415
private void DiagramManager_KeyDown(KeyboardEventArgs e)

src/Blazor.Diagrams.Core/Default/PanSubManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private void DiagramManager_MouseMove(Model model, MouseEventArgs e)
3434

3535
var deltaX = e.ClientX - _lastClientX - (DiagramManager.Pan.X - _initialPan.X);
3636
var deltaY = e.ClientY - _lastClientY - (DiagramManager.Pan.Y - _initialPan.Y);
37-
DiagramManager.ChangePan(deltaX, deltaY);
37+
DiagramManager.UpdatePan(deltaX, deltaY);
3838
}
3939

4040
private void DiagramManager_MouseUp(Model model, MouseEventArgs e)

src/Blazor.Diagrams.Core/Default/ZoomSubManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private void DiagramManager_Wheel(WheelEventArgs e)
3838
var newPanY = DiagramManager.Pan.Y - heightDiff * yFactor;
3939

4040
DiagramManager.Pan = new Point(newPanX, newPanY);
41-
DiagramManager.ChangeZoom(newZoom);
41+
DiagramManager.SetZoom(newZoom);
4242
}
4343

4444
public override void Dispose()

0 commit comments

Comments
 (0)