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

restore tipannotations; fix #53 #60

Merged
merged 3 commits into from
Jul 8, 2021

Conversation

BenjaminDoran
Copy link
Contributor

This should fix issue #53,

what I had to do

There may be a better way. but I put in a new @series begin ... end block with changes below, which seems to show the annotations again.

It required adding Plots as a dependency to get access to the Plots.text function. Pending issue JuliaPlots/RecipesBase.jl#72 this seemed to be the only way to do it.

dendrogram example

if dend.showtips
    @series begin
        seriestype := :scatter
        markersize := 0
        series_annotations := map(x -> text(x[3], :left, dend.tipfont...), dend.tipannotations)
        getindex.(dend.tipannotations, 1), getindex.(dend.tipannotations, 2)
    end
end

fan example

if fan.showtips
    @series begin
        seriestype := :scatter
        markersize := 0
        series_annotations := map(x -> text(x[3], :left, rad2deg(adjust(x[2])), fan.tipfont...), fan.tipannotations)
        xys = map(x-> (_tocirc.(x[1], adjust.(x[2]))), fan.tipannotations)
        first.(xys), last.(xys)
    end
end

Minimum example

using Phylo
using StatsPlots
tree = rand(Ultrametric(10))
plot(tree, treetype=:dendrogram, size=(400,400))
tree = rand(Ultrametric(10))
plot(tree, treetype=:fan, size=(400,400))

image

image

@mkborregaard
Copy link
Member

Great, I'll have a look. I can say immediately that adding a Plots dep is not acceptable, but I don't think that should be necessary either.

src/plot.jl Outdated
@series begin
seriestype := :scatter
markersize := 0
series_annotations := map(x -> text(x[3], :left, dend.tipfont...), dend.tipannotations)
Copy link
Member

Choose a reason for hiding this comment

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

do you need the text here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for this solution, yes. It writes out the unformatted entire tuple otherwise.

@mkborregaard
Copy link
Member

mkborregaard commented Jul 6, 2021

I can't work out why the original code doesn't work as it is. Consider

struct MyType end

@recipe function f(x::MyType)
    seriestype := :myseries
    1:10, 1:10
end

@recipe function f(::Type{Val{:myseries}}, x, y, z)
    annotations := [(2, 4, ( "test", :right, 20)), (3, 4, ("test2", :left, 10))]
    seriestype := :path
    x, y
end

plot(MyType())

Skærmbillede 2021-07-06 kl  15 43 35

Seems to me like exactly what we have in the original code?

@BenjaminDoran
Copy link
Contributor Author

Thanks for the test example, I don't really know why, but changing the location of the annotations argument fixes the issue.

i.e.

Doesn't work

struct MyType end
struct myseries; x; y; end

@recipe function f(x::MyType)
    seriestype := :myseries
    myseries(1:10, 1:10)
end


@recipe function f(ms::myseries)
    @series begin
        seriestype := :path
        ms.x, ms.y
    end
    annotations := [(2, 4, ( "test", :right, 20)), (3, 4, ("test2", :left, 10))]
    nothing
end

plot(MyType())

works

struct MyType end
struct myseries; x; y; end

@recipe function f(x::MyType)
    seriestype := :myseries
    myseries(1:10, 1:10)
end


@recipe function f(ms::myseries)
    annotations := [(2, 4, ( "test", :right, 20)), (3, 4, ("test2", :left, 10))]
    @series begin
        seriestype := :path
        ms.x, ms.y
    end
    nothing
end

plot(MyType())

I agree it is a much better solution, than needing the plots dependency. I reverted my commit and just moved your code blocks to above the other series blocks. And, it seems to work now!

image

src/plot.jl Outdated
series_annotations := map(x -> text(x[3], :left, dend.tipfont...), dend.tipannotations)
getindex.(dend.tipannotations, 1), getindex.(dend.tipannotations, 2)
end
end
primary = false
label = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also what are these two lines doing? are they meant to be primary := false; label := ""? or just deleted?

Copy link
Member

Choose a reason for hiding this comment

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

primary := false; label := "" as you say 👍

Copy link
Member

Choose a reason for hiding this comment

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

do you mind updating that before I merge?

@mkborregaard
Copy link
Member

Awesome!

@coveralls
Copy link

coveralls commented Jul 7, 2021

Pull Request Test Coverage Report for Build 1008891194

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 66 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+2.1%) to 56.993%

Files with Coverage Reduction New Missed Lines %
src/plot.jl 66 0%
Totals Coverage Status
Change from base Build 807062543: 2.1%
Covered Lines: 1088
Relevant Lines: 1909

💛 - Coveralls

@mkborregaard mkborregaard changed the title change annotations to separate series_annotations restore tipannotations; fix #53 Jul 8, 2021
@mkborregaard mkborregaard merged commit fcaaec2 into EcoJulia:dev Jul 8, 2021
@mkborregaard
Copy link
Member

Thanks a lot @BenjaminDoran !

@richardreeve
Copy link
Member

Yes, thanks so much for fixing this - knowing nothing about plotting it has just been sitting around mildly annoying me for ages! Looking at the PR, it's not remotely clear to me why this solution works either, but never mind :)

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