1. <i id='OZTZ7'><tr id='OZTZ7'><dt id='OZTZ7'><q id='OZTZ7'><span id='OZTZ7'><b id='OZTZ7'><form id='OZTZ7'><ins id='OZTZ7'></ins><ul id='OZTZ7'></ul><sub id='OZTZ7'></sub></form><legend id='OZTZ7'></legend><bdo id='OZTZ7'><pre id='OZTZ7'><center id='OZTZ7'></center></pre></bdo></b><th id='OZTZ7'></th></span></q></dt></tr></i><div id='OZTZ7'><tfoot id='OZTZ7'></tfoot><dl id='OZTZ7'><fieldset id='OZTZ7'></fieldset></dl></div>

      <legend id='OZTZ7'><style id='OZTZ7'><dir id='OZTZ7'><q id='OZTZ7'></q></dir></style></legend>
    1. <small id='OZTZ7'></small><noframes id='OZTZ7'>

      • <bdo id='OZTZ7'></bdo><ul id='OZTZ7'></ul>

    2. <tfoot id='OZTZ7'></tfoot>

      自定义工具提示定位

      Custom tooltip positioning(自定义工具提示定位)
        <tbody id='0OnSW'></tbody>
      <tfoot id='0OnSW'></tfoot>
    3. <i id='0OnSW'><tr id='0OnSW'><dt id='0OnSW'><q id='0OnSW'><span id='0OnSW'><b id='0OnSW'><form id='0OnSW'><ins id='0OnSW'></ins><ul id='0OnSW'></ul><sub id='0OnSW'></sub></form><legend id='0OnSW'></legend><bdo id='0OnSW'><pre id='0OnSW'><center id='0OnSW'></center></pre></bdo></b><th id='0OnSW'></th></span></q></dt></tr></i><div id='0OnSW'><tfoot id='0OnSW'></tfoot><dl id='0OnSW'><fieldset id='0OnSW'></fieldset></dl></div>
    4. <legend id='0OnSW'><style id='0OnSW'><dir id='0OnSW'><q id='0OnSW'></q></dir></style></legend>

            <small id='0OnSW'></small><noframes id='0OnSW'>

                <bdo id='0OnSW'></bdo><ul id='0OnSW'></ul>
                本文介绍了自定义工具提示定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 Plotly.js 热图上正确定位自定义工具提示时遇到问题.

                I'm facing issues to properly position a custom tooltip on a Plotly.js heatmap.

                我使用 l2p 方法(这个首字母缩写词代表什么?)结合 pointNumber 数据来获得热图中的相对定位.它看起来像:

                I'm using the l2p method (what's this acronym standing for?) in combination with the pointNumber data to get a relative positioning within the heatmap. It looks like:

                x: point.xaxis.l2p(point.pointNumber[1]),
                y: point.yaxis.l2p(point.pointNumber[0])
                

                但问题在于它相对于热图 svg 本身的顶部/左侧原点,没有外部 x 轴和 y 轴标签,所以我实际上错过了那部分,想知道是否有'直接获取此定位信息的内置功能?使用外部 div 作为工具提示区域的问题是它们完全位于图表之外,因此我需要参考图表外部的上/左原点和轴标签的信息.

                But the problem with that is that it is relative to the top/left origin of the heatmap svg itself without the outer x- and y-axis labels, so I'm actually missing that part and wonder about whether there isn't a built-in functionality to get this positioning information directly? The problem by using external divs as tooltip area is that they are located completely outside of the chart and with that I need the information with reference to the top/left origin outside of the chart and the axis labeling.

                似乎可行的是使用轴私有_offset属性并将其添加到上面的x和y位置,所以我得到

                What seems to work is to use the axis private _offset property and add it to the x and y positions above, so I get

                x: point.xaxis.l2p(point.pointNumber[1]) + point.xaxis._offset,
                y: point.yaxis.l2p(point.pointNumber[0]) + point.yaxis._offset
                

                但这对我来说看起来很讨厌.有人可以指点我一些关于如何做到这一点的文档或演示情节方式",尤其是.热图?

                But that looks quite nasty to me. Can someone point me to some documentation or demo on how to do that "the plotly way" esp. for the heatmap?

                推荐答案

                你可以使用 Javascript 的 pageXpageY 函数并将它们与 Plotly 的悬停事件结合起来.

                You could use Javascript's pageX and pageY functions and combine them the with Plotly's hover event.

                您可以获取绝对像素的光标位置并直接使用它.在下面的代码片段中,当鼠标位于 Plotly div 上方时,一个点与光标一起移动.它的大小和颜色由光标所在的数据决定.

                You can get the cursor position in absolute pixels and use it directly. In the snippet below a dot is moving together with the cursor when the mouse is above the Plotly div. Its size and color are determined by the data over which the cursor is located.

                当然你可以绑定 onmousemove 事件也可以添加到情节的任何部分,并制作出比点更复杂的东西.

                Of course you can bind the onmousemove event to any part of the plot as well and make something more sophisticated than just a dot.

                //create some random data
                var data = [{z: [], type: 'heatmap'}];
                var z = [];
                	
                for (var i = 0; i < 10; i += 1) {
                  z = [];
                  for (var j = 0; j < 10; j += 1) {
                    z.push(Math.random());
                  }
                  data[0].z.push(z);
                }	
                
                var myPlot = document.getElementById('myDiv');
                var myPoint = document.getElementById('myPoint');
                var colors = Plotly.d3.scale.category20();
                
                //move the red dot
                myPlot.onmousemove = function(event) {
                  myPoint.style.left = event.pageX + "px";
                  myPoint.style.top = event.pageY + "px";
                }
                myPlot.onmouseleave = function() {
                  myPoint.style.left = "-999px";
                  myPoint.style.top = "-999px";
                }
                
                //create the plot
                Plotly.newPlot('myDiv', data);
                //use Plotly's hover event to get the data
                myPlot.on('plotly_hover', function(data){
                	myPoint.style.border = "solid " + (2 + (data.points[0].z * 5)) +"px " + colors(Math.abs(1 - data.points[0].z));
                });

                <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
                <div id='myDiv'>
                </div>
                <div id="myPoint" style="top: -999px; left: -999px; border: 5px solid #ff0000; border-radius: 50%; position: absolute; z-index: 999;">
                </div>

                这篇关于自定义工具提示定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                      <bdo id='wzu6W'></bdo><ul id='wzu6W'></ul>

                    • <legend id='wzu6W'><style id='wzu6W'><dir id='wzu6W'><q id='wzu6W'></q></dir></style></legend>

                        <tbody id='wzu6W'></tbody>

                      <small id='wzu6W'></small><noframes id='wzu6W'>

                        1. <tfoot id='wzu6W'></tfoot>
                          <i id='wzu6W'><tr id='wzu6W'><dt id='wzu6W'><q id='wzu6W'><span id='wzu6W'><b id='wzu6W'><form id='wzu6W'><ins id='wzu6W'></ins><ul id='wzu6W'></ul><sub id='wzu6W'></sub></form><legend id='wzu6W'></legend><bdo id='wzu6W'><pre id='wzu6W'><center id='wzu6W'></center></pre></bdo></b><th id='wzu6W'></th></span></q></dt></tr></i><div id='wzu6W'><tfoot id='wzu6W'></tfoot><dl id='wzu6W'><fieldset id='wzu6W'></fieldset></dl></div>