bnosac / textplot

Text Plots
GNU General Public License v2.0
54 stars 8 forks source link

[textplot_dependencyparser.default] Add layout argument #8

Closed discoleo closed 2 years ago

discoleo commented 2 years ago

Function textplot_dependencyparser.default

Add a layout argument:

Code changes

[...]
ggraph::ggraph(g, layout = layout) +
[...]

Example

Problem:

Sentence

idS = 1 textplot_dependencyparser(ann[ann$sentence_id == idS,])

discoleo commented 2 years ago

Basic code for Multi-line Layout

Note:

layoutSplit = function(x, y=NULL, nr=2, scale=c(1, 30), dx=3) {
    len = nchar(x);
    if( ! is.null(y)) len = pmax(len, nchar(y));
    len = len + dx;
    if(nr > 1) {
        nm = length(len) %% nr;
        if(nm != 0) len = c(len, rep(0, nr - nm));
    } else nm = 0;
    nc  = length(len) %/% nr;
    len = matrix(len, ncol=nr);
    # x-Coord = cumsum() + mid;
    pos = apply(len, 2, cumsum);
    pos = rbind(0, pos[ - nrow(pos), ]);
    pos = pos + len / 2; # midpoint
    dim(pos) = NULL;
    pos = pos * scale[1];
    xdf = data.frame(
        x = pos,
        y = rep(seq(nr, 1, by=-1) * scale[2], each=nc));
    if(nm > 0) {
        xdf = xdf[ seq(nr - nm) - 1 - nrow(xdf), ];
    }
    return(xdf)
}

Usage

jwijffels commented 2 years ago

We can certainly add the layout argument in the function definition so that you can pass whichever on.

Note getting this currently with your layoutSplit

image

discoleo commented 2 years ago

Latest version of layoutSplit:

Note:

jwijffels commented 2 years ago

I've added the layout argument in commit https://github.com/bnosac/textplot/commit/6097d2b0453ad19d01b03e55dd17e88bccbbec8d and will upload the package to CRAN