JuliaGraphics / Luxor.jl

Simple drawings using vector graphics; Cairo "for tourists!"
http://juliagraphics.github.io/Luxor.jl/
Other
588 stars 71 forks source link

arc over the arrow #318

Closed ghost closed 3 months ago

ghost commented 3 months ago

hallo, i am writing a new package and i wrote this function and i am trying to superimpose a arc over an arrow. Can you point me to the way in Luxor where i can superimpose the arc over the arrow.

My code is given below:

Thank you, Gaurav

function vectorgraph(reactionfile, startreaction, endreaction):
    # the format of the reaction file is the following 
    # http://bigg.ucsd.edu/models/iJO1366/reactions/PRASCSi
    readfile = open(reactionfile)
    idstringStart = String[]
    idstringEnd = String[]
    interaction_enter = String[]
    interaction_out = String[]
    for i in readfile.readlines
      push!(idstringStart,split(i, ",")[1])
      push!(idstringEnd,split(i,",")[2])
      if length(idstringStart) != length(idstringEnd)
        println("program execution halted")
      end 
      if length(idstringStart) == length(idarrayEnd)
         start = startreaction
         end = enreaction
        @png begin 
            background("white")
            setdash("dot")
            arrow(startreaction, reactionend, action = :stroke)
            label(startreaction, :NW, start)
            label(endreaction, :NW, end)
            for i in 1:length(idstringStart)
                for j in 1:length(idstringEnd)
                    arc(Point(-1, 1, ))
                    label(idstringStart[i], 0.0)
                    label(idstringEnd, pi)
                end
            end
        end
cormullion commented 3 months ago

Hi Gaurav! Can you show a rough sketch of what you’re hoping to see?

ghost commented 3 months ago

sure, here is an example: http://bigg.ucsd.edu/models/iJO1366/reactions/PRASCSi and my code is here: https://github.com/gauravcodepro/metabolic-maps-vectorgraphs.jl

which also says that how to prepare the file for the package that i am writing. So in the end of the arc, i made a arrow and then i made an iter arc and now i have to superimpose the same arc over the arrow. so i dont have a linedit distance, so either i can give a

[1:10,0.5] as iter

let me know what do you reckon and can help with.

I am putting this behind a javascript and a nodejs to call it faster and interacting with the react so that it will use the julia and the react as a native.

Thank you for the help, Gaurav

ghost commented 3 months ago

i made the arc also visible and also put a heap so that if the next one is a start then pop out the first one and insert at the same place. I just need to see that how does the arc combine with the arrow on the line of the conjuction. If there are any docs for the same. Kindly let me know, so that i can finish this by tomorrow and release of my list. Thank you for the effort.

cormullion commented 3 months ago

I’ll try to look tonight - currently away from keyboard.

cormullion commented 3 months ago

Are you using the arrow(centerpos::Point, radius… method?

ghost commented 3 months ago

Yes i am using the same but not getting the arc to juxtapose on the linear arrow. I implemented this using a acyclic non-directed graph but i want to show this way. Thank you for the help and take your time.

cormullion commented 3 months ago

HI! I tried running some of your code, but it doesn't run (lots of syntax errors).

Here's a simple answer to your question:

using Luxor

@draw begin
    background("white")

    # arrow
    sethue("black")
    setdash("dot")
    centerpoint = Point(10, 10)
    arrow(centerpoint, 100, 0, π/2, linewidth=15, arrowheadlength=20)

    # arc
    setdash("solid")
    sethue("orange")
    setline(2)
    arc(centerpoint, 100, 0, π/2)
    strokepath()

end 300 300
Screenshot 2024-06-26 at 18 20 58

It's always helpful if you can reduce your problem to the minimum possible case - just use dummy data, no files, etc. Then we can focus on the central problem... :)

ghost commented 3 months ago

Thank you and i made the dummy data this afternoon and will check this. My code was not final as this is the reason that i asked what actually Luxor uses for the arc.

I was able to make this with the dummy data. The point is that, if i have a arrow and if i have a arc then how i put the arc superimpose over the arrow. This is where i am getting error.

In short, a arrow and then then a arc superimposed on the same arrow radiating from it.

ghost commented 3 months ago

I just ran your code

julia luxor.jl

and it is not giving me a graphic output. Should i add the save option. Thanks for the discussion, started coding in Julia 1-2 weeks back and getting hold of the same through the discussion and reading.

cormullion commented 3 months ago

It’s always better to run scripts inside a Julia session. Otherwise you’re incurring the compilation cost each time. And you won’t get the results displayed.

ghost commented 3 months ago

thank you didnt know that point of the julia language compilation. it is always a stepping point to learn when you are getting to learn a new language.

I dont ask AI to write code for me as i take different approaches and make it faster and therefore i ask where i stumbled upon. I write code myself.

I hope to get this one completed in a month or so. Thank you for the insights and will come back if there are additional questions.

cormullion commented 3 months ago

Yes AI is not always useful, unless it’s a very common language such as JavaScript or Python. Get simple things working first, then build up complex programs. And use functions frequently, since these get compiled to machine language the first time they run.

ghost commented 3 months ago

Very true, I also dont use in Javascript and Python or any other programming language as it shows really crap all the time and disturbs more than actually helping it plus you loose the joy of writing and putting your mind and abilities in doing the same.

ask AI to show a binary tree, same code all over the place, so you dont know and cant think that if you want to implement then implement a Patricia Trie over the binary tree as it is already a heap sorted tree.

ghost commented 3 months ago

Thank you for the answers and a proper discussion, which i really like doing with scientific people. I read yesterday night and also made some some changes and i finally made it to the final version, which draws exactly the path of the metabolic reactions.

I shall be positing here along with the code and will thank you accordingly in the code repository.

ghost commented 3 months ago

I almost finished the code and this is what i added and it gives the look of the same. An arc imposed over the arrow.

arrow(Point(0, 0), Point(0, -65))
arrow(Point(0, 0), Point(100, -65), arrowheadlength=20, arrowheadangle=pi/4, linewidth=.3)
arrow(Point(0, 0), 100, π, π/2, arrowheadlength=25,   arrowheadangle=pi/12, linewidth=1.25)

I will put a epsilon and a pie/2 to add more to this and a rotate one. Thank you for having this discussion.