From 06ae976f11537c618b4ba407c0cb6557d16fa18c Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 2 Nov 2023 21:42:43 +1100 Subject: [PATCH 01/21] design spike --- .../Controls/Default/ResizeControl.cs | 29 +++++++ .../Positions/BottomRightResizerProvider.cs | 78 ++++++++++++++++++ .../Positions/IResizeProvider.cs | 13 +++ src/Blazor.Diagrams/BlazorDiagram.cs | 3 +- .../Controls/ResizeControlWidget.razor | 10 +++ .../Components/NodeWidget.razor | 10 ++- .../wwwroot/default.styles.css | 8 ++ .../wwwroot/default.styles.min.css | 2 +- .../wwwroot/default.styles.min.css.gz | Bin 683 -> 704 bytes src/Blazor.Diagrams/wwwroot/style.min.css.gz | Bin 409 -> 409 bytes 10 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs create mode 100644 src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs create mode 100644 src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs create mode 100644 src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor diff --git a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs new file mode 100644 index 000000000..d64174f6b --- /dev/null +++ b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs @@ -0,0 +1,29 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models.Base; +using Blazor.Diagrams.Core.Positions; +using System.Threading.Tasks; + +namespace Blazor.Diagrams.Core.Controls.Default +{ + public class ResizeControl : ExecutableControl + { + private readonly IResizeProvider _resizeProvider; + + public ResizeControl(IResizeProvider resizeProvider) + { + _resizeProvider = resizeProvider; + } + + public override Point? GetPosition(Model model) => _resizeProvider.GetPosition(model); + + public override ValueTask OnPointerDown(Diagram diagram, Model model, PointerEventArgs e) + { + _resizeProvider.OnResizeStart(diagram, model, e); + diagram.PointerMove += _resizeProvider.OnPointerMove; + diagram.PointerUp += _resizeProvider.OnResizeEnd; + + return ValueTask.CompletedTask; + } + } +} diff --git a/src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs new file mode 100644 index 000000000..91741d980 --- /dev/null +++ b/src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs @@ -0,0 +1,78 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Models.Base; + +namespace Blazor.Diagrams.Core.Positions +{ + public class BottomRightResizerProvider : IResizeProvider + { + private Size _originalSize = null!; + private Point _originalPosition = null!; + private Point _originalMousePosition = null!; + private NodeModel _nodeModel = null!; + private Diagram _diagram = null!; + + public Point? GetPosition(Model model) + { + if (model is NodeModel nodeModel && nodeModel.Size is not null) + { + return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + } + return null; + } + + public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs) + { + if (model is NodeModel nodeModel) + { + _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y); + _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); + _originalSize = nodeModel.Size!; + _nodeModel = nodeModel; + _diagram = diagram; + } + } + + public void OnPointerMove(Model? model, PointerEventArgs args) + { + if (_nodeModel is null) + { + return; + } + var width = _originalSize.Width; + var height = _originalSize.Height; + var positionX = _nodeModel.Position.X; + var positionY = _nodeModel.Position.Y; + + height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + + //if (width < model.MinimumDimensions.Width) + //{ + // width = model.MinimumDimensions.Width; + // positionX = model.Position.X; + //} + //if (height < model.MinimumDimensions.Height) + //{ + // height = model.MinimumDimensions.Height; + // positionY = model.Position.Y; + //} + _nodeModel.SetPosition(positionX, positionY); + _nodeModel.Size = new Size(width, height); + } + + public void OnResizeEnd(Model? model, PointerEventArgs args) + { + _diagram.PointerMove -= OnPointerMove; + _diagram.PointerUp -= OnResizeEnd; + + _originalSize = null!; + _originalPosition = null!; + _originalMousePosition = null!; + _nodeModel = null!; + _diagram = null!; + } + + } +} diff --git a/src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs b/src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs new file mode 100644 index 000000000..06180c73e --- /dev/null +++ b/src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs @@ -0,0 +1,13 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Models.Base; + +namespace Blazor.Diagrams.Core.Positions +{ + public interface IResizeProvider : IPositionProvider + { + public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs); + public void OnPointerMove(Model? model, PointerEventArgs args); + public void OnResizeEnd(Model? model, PointerEventArgs args); + } +} diff --git a/src/Blazor.Diagrams/BlazorDiagram.cs b/src/Blazor.Diagrams/BlazorDiagram.cs index ab61d98a8..b18eab9dc 100644 --- a/src/Blazor.Diagrams/BlazorDiagram.cs +++ b/src/Blazor.Diagrams/BlazorDiagram.cs @@ -19,7 +19,8 @@ public BlazorDiagram(BlazorDiagramOptions? options = null) [typeof(RemoveControl)] = typeof(RemoveControlWidget), [typeof(BoundaryControl)] = typeof(BoundaryControlWidget), [typeof(DragNewLinkControl)] = typeof(DragNewLinkControlWidget), - [typeof(ArrowHeadControl)] = typeof(ArrowHeadControlWidget) + [typeof(ArrowHeadControl)] = typeof(ArrowHeadControlWidget), + [typeof(ResizeControl)] = typeof(ResizeControlWidget) }; Options = options ?? new BlazorDiagramOptions(); diff --git a/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor b/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor new file mode 100644 index 000000000..ddbffd330 --- /dev/null +++ b/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor @@ -0,0 +1,10 @@ +
+ +@code +{ + [Parameter] + public ResizeControl Control { get; set; } = null!; + + [Parameter] + public Model Model { get; set; } = null!; +} diff --git a/src/Blazor.Diagrams/Components/NodeWidget.razor b/src/Blazor.Diagrams/Components/NodeWidget.razor index 37ff3da8d..726e51d2c 100644 --- a/src/Blazor.Diagrams/Components/NodeWidget.razor +++ b/src/Blazor.Diagrams/Components/NodeWidget.razor @@ -1,4 +1,4 @@ -
+
@(Node.Title ?? "Title") @foreach (var port in Node.Ports) { @@ -11,4 +11,12 @@ [Parameter] public NodeModel Node { get; set; } = null!; + private string GenerateStyle() + { + if (Node.Size is not null) + { + return $"width: {Node.Size.Width}px; height: {Node.Size.Height}px"; + } + return string.Empty; + } } \ No newline at end of file diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.css b/src/Blazor.Diagrams/wwwroot/default.styles.css index b095bbe4e..ea267bb66 100644 --- a/src/Blazor.Diagrams/wwwroot/default.styles.css +++ b/src/Blazor.Diagrams/wwwroot/default.styles.css @@ -127,4 +127,12 @@ g.diagram-group.default.selected > rect { transform: translate(-50%, -50%); } +.default-node-resizer { + width: 5px; + height: 5px; + background-color: #f5f5f5; + border: 1px solid #6e9fd4; + position: absolute; +} + /*# sourceMappingURL=wwwroot\default.styles.css.map */ diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.min.css b/src/Blazor.Diagrams/wwwroot/default.styles.min.css index c44adedc3..e5378f1ae 100644 --- a/src/Blazor.Diagrams/wwwroot/default.styles.min.css +++ b/src/Blazor.Diagrams/wwwroot/default.styles.min.css @@ -1 +1 @@ -.default-node{width:100px;height:80px;border-radius:10px;background-color:#f5f5f5;border:1px solid #e8e8e8;-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;}.default-node.selected{border:1px solid #6e9fd4;}.default-node.selected .diagram-port{border:1px solid #6e9fd4;}.default-node .diagram-port,.default.diagram-group .diagram-port{width:20px;height:20px;margin:-10px;border-radius:50%;background-color:#f5f5f5;border:1px solid #d4d4d4;cursor:pointer;position:absolute;}.default-node .diagram-port:hover,.default-node .diagram-port.has-links,.default.diagram-group .diagram-port.has-links{background-color:#000;}.default-node .diagram-port.bottom,.default.diagram-group .diagram-port.bottom{bottom:0;left:50%;}.default-node .diagram-port.bottomleft,.default.diagram-group .diagram-port.bottomleft{bottom:0;left:0;}.default-node .diagram-port.bottomright,.default.diagram-group .diagram-port.bottomright{bottom:0;right:0;}.default-node .diagram-port.top,.default.diagram-group .diagram-port.top{top:0;left:50%;}.default-node .diagram-port.topleft,.default.diagram-group .diagram-port.topleft{top:0;left:0;}.default-node .diagram-port.topright,.default.diagram-group .diagram-port.topright{top:0;right:0;}.default-node .diagram-port.left,.default.diagram-group .diagram-port.left{left:0;top:50%;}.default-node .diagram-port.right,.default.diagram-group .diagram-port.right{right:0;top:50%;}.diagram-navigator.default{position:absolute;bottom:10px;right:10px;border:3px solid #9ba8b0;border-radius:15px;padding:20px;background-color:#fff;}div.diagram-group.default{outline:2px solid #000;background:#c6c6c6;}div.diagram-group.default.selected{outline:2px solid #6e9fd4;}g.diagram-group.default rect{outline:2px solid #000;fill:#c6c632;}g.diagram-group.default.selected>rect{outline:2px solid #008000;}.diagram-link div.default-link-label{display:inline-block;color:#fff;background-color:#6e9fd4;border-radius:.25rem;padding:.25rem;text-align:center;font-size:.875rem;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;min-width:3rem;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);} \ No newline at end of file +.default-node{width:100px;height:80px;border-radius:10px;background-color:#f5f5f5;border:1px solid #e8e8e8;-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;}.default-node.selected{border:1px solid #6e9fd4;}.default-node.selected .diagram-port{border:1px solid #6e9fd4;}.default-node .diagram-port,.default.diagram-group .diagram-port{width:20px;height:20px;margin:-10px;border-radius:50%;background-color:#f5f5f5;border:1px solid #d4d4d4;cursor:pointer;position:absolute;}.default-node .diagram-port:hover,.default-node .diagram-port.has-links,.default.diagram-group .diagram-port.has-links{background-color:#000;}.default-node .diagram-port.bottom,.default.diagram-group .diagram-port.bottom{bottom:0;left:50%;}.default-node .diagram-port.bottomleft,.default.diagram-group .diagram-port.bottomleft{bottom:0;left:0;}.default-node .diagram-port.bottomright,.default.diagram-group .diagram-port.bottomright{bottom:0;right:0;}.default-node .diagram-port.top,.default.diagram-group .diagram-port.top{top:0;left:50%;}.default-node .diagram-port.topleft,.default.diagram-group .diagram-port.topleft{top:0;left:0;}.default-node .diagram-port.topright,.default.diagram-group .diagram-port.topright{top:0;right:0;}.default-node .diagram-port.left,.default.diagram-group .diagram-port.left{left:0;top:50%;}.default-node .diagram-port.right,.default.diagram-group .diagram-port.right{right:0;top:50%;}.diagram-navigator.default{position:absolute;bottom:10px;right:10px;border:3px solid #9ba8b0;border-radius:15px;padding:20px;background-color:#fff;}div.diagram-group.default{outline:2px solid #000;background:#c6c6c6;}div.diagram-group.default.selected{outline:2px solid #6e9fd4;}g.diagram-group.default rect{outline:2px solid #000;fill:#c6c632;}g.diagram-group.default.selected>rect{outline:2px solid #008000;}.diagram-link div.default-link-label{display:inline-block;color:#fff;background-color:#6e9fd4;border-radius:.25rem;padding:.25rem;text-align:center;font-size:.875rem;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;min-width:3rem;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);}.default-node-resizer{width:5px;height:5px;background-color:#f5f5f5;border:1px solid #6e9fd4;position:absolute;} \ No newline at end of file diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz b/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz index 905f20cd3084e4807fd8feb323b3f30ca017d835..1d3b8cb1fbe3a9826d682a1e2935b372cd2eb50f 100644 GIT binary patch delta 696 zcmV;p0!RI;1;7Q66n|)?R*DfJNt+sJ?_%&kyfHSiO`109$@a${X|J$0m;faY@?&K| z@c5hecqV^;{|P8$q~Zn%N#XR)sM+CV7?#I)2Q1$iymjA+R1_3agtAK8b4McSK3B35 z6s3|&h3DDEEsw>^@;K9yGdi2Y)~y)5L$YTECGv>$j!^lI!+%+1VGfGiOXUf93Kwn# z(eom#Puvp@j+X28Y&AZMo~;G{SwSf^GfWDsfD^+G5L2d0PCjtY$BtHLlyNxrX>LCV z2;nRjI0a!q#VyB>T5k|DQ0OzTC!w?n842hUe^uJB?8BzZZiQ*dUxN||G;l}_(9<}N zFYuPp^)-fBKz|v@6)8|Dm6^&u_sK zbnRB0R!Uo3DOnw;bJj^>ag~9auHcx!u7}V^_j3ylG94NMmF% zO;Llj8FW85j5%bc4&ek14*Q4}hySK&k|)aL{SieqLw~2K-riGXWI0WR1)l6PIaU@s zJy0IpS8(6%2jbJBy@E-RnQnb;x;NS>xEq@XEN{$i4em+zAVCf+Cq}AP+G%`;eMQtw zqmk6>A9&R@g|~!klkoc}+*oW$C}kpVy3mC-lV$N2Wrv|FXOm=Q?5zeIb*kKL?&RQk z`r_6NA%9)hz96mbyZL3_nX;VMtjHMWjs8`1Rl-^O&+DSLzC(F_*T-hHJH8Mc0dbN5 zKeaQG2`2_6T&DZD7t3*ky@$ip1kpx8aZZlk8aSHaSk3G>M4Ej94z{l~rk$#lw$d8k zu#f`mSe2ibsCrBs5eg*N_6| es`4|`Rj(hR?(=~W=|g^DCjJA6Jcwvj3IG7r(n$aS delta 675 zcmV;U0$lyT1*-*+6n|=^Mv4(3O`95N?_%&kyfHSiO_Db1$@a${X|J%hfdC~B@?&Ks z!Q*e{n-}B!{rxAPkdcZTBqW8?fl;%?%P=gD@fKLVHF)Em6R9XDqzGk|w&zYn(p|1( zB`8WImkK{+YquIKUY5t1mYmVq6Kvdy(E*YjGboWqq_>311Ah)@k%c)Za$hP>$aA=G zD~RTc(4V+ZI5=9qv}ddFSv0pE{AYqvYG#-eSOF)7?IEU2mz;dyUW}cr&?w_@?91GK zkPyOIE^rFMfQnmGf?O=uxFvP1sNIW3x8GGu zF^#Ck+6uZK9L5|n<5M_+!C@a^arkdclOj>B?vD_8g@2C8Z|_kVSx%#{z?1z<&XvVZ zPgDc$6WsUvf&8@ShG0@=rhD&QZ=7}ncXRWA=e66d!#(Q_NRU0tiIJ+cb{fCKO-J~l zQCsTG54`Gz!h1qCN%;LLTw82OC}kqAr_hBllV$N2W&2?$XP0DU>{|^u>Zsh?+}XiT z>8o2ejDK`f`+~K0?&gnuI z{M6o&OgJ+r;WFLDy0SB8mk7;k!N?U7n zY*|0P>Qu$-wAj|wu=|;Ywm5|f!sO%`Ul{I JI$Grk005R}Ows@V diff --git a/src/Blazor.Diagrams/wwwroot/style.min.css.gz b/src/Blazor.Diagrams/wwwroot/style.min.css.gz index e72cb7d8af23d7af571c773a260d0f0ccfe835f3..4a312feec6aef85e5620eea68d1cd461ca9d351d 100644 GIT binary patch delta 381 zcmV-@0fPRS1DOMmC4Wh48BgYeNAe1;l%j3Z86SNj{7L?N|FY!s{UbN1Td#Z7Xcu)D zcWAgPABy6>>Hyo0kK-)`WF%L5u$nPKMFU%OP&#t*62Y%6?aB^~0arDH59CX=gL;Fk z6C6J%gNzw0SU2HR=mQhi8IB*h!$TIvxoU~RwS{bX3>OT_UX z1D}fT$UuVg#54qf4Pc?+8MdcGN)6ZIl`!{6FF2Ql(AHi+<(8Tam~q}Tum813`g1d0 z*v$E!^|xxOn|6Dhj@W7@KOPi11AD1cYC6ls!i%+v2)jg`YVrnr`MBL@qM*s{isH9Z z>uK2jyZTO4lC48)Bwd29$0&$UI4J=p}{ bTMm0@2G-(}Sbi1$vK77n8oH^c9R&aY=R@iQw0k#`U0GyBrTUPbNQyVgwbUbGz}oKP{bX3>OT_6P z1D}fT$UuVg#54qf4Pc?+8Mddllp3zZD`D=DUT`i8p{>1u$}Ke;Fw?wgUjJ*6^yg-} zu$l8c>%D5Kn|6Dhj@W7@KfNh*26j@X)O41Mg%@iT5ynKFYVrnr`MBL>qM*s{isH9Z z>uK2jyZW|!D#_NNHIgpDchxbe#y$TQnKYyHoO`NYgy?Kaeuo Date: Fri, 17 Nov 2023 11:26:54 +1100 Subject: [PATCH 02/21] move to resizing folder --- site/Site/Pages/Documentation/Controls/Overview.razor | 4 ++++ src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs | 2 +- .../Positions/{ => Resizing}/BottomRightResizerProvider.cs | 6 +++--- .../Positions/{ => Resizing}/IResizeProvider.cs | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) rename src/Blazor.Diagrams.Core/Positions/{ => Resizing}/BottomRightResizerProvider.cs (95%) rename src/Blazor.Diagrams.Core/Positions/{ => Resizing}/IResizeProvider.cs (89%) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index bd87fa9a1..0139f3667 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -3,6 +3,7 @@ @using Blazor.Diagrams.Core.Controls; @using Blazor.Diagrams.Core.PathGenerators; @using Blazor.Diagrams.Core.Positions; +@using Blazor.Diagrams.Core.Positions.Resizing; @using Blazor.Diagrams.Core.Routers; @layout DocumentationLayout @inherits DocumentationPage @@ -159,6 +160,8 @@ Diagram.Controls.AddFor(SomeModel) bNode2.Title = "Hover on me"; bLink1.AddLabel("Select me", distance: 0.5); _bDiagram.Controls.AddFor(bNode1, ControlsType.OnSelection).Add(new BoundaryControl()); + _bDiagram.Controls.AddFor(bNode1).Add(new ResizeControl(new BottomRightResizerProvider())); + _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomRightResizerProvider())); _bDiagram.Controls.AddFor(bNode2, ControlsType.OnHover).Add(new BoundaryControl()); _bDiagram.Controls.AddFor(bLink1, ControlsType.OnSelection).Add(new BoundaryControl()); _bDiagram.SelectModel(bNode1, false); @@ -172,6 +175,7 @@ Diagram.Controls.AddFor(SomeModel) rNode2.Title = "Select me"; rLink1.AddLabel("Select me", distance: 0.5); _rDiagram.Controls.AddFor(rNode1, ControlsType.OnSelection).Add(new RemoveControl(0.5, 0)); + _rDiagram.Controls.AddFor(rNode1, ControlsType.OnHover).Add(new ResizeControl(new BottomRightResizerProvider())); _rDiagram.Controls.AddFor(rNode2, ControlsType.OnSelection).Add(new RemoveControl(0.5, 1)); _rDiagram.Controls.AddFor(rLink1, ControlsType.OnSelection).Add(new RemoveControl(new LinkPathPositionProvider(0.8, 0, -10))); _rDiagram.SelectModel(rNode1, false); diff --git a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs index d64174f6b..9fa420457 100644 --- a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs +++ b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs @@ -1,7 +1,7 @@ using Blazor.Diagrams.Core.Events; using Blazor.Diagrams.Core.Geometry; using Blazor.Diagrams.Core.Models.Base; -using Blazor.Diagrams.Core.Positions; +using Blazor.Diagrams.Core.Positions.Resizing; using System.Threading.Tasks; namespace Blazor.Diagrams.Core.Controls.Default diff --git a/src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs similarity index 95% rename from src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs rename to src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index 91741d980..db72bb841 100644 --- a/src/Blazor.Diagrams.Core/Positions/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -3,9 +3,9 @@ using Blazor.Diagrams.Core.Models; using Blazor.Diagrams.Core.Models.Base; -namespace Blazor.Diagrams.Core.Positions +namespace Blazor.Diagrams.Core.Positions.Resizing { - public class BottomRightResizerProvider : IResizeProvider + public class BottomRightResizerProvider : IResizeProvider { private Size _originalSize = null!; private Point _originalPosition = null!; @@ -72,7 +72,7 @@ public void OnResizeEnd(Model? model, PointerEventArgs args) _originalMousePosition = null!; _nodeModel = null!; _diagram = null!; - } + } } } diff --git a/src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs similarity index 89% rename from src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs rename to src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs index 06180c73e..410ff684a 100644 --- a/src/Blazor.Diagrams.Core/Positions/IResizeProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs @@ -2,7 +2,7 @@ using Blazor.Diagrams.Core.Models; using Blazor.Diagrams.Core.Models.Base; -namespace Blazor.Diagrams.Core.Positions +namespace Blazor.Diagrams.Core.Positions.Resizing { public interface IResizeProvider : IPositionProvider { From 15fee1d0ae52d262e21afb6d5af42fec922baa9a Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Fri, 17 Nov 2023 14:08:17 +1100 Subject: [PATCH 03/21] add resize control test --- .../Controls/Default/ResizeControl.cs | 7 ++ .../Resizing/BottomRightResizerProvider.cs | 3 - .../Controls/ResizeControlTests.cs | 80 +++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs diff --git a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs index 9fa420457..3673487e3 100644 --- a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs +++ b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs @@ -22,8 +22,15 @@ public override ValueTask OnPointerDown(Diagram diagram, Model model, PointerEve _resizeProvider.OnResizeStart(diagram, model, e); diagram.PointerMove += _resizeProvider.OnPointerMove; diagram.PointerUp += _resizeProvider.OnResizeEnd; + diagram.PointerUp += (_, _) => OnResizeEnd(diagram); return ValueTask.CompletedTask; } + + void OnResizeEnd(Diagram diagram) + { + diagram.PointerMove -= _resizeProvider.OnPointerMove; + diagram.PointerUp -= _resizeProvider.OnResizeEnd; + } } } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index db72bb841..e58d30ce7 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -64,9 +64,6 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { - _diagram.PointerMove -= OnPointerMove; - _diagram.PointerUp -= OnResizeEnd; - _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; diff --git a/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs new file mode 100644 index 000000000..a6682c40c --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs @@ -0,0 +1,80 @@ +using Blazor.Diagrams.Core.Controls.Default; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Models.Base; +using Blazor.Diagrams.Core.Positions.Resizing; +using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Controls +{ + public class ResizeControlTests + { + [Fact] + public void GetPosition_ShouldUseResizeProviderGetPosition() + { + var resizeProvider = new Mock(); + var control = new ResizeControl(resizeProvider.Object); + var model = new Mock(); + + control.GetPosition(model.Object); + + resizeProvider.Verify(m => m.GetPosition(model.Object), Times.Once()); + } + + [Fact] + public void OnPointerDown_ShouldInvokeResizeStart() + { + var resizeProvider = new Mock(); + var control = new ResizeControl(resizeProvider.Object); + var diagram = Mock.Of(); + var model = Mock.Of(); + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true); + + control.OnPointerDown(diagram, model, eventArgs); + + resizeProvider.Verify(m => m.OnResizeStart(diagram, model, eventArgs), Times.Once()); + } + + [Fact] + public void OnPointerDown_ShouldAddEventHandlers() + { + var resizeProvider = new Mock(); + var control = new ResizeControl(resizeProvider.Object); + var diagram = new TestDiagram(); + var model = Mock.Of(); + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true); + + control.OnPointerDown(diagram, model, eventArgs); + + diagram.TriggerPointerMove(model, eventArgs); + resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Once()); + + diagram.TriggerPointerUp(model, eventArgs); + resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once()); + } + + [Fact] + public void OnPointerUp_ShouldRemoveEventHandlers() + { + var resizeProvider = new Mock(); + var control = new ResizeControl(resizeProvider.Object); + var diagram = new TestDiagram(); + var model = Mock.Of(); + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true); + + control.OnPointerDown(diagram, model, eventArgs); + diagram.TriggerPointerUp(model, eventArgs); + + diagram.TriggerPointerMove(model, eventArgs); + resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Never()); + + diagram.TriggerPointerUp(model, eventArgs); + resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once()); + } + } +} From ad8b19aea4c4a85d8fcfa3542d816ef3c084c169 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Tue, 21 Nov 2023 15:10:02 +1100 Subject: [PATCH 04/21] tidy --- .../Controls/ResizeControlTests.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs index a6682c40c..ae266bdef 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs @@ -3,11 +3,6 @@ using Blazor.Diagrams.Core.Models.Base; using Blazor.Diagrams.Core.Positions.Resizing; using Moq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; namespace Blazor.Diagrams.Core.Tests.Controls @@ -23,7 +18,7 @@ public void GetPosition_ShouldUseResizeProviderGetPosition() control.GetPosition(model.Object); - resizeProvider.Verify(m => m.GetPosition(model.Object), Times.Once()); + resizeProvider.Verify(m => m.GetPosition(model.Object), Times.Once); } [Fact] @@ -37,7 +32,7 @@ public void OnPointerDown_ShouldInvokeResizeStart() control.OnPointerDown(diagram, model, eventArgs); - resizeProvider.Verify(m => m.OnResizeStart(diagram, model, eventArgs), Times.Once()); + resizeProvider.Verify(m => m.OnResizeStart(diagram, model, eventArgs), Times.Once); } [Fact] @@ -52,10 +47,10 @@ public void OnPointerDown_ShouldAddEventHandlers() control.OnPointerDown(diagram, model, eventArgs); diagram.TriggerPointerMove(model, eventArgs); - resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Once()); + resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Once); diagram.TriggerPointerUp(model, eventArgs); - resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once()); + resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once); } [Fact] @@ -71,10 +66,10 @@ public void OnPointerUp_ShouldRemoveEventHandlers() diagram.TriggerPointerUp(model, eventArgs); diagram.TriggerPointerMove(model, eventArgs); - resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Never()); + resizeProvider.Verify(m => m.OnPointerMove(model, eventArgs), Times.Never); diagram.TriggerPointerUp(model, eventArgs); - resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once()); + resizeProvider.Verify(m => m.OnResizeEnd(model, eventArgs), Times.Once); } } } From bab35cab3f5b0a1c069c9875c0b121641c310059 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Tue, 21 Nov 2023 16:04:43 +1100 Subject: [PATCH 05/21] add tests for bottom right resize provider --- .../BottomRightResizerProviderTests.cs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomRightResizerProviderTests.cs diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomRightResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomRightResizerProviderTests.cs new file mode 100644 index 000000000..20ab27770 --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomRightResizerProviderTests.cs @@ -0,0 +1,80 @@ +using Blazor.Diagrams.Core.Controls.Default; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Positions.Resizing; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Positions.Resizing +{ + public class BottomRightResizerProviderTests + { + [Fact] + public void DragResizer_ShouldResizeNode() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new BottomRightResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(10, 15, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(110); + node.Size.Height.Should().Be(215); + } + + [Fact] + public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new BottomRightResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(-300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(0); + node.Size.Height.Should().Be(0); + } + } +} From 002694d9cdca0c14b8868e283b634cb7d73676e1 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Tue, 21 Nov 2023 16:18:12 +1100 Subject: [PATCH 06/21] add tests for remaining resizer providers --- .../Resizing/BottomLeftResizerProvider.cs | 75 +++++++++++++++++ .../Resizing/TopLeftResizerProvider.cs | 75 +++++++++++++++++ .../Resizing/TopRightResizerProvider.cs | 75 +++++++++++++++++ .../BottomLeftResizerProviderTests.cs | 80 +++++++++++++++++++ .../Resizing/TopLeftResizerProviderTests.cs | 80 +++++++++++++++++++ .../Resizing/TopRightResizerProviderTests.cs | 80 +++++++++++++++++++ 6 files changed, 465 insertions(+) create mode 100644 src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs create mode 100644 src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs create mode 100644 src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs create mode 100644 tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs create mode 100644 tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs create mode 100644 tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs new file mode 100644 index 000000000..5b7e1e4bc --- /dev/null +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -0,0 +1,75 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Models.Base; + +namespace Blazor.Diagrams.Core.Positions.Resizing +{ + public class BottomLeftResizerProvider : IResizeProvider + { + private Size _originalSize = null!; + private Point _originalPosition = null!; + private Point _originalMousePosition = null!; + private NodeModel _nodeModel = null!; + private Diagram _diagram = null!; + + public Point? GetPosition(Model model) + { + if (model is NodeModel nodeModel && nodeModel.Size is not null) + { + return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + } + return null; + } + + public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs) + { + if (model is NodeModel nodeModel) + { + _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y); + _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); + _originalSize = nodeModel.Size!; + _nodeModel = nodeModel; + _diagram = diagram; + } + } + + public void OnPointerMove(Model? model, PointerEventArgs args) + { + if (_nodeModel is null) + { + return; + } + var width = _originalSize.Width; + var height = _originalSize.Height; + var positionX = _nodeModel.Position.X; + var positionY = _nodeModel.Position.Y; + + height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + + //if (width < model.MinimumDimensions.Width) + //{ + // width = model.MinimumDimensions.Width; + // positionX = model.Position.X; + //} + //if (height < model.MinimumDimensions.Height) + //{ + // height = model.MinimumDimensions.Height; + // positionY = model.Position.Y; + //} + _nodeModel.SetPosition(positionX, positionY); + _nodeModel.Size = new Size(width, height); + } + + public void OnResizeEnd(Model? model, PointerEventArgs args) + { + _originalSize = null!; + _originalPosition = null!; + _originalMousePosition = null!; + _nodeModel = null!; + _diagram = null!; + } + + } +} diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs new file mode 100644 index 000000000..7693b7e3c --- /dev/null +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -0,0 +1,75 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Models.Base; + +namespace Blazor.Diagrams.Core.Positions.Resizing +{ + public class TopLeftResizerProvider : IResizeProvider + { + private Size _originalSize = null!; + private Point _originalPosition = null!; + private Point _originalMousePosition = null!; + private NodeModel _nodeModel = null!; + private Diagram _diagram = null!; + + public Point? GetPosition(Model model) + { + if (model is NodeModel nodeModel && nodeModel.Size is not null) + { + return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + } + return null; + } + + public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs) + { + if (model is NodeModel nodeModel) + { + _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y); + _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); + _originalSize = nodeModel.Size!; + _nodeModel = nodeModel; + _diagram = diagram; + } + } + + public void OnPointerMove(Model? model, PointerEventArgs args) + { + if (_nodeModel is null) + { + return; + } + var width = _originalSize.Width; + var height = _originalSize.Height; + var positionX = _nodeModel.Position.X; + var positionY = _nodeModel.Position.Y; + + height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + + //if (width < model.MinimumDimensions.Width) + //{ + // width = model.MinimumDimensions.Width; + // positionX = model.Position.X; + //} + //if (height < model.MinimumDimensions.Height) + //{ + // height = model.MinimumDimensions.Height; + // positionY = model.Position.Y; + //} + _nodeModel.SetPosition(positionX, positionY); + _nodeModel.Size = new Size(width, height); + } + + public void OnResizeEnd(Model? model, PointerEventArgs args) + { + _originalSize = null!; + _originalPosition = null!; + _originalMousePosition = null!; + _nodeModel = null!; + _diagram = null!; + } + + } +} diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs new file mode 100644 index 000000000..47cb1b75e --- /dev/null +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -0,0 +1,75 @@ +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Models.Base; + +namespace Blazor.Diagrams.Core.Positions.Resizing +{ + public class TopRightResizerProvider : IResizeProvider + { + private Size _originalSize = null!; + private Point _originalPosition = null!; + private Point _originalMousePosition = null!; + private NodeModel _nodeModel = null!; + private Diagram _diagram = null!; + + public Point? GetPosition(Model model) + { + if (model is NodeModel nodeModel && nodeModel.Size is not null) + { + return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + } + return null; + } + + public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs) + { + if (model is NodeModel nodeModel) + { + _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y); + _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); + _originalSize = nodeModel.Size!; + _nodeModel = nodeModel; + _diagram = diagram; + } + } + + public void OnPointerMove(Model? model, PointerEventArgs args) + { + if (_nodeModel is null) + { + return; + } + var width = _originalSize.Width; + var height = _originalSize.Height; + var positionX = _nodeModel.Position.X; + var positionY = _nodeModel.Position.Y; + + height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + + //if (width < model.MinimumDimensions.Width) + //{ + // width = model.MinimumDimensions.Width; + // positionX = model.Position.X; + //} + //if (height < model.MinimumDimensions.Height) + //{ + // height = model.MinimumDimensions.Height; + // positionY = model.Position.Y; + //} + _nodeModel.SetPosition(positionX, positionY); + _nodeModel.Size = new Size(width, height); + } + + public void OnResizeEnd(Model? model, PointerEventArgs args) + { + _originalSize = null!; + _originalPosition = null!; + _originalMousePosition = null!; + _nodeModel = null!; + _diagram = null!; + } + + } +} diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs new file mode 100644 index 000000000..1b23ae3bc --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs @@ -0,0 +1,80 @@ +using Blazor.Diagrams.Core.Controls.Default; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Positions.Resizing; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Positions.Resizing +{ + public class BottomLeftResizerProviderTests + { + [Fact] + public void DragResizer_ShouldResizeNode() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new BottomLeftResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(10, 15, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(10); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(90); + node.Size.Height.Should().Be(215); + } + + [Fact] + public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new BottomLeftResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(100); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(0); + node.Size.Height.Should().Be(0); + } + } +} diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs new file mode 100644 index 000000000..f594b1ca4 --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs @@ -0,0 +1,80 @@ +using Blazor.Diagrams.Core.Controls.Default; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Positions.Resizing; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Positions.Resizing +{ + public class TopLeftResizerProviderTests + { + [Fact] + public void DragResizer_ShouldResizeNode() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new TopLeftResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(10, 15, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(10); + node.Position.Y.Should().Be(15); + node.Size.Width.Should().Be(90); + node.Size.Height.Should().Be(185); + } + + [Fact] + public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new TopLeftResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(100); + node.Position.Y.Should().Be(200); + node.Size.Width.Should().Be(0); + node.Size.Height.Should().Be(0); + } + } +} diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs new file mode 100644 index 000000000..ab0fd5500 --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs @@ -0,0 +1,80 @@ +using Blazor.Diagrams.Core.Controls.Default; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Blazor.Diagrams.Core.Positions.Resizing; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Positions.Resizing +{ + public class TopRightResizerProviderTests + { + [Fact] + public void DragResizer_ShouldResizeNode() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new TopRightResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(10, 15, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(15); + node.Size.Width.Should().Be(110); + node.Size.Height.Should().Be(185); + } + + [Fact] + public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() + { + // setup + var diagram = new TestDiagram(); + diagram.SetContainer(new Rectangle(0, 0, 1000, 400)); + var node = new NodeModel(position: new Point(0, 0)); + node.Size = new Size(100, 200); + var control = new ResizeControl(new TopRightResizerProvider()); + diagram.Controls.AddFor(node).Add(control); + diagram.SelectModel(node, false); + + // before resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(0); + node.Size.Width.Should().Be(100); + node.Size.Height.Should().Be(200); + + // resize + var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + control.OnPointerDown(diagram, node, eventArgs); + eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + + // after resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(200); + node.Size.Width.Should().Be(0); + node.Size.Height.Should().Be(0); + } + } +} From 87a7ae466545d5d4910821432df9ee9ddd733109 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Tue, 21 Nov 2023 16:42:23 +1100 Subject: [PATCH 07/21] add widget test --- .../Controls/ResizeControlWidgetTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs diff --git a/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs b/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs new file mode 100644 index 000000000..598bad4f5 --- /dev/null +++ b/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs @@ -0,0 +1,25 @@ +using Blazor.Diagrams.Components.Controls; +using Blazor.Diagrams.Components.Renderers; +using Bunit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Blazor.Diagrams.Tests.Components.Controls +{ + public class ResizeControlWidgetTests + { + [Fact] + public void ShouldRenderDiv() + { + using var ctx = new TestContext(); + + var cut = ctx.RenderComponent(); + + cut.MarkupMatches("
"); + } + } +} From 5831d34e9cec8b12a4d2c454c4fe0c0846645ad3 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Wed, 22 Nov 2023 09:41:11 +1100 Subject: [PATCH 08/21] add logic for resizing --- .../Positions/Resizing/BottomLeftResizerProvider.cs | 5 ++++- .../Positions/Resizing/TopLeftResizerProvider.cs | 7 +++++-- .../Positions/Resizing/TopRightResizerProvider.cs | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs index 5b7e1e4bc..166f539fc 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -46,7 +46,10 @@ public void OnPointerMove(Model? model, PointerEventArgs args) var positionY = _nodeModel.Position.Y; height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); + + positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); + positionY = _originalPosition.Y; //if (width < model.MinimumDimensions.Width) //{ diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index 7693b7e3c..7baa8438d 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -45,8 +45,11 @@ public void OnPointerMove(Model? model, PointerEventArgs args) var positionX = _nodeModel.Position.X; var positionY = _nodeModel.Position.Y; - height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); + width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); + + positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); + positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); //if (width < model.MinimumDimensions.Width) //{ diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index 47cb1b75e..0b4abcdcb 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -45,9 +45,12 @@ public void OnPointerMove(Model? model, PointerEventArgs args) var positionX = _nodeModel.Position.X; var positionY = _nodeModel.Position.Y; - height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + positionX = _originalPosition.X; + positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); + //if (width < model.MinimumDimensions.Width) //{ // width = model.MinimumDimensions.Width; From 67d8d3cd9853f69e135d8e9d426cef75d10060ed Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Wed, 22 Nov 2023 09:58:48 +1100 Subject: [PATCH 09/21] add changes for minimum size, implement get position --- .../Documentation/Controls/Overview.razor | 3 ++ src/Blazor.Diagrams.Core/Models/NodeModel.cs | 1 + .../Resizing/BottomLeftResizerProvider.cs | 35 +++++++++---------- .../Resizing/BottomRightResizerProvider.cs | 27 +++++++------- .../Resizing/TopLeftResizerProvider.cs | 35 +++++++++---------- .../Resizing/TopRightResizerProvider.cs | 34 ++++++++---------- 6 files changed, 64 insertions(+), 71 deletions(-) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index 0139f3667..4e2bc80d8 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -162,6 +162,9 @@ Diagram.Controls.AddFor(SomeModel) _bDiagram.Controls.AddFor(bNode1, ControlsType.OnSelection).Add(new BoundaryControl()); _bDiagram.Controls.AddFor(bNode1).Add(new ResizeControl(new BottomRightResizerProvider())); _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomRightResizerProvider())); + _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new TopRightResizerProvider())); + _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomLeftResizerProvider())); + _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new TopLeftResizerProvider())); _bDiagram.Controls.AddFor(bNode2, ControlsType.OnHover).Add(new BoundaryControl()); _bDiagram.Controls.AddFor(bLink1, ControlsType.OnSelection).Add(new BoundaryControl()); _bDiagram.SelectModel(bNode1, false); diff --git a/src/Blazor.Diagrams.Core/Models/NodeModel.cs b/src/Blazor.Diagrams.Core/Models/NodeModel.cs index 053c5b3d8..5e18ac210 100644 --- a/src/Blazor.Diagrams.Core/Models/NodeModel.cs +++ b/src/Blazor.Diagrams.Core/Models/NodeModel.cs @@ -11,6 +11,7 @@ public class NodeModel : MovableModel, IHasBounds, IHasShape, ILinkable private readonly List _ports = new(); private readonly List _links = new(); private Size? _size; + public Size MinimumDimensions { get; set; } = new Size(1, 1); public event Action? SizeChanged; public event Action? Moving; diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs index 166f539fc..251887826 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -17,7 +17,7 @@ public class BottomLeftResizerProvider : IResizeProvider { if (model is NodeModel nodeModel && nodeModel.Size is not null) { - return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + return new Point(nodeModel.Position.X - 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); } return null; } @@ -40,27 +40,24 @@ public void OnPointerMove(Model? model, PointerEventArgs args) { return; } - var width = _originalSize.Width; - var height = _originalSize.Height; - var positionX = _nodeModel.Position.X; - var positionY = _nodeModel.Position.Y; - height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); + var height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + var width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); - positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); - positionY = _originalPosition.Y; + var positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); + var positionY = _originalPosition.Y; + + if (width < _nodeModel.MinimumDimensions.Width) + { + width = _nodeModel.MinimumDimensions.Width; + positionX = _nodeModel.Position.X; + } + if (height < _nodeModel.MinimumDimensions.Height) + { + height = _nodeModel.MinimumDimensions.Height; + positionY = _nodeModel.Position.Y; + } - //if (width < model.MinimumDimensions.Width) - //{ - // width = model.MinimumDimensions.Width; - // positionX = model.Position.X; - //} - //if (height < model.MinimumDimensions.Height) - //{ - // height = model.MinimumDimensions.Height; - // positionY = model.Position.Y; - //} _nodeModel.SetPosition(positionX, positionY); _nodeModel.Size = new Size(width, height); } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index e58d30ce7..fc2e0adf2 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -40,24 +40,23 @@ public void OnPointerMove(Model? model, PointerEventArgs args) { return; } - var width = _originalSize.Width; - var height = _originalSize.Height; var positionX = _nodeModel.Position.X; var positionY = _nodeModel.Position.Y; - height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + var height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); + var width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + + if (width < _nodeModel.MinimumDimensions.Width) + { + width = _nodeModel.MinimumDimensions.Width; + positionX = _nodeModel.Position.X; + } + if (height < _nodeModel.MinimumDimensions.Height) + { + height = _nodeModel.MinimumDimensions.Height; + positionY = _nodeModel.Position.Y; + } - //if (width < model.MinimumDimensions.Width) - //{ - // width = model.MinimumDimensions.Width; - // positionX = model.Position.X; - //} - //if (height < model.MinimumDimensions.Height) - //{ - // height = model.MinimumDimensions.Height; - // positionY = model.Position.Y; - //} _nodeModel.SetPosition(positionX, positionY); _nodeModel.Size = new Size(width, height); } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index 7baa8438d..5a128aa10 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -17,7 +17,7 @@ public class TopLeftResizerProvider : IResizeProvider { if (model is NodeModel nodeModel && nodeModel.Size is not null) { - return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + return new Point(nodeModel.Position.X - 5, nodeModel.Position.Y - 5); } return null; } @@ -40,27 +40,24 @@ public void OnPointerMove(Model? model, PointerEventArgs args) { return; } - var width = _originalSize.Width; - var height = _originalSize.Height; - var positionX = _nodeModel.Position.X; - var positionY = _nodeModel.Position.Y; - height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); + var height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); + var width = _originalSize.Width - (args.ClientX - _originalMousePosition.X); - positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); - positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); + var positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X); + var positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); + + if (width < _nodeModel.MinimumDimensions.Width) + { + width = _nodeModel.MinimumDimensions.Width; + positionX = _nodeModel.Position.X; + } + if (height < _nodeModel.MinimumDimensions.Height) + { + height = _nodeModel.MinimumDimensions.Height; + positionY = _nodeModel.Position.Y; + } - //if (width < model.MinimumDimensions.Width) - //{ - // width = model.MinimumDimensions.Width; - // positionX = model.Position.X; - //} - //if (height < model.MinimumDimensions.Height) - //{ - // height = model.MinimumDimensions.Height; - // positionY = model.Position.Y; - //} _nodeModel.SetPosition(positionX, positionY); _nodeModel.Size = new Size(width, height); } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index 0b4abcdcb..779d262d1 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -17,7 +17,7 @@ public class TopRightResizerProvider : IResizeProvider { if (model is NodeModel nodeModel && nodeModel.Size is not null) { - return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y + nodeModel.Size.Height + 5); + return new Point(nodeModel.Position.X + nodeModel.Size.Width + 5, nodeModel.Position.Y - 5); } return null; } @@ -40,27 +40,23 @@ public void OnPointerMove(Model? model, PointerEventArgs args) { return; } - var width = _originalSize.Width; - var height = _originalSize.Height; - var positionX = _nodeModel.Position.X; - var positionY = _nodeModel.Position.Y; + var height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); + var width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); - height = _originalSize.Height - (args.ClientY - _originalMousePosition.Y); - width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); + var positionX = _originalPosition.X; + var positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); - positionX = _originalPosition.X; - positionY = _originalPosition.Y + (args.ClientY - _originalMousePosition.Y); + if (width < _nodeModel.MinimumDimensions.Width) + { + width = _nodeModel.MinimumDimensions.Width; + positionX = _nodeModel.Position.X; + } + if (height < _nodeModel.MinimumDimensions.Height) + { + height = _nodeModel.MinimumDimensions.Height; + positionY = _nodeModel.Position.Y; + } - //if (width < model.MinimumDimensions.Width) - //{ - // width = model.MinimumDimensions.Width; - // positionX = model.Position.X; - //} - //if (height < model.MinimumDimensions.Height) - //{ - // height = model.MinimumDimensions.Height; - // positionY = model.Position.Y; - //} _nodeModel.SetPosition(positionX, positionY); _nodeModel.Size = new Size(width, height); } From 7da39d8ab46eb1d25e8a600d7fe6af0fde466f93 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Wed, 22 Nov 2023 10:18:01 +1100 Subject: [PATCH 10/21] update tests --- src/Blazor.Diagrams.Core/Models/NodeModel.cs | 2 +- .../Resizing/BottomLeftResizerProviderTests.cs | 6 ++++-- .../Positions/Resizing/TopLeftResizerProviderTests.cs | 10 ++++++---- .../Positions/Resizing/TopRightResizerProviderTests.cs | 10 ++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Models/NodeModel.cs b/src/Blazor.Diagrams.Core/Models/NodeModel.cs index 5e18ac210..d1405b79e 100644 --- a/src/Blazor.Diagrams.Core/Models/NodeModel.cs +++ b/src/Blazor.Diagrams.Core/Models/NodeModel.cs @@ -11,7 +11,7 @@ public class NodeModel : MovableModel, IHasBounds, IHasShape, ILinkable private readonly List _ports = new(); private readonly List _links = new(); private Size? _size; - public Size MinimumDimensions { get; set; } = new Size(1, 1); + public Size MinimumDimensions { get; set; } = new Size(0, 0); public event Action? SizeChanged; public event Action? Moving; diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs index 1b23ae3bc..904600c0b 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs @@ -67,11 +67,13 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() // resize var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); control.OnPointerDown(diagram, node, eventArgs); - eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + eventArgs = new PointerEventArgs(99, -199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); // after resize - node.Position.X.Should().Be(100); + node.Position.X.Should().Be(99); node.Position.Y.Should().Be(0); node.Size.Width.Should().Be(0); node.Size.Height.Should().Be(0); diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs index f594b1ca4..867ca4abd 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs @@ -67,12 +67,14 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() // resize var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); control.OnPointerDown(diagram, node, eventArgs); - eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + eventArgs = new PointerEventArgs(99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); - // after resize - node.Position.X.Should().Be(100); - node.Position.Y.Should().Be(200); + // after resize + node.Position.X.Should().Be(99); + node.Position.Y.Should().Be(199); node.Size.Width.Should().Be(0); node.Size.Height.Should().Be(0); } diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs index ab0fd5500..c67d08b11 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs @@ -67,12 +67,14 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() // resize var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); control.OnPointerDown(diagram, node, eventArgs); - eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + eventArgs = new PointerEventArgs(-99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); - // after resize - node.Position.X.Should().Be(0); - node.Position.Y.Should().Be(200); + // after resize + node.Position.X.Should().Be(0); + node.Position.Y.Should().Be(199); node.Size.Width.Should().Be(0); node.Size.Height.Should().Be(0); } From 590f165bf68580786e8bbe115f10d6938a35553d Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Wed, 22 Nov 2023 10:22:22 +1100 Subject: [PATCH 11/21] tidy up --- .../Positions/Resizing/BottomLeftResizerProvider.cs | 3 --- .../Positions/Resizing/BottomRightResizerProvider.cs | 6 ------ .../Positions/Resizing/TopLeftResizerProvider.cs | 3 --- .../Positions/Resizing/TopRightResizerProvider.cs | 3 --- 4 files changed, 15 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs index 251887826..6be4ea92b 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -11,7 +11,6 @@ public class BottomLeftResizerProvider : IResizeProvider private Point _originalPosition = null!; private Point _originalMousePosition = null!; private NodeModel _nodeModel = null!; - private Diagram _diagram = null!; public Point? GetPosition(Model model) { @@ -30,7 +29,6 @@ public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventAr _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); _originalSize = nodeModel.Size!; _nodeModel = nodeModel; - _diagram = diagram; } } @@ -68,7 +66,6 @@ public void OnResizeEnd(Model? model, PointerEventArgs args) _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; - _diagram = null!; } } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index fc2e0adf2..493abe2d8 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -8,10 +8,8 @@ namespace Blazor.Diagrams.Core.Positions.Resizing public class BottomRightResizerProvider : IResizeProvider { private Size _originalSize = null!; - private Point _originalPosition = null!; private Point _originalMousePosition = null!; private NodeModel _nodeModel = null!; - private Diagram _diagram = null!; public Point? GetPosition(Model model) { @@ -26,11 +24,9 @@ public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventAr { if (model is NodeModel nodeModel) { - _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y); _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); _originalSize = nodeModel.Size!; _nodeModel = nodeModel; - _diagram = diagram; } } @@ -64,10 +60,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { _originalSize = null!; - _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; - _diagram = null!; } } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index 5a128aa10..88b19f692 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -11,7 +11,6 @@ public class TopLeftResizerProvider : IResizeProvider private Point _originalPosition = null!; private Point _originalMousePosition = null!; private NodeModel _nodeModel = null!; - private Diagram _diagram = null!; public Point? GetPosition(Model model) { @@ -30,7 +29,6 @@ public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventAr _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); _originalSize = nodeModel.Size!; _nodeModel = nodeModel; - _diagram = diagram; } } @@ -68,7 +66,6 @@ public void OnResizeEnd(Model? model, PointerEventArgs args) _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; - _diagram = null!; } } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index 779d262d1..be4a7f4e7 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -11,7 +11,6 @@ public class TopRightResizerProvider : IResizeProvider private Point _originalPosition = null!; private Point _originalMousePosition = null!; private NodeModel _nodeModel = null!; - private Diagram _diagram = null!; public Point? GetPosition(Model model) { @@ -30,7 +29,6 @@ public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventAr _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY); _originalSize = nodeModel.Size!; _nodeModel = nodeModel; - _diagram = diagram; } } @@ -67,7 +65,6 @@ public void OnResizeEnd(Model? model, PointerEventArgs args) _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; - _diagram = null!; } } From 2338e6ae5e1a073649f3b6f22f112f084a7c11a9 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Wed, 22 Nov 2023 10:27:26 +1100 Subject: [PATCH 12/21] undo changes to website --- site/Site/Pages/Documentation/Controls/Overview.razor | 7 ------- 1 file changed, 7 deletions(-) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index 4e2bc80d8..bd87fa9a1 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -3,7 +3,6 @@ @using Blazor.Diagrams.Core.Controls; @using Blazor.Diagrams.Core.PathGenerators; @using Blazor.Diagrams.Core.Positions; -@using Blazor.Diagrams.Core.Positions.Resizing; @using Blazor.Diagrams.Core.Routers; @layout DocumentationLayout @inherits DocumentationPage @@ -160,11 +159,6 @@ Diagram.Controls.AddFor(SomeModel) bNode2.Title = "Hover on me"; bLink1.AddLabel("Select me", distance: 0.5); _bDiagram.Controls.AddFor(bNode1, ControlsType.OnSelection).Add(new BoundaryControl()); - _bDiagram.Controls.AddFor(bNode1).Add(new ResizeControl(new BottomRightResizerProvider())); - _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomRightResizerProvider())); - _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new TopRightResizerProvider())); - _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomLeftResizerProvider())); - _bDiagram.Controls.AddFor(bNode2, ControlsType.OnSelection).Add(new ResizeControl(new TopLeftResizerProvider())); _bDiagram.Controls.AddFor(bNode2, ControlsType.OnHover).Add(new BoundaryControl()); _bDiagram.Controls.AddFor(bLink1, ControlsType.OnSelection).Add(new BoundaryControl()); _bDiagram.SelectModel(bNode1, false); @@ -178,7 +172,6 @@ Diagram.Controls.AddFor(SomeModel) rNode2.Title = "Select me"; rLink1.AddLabel("Select me", distance: 0.5); _rDiagram.Controls.AddFor(rNode1, ControlsType.OnSelection).Add(new RemoveControl(0.5, 0)); - _rDiagram.Controls.AddFor(rNode1, ControlsType.OnHover).Add(new ResizeControl(new BottomRightResizerProvider())); _rDiagram.Controls.AddFor(rNode2, ControlsType.OnSelection).Add(new RemoveControl(0.5, 1)); _rDiagram.Controls.AddFor(rLink1, ControlsType.OnSelection).Add(new RemoveControl(new LinkPathPositionProvider(0.8, 0, -10))); _rDiagram.SelectModel(rNode1, false); From e526cc20961ce84374b12bf76ceb60827154edaa Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 30 Nov 2023 11:29:35 +1100 Subject: [PATCH 13/21] fix formatting --- .../Positions/Resizing/BottomLeftResizerProviderTests.cs | 6 +++--- .../Positions/Resizing/TopLeftResizerProviderTests.cs | 8 ++++---- .../Positions/Resizing/TopRightResizerProviderTests.cs | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs index 904600c0b..79ef6c17b 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/BottomLeftResizerProviderTests.cs @@ -67,9 +67,9 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() // resize var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); control.OnPointerDown(diagram, node, eventArgs); - eventArgs = new PointerEventArgs(99, -199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); - diagram.TriggerPointerMove(null, eventArgs); - eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + eventArgs = new PointerEventArgs(99, -199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); // after resize diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs index 867ca4abd..1cc715d59 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopLeftResizerProviderTests.cs @@ -69,11 +69,11 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() control.OnPointerDown(diagram, node, eventArgs); eventArgs = new PointerEventArgs(99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); - eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); - diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); - // after resize - node.Position.X.Should().Be(99); + // after resize + node.Position.X.Should().Be(99); node.Position.Y.Should().Be(199); node.Size.Width.Should().Be(0); node.Size.Height.Should().Be(0); diff --git a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs index c67d08b11..a138d524f 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Positions/Resizing/TopRightResizerProviderTests.cs @@ -69,11 +69,11 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize() control.OnPointerDown(diagram, node, eventArgs); eventArgs = new PointerEventArgs(-99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); diagram.TriggerPointerMove(null, eventArgs); - eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); - diagram.TriggerPointerMove(null, eventArgs); + eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true); + diagram.TriggerPointerMove(null, eventArgs); - // after resize - node.Position.X.Should().Be(0); + // after resize + node.Position.X.Should().Be(0); node.Position.Y.Should().Be(199); node.Size.Width.Should().Be(0); node.Size.Height.Should().Be(0); From 065b1534449cc32ec365b0687ceabbf14c003c80 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Fri, 1 Dec 2023 14:10:02 +1100 Subject: [PATCH 14/21] add SetSize method to refresh as size updates --- src/Blazor.Diagrams.Core/Models/NodeModel.cs | 12 ++++++++++-- .../Positions/Resizing/BottomLeftResizerProvider.cs | 2 +- .../Positions/Resizing/BottomRightResizerProvider.cs | 7 +------ .../Positions/Resizing/TopLeftResizerProvider.cs | 4 ++-- .../Positions/Resizing/TopRightResizerProvider.cs | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Models/NodeModel.cs b/src/Blazor.Diagrams.Core/Models/NodeModel.cs index d1405b79e..1b9c2f648 100644 --- a/src/Blazor.Diagrams.Core/Models/NodeModel.cs +++ b/src/Blazor.Diagrams.Core/Models/NodeModel.cs @@ -14,7 +14,7 @@ public class NodeModel : MovableModel, IHasBounds, IHasShape, ILinkable public Size MinimumDimensions { get; set; } = new Size(0, 0); public event Action? SizeChanged; - public event Action? Moving; + public event Action? Moving; public NodeModel(Point? position = null) : base(position) { @@ -104,7 +104,15 @@ public override void SetPosition(double x, double y) Moving?.Invoke(this); } - public virtual void UpdatePositionSilently(double deltaX, double deltaY) + public void SetSize(double width, double height) + { + Size = new Size(width, height); + + Refresh(); + RefreshLinks(); + } + + public virtual void UpdatePositionSilently(double deltaX, double deltaY) { base.SetPosition(Position.X + deltaX, Position.Y + deltaY); UpdatePortPositions(deltaX, deltaY); diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs index 6be4ea92b..011ed0c60 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -57,7 +57,7 @@ public void OnPointerMove(Model? model, PointerEventArgs args) } _nodeModel.SetPosition(positionX, positionY); - _nodeModel.Size = new Size(width, height); + _nodeModel.SetSize(width, height); } public void OnResizeEnd(Model? model, PointerEventArgs args) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index 493abe2d8..5211aec39 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -36,8 +36,6 @@ public void OnPointerMove(Model? model, PointerEventArgs args) { return; } - var positionX = _nodeModel.Position.X; - var positionY = _nodeModel.Position.Y; var height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y); var width = _originalSize.Width + (args.ClientX - _originalMousePosition.X); @@ -45,16 +43,13 @@ public void OnPointerMove(Model? model, PointerEventArgs args) if (width < _nodeModel.MinimumDimensions.Width) { width = _nodeModel.MinimumDimensions.Width; - positionX = _nodeModel.Position.X; } if (height < _nodeModel.MinimumDimensions.Height) { height = _nodeModel.MinimumDimensions.Height; - positionY = _nodeModel.Position.Y; } - _nodeModel.SetPosition(positionX, positionY); - _nodeModel.Size = new Size(width, height); + _nodeModel.SetSize(width, height); } public void OnResizeEnd(Model? model, PointerEventArgs args) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index 88b19f692..95c6d4013 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -57,8 +57,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) } _nodeModel.SetPosition(positionX, positionY); - _nodeModel.Size = new Size(width, height); - } + _nodeModel.SetSize(width, height); + } public void OnResizeEnd(Model? model, PointerEventArgs args) { diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index be4a7f4e7..f9f4e2e5d 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -56,8 +56,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) } _nodeModel.SetPosition(positionX, positionY); - _nodeModel.Size = new Size(width, height); - } + _nodeModel.SetSize(width, height); + } public void OnResizeEnd(Model? model, PointerEventArgs args) { From 9f036f2cef8a59019e2f72f3ebfff3faba99514c Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Fri, 1 Dec 2023 14:18:30 +1100 Subject: [PATCH 15/21] add size changed event --- src/Blazor.Diagrams.Core/Models/GroupModel.cs | 8 ++++---- src/Blazor.Diagrams.Core/Models/NodeModel.cs | 12 +++++++++--- .../Positions/Resizing/BottomLeftResizerProvider.cs | 1 + .../Positions/Resizing/BottomRightResizerProvider.cs | 3 ++- .../Positions/Resizing/TopLeftResizerProvider.cs | 3 ++- .../Positions/Resizing/TopRightResizerProvider.cs | 3 ++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Models/GroupModel.cs b/src/Blazor.Diagrams.Core/Models/GroupModel.cs index 041d872ec..5c3780afc 100644 --- a/src/Blazor.Diagrams.Core/Models/GroupModel.cs +++ b/src/Blazor.Diagrams.Core/Models/GroupModel.cs @@ -27,7 +27,7 @@ public void AddChild(NodeModel child) { _children.Add(child); child.Group = this; - child.SizeChanged += OnNodeChanged; + child.SizeChanging += OnNodeChanged; child.Moving += OnNodeChanged; if (UpdateDimensions()) @@ -42,7 +42,7 @@ public void RemoveChild(NodeModel child) return; child.Group = null; - child.SizeChanged -= OnNodeChanged; + child.SizeChanging -= OnNodeChanged; child.Moving -= OnNodeChanged; if (UpdateDimensions()) @@ -83,7 +83,7 @@ public void Ungroup() foreach (var child in Children) { child.Group = null; - child.SizeChanged -= OnNodeChanged; + child.SizeChanging -= OnNodeChanged; child.Moving -= OnNodeChanged; } @@ -96,7 +96,7 @@ private void Initialize(IEnumerable children) { _children.Add(child); child.Group = this; - child.SizeChanged += OnNodeChanged; + child.SizeChanging += OnNodeChanged; child.Moving += OnNodeChanged; } diff --git a/src/Blazor.Diagrams.Core/Models/NodeModel.cs b/src/Blazor.Diagrams.Core/Models/NodeModel.cs index 1b9c2f648..079b0951a 100644 --- a/src/Blazor.Diagrams.Core/Models/NodeModel.cs +++ b/src/Blazor.Diagrams.Core/Models/NodeModel.cs @@ -13,7 +13,8 @@ public class NodeModel : MovableModel, IHasBounds, IHasShape, ILinkable private Size? _size; public Size MinimumDimensions { get; set; } = new Size(0, 0); - public event Action? SizeChanged; + public event Action? SizeChanging; + public event Action? SizeChanged; public event Action? Moving; public NodeModel(Point? position = null) : base(position) @@ -33,7 +34,7 @@ public Size? Size return; _size = value; - SizeChanged?.Invoke(this); + SizeChanging?.Invoke(this); } } public bool ControlledSize { get; init; } @@ -112,6 +113,11 @@ public void SetSize(double width, double height) RefreshLinks(); } + public void TriggerSizeChanged() + { + SizeChanged?.Invoke(this); + } + public virtual void UpdatePositionSilently(double deltaX, double deltaY) { base.SetPosition(Position.X + deltaX, Position.Y + deltaY); @@ -165,7 +171,7 @@ protected void TriggerMoving() Moving?.Invoke(this); } - void ILinkable.AddLink(BaseLinkModel link) => _links.Add(link); + void ILinkable.AddLink(BaseLinkModel link) => _links.Add(link); void ILinkable.RemoveLink(BaseLinkModel link) => _links.Remove(link); } \ No newline at end of file diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs index 011ed0c60..98ff760fc 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs @@ -62,6 +62,7 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { + _nodeModel?.TriggerSizeChanged(); _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index 5211aec39..f7a7a97dc 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -54,7 +54,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalMousePosition = null!; _nodeModel = null!; } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index 95c6d4013..ee96c278c 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -62,7 +62,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index f9f4e2e5d..3fd462a9a 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -61,7 +61,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; From 25a23f817013c606d0f28aaaa13e93a9acf55f4d Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 7 Dec 2023 11:51:54 +1100 Subject: [PATCH 16/21] change size setting & events to be more similar to position setting & events --- src/Blazor.Diagrams.Core/Models/GroupModel.cs | 18 +++------- src/Blazor.Diagrams.Core/Models/NodeModel.cs | 36 +++++++++---------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Models/GroupModel.cs b/src/Blazor.Diagrams.Core/Models/GroupModel.cs index 5c3780afc..4a450be1b 100644 --- a/src/Blazor.Diagrams.Core/Models/GroupModel.cs +++ b/src/Blazor.Diagrams.Core/Models/GroupModel.cs @@ -30,10 +30,7 @@ public void AddChild(NodeModel child) child.SizeChanging += OnNodeChanged; child.Moving += OnNodeChanged; - if (UpdateDimensions()) - { - Refresh(); - } + UpdateDimensions(); } public void RemoveChild(NodeModel child) @@ -45,11 +42,7 @@ public void RemoveChild(NodeModel child) child.SizeChanging -= OnNodeChanged; child.Moving -= OnNodeChanged; - if (UpdateDimensions()) - { - Refresh(); - RefreshLinks(); - } + UpdateDimensions(); } public override void SetPosition(double x, double y) @@ -105,10 +98,7 @@ private void Initialize(IEnumerable children) private void OnNodeChanged(NodeModel node) { - if (UpdateDimensions()) - { - Refresh(); - } + UpdateDimensions(); } private bool UpdateDimensions() @@ -128,7 +118,7 @@ private bool UpdateDimensions() TriggerMoving(); } - Size = new Size(bounds.Width + Padding * 2, bounds.Height + Padding * 2); + SetSize(bounds.Width + Padding * 2, bounds.Height + Padding * 2); return true; } } diff --git a/src/Blazor.Diagrams.Core/Models/NodeModel.cs b/src/Blazor.Diagrams.Core/Models/NodeModel.cs index 079b0951a..610a5aac3 100644 --- a/src/Blazor.Diagrams.Core/Models/NodeModel.cs +++ b/src/Blazor.Diagrams.Core/Models/NodeModel.cs @@ -14,8 +14,8 @@ public class NodeModel : MovableModel, IHasBounds, IHasShape, ILinkable public Size MinimumDimensions { get; set; } = new Size(0, 0); public event Action? SizeChanging; - public event Action? SizeChanged; - public event Action? Moving; + public event Action? SizeChanged; + public event Action? Moving; public NodeModel(Point? position = null) : base(position) { @@ -30,11 +30,7 @@ public Size? Size get => _size; set { - if (value?.Equals(_size) == true) - return; - _size = value; - SizeChanging?.Invoke(this); } } public bool ControlledSize { get; init; } @@ -105,20 +101,24 @@ public override void SetPosition(double x, double y) Moving?.Invoke(this); } - public void SetSize(double width, double height) - { - Size = new Size(width, height); + public void SetSize(double width, double height) + { + var newSize = new Size(width, height); + if (newSize.Equals(_size) == true) + return; - Refresh(); - RefreshLinks(); - } + Size = newSize; + Refresh(); + RefreshLinks(); + SizeChanging?.Invoke(this); + } - public void TriggerSizeChanged() - { - SizeChanged?.Invoke(this); - } + public void TriggerSizeChanged() + { + SizeChanged?.Invoke(this); + } - public virtual void UpdatePositionSilently(double deltaX, double deltaY) + public virtual void UpdatePositionSilently(double deltaX, double deltaY) { base.SetPosition(Position.X + deltaX, Position.Y + deltaY); UpdatePortPositions(deltaX, deltaY); @@ -171,7 +171,7 @@ protected void TriggerMoving() Moving?.Invoke(this); } - void ILinkable.AddLink(BaseLinkModel link) => _links.Add(link); + void ILinkable.AddLink(BaseLinkModel link) => _links.Add(link); void ILinkable.RemoveLink(BaseLinkModel link) => _links.Remove(link); } \ No newline at end of file From 9ea4c5a0915d6b9b301028a14e3cd67bc35eb37a Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 7 Dec 2023 12:00:43 +1100 Subject: [PATCH 17/21] fix formatting --- .../Positions/Resizing/BottomRightResizerProvider.cs | 4 ++-- .../Positions/Resizing/TopLeftResizerProvider.cs | 8 ++++---- .../Positions/Resizing/TopRightResizerProvider.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs index f7a7a97dc..363661cc6 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs @@ -54,8 +54,8 @@ public void OnPointerMove(Model? model, PointerEventArgs args) public void OnResizeEnd(Model? model, PointerEventArgs args) { - _nodeModel?.TriggerSizeChanged(); - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalMousePosition = null!; _nodeModel = null!; } diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs index ee96c278c..d237ab715 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs @@ -57,13 +57,13 @@ public void OnPointerMove(Model? model, PointerEventArgs args) } _nodeModel.SetPosition(positionX, positionY); - _nodeModel.SetSize(width, height); - } + _nodeModel.SetSize(width, height); + } public void OnResizeEnd(Model? model, PointerEventArgs args) { - _nodeModel?.TriggerSizeChanged(); - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs index 3fd462a9a..e53e31999 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs @@ -56,13 +56,13 @@ public void OnPointerMove(Model? model, PointerEventArgs args) } _nodeModel.SetPosition(positionX, positionY); - _nodeModel.SetSize(width, height); - } + _nodeModel.SetSize(width, height); + } public void OnResizeEnd(Model? model, PointerEventArgs args) { - _nodeModel?.TriggerSizeChanged(); - _originalSize = null!; + _nodeModel?.TriggerSizeChanged(); + _originalSize = null!; _originalPosition = null!; _originalMousePosition = null!; _nodeModel = null!; From ead9e9137a025a63ec764c7804d67e9a4048822a Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 7 Dec 2023 14:46:26 +1100 Subject: [PATCH 18/21] add documentation for resize control --- .../Documentation/Controls/Overview.razor | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index bd87fa9a1..e0efec975 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -3,6 +3,7 @@ @using Blazor.Diagrams.Core.Controls; @using Blazor.Diagrams.Core.PathGenerators; @using Blazor.Diagrams.Core.Positions; +@using Blazor.Diagrams.Core.Positions.Resizing; @using Blazor.Diagrams.Core.Routers; @layout DocumentationLayout @inherits DocumentationPage @@ -135,6 +136,26 @@ Diagram.Controls.AddFor(SomeModel)
+

Resize Control

+ +

+ The ResizeControl adds a resizer which is a box that when dragged, can resize the node. The resizer position and movement of the node is controlled using a Resizer Provider.
+ There are four `ResizerProvider`s, one for each corner. Custom resizing behavior can be created by implementing `IResizeProvider`. +

+ +

+Diagram.Controls.AddFor(SomeModel).Add(new ResizeControl(new BottomRightResizerProvider()));
+Diagram.Controls.AddFor(SomeModel).Add(new ResizeControl(new BottomLeftResizerProvider()));
+Diagram.Controls.AddFor(SomeModel).Add(new ResizeControl(new TopRightResizerProvider()));
+Diagram.Controls.AddFor(SomeModel).Add(new ResizeControl(new TopLeftResizerProvider()));
+
+ +
+ + + +
+ @@ -143,6 +164,7 @@ Diagram.Controls.AddFor(SomeModel) private BlazorDiagram _rDiagram = new(); private BlazorDiagram _ahDiagram = new(); private BlazorDiagram _dnlDiagram = new(); + private BlazorDiagram _resizerDiagram = new(); protected override void OnInitialized() { @@ -198,5 +220,18 @@ Diagram.Controls.AddFor(SomeModel) _dnlDiagram.Controls.AddFor(dnlNode2).Add(new DragNewLinkControl(0, 0.5, offsetX: -20)); _dnlDiagram.SelectModel(dnlNode1, false); _dnlDiagram.SelectModel(dnlNode2, false); + + // Resize Control + var resizeNode1 = _resizerDiagram.Nodes.Add(new NodeModel(new Point(100, 100))); + var resizeNode2 = _resizerDiagram.Nodes.Add(new NodeModel(new Point(500, 150))); + resizeNode1.Title = "Title"; + resizeNode2.Title = "Title"; + _resizerDiagram.Controls.AddFor(resizeNode1, ControlsType.OnSelection).Add(new ResizeControl(new BottomRightResizerProvider())); + _resizerDiagram.Controls.AddFor(resizeNode1, ControlsType.OnSelection).Add(new ResizeControl(new BottomLeftResizerProvider())); + _resizerDiagram.Controls.AddFor(resizeNode1, ControlsType.OnSelection).Add(new ResizeControl(new TopRightResizerProvider())); + _resizerDiagram.Controls.AddFor(resizeNode1, ControlsType.OnSelection).Add(new ResizeControl(new TopLeftResizerProvider())); + _resizerDiagram.Controls.AddFor(resizeNode2, ControlsType.OnSelection).Add(new ResizeControl(new BottomRightResizerProvider())); + _resizerDiagram.SelectModel(resizeNode1, false); + _resizerDiagram.SelectModel(resizeNode2, false); } } \ No newline at end of file From 32b36b6d6b86ead9e596c0c51820ba5d65fdb941 Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 7 Dec 2023 14:48:21 +1100 Subject: [PATCH 19/21] rename IResizeProvider to IResizerProvider --- .../Documentation/Controls/Overview.razor | 2 +- .../Controls/Default/ResizeControl.cs | 4 +- .../Resizing/BottomLeftResizeProvider.cs | 73 +++++++++++++++++++ .../Resizing/BottomLeftResizerProvider.cs | 2 +- .../Resizing/BottomRightResizerProvider.cs | 2 +- ...IResizeProvider.cs => IResizerProvider.cs} | 2 +- .../Resizing/TopLeftResizerProvider.cs | 2 +- .../Resizing/TopRightResizerProvider.cs | 2 +- .../Controls/ResizeControlTests.cs | 8 +- 9 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs rename src/Blazor.Diagrams.Core/Positions/Resizing/{IResizeProvider.cs => IResizerProvider.cs} (87%) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index e0efec975..6c6c6b1b9 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -140,7 +140,7 @@ Diagram.Controls.AddFor(SomeModel)

The ResizeControl adds a resizer which is a box that when dragged, can resize the node. The resizer position and movement of the node is controlled using a Resizer Provider.
- There are four `ResizerProvider`s, one for each corner. Custom resizing behavior can be created by implementing `IResizeProvider`. + There are four `ResizerProvider`s, one for each corner. Custom resizing behavior can be created by implementing `IResizerProvider`.


diff --git a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
index 3673487e3..374e944e0 100644
--- a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
+++ b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
@@ -8,9 +8,9 @@ namespace Blazor.Diagrams.Core.Controls.Default
 {
     public class ResizeControl : ExecutableControl
     {
-        private readonly IResizeProvider _resizeProvider;
+        private readonly IResizerProvider _resizeProvider;
 
-        public ResizeControl(IResizeProvider resizeProvider)
+        public ResizeControl(IResizerProvider resizeProvider)
         {
             _resizeProvider = resizeProvider;
         }
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs
new file mode 100644
index 000000000..72dfdc53b
--- /dev/null
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs
@@ -0,0 +1,73 @@
+using Blazor.Diagrams.Core.Events;
+using Blazor.Diagrams.Core.Geometry;
+using Blazor.Diagrams.Core.Models;
+using Blazor.Diagrams.Core.Models.Base;
+
+namespace Blazor.Diagrams.Core.Positions.Resizing
+{
+    public class BottomLeftResizeProvider : IResizerProvider
+    {
+        private Size _originalSize = null!;
+        private Point _originalPosition = null!;
+        private Point _originalMousePosition = null!;
+        private NodeModel _nodeModel = null!;
+
+        public Point? GetPosition(Model model)
+        {
+            if (model is NodeModel nodeModel && nodeModel.Size is not null)
+            {
+                return new Point(nodeModel.Position.X - 5, nodeModel.Position.Y + nodeModel.Size.Height + 5);
+            }
+            return null;
+        }
+
+        public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs)
+        {
+            if (model is NodeModel nodeModel)
+            {
+                _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y);
+                _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY);
+                _originalSize = nodeModel.Size!;
+                _nodeModel = nodeModel;
+            }
+        }
+
+        public void OnPointerMove(Model? model, PointerEventArgs args)
+        {
+            if (_nodeModel is null)
+            {
+                return;
+            }
+
+            var height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y);
+            var width = _originalSize.Width - (args.ClientX - _originalMousePosition.X);
+
+            var positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X);
+            var positionY = _originalPosition.Y;
+
+            if (width < _nodeModel.MinimumDimensions.Width)
+            {
+                width = _nodeModel.MinimumDimensions.Width;
+                positionX = _nodeModel.Position.X;
+            }
+            if (height < _nodeModel.MinimumDimensions.Height)
+            {
+                height = _nodeModel.MinimumDimensions.Height;
+                positionY = _nodeModel.Position.Y;
+            }
+
+            _nodeModel.SetPosition(positionX, positionY);
+            _nodeModel.SetSize(width, height);
+        }
+
+        public void OnResizeEnd(Model? model, PointerEventArgs args)
+        {
+            _nodeModel?.TriggerSizeChanged();
+            _originalSize = null!;
+            _originalPosition = null!;
+            _originalMousePosition = null!;
+            _nodeModel = null!;
+        }
+
+    }
+}
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
index 98ff760fc..3fc4b68f9 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
@@ -5,7 +5,7 @@
 
 namespace Blazor.Diagrams.Core.Positions.Resizing
 {
-    public class BottomLeftResizerProvider : IResizeProvider
+    public class BottomLeftResizerProvider : IResizerProvider
     {
         private Size _originalSize = null!;
         private Point _originalPosition = null!;
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
index 363661cc6..558a4cf73 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
@@ -5,7 +5,7 @@
 
 namespace Blazor.Diagrams.Core.Positions.Resizing
 {
-    public class BottomRightResizerProvider : IResizeProvider
+    public class BottomRightResizerProvider : IResizerProvider
     {
         private Size _originalSize = null!;
         private Point _originalMousePosition = null!;
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
similarity index 87%
rename from src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs
rename to src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
index 410ff684a..1440eff64 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/IResizeProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
@@ -4,7 +4,7 @@
 
 namespace Blazor.Diagrams.Core.Positions.Resizing
 {
-    public interface IResizeProvider : IPositionProvider
+    public interface IResizerProvider : IPositionProvider
     {
         public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs);
         public void OnPointerMove(Model? model, PointerEventArgs args);
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
index d237ab715..396690866 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
@@ -5,7 +5,7 @@
 
 namespace Blazor.Diagrams.Core.Positions.Resizing
 {
-    public class TopLeftResizerProvider : IResizeProvider
+    public class TopLeftResizerProvider : IResizerProvider
     {
         private Size _originalSize = null!;
         private Point _originalPosition = null!;
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
index e53e31999..efb1451c5 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
@@ -5,7 +5,7 @@
 
 namespace Blazor.Diagrams.Core.Positions.Resizing
 {
-    public class TopRightResizerProvider : IResizeProvider
+    public class TopRightResizerProvider : IResizerProvider
     {
         private Size _originalSize = null!;
         private Point _originalPosition = null!;
diff --git a/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs
index ae266bdef..dcd9bab14 100644
--- a/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs
+++ b/tests/Blazor.Diagrams.Core.Tests/Controls/ResizeControlTests.cs
@@ -12,7 +12,7 @@ public class ResizeControlTests
         [Fact]
         public void GetPosition_ShouldUseResizeProviderGetPosition()
         {
-            var resizeProvider = new Mock();
+            var resizeProvider = new Mock();
             var control = new ResizeControl(resizeProvider.Object);
             var model = new Mock();
 
@@ -24,7 +24,7 @@ public void GetPosition_ShouldUseResizeProviderGetPosition()
         [Fact]
         public void OnPointerDown_ShouldInvokeResizeStart()
         {
-            var resizeProvider = new Mock();
+            var resizeProvider = new Mock();
             var control = new ResizeControl(resizeProvider.Object);
             var diagram = Mock.Of();
             var model = Mock.Of();
@@ -38,7 +38,7 @@ public void OnPointerDown_ShouldInvokeResizeStart()
         [Fact]
         public void OnPointerDown_ShouldAddEventHandlers()
         {
-            var resizeProvider = new Mock();
+            var resizeProvider = new Mock();
             var control = new ResizeControl(resizeProvider.Object);
             var diagram = new TestDiagram();
             var model = Mock.Of();
@@ -56,7 +56,7 @@ public void OnPointerDown_ShouldAddEventHandlers()
         [Fact]
         public void OnPointerUp_ShouldRemoveEventHandlers()
         {
-            var resizeProvider = new Mock();
+            var resizeProvider = new Mock();
             var control = new ResizeControl(resizeProvider.Object);
             var diagram = new TestDiagram();
             var model = Mock.Of();

From d15c24acc290b2eef7402cc807cb1a2c771f669c Mon Sep 17 00:00:00 2001
From: Heather Cox 
Date: Thu, 7 Dec 2023 15:06:00 +1100
Subject: [PATCH 20/21] add cursors

---
 .../Controls/Default/ResizeControl.cs         |   2 +
 .../Resizing/BottomLeftResizeProvider.cs      |  73 ------------------
 .../Resizing/BottomLeftResizerProvider.cs     |   4 +-
 .../Resizing/BottomRightResizerProvider.cs    |   4 +-
 .../Positions/Resizing/IResizerProvider.cs    |   1 +
 .../Resizing/TopLeftResizerProvider.cs        |   4 +-
 .../Resizing/TopRightResizerProvider.cs       |   4 +-
 .../Controls/ResizeControlWidget.razor        |   2 +-
 .../wwwroot/default.styles.css                |  16 ++++
 .../wwwroot/default.styles.min.css            |   2 +-
 .../wwwroot/default.styles.min.css.gz         | Bin 704 -> 735 bytes
 11 files changed, 33 insertions(+), 79 deletions(-)
 delete mode 100644 src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs

diff --git a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
index 374e944e0..4517f673d 100644
--- a/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
+++ b/src/Blazor.Diagrams.Core/Controls/Default/ResizeControl.cs
@@ -17,6 +17,8 @@ public ResizeControl(IResizerProvider resizeProvider)
 
         public override Point? GetPosition(Model model) => _resizeProvider.GetPosition(model);
 
+        public string? Class => _resizeProvider.Class;
+
         public override ValueTask OnPointerDown(Diagram diagram, Model model, PointerEventArgs e)
         {
             _resizeProvider.OnResizeStart(diagram, model, e);
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs
deleted file mode 100644
index 72dfdc53b..000000000
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizeProvider.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using Blazor.Diagrams.Core.Events;
-using Blazor.Diagrams.Core.Geometry;
-using Blazor.Diagrams.Core.Models;
-using Blazor.Diagrams.Core.Models.Base;
-
-namespace Blazor.Diagrams.Core.Positions.Resizing
-{
-    public class BottomLeftResizeProvider : IResizerProvider
-    {
-        private Size _originalSize = null!;
-        private Point _originalPosition = null!;
-        private Point _originalMousePosition = null!;
-        private NodeModel _nodeModel = null!;
-
-        public Point? GetPosition(Model model)
-        {
-            if (model is NodeModel nodeModel && nodeModel.Size is not null)
-            {
-                return new Point(nodeModel.Position.X - 5, nodeModel.Position.Y + nodeModel.Size.Height + 5);
-            }
-            return null;
-        }
-
-        public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs)
-        {
-            if (model is NodeModel nodeModel)
-            {
-                _originalPosition = new Point(nodeModel.Position.X, nodeModel.Position.Y);
-                _originalMousePosition = new Point(eventArgs.ClientX, eventArgs.ClientY);
-                _originalSize = nodeModel.Size!;
-                _nodeModel = nodeModel;
-            }
-        }
-
-        public void OnPointerMove(Model? model, PointerEventArgs args)
-        {
-            if (_nodeModel is null)
-            {
-                return;
-            }
-
-            var height = _originalSize.Height + (args.ClientY - _originalMousePosition.Y);
-            var width = _originalSize.Width - (args.ClientX - _originalMousePosition.X);
-
-            var positionX = _originalPosition.X + (args.ClientX - _originalMousePosition.X);
-            var positionY = _originalPosition.Y;
-
-            if (width < _nodeModel.MinimumDimensions.Width)
-            {
-                width = _nodeModel.MinimumDimensions.Width;
-                positionX = _nodeModel.Position.X;
-            }
-            if (height < _nodeModel.MinimumDimensions.Height)
-            {
-                height = _nodeModel.MinimumDimensions.Height;
-                positionY = _nodeModel.Position.Y;
-            }
-
-            _nodeModel.SetPosition(positionX, positionY);
-            _nodeModel.SetSize(width, height);
-        }
-
-        public void OnResizeEnd(Model? model, PointerEventArgs args)
-        {
-            _nodeModel?.TriggerSizeChanged();
-            _originalSize = null!;
-            _originalPosition = null!;
-            _originalMousePosition = null!;
-            _nodeModel = null!;
-        }
-
-    }
-}
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
index 3fc4b68f9..c4e576c92 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomLeftResizerProvider.cs
@@ -7,7 +7,9 @@ namespace Blazor.Diagrams.Core.Positions.Resizing
 {
     public class BottomLeftResizerProvider : IResizerProvider
     {
-        private Size _originalSize = null!;
+		public string? Class => "bottomleft";
+
+		private Size _originalSize = null!;
         private Point _originalPosition = null!;
         private Point _originalMousePosition = null!;
         private NodeModel _nodeModel = null!;
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
index 558a4cf73..f55e26d71 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/BottomRightResizerProvider.cs
@@ -7,11 +7,13 @@ namespace Blazor.Diagrams.Core.Positions.Resizing
 {
     public class BottomRightResizerProvider : IResizerProvider
     {
+        public string? Class => "bottomright";
+
         private Size _originalSize = null!;
         private Point _originalMousePosition = null!;
         private NodeModel _nodeModel = null!;
 
-        public Point? GetPosition(Model model)
+		public Point? GetPosition(Model model)
         {
             if (model is NodeModel nodeModel && nodeModel.Size is not null)
             {
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
index 1440eff64..65a2ecdde 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/IResizerProvider.cs
@@ -6,6 +6,7 @@ namespace Blazor.Diagrams.Core.Positions.Resizing
 {
     public interface IResizerProvider : IPositionProvider
     {
+        public string? Class { get; }
         public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs);
         public void OnPointerMove(Model? model, PointerEventArgs args);
         public void OnResizeEnd(Model? model, PointerEventArgs args);
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
index 396690866..7c3afe5ce 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopLeftResizerProvider.cs
@@ -7,7 +7,9 @@ namespace Blazor.Diagrams.Core.Positions.Resizing
 {
     public class TopLeftResizerProvider : IResizerProvider
     {
-        private Size _originalSize = null!;
+		public string? Class => "topleft";
+
+		private Size _originalSize = null!;
         private Point _originalPosition = null!;
         private Point _originalMousePosition = null!;
         private NodeModel _nodeModel = null!;
diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
index efb1451c5..e9ea4e14a 100644
--- a/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
+++ b/src/Blazor.Diagrams.Core/Positions/Resizing/TopRightResizerProvider.cs
@@ -7,7 +7,9 @@ namespace Blazor.Diagrams.Core.Positions.Resizing
 {
     public class TopRightResizerProvider : IResizerProvider
     {
-        private Size _originalSize = null!;
+		public string? Class => "topright";
+
+		private Size _originalSize = null!;
         private Point _originalPosition = null!;
         private Point _originalMousePosition = null!;
         private NodeModel _nodeModel = null!;
diff --git a/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor b/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor
index ddbffd330..cfd15bd7b 100644
--- a/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor
+++ b/src/Blazor.Diagrams/Components/Controls/ResizeControlWidget.razor
@@ -1,4 +1,4 @@
-
+
@code { diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.css b/src/Blazor.Diagrams/wwwroot/default.styles.css index ea267bb66..2b355029a 100644 --- a/src/Blazor.Diagrams/wwwroot/default.styles.css +++ b/src/Blazor.Diagrams/wwwroot/default.styles.css @@ -135,4 +135,20 @@ g.diagram-group.default.selected > rect { position: absolute; } +.default-node-resizer.bottomright { + cursor: nwse-resize; +} + +.default-node-resizer.topright { + cursor: nesw-resize; +} + +.default-node-resizer.bottomleft { + cursor: nesw-resize; +} + +.default-node-resizer.topleft { + cursor: nwse-resize; +} + /*# sourceMappingURL=wwwroot\default.styles.css.map */ diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.min.css b/src/Blazor.Diagrams/wwwroot/default.styles.min.css index e5378f1ae..e794e823e 100644 --- a/src/Blazor.Diagrams/wwwroot/default.styles.min.css +++ b/src/Blazor.Diagrams/wwwroot/default.styles.min.css @@ -1 +1 @@ -.default-node{width:100px;height:80px;border-radius:10px;background-color:#f5f5f5;border:1px solid #e8e8e8;-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;}.default-node.selected{border:1px solid #6e9fd4;}.default-node.selected .diagram-port{border:1px solid #6e9fd4;}.default-node .diagram-port,.default.diagram-group .diagram-port{width:20px;height:20px;margin:-10px;border-radius:50%;background-color:#f5f5f5;border:1px solid #d4d4d4;cursor:pointer;position:absolute;}.default-node .diagram-port:hover,.default-node .diagram-port.has-links,.default.diagram-group .diagram-port.has-links{background-color:#000;}.default-node .diagram-port.bottom,.default.diagram-group .diagram-port.bottom{bottom:0;left:50%;}.default-node .diagram-port.bottomleft,.default.diagram-group .diagram-port.bottomleft{bottom:0;left:0;}.default-node .diagram-port.bottomright,.default.diagram-group .diagram-port.bottomright{bottom:0;right:0;}.default-node .diagram-port.top,.default.diagram-group .diagram-port.top{top:0;left:50%;}.default-node .diagram-port.topleft,.default.diagram-group .diagram-port.topleft{top:0;left:0;}.default-node .diagram-port.topright,.default.diagram-group .diagram-port.topright{top:0;right:0;}.default-node .diagram-port.left,.default.diagram-group .diagram-port.left{left:0;top:50%;}.default-node .diagram-port.right,.default.diagram-group .diagram-port.right{right:0;top:50%;}.diagram-navigator.default{position:absolute;bottom:10px;right:10px;border:3px solid #9ba8b0;border-radius:15px;padding:20px;background-color:#fff;}div.diagram-group.default{outline:2px solid #000;background:#c6c6c6;}div.diagram-group.default.selected{outline:2px solid #6e9fd4;}g.diagram-group.default rect{outline:2px solid #000;fill:#c6c632;}g.diagram-group.default.selected>rect{outline:2px solid #008000;}.diagram-link div.default-link-label{display:inline-block;color:#fff;background-color:#6e9fd4;border-radius:.25rem;padding:.25rem;text-align:center;font-size:.875rem;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;min-width:3rem;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);}.default-node-resizer{width:5px;height:5px;background-color:#f5f5f5;border:1px solid #6e9fd4;position:absolute;} \ No newline at end of file +.default-node{width:100px;height:80px;border-radius:10px;background-color:#f5f5f5;border:1px solid #e8e8e8;-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12);position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;}.default-node.selected{border:1px solid #6e9fd4;}.default-node.selected .diagram-port{border:1px solid #6e9fd4;}.default-node .diagram-port,.default.diagram-group .diagram-port{width:20px;height:20px;margin:-10px;border-radius:50%;background-color:#f5f5f5;border:1px solid #d4d4d4;cursor:pointer;position:absolute;}.default-node .diagram-port:hover,.default-node .diagram-port.has-links,.default.diagram-group .diagram-port.has-links{background-color:#000;}.default-node .diagram-port.bottom,.default.diagram-group .diagram-port.bottom{bottom:0;left:50%;}.default-node .diagram-port.bottomleft,.default.diagram-group .diagram-port.bottomleft{bottom:0;left:0;}.default-node .diagram-port.bottomright,.default.diagram-group .diagram-port.bottomright{bottom:0;right:0;}.default-node .diagram-port.top,.default.diagram-group .diagram-port.top{top:0;left:50%;}.default-node .diagram-port.topleft,.default.diagram-group .diagram-port.topleft{top:0;left:0;}.default-node .diagram-port.topright,.default.diagram-group .diagram-port.topright{top:0;right:0;}.default-node .diagram-port.left,.default.diagram-group .diagram-port.left{left:0;top:50%;}.default-node .diagram-port.right,.default.diagram-group .diagram-port.right{right:0;top:50%;}.diagram-navigator.default{position:absolute;bottom:10px;right:10px;border:3px solid #9ba8b0;border-radius:15px;padding:20px;background-color:#fff;}div.diagram-group.default{outline:2px solid #000;background:#c6c6c6;}div.diagram-group.default.selected{outline:2px solid #6e9fd4;}g.diagram-group.default rect{outline:2px solid #000;fill:#c6c632;}g.diagram-group.default.selected>rect{outline:2px solid #008000;}.diagram-link div.default-link-label{display:inline-block;color:#fff;background-color:#6e9fd4;border-radius:.25rem;padding:.25rem;text-align:center;font-size:.875rem;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;min-width:3rem;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);}.default-node-resizer{width:5px;height:5px;background-color:#f5f5f5;border:1px solid #6e9fd4;position:absolute;}.default-node-resizer.bottomright{cursor:nwse-resize;}.default-node-resizer.topright{cursor:nesw-resize;}.default-node-resizer.bottomleft{cursor:nesw-resize;}.default-node-resizer.topleft{cursor:nwse-resize;} \ No newline at end of file diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz b/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz index 1d3b8cb1fbe3a9826d682a1e2935b372cd2eb50f..3c43a8a10a61907cb9619cdbdc3efc83f8d13ceb 100644 GIT binary patch literal 735 zcmV<50wDb#iwFP!000003bj^kj@mE~y$aH*(yoM~5SEs8q~68Bli=dmk?jDxXiwH3 zJyNewJ8`}?K*Ep80^;$Tc{Ah541a(B2`HqbzCFD6=x)nq(%dk3epKx%rdTq|u>AFgzUXfPM zIZ+uC7_G(?y9vKNQn2*Zt$0@|ZE=NURifHkCyB+C2JVJ}_wop8c?S{fiAJ1>gPs+3 z2fvI%3B&NNH$ftek@-BL8f$OR{opX>keVumGZ-B95f+F4!Za%qwzn9R)sp4V(+*oWuC}kq6yU>+3lcw<}WyfJCtxK{r z_N@jSbyV(c?(E>F-FLU{80ot96>Cl3&93V%l-0cDManp@`Pb1+3oZN4+ora@LwSAI z#}-vMz7U)MagqSPG&7P3X9gu)?hbJ;m*Wik2!~e_L>mQpdpUk<;B1CtHMQdqY4!m) z*#4+6%~UP5wN}T5g%n`Ns{FVn)nnmEkTZem!L{yl7)69mrOI*jWdBaUGqP2@bYCx( z?Fq=l@$g+k3S6kl&(KXbLfzv7BhsgQY9=;(gC^|fsyON9{FYYRni>_*rwNtbSedWX RwAgE&{R6yf)WanU007NuYeE13 literal 704 zcmV;x0zds9iwFP!000003bj^iZlf>|zDlHMrB;d&AxWDWY42k2K)f+FvQ3&c>dE%U z9%-+zHkbe<5AtJWLGbvS_jo3MfBy+6WTfH-2}$Af&ZybpWf+#ncn2)s8N7AhiBuF6 zQiQTf+jB=E={{Go5)`G9ONHmz#x0M<%kntWk~2D+!`7`By+g8R1|{-{^o~&Zj>B1G zVGfGiOXUf93Kwn#(eom#Puvp@j+X28Y&AZMo~;G{SwSf^GfWDsfD^+G5L2d0PCjtY z$BtHLlyNxrX>LCV2;nRjI0a!q#VyB>T5k|DQ0OzTC!w?n842hUe^uJB?8BzZZiQ*d zUxN||G;l}_(9<}NFYuPp^)-fBKpDvuDNreunaV!oTC`_psw=Vbo9L!Wqh68L-vv=Q z6BsSW6}t(4JW{Z9?N*#tN?TkhSskcz)=6S| zSHdv7X-$wwV`MQ+QG>M^bU!$ZIb@~|;RFp1`-m2Y|E6h@C(7mh5k)mar>WlFQ)Og1 zO@#%X>@zu57CSvq9^6-O-|h$E)1tkCNs*aueQmlo+9|jjn+Gg!%x(?tN%tT@4lE}| zs#e-*e20BS)J>z2)axI3)is5;glv=W`zYL4Y)L3(B5%6Tg*KCA@fT%>p(|&TWM%BF z1{`&&+->gU;CcGu)(s(D*S;XF?YsG9-kGwT*R04G=Z*eVbXCGx`_Jp5w!TAoe%Hrl zwL88L9075X06(=ek_jgUC0wTaxEITDguREu)CAE+L2*uw-x@fY;aJV=I7FI#0uHvX zHKv`amA29v->{GZ>{ykbm#BJ791#j8P&2qzeH}&-p);upTz}cW6Yzv=6))WDxt4tg ma_4w>*N_6|s`4|`Rj(hR?(=~W=|g^DCjJA6Jcwvj3IG6UY)NVW From 7a0872c29594d51f98ee7df9678cc42879661d7d Mon Sep 17 00:00:00 2001 From: Heather Cox Date: Thu, 7 Dec 2023 15:13:26 +1100 Subject: [PATCH 21/21] update test --- .../Documentation/Controls/Overview.razor | 2 +- .../Controls/ResizeControlWidgetTests.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index 6c6c6b1b9..335838ae5 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -140,7 +140,7 @@ Diagram.Controls.AddFor(SomeModel)

The ResizeControl adds a resizer which is a box that when dragged, can resize the node. The resizer position and movement of the node is controlled using a Resizer Provider.
- There are four `ResizerProvider`s, one for each corner. Custom resizing behavior can be created by implementing `IResizerProvider`. + There are four ResizerProviders, one for each corner. Custom resizing behavior can be created by implementing IResizerProvider.


diff --git a/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs b/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs
index 598bad4f5..bf51e541c 100644
--- a/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs
+++ b/tests/Blazor.Diagrams.Tests/Components/Controls/ResizeControlWidgetTests.cs
@@ -1,23 +1,23 @@
 using Blazor.Diagrams.Components.Controls;
-using Blazor.Diagrams.Components.Renderers;
+using Blazor.Diagrams.Core.Controls.Default;
+using Blazor.Diagrams.Core.Positions.Resizing;
 using Bunit;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Moq;
 using Xunit;
 
 namespace Blazor.Diagrams.Tests.Components.Controls
 {
-    public class ResizeControlWidgetTests
+	public class ResizeControlWidgetTests
     {
         [Fact]
         public void ShouldRenderDiv()
         {
             using var ctx = new TestContext();
-
-            var cut = ctx.RenderComponent();
+            var providerMock = Mock.Of();
+ 
+            var cut = ctx.RenderComponent(parameters =>
+                parameters.Add(w => w.Control, new ResizeControl(providerMock))
+            );
 
             cut.MarkupMatches("
"); }