低高度图上高点的工具提示不显示 [英] Tooltips for high points on low-height charts not displaying

查看:239
本文介绍了低高度图上高点的工具提示不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据图表/浏览器窗口的大小,我遇到工具提示无法显示的问题。这最初看起来像是一个有关方面图的问题,但是在常规/单个图表上这种行为也很明显。我已经做了很多搜索,到目前为止还没有发现任何东西。截至目前,还有一个类似的帖子在积极的论坛上没有答案。



以下是单张图表的MRE( HT )...



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ < - function(n){
random.string < - rep(NA,n)
randomizeString < - function(x){
a <-sample(letters,替换= TRUE)
返回(a)
}
返回(粘贴(c(sapply(random.string,randomizeString,simplify = TRUE)),collapse =))
}

xvar = replicate(10,randomName(15))

df1 < - data.frame(x = xvar,y = xvar,z = runif(10 ))

df1 $ tooltip< - sprintf(x:%s< br> y:%s< br> z:%s< br> 2x:%s< br> 2y:% s< br> 2z:%s< br> 3x:%s< br> 3y:%s< br> 3z:%s
,df1 $ x,df1 $ y,df1 $ z,df1 $ x ,df1 $ y,df1 $ z,df1 $ x,df1 $ y,df1 $ z)
$ bg = ggplot(df1,aes(x,y,fill = z,text = tooltip))+
geom_tile()

ggplotly(g,tooltip =tooltip)

如果您调整浏览器窗口到足够小的高度时,您会注意到当悬停在靠近图表顶部的图块时,工具提示不会显示。问题似乎是工具提示太高而无法显示,因此悬停位置会将工具提示框的顶部放在图表顶部之外。即使有问题,这种情况也是有道理的。然而,这个MRE的例子有点人为和​​不切实际。

这个行为成为一个真正的问题,在一个需要工具提示的方面有很多方面。这是一个方面图的MRE。即使使用最大化的浏览器窗口,同样的工具提示问题也是显而易见的。

  require(ggplot2)
require(plotly)

randomName< - function(n){
random.string< - rep(NA,n)
randomizeString< - function(x){
a< ; -sample(letters,1,replace = TRUE)
return(a)
}
return(paste(c(sapply(random.string,randomizeString,simplify = TRUE)),collapse =))
}

xvar = replicate(10,randomName(15))
facet_var = replicate(12,randomName(2))

df1 < - data.frame(x = xvar,y = xvar,z = runif(10))
df1< - merge(x = facet_var,y = df1,by = NULL)

#df1 $ tooltip< - sprintf(x:%s< br> y:%s< br> z:%s< br> x + x:%s< br> y + y:% s< br> z + z:%s
df1 $ tooltip< - sprintf(facet:%s< br> x:%s< br> y:%s< br> z:%s< 2s:%s:2y:%s:2z:%s:3x:%s:3y:%s:3z:%s:
,df1 $ xx,df1 $ xy,df1 $ y,df1 $ z,df1 $ xy,df1 $ y,df1 $ z,df1 $ xy,df1 $ y,df1 $ z)

g = ggplot(df1,aes(xy,y,fill = z,text = tooltip))+
geom_tile()+
facet_wrap(〜xx,ncol = 2)

ggplotly (g,tooltip =tooltip)

这个问题对于默认和定制工具提示都存在 - Chrome(v56)和Edge(v38)。



我有一个关于SO的问题,但我的分析结果不合格,我的例子不是MRE,我已经关闭/回答了这个问题因为。



我可以减少工具提示中的行数来消除问题,但我宁愿不必这样做。这是一个已知的功能,或者有这种行为的解决方法吗?

解决方案

我可以看到解决此问题的唯一方法行为的目的是为了确保tootip不会超过1或2行深度,这是我想,首先提示工具提示的意图!这就是我要去的。



