Skip to content

Commit

Permalink
More distance.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Oct 17, 2024
1 parent 47dc167 commit 660d28e
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
NodeImageMapper="n => n.Image"
NodeRepulsionMapper="_ => 1200"
EdgeSpringConstantMapper="_ => 0.8"
EdgeSpringLengthMapper="_ => 250"
EdgeFromMapper="e => e.from"
EdgeToMapper="e => e.to"
EdgeSpringLengthMapper="e => e.EdgeLength"
EdgeFromMapper="e => e.From"
EdgeToMapper="e => e.To"
EdgeWidthMapper="_ => 5"
NodeSelectionCallback="async (user) => { selectedUser = user; await InvokeAsync(StateHasChanged); }" />
</div>
Expand Down Expand Up @@ -94,6 +94,9 @@

private async Task AddMoreUsers(User fromUser, int size)
{
selectedUser = null;
StateHasChanged();

var response = await httpClient.GetAsync($"https://kristoffer-strube.dk/API/mastodon/Following/{fromUser.Id}");

if (!response.IsSuccessStatusCode)
Expand All @@ -114,12 +117,18 @@

users = [.. users, .. allNewUsers];

// Increase distance to this user to make room for new neighbors.
foreach (var edge in edges.Where(e => e.To.Equals(fromUser) || e.From.Equals(fromUser)))
{
edge.EdgeLength = 500;
}

foreach (var follow in following)
{
var newEdge = new Follow(fromUser, follow);
if (!edges.Contains(newEdge))
if (!edges.Any(e => e.Equals(newEdge)))
{
edges.Add(new Follow(fromUser, follow));
edges.Add(newEdge);
}
}

Expand Down Expand Up @@ -152,7 +161,15 @@

public override int GetHashCode() => Id.GetHashCode();
}
public record Follow(User from, User to);
public class Follow(User from, User to) : IEquatable<Follow>
{
public User From => from;
public User To => to;

public float EdgeLength { get; set; } = 250;

public bool Equals(Follow? other) => other is not null && other.From.Equals(From) && other.To.Equals(To);
}

public void Dispose()
{
Expand Down

0 comments on commit 660d28e

Please sign in to comment.