Skip to content

Commit

Permalink
fix: NavigatorWidget not handling negative node positions + Add FillC…
Browse files Browse the repository at this point in the history
…olor option
  • Loading branch information
zHaytam committed Mar 6, 2021
1 parent 667ab2d commit e359f5a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
19 changes: 10 additions & 9 deletions src/Blazor.Diagrams/Components/NavigatorWidget.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@if (Diagram.Container != null)
{
var addedNodeX = Math.Max(0, Diagram.Pan.X);
var addedNodeY = Math.Max(0, Diagram.Pan.Y);
var addedCurrentViewX = Math.Abs(Math.Min(0, Diagram.Pan.X)) * XFactor;
var addedCurrentViewY = Math.Abs(Math.Min(0, Diagram.Pan.Y)) * YFactor;
var addedNodeX = Math.Max(0, Diagram.Pan.X) + NodePositionAdjustment.X;
var addedNodeY = Math.Max(0, Diagram.Pan.Y) + NodePositionAdjustment.Y;
var addedCurrentViewX = (Math.Abs(Math.Min(0, Diagram.Pan.X)) + NodePositionAdjustment.X) * XFactor;
var addedCurrentViewY = (Math.Abs(Math.Min(0, Diagram.Pan.Y)) + NodePositionAdjustment.Y) * YFactor;
var currentViewWidth = Diagram.Container.Width * XFactor;
var currentViewHeight = Diagram.Container.Height * YFactor;

Expand All @@ -13,18 +13,19 @@
style="top: @(addedCurrentViewY.ToInvariantString())px;
left: @(addedCurrentViewX.ToInvariantString())px;
width: @(currentViewWidth.ToInvariantString())px;
height: @(currentViewHeight.ToInvariantString())px;"></div>
height: @(currentViewHeight.ToInvariantString())px;
border: 2px solid @FillColor;"></div>
</div>
<svg width="@(Width.ToInvariantString())px" height="@(Height.ToInvariantString())px">
@foreach (var node in Diagram.Nodes.Where(n => n.Size != null))
{
var left = (Math.Max(0, node.Position.X * Diagram.Zoom) + addedNodeX) * XFactor;
var top = (Math.Max(0, node.Position.Y * Diagram.Zoom) + addedNodeY) * YFactor;
var left = ((node.Position.X * Diagram.Zoom) + addedNodeX) * XFactor;
var top = ((node.Position.Y * Diagram.Zoom) + addedNodeY) * YFactor;
var width = node.Size.Width * Diagram.Zoom * XFactor;
var height = node.Size.Height * Diagram.Zoom * YFactor;

<g @key="node.Id" transform="translate(@left.ToInvariantString(), @top.ToInvariantString())">
<rect fill="#40babd"
<rect fill="@FillColor"
width="@width.ToInvariantString()"
height="@height.ToInvariantString()"></rect>
</g>
Expand All @@ -38,7 +39,7 @@
var height = group.Size.Height * Diagram.Zoom * YFactor;

<g @key="group.Id" transform="translate(@left.ToInvariantString(), @top.ToInvariantString())">
<rect stroke="#40babd"
<rect stroke="@FillColor"
stroke-width="2"
fill="none"
width="@width.ToInvariantString()"
Expand Down
23 changes: 9 additions & 14 deletions src/Blazor.Diagrams/Components/NavigatorWidget.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ namespace Blazor.Diagrams.Components
{
public partial class NavigatorWidget : IDisposable
{
[CascadingParameter] public Diagram Diagram { get; set; }
[Parameter] public double Width { get; set; }
[Parameter] public double Height { get; set; }
[Parameter] public string FillColor { get; set; } = "#40babd";
[Parameter] public bool DefaultStyle { get; set; }

[CascadingParameter]
public Diagram Diagram { get; set; }

[Parameter]
public double Width { get; set; }

[Parameter]
public double Height { get; set; }

[Parameter]
public bool DefaultStyle { get; set; }

protected double XFactor { get; set; }
protected double YFactor { get; set; }
private Point NodePositionAdjustment { get; set; }
private double XFactor { get; set; }
private double YFactor { get; set; }

protected override void OnParametersSet()
{
Expand Down Expand Up @@ -77,6 +71,7 @@ private void Refresh()
(double fullSizeWidth, double fullSizeHeight) = GetFullSize(nodesMaxX, nodesMaxY);
AdjustFullSizeWithNodesRect(nodesMinX, nodesMinY, ref fullSizeWidth, ref fullSizeHeight);

NodePositionAdjustment = new Point(nodesMinX < 0 ? Math.Abs(nodesMinX) : 0, nodesMinY < 0 ? Math.Abs(nodesMinY) : 0);
XFactor = Width / fullSizeWidth;
YFactor = Height / fullSizeHeight;
StateHasChanged();
Expand Down
4 changes: 0 additions & 4 deletions src/Blazor.Diagrams/wwwroot/default.styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Blazor.Diagrams/wwwroot/default.styles.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz
Binary file not shown.

0 comments on commit e359f5a

Please sign in to comment.