Giter Site home page Giter Site logo

Comments (19)

cormullion avatar cormullion commented on May 22, 2024 2

use O not 0.

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024 2

Yeah, i should have used copy paste... Yep it works just fine.

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

I have looked into it a bit right now and landed here as well.

The question:
Can the macros @png and @svg be modified so they would accept a parameter for only in-memory drawing.

They certainly could, wouldn't be a complicated task.
However the issue with that is in the preview function.
The preview function currently needs a current_filename.
Which means, the in-memory png drawings can't be previewed.

So we need to modify the macros and the preview function.

I lack on knowledge about juno and jupyter, how to display images from data.
I guess the current_buffer function in Luxor might help.

The preview function also opens windows on Windows, Apple and Linux operating systems.
I don't have any expertise about that.

Proposal:
Change macros for supporting in-memory drawings.
Adapt preview (in the case of jupyter and juno) in order to show in-memory drawings.
If the adaption of preview is not possible, then this whole issue doesn't make any sense.

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

Sounds like a great idea... Perhaps - a new macro called @draw would be even better, since we're not worried about the format. (?) Then use temp files and another (internal) function to preview them. The existing macros are good, but they're quite restricted in some ways - for example, you can't use string interpolation in the output filenames (there's a regex stage now, I believe).

I know nothing about the in-memory code here, it was added by @barche and it works great but if we want to modify/extend it we'll have to get to grips with Juno/Jupyter display systems...

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

So the approach would be:

Create a new macro @draw
approach a) If possible (and in python it is possible) handle the image in memory and display it.
- When if at all do i need to "delete" the image in memory?
- Pros: Should be faster
- Cons: need to tinker with each framework/backend separately
approach b) create a temp file in temp directory.
- When if at all do i need to delete the temp file?
- Pros: Should be easy to implement, since there is no need to change the preview function.
- Cons: Depends on IO

I'll try to cook something together.
Might take a while, i am new to julia and it's whole working process.

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

I have implemented the approach b), since i didn't want to disrupt anything.
Regarding jupyter, everything should be handled by the display function, so in-memory picture shouldn't be too hard either.

I am still thinking about the possibility to also do :svg, but i don't want too many parameters.
After all this should be used for immediate view in jupyter/juno

#68

Old info


By the way, as copied from the documentation, all circle functions don't work, no matter what macro i am using...

I am not sure what i am doing wrong here.

> @png circle(0, 20, :fill)

MethodError: no method matching arc(::Cairo.CairoContext, ::Int64, ::Int64, ::Symbol, ::Int64, ::Float64)
Closest candidates are:
  arc(::Cairo.CairoContext, ::Real, ::Real, !Matched::Real, ::Real, ::Real) at /home/hrom/.julia/packages/Cairo/htbtf/src/Cairo.jl:688
  arc(::Graphics.GraphicsContext, ::Real, ::Real, !Matched::Real, ::Real, ::Real) at none:0

Stacktrace:
 [1] circle(::Int64, ::Int64, ::Symbol, ::Symbol) at /home/hrom/.julia/dev/Luxor/src/curves.jl:15
 [2] circle(::Int64, ::Int64, ::Symbol) at /home/hrom/.julia/dev/Luxor/src/curves.jl:12
 [3] top-level scope at /home/hrom/.julia/dev/Luxor/src/drawings.jl:391
 [4] top-level scope at In[15]:1

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

testing is going to be interesting... I’ll take a look tomorrow.

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

Yeah, about the tests. I coudn't find any tests on the macros png, pdf either.
Does the testing pipeline run the code in the documentation string as well?

from luxor.jl.

barche avatar barche commented on May 22, 2024

Note that this is already possible if you use Drawing directly instead of the macros:

#26

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

Sorry I just got round to looking at this properly (on my phone over the weekend).

If you want a simple macro that does in-memory drawing and display (for PNG) when using Juno or Jupyter, add this code to drawings.jl and export @draw:

macro draw(body, width=600, height=600)
    quote
        Drawing($width, $height, :png)
        origin()
        background("white")
        sethue("black")
        $(esc(body))
        finish()
        (isdefined(Main, :IJulia) && Main.IJulia.inited) ? jupyter = true : jupyter = false
        Juno.isactive() ? juno = true : juno = false
        if juno || jupyter
            display(CURRENTDRAWING[1])
        else
            @info "use Juno or Jupyter"
        end
    end
end

In Juno, you'd see this:

Screenshot 2019-10-07 at 09 42 14

In Jupyter, you'd see this:

Screenshot 2019-10-07 at 09 43 11

In the Terminal, you'd see this:

Screenshot 2019-10-07 at 09 44 01

It appears to work, but it might be what you're looking for?

Perhaps the message should be more helpful... :)

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

Yep, that does the job as well.

Should i change it to this and create a new pull-request?

Or should we use the temporary-file approach?
I liked that it is almost the same as the previous png macro.
Reusing code is always good :)

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

Well, it depends on whether the purpose of the original issue (and your subsequent interest) was to do in-memory drawing or just to not have to worry about creating/deleting temporary files. It seemed to start off as the former, and end up as the latter... :)

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

I approached it from the user perspective, where i don't care, i just want to see a pretty picture, and i don't want to deal with created files :D

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

On macOS, I think your macro launches Preview and displays a window that contains no graphics (because the file gets deleted while Preview is launching :)).

Screenshot 2019-10-07 at 13 16 08

Not sure what it might do on faster/slower machines...

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

On my machine it works.

Also i don't know if i have to delete the file, or if i can leave it, since it is in a tmp directory.

On Wednesday i can look into the in-memory only option.

from luxor.jl.

barche avatar barche commented on May 22, 2024

I have two reasons for choosing the completely in-memory approach for my notebooks:

  • Faster updates when using Interact.jl to manipulate the drawing
  • We have a read-only dir with notebooks on jupyterhub, it used to be that the temp files were in the same dir and that wouldn't work

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

@barche Thanks, useful info.

from luxor.jl.

m3m0ry avatar m3m0ry commented on May 22, 2024

I copied your code and tested it. You can merge it.

from luxor.jl.

cormullion avatar cormullion commented on May 22, 2024

@m3m0ry Thanks for adding this!

from luxor.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.