SankeyPlots.jl icon indicating copy to clipboard operation
SankeyPlots.jl copied to clipboard

Adding flow values

Open Mastomaki opened this issue 3 years ago • 4 comments

In addition to node labels, one should have the possibility to add flow values as labels.

Mastomaki avatar Feb 16 '22 13:02 Mastomaki

Thanks @Mastomaki for the suggestion, that may be interesting, let's keep the issue open. Currently, I have no time to work on that, but feel free to add a pull request on that if you wish.

Anyway, it may not be easy to show the labels and make them readable; maybe a size legend may be more appropriate.

davide-f avatar Feb 17 '22 18:02 davide-f

I don't know how to make a pull request. But adding edge_labels (bool) as new parameter, here is my suggestion:

code added to line 133:

               # add flow labels
                if edge_labels == true
                    y_flowlab1 = y[i] + h - src_offsets[i, j]
                    y_flowlab2 = y[j] + vw[j] / (2m) - dst_offsets[j, i]
                    @series begin
                        primary := :false
                        seriestype := :scatter
                        markeralpha := 0
                        flowlabel = @sprintf("%.2g", get_prop(g, edge_it, :weight))
                        series_annotations := text.([flowlabel],
                                                    :center,
                                                    label_size)                  
                        [(x[i] + x[j])/2], [(y_flowlab1 + y_flowlab2)/2]
                    end
                end

Mastomaki avatar Mar 24 '22 13:03 Mastomaki

@Mastomaki thank you for the suggestion; indeed it can be made; do you wish to make the contribution? To do so, you just need to fork the repo, make the changes in your fork and then after doing the changes you can open the pull request.

This link may be in handy: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

What do you think?

davide-f avatar Mar 24 '22 17:03 davide-f

Hi @davide-f and @Mastomaki , in the new version of the code, the line numbers have been changed. So I don't know where to put this snippet in.

I thought it should be 143line which might be 133 originally, like to following, but it doesn't pass the compiling. Please could you elaborate where to put this code. Or will the code work in the new version of SankeyPlots. Thank you very much!

`

           # add flow labels
        if edge_labels == true
            y_flowlab1 = y[i] + h - src_offsets[i, j]
            y_flowlab2 = y[j] + vw[j] / (2m) - dst_offsets[j, i]
            @series begin
                primary := :false
                seriestype := :scatter
                markeralpha := 0
                flowlabel = @sprintf("%.2g", get_prop(g, edge_it, :weight))
                series_annotations := text.([flowlabel],
                                            :center,
                                            label_size)                  
                [(x[i] + x[j])/2], [(y_flowlab1 + y_flowlab2)/2]
            end
        end            
        if label_position !== :legend
            xlab, orientation = if label_position in (:node, :top, :bottom)
                olab = if label_position === :top
                    :bottom

`

syou83syou83 avatar May 19 '23 11:05 syou83syou83