Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: bitmap nodes #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TeroFrondelius
Copy link

@TeroFrondelius TeroFrondelius commented Nov 26, 2018

Answering #74

usage example:

logo_urls = [
    "https://github.com/JuliaFEM/JuliaFEM.jl/raw/master/docs/logo/JuliaFEMLogo_96x96.png",
    "https://user-images.githubusercontent.com/25916/36773410-843e61b0-1c7f-11e8-818b-3edb08da8f41.png",
    "http://docs.juliadiffeq.org/v2.0.0/assets/logo.png",
    "https://raw.githubusercontent.com/JuliaLang/IJulia.jl/master/deps/ijulialogo.png"
]

fnames = []
for logo in logo_urls
    fname = tempname()
    push!(fnames,fname)
    download(logo,fname)
end

logos = read.(fnames)

g = SimpleGraph(ones(Int,length(fnames),length(fnames)))

simg = gplot(g, node_bitmap=logos)

image

The current problem is the horizontal light gray line under the logos especially if the logo is transparent like highest one at the above picture.

Another usage example:

logo_name = tempname() * ".png"
# CC BY-SA 3.0 https://commons.wikimedia.org/wiki/File:Personal_Computer_Icon.png
download("https://upload.wikimedia.org/wikipedia/commons/0/06/Personal_Computer_Icon.png",logo_name)
computer_logo = read(logo_name)

g = SimpleGraph(ones(Int,20,20))
gplot(g, node_bitmap=[computer_logo for i in 1:nv(g)])

image

Third example:

# License: Freeware http://www.iconarchive.com/show/karate-icons-by-findhold/karate-flyingkick-icon.html
# License: Freeware http://www.iconarchive.com/show/karate-icons-by-findhold/karate-block-icon.html
karateka = tempname() * ".png"
karateka2 = tempname() * ".png"
download("http://icons.iconarchive.com/icons/findhold/karate/128/karate-flyingkick-icon.png",karateka)
download("http://icons.iconarchive.com/icons/findhold/karate/128/karate-block-icon.png", karateka2)
karateka_pngs = read.([karateka,karateka2])

g = graphfamous("karate")
membership = [1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2]
pictures = karateka_pngs[membership]
gplot(g, node_bitmap=pictures)

image

@codecov
Copy link

codecov bot commented Nov 26, 2018

Codecov Report

Merging #75 into master will decrease coverage by 31.74%.
The diff coverage is 28.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #75       +/-   ##
===========================================
- Coverage   48.21%   16.46%   -31.75%     
===========================================
  Files           3        8        +5     
  Lines         168      498      +330     
===========================================
+ Hits           81       82        +1     
- Misses         87      416      +329
Impacted Files Coverage Δ
src/layout.jl 22.07% <0%> (-77.93%) ⬇️
src/plot.jl 34.06% <33.33%> (-39.11%) ⬇️
src/lines.jl 22.07% <0%> (-8.84%) ⬇️
src/pienode.jl 0% <0%> (ø)
src/collapse_plot.jl 0% <0%> (ø)
src/deprecations.jl 0% <0%> (ø)
src/shape.jl 0% <0%> (ø)
src/stress.jl 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update adeda23...9130d0d. Read the comment docs.

@@ -216,9 +225,11 @@ function gplot(g::AbstractGraph{T},
compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)),
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
#compose(context(), nodes),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why that?

if nv(g) == 1
return [0.0], [0.0]
else
# Discard the extra angle since it matches 0 radians.
θ = range(0, stop=2pi, length=_nv(G)+1)[1:end-1]
θ = range(0, stop=2pi, length=nv(g)+1)[1:end-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, we really need more tests, so errors like this one do not get unnoticed.

@simonschoelly
Copy link
Member

That's an interesting addition. Is there a way, that also compose contexts could be used instead of bitmap? (not sure if we would need that though).

I think the problem with the gray line under the transarent logos is, that we currently don't handle self loops correctly.

@TeroFrondelius
Copy link
Author

I am not expert on Compose.jl. I wanted to have a plot with logos and made quick and dirty solution. I am willing to finalize it, if you think it's a good addition. Some tests should be added but I don't have an idea how to test it.

Now spending Christmas with my family and left my computer home.

@matbesancon
Copy link
Member

bump @TeroFrondelius, now that two Christmas have passed

@TeroFrondelius
Copy link
Author

If someone wants to finalize this please feel welcome. I don't remember the details anymore and it seems that I won't find time to work on this.

@Garcese
Copy link

Garcese commented Dec 3, 2022

I know it's an old thread, but just wanted to say this feature would be incredibly useful! Busy at the moment, and don't have much programming skills, but maybe in the future I could help look at it. But maybe someone else too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants