Giter VIP home page Giter VIP logo

Comments (4)

hexaeder avatar hexaeder commented on August 18, 2024

How does your code work? Checking the positions of the nodes in pixel space and changing elabels_opposite and elabels_align accordingly?

I am open to changes to the whole elabel positioning business, I think there are so many options that it is pretty confusing.

from graphmakie.jl.

filchristou avatar filchristou commented on August 18, 2024

Yes, exactly.
First I check the angle of the position of the nodes with a function looking something like this:

function angle_between(ndpos, i, j) 
    x = ndpos[i]
    y = ndpos[j]
    θ = [ atan(d[2]/d[1]) for d in [y - x] ][] |> abs
    if y[2] >= x[2] && y[1] >= x[1]
        return θ |> rad2deg
    elseif y[2] >= x[2] && y[1] <= x[1]
        return π - θ |> rad2deg
    elseif y[2] <= x[2] && y[1] <= x[1]
        return π + θ |> rad2deg
    elseif y[2] <= x[2] && y[1] >= x[1]
        return 2π - θ |> rad2deg
    end
end

(maybe there is one already available ?)

And then if angle is between 90 and 270 I consider it upside down and I add it in the elabels_opposite

    p.elabels_opposite[] = [i for (i,e) in  enumerate(edges(G)) if  90 < angle_between(p[:node_pos].val, e) < 270]

After I iterate through the elabels_opposite and I toggle :top <=> :bottom for elabels_align

Suprisingly the update is not instant and then I have to manually trigger it by doing something trivial such as p.elabels_opposite[] = p.elabels_opposite[]

(Maybe this is actually an issue on its own that code like p.elabels_align[] = fill((:right, :bottom), length(edges(gc))) doesn't update the graph plot.)

I think it would be nice to have it as a default behavior, because the truth is I struggled a little bit to get it working. And I am not sure that every new user will want to invest the same time.
Of course handing in a specific elabels_align or elabels_opposite should overwrite such a default behavior.

I am open to changes to the whole elabel positioning business, I think there are so many options that it is pretty confusing.

For the time being I wouldn't have much to suggest besides this little thingy

from graphmakie.jl.

hexaeder avatar hexaeder commented on August 18, 2024

I'd be totally on board with a new default elabels_opposite=Makie.automatic instead of Int[], such that the labels will always end up in certain angle range. This could be incorporated somewhere here

https://github.com/JuliaPlots/GraphMakie.jl/blob/0141a0d4d8f450f587e1ecb1bd02cfa25dc318e5/src/recipes.jl#L273-L292

I am not that sure about the right interface for the align thing. Do you think this is also necessary? It seems like the choice of the proper align is kinda arbitrary anyway because it directly depends on the node enumeration anyway... but i have not thought this through. Well it might matter for curvy edges using the new curve_distance parameters, they tend to bent to the left and the labels should stay on the outside....

Feel free to open an issue for the update of align and opposite... this might be a problem within the text recipe itself though, at a first glance it seems like they are properly passed down as observables...

from graphmakie.jl.

filchristou avatar filchristou commented on August 18, 2024

closed by #73

from graphmakie.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.