【问题标题】:hightcharts: change standard position of tooltip AND shadow (hover)highcharts:更改工具提示和阴影的标准位置(悬停)
【发布时间】:2015-05-21 01:11:51
【问题描述】:

请看这个:http://jsfiddle.net/zb443xj9/

气泡被半径拉得更高。 因此“drawPoints”方法更改如下(因为该“更改功能”在框架中没有实现):

    (function (H) {
    H.wrap(H.seriesTypes.bubble.prototype, 'drawPoints', function (p) {
        var series = this;
        H.each(series.points, function (point, i) {
            point.shapeArgs.y -= point.shapeArgs.r; //moved up by radius
        });

        p.call(this);
    });
})(Highcharts);

如果您将鼠标悬停在您看到的气泡上,阴影和工具提示仍然指向“旧”中心。 有人知道绘制阴影和工具提示的方法是怎么命名的吗?

我也很想覆盖这两种方法。 我希望它们被称为“drawShadow”和“drawTooltip”之类的东西,但不幸的是没有。

谢谢!

【问题讨论】:

  • 这个阴影(光环)是串联对象,动态呈现为路径,因此您还需要包装光环函数(haloPath)。
  • 完美!我只是复制并粘贴包装函数并通过“halo”替换“drawPoints”!工具提示呢?你也知道这个函数名吗?
  • "haloPath" @SebastianBochan 是什么意思? ...H.wrap(H.seriesTypes.bubble.prototype, 'haloPath', function (p) {... 没有影响。

标签: javascript jquery highcharts tooltip shadow


【解决方案1】:

您应该将 haloPath 方法包装在点选项中。然后覆盖点内的“this”对象。

H.wrap(H.Point.prototype, 'haloPath', function (proceed) {

                if(this.oldY === UNDEFINED) {
                    this.oldY = this.plotY;
                    this.plotY -= (this.shapeArgs.r);
                }

                return proceed.apply(this, 

Array.prototype.slice.call(arguments, 1));
});

H.wrap(H.Tooltip.prototype, 'getAnchor', function (proceed, points, mouseEvent) {
        var ret,
        chart = this.chart,
            inverted = chart.inverted,
            plotTop = chart.plotTop,
            plotLeft = chart.plotLeft,
            plotX = 0,
            plotY = 0,
            yAxis,
            xAxis;

        points = splat(points);

        // Pie uses a special tooltipPos
        ret = points[0].tooltipPos;

        // When tooltip follows mouse, relate the position to the mouse
        if (this.followPointer && mouseEvent) {
            if (mouseEvent.chartX === UNDEFINED) {
                mouseEvent = chart.pointer.normalize(mouseEvent);
            }
            ret = [
            mouseEvent.chartX - chart.plotLeft,
            mouseEvent.chartY - plotTop];
        }
        // When shared, use the average position
        if (!ret) {
            each(points, function (point) {
                yAxis = point.series.yAxis;
                xAxis = point.series.xAxis;
                plotX += point.plotX + (!inverted && xAxis ? xAxis.left - plotLeft : 0);
                plotY += (point.plotLow ? (point.plotLow + point.plotHigh) / 2 : point.plotY) + (!inverted && yAxis ? yAxis.top - plotTop : 0); // #1151
            });

            plotX /= points.length;
            plotY /= points.length;

            ret = [
            inverted ? chart.plotWidth - plotY : plotX,
            this.shared && !inverted && points.length > 1 && mouseEvent ? mouseEvent.chartY - plotTop : // place shared tooltip next to the mouse (#424)
            inverted ? chart.plotHeight - plotX : plotY];
        }

        if(points[0].oldY === UNDEFINED) {
            ret[1] -= points[0].shapeArgs.r;
        }

        return map(ret, mathRound);
    });

编辑: 示例:http://jsfiddle.net/zb443xj9/6/

【讨论】:

  • 但这只有在我将鼠标悬停在气泡上 2 次时才有效。我第一次悬停时,工具提示位于其原始居中位置。在我将鼠标移动到另一个气泡并返回到该气泡后,工具提示会按半径向上移动。你看到@SebastianBochan 了吗?也许我们必须以某种方式更改 if 分支?
  • 但是你想在哪里有一个工具提示,在中心“新移动的气泡”内?
  • 如果你第一次悬停它太“深”。如果工具提示定位在“新移动气泡”的中心,那就完美了!第二次悬停的位置也很棒。重要的是,它不应在第一次和第二次悬停时呈现在不同的位置。
  • 你需要为工具提示包装getAnchor函数,看我更新的demo
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多