krzysu/flot.tooltip — pull request #66 by vitorbaptista (2014-03-10 15:27:01+00:00)
Title: Fix tooltip when displaying multiple series

We replace the "%x" in the tooltip string with the corresponding item tick's
label. We do so by looking at the item's index in the chart's data array
(dataIndex), and getting the tick in the same index in the ticks' array.
That works fine if you have a single series, but doesn't work with multiple
ones.

In that case, you have multiple data arrays, one for each series, but you still
have a single ticks array. For example, if you have the plot's data as:

[
{ data: [ ["Foo", 5] ] },
{ data: [ ["Bar", 10] ] }
]

Both item's dataIndex will be 0, because each one is the first element on its
series' data array. But the ticks array is something like:

["Foo", "Bar"]

If you use only dataIndex, you'll get the tick "Foo" for both items. What we
need is an offset which tells us which series the current item is in: that's
seriesIndex. The ticks' index is then calculated as ```seriesIndex +
dataIndex```.

That solves our problem. In our example, even though the dataIndex for both
items is 0, the seriesIndex for "Foo" is 0, and for "Bar" is 1. Everything
works as expected.

This fixes #65.