我希望详细说明工具提示是否有一个格式良好的包含td / table的工具提示。也许有另一种方法来达到这种效果?


I have a problem with tooltips not showing depending on the size of the chart/browser window. This originally looked to me like a problem with facet charts but the behaviour is also evident on regular/single charts. I've done a lot of searching for this and not found anything so far. There is a similar post over on plotly forums with no answers as of yet.

Here is an MRE for a single chart (HT)...

require(ggplot2)
require(plotly)

randomName <- function(n) {
    random.string <- rep(NA, n)
    randomizeString <- function(x) {
        a <-sample(letters, 1, replace = TRUE)
        return(a)
    }
    return(paste(c(sapply(random.string, randomizeString, simplify = TRUE)), collapse = ""))
}

xvar = replicate(10, randomName(15))

df1 <- data.frame(x = xvar, y = xvar, z = runif(10) )

df1$tooltip <- sprintf("x: %s<br>y: %s<br>z: %s<br>2x: %s<br>2y: %s<br>2z: %s<br>3x: %s<br>3y: %s<br>3z: %s"
                                        ,df1$x, df1$y, df1$z, df1$x, df1$y, df1$z, df1$x, df1$y, df1$z)

g = ggplot(df1, aes(x,y,fill=z, text = tooltip)) +
        geom_tile()

ggplotly(g, tooltip = "tooltip")

If you resize the browser window to a small enough height you will notice that the tooltip will not be displayed when hovering over the tiles near the top of the chart. The problem appears to be that the tooltip is too tall to display whereby the hover position would place the top of the tooltip box outside the top of the chart. This kind of makes sense even if problematic. However, this MRE example is a bit contrived and unrealistic.

This behaviour becomes a real issue on a facet chart with a large number of facets requiring tooltips. Here is an MRE for a facet chart. Even with a maximised browser window the same tooltip issue is evident.

require(ggplot2)
require(plotly)

randomName <- function(n) {
    random.string <- rep(NA, n)
    randomizeString <- function(x) {
        a <-sample(letters, 1, replace = TRUE)
        return(a)
    }
    return(paste(c(sapply(random.string, randomizeString, simplify = TRUE)), collapse = ""))
}

xvar = replicate(10, randomName(15))
facet_var = replicate(12, randomName(2))

df1 <- data.frame(x = xvar, y = xvar, z = runif(10) )
df1 <- merge(x = facet_var, y = df1, by = NULL)

#df1$tooltip <- sprintf("x: %s<br>y: %s<br>z: %s<br>x+x: %s<br>y+y: %s<br>z+z: %s"
df1$tooltip <- sprintf("facet: %s<br>x: %s<br>y: %s<br>z: %s<br>2x: %s<br>2y: %s<br>2z: %s<br>3x: %s<br>3y: %s<br>3z: %s"
                                        ,df1$x.x, df1$x.y, df1$y, df1$z, df1$x.y, df1$y, df1$z, df1$x.y, df1$y, df1$z)

g = ggplot(df1, aes(x.y,y,fill=z, text = tooltip)) +
        geom_tile() +
        facet_wrap(~x.x, ncol=2)

ggplotly(g, tooltip = "tooltip")

This issue exists both for default and bespoke tooltips - tested in Chrome(v56) and Edge(v38).

I had an earlier question posted on SO regarding this issue but my analysis was off the mark, and my example not an MRE, and I have closed/answered that question since.

I could reduce the number of lines in the tooltip to obviate the problem but I'd prefer not to have to do that. Is this a known feature or is there a workaround for this behaviour?

解决方案

The only way that I can see of working around this behaviour is to ensure that the tootip is no more that 1 or two lines deep which is, I suppose, what the intention of a tooltip is in the first place! That is what I am going to go with.

I was hoping to elaborate on the "tooltip" to have a nicely formatted tooltip containing a td/table. Maybe there is an alternative approach to achieving this effect?

这篇关于低高度图上高点的工具提示不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