问题
I've been working with Dimple.js recently and have found the need to change the default tooltip behavior in some cases. The method for doing this via the API is described here.
However, the dimple.eventArgs object that is passed into the function that is supposed to contain all of the information about the hovered element that triggered the event appears to be lacking some of the data it should contain. jsFiddle example here. Hovering a point on the plot shows that the eventArgs object that was received contains the correct yValue property for the datapoint, but the xValue property is always null.
In contrast, commenting out the lines from the fiddle
s.getTooltipText = function (e) {
alert("Object xValue: " + e.xValue + " , Object yValue: " + e.yValue);
return [e.xValue, e.yValue];
};
shows that default tooltip behavior does receive the correct xValue property.
How can I access these values when overriding the default handler?
回答1:
The default tooltip handler actually gets the same information passed to your overridden method : https://github.com/PMSI-AlignAlytics/dimple/blob/master/src/objects/series/methods/getTooltipText.js
If you are looking for just the same formatted text you would get from the standard tooltip, you could get it by accessing the private method used to get that for the standard tooltip. Your overridden getTooltipText
function will be called in the context of the series, so this
will have any of the dimple.series
methods available (which is how the default one computes the text).
var rows = [];
this.x._getTooltipText(rows, e); //x is your x dimple.axis object
Also note that 'rows' will be mutated inside that function and it doesn't return anything. If you're looking for the original data point used to compute its position, that should be available on e.x
. The dimple.eventArgs
object is only created if you manually use series.addEventListener
.
来源:https://stackoverflow.com/questions/26258732/eventargs-in-dimple-js-appear-incomplete