krzysu / flot.tooltip

tooltip plugin for wonderful Flot plotting library
https://github.com/krzysu/flot.tooltip
187 stars 153 forks source link

Tooltips incorrectly assigned when using steps option in flot #71

Closed tiefpunkt closed 10 years ago

tiefpunkt commented 10 years ago

When using the steps option in flot, as below, tooltips are not assigned to the correct datapoints.

lines: {
        show: true,
        steps: true
    }

screenshot - 04072014 - 02 34 52 pm This is probably due to the fact that flot adds additional datapoints to the graph when steps is set to true. Ideally, flot.tooltip should ignore them, and only show tooltips on the "real" datapoints.

wq9 commented 10 years ago

The plugin is reading data from the wrong place.

Replace line 218 with

if (typeof item.series.threshold === "undefined") {
krzysu commented 10 years ago

@wq9 no, it is more complicated, tooltip needs to support many different plugins, if that really solves this problem, then just add new if statement with steps === true and then read data from correct place. pull request is always welcome :)

wq9 commented 10 years ago

I think you wrote the wrong if statement, the correct one is below:

        // for threshold plugin we need to read data from different place
        if (typeof item.series.threshold === "undefined") {
            //no threshold plugin, read hovered data point
            x = item.datapoint[0];
            y = item.datapoint[1];
        } else {
            //threshold plugin in use, read data from source using index
            x = item.series.data[item.dataIndex][0];
            y = item.series.data[item.dataIndex][1];
        }

Or you can swap the stuff inside the if...else. That would be better.

        // for threshold plugin we need to read data from different place
        if (typeof item.series.threshold !== "undefined") {
            //threshold plugin in use, read data from source using index
            x = item.series.data[item.dataIndex][0];
            y = item.series.data[item.dataIndex][1];            

        } else {
            //no threshold plugin, read hovered data point
            x = item.datapoint[0];
            y = item.datapoint[1];
        }
krzysu commented 10 years ago

should be fixed after merging #78