Use linear interpolation on rate charts to prevent tooltip from drawing in the wrong y position
@@ -969,8 +969,10 @@ var QDR = (function(QDR) {
.range([height - margin.top - margin.bottom, 0]);
}
if (attrs.type == "rate") {
- area.interpolate("basis"); // rate charts look better smoothed
- line.interpolate("basis");
+ area.interpolate("linear"); // rate charts look better smoothed, but the tooltop is in the wrong place
+ line.interpolate("linear");
+// area.interpolate("basis"); // rate charts look better smoothed
+// line.interpolate("basis");
} else {
area.interpolate("linear"); // don't smooth value charts
line.interpolate("linear");
@@ -1150,3 +1152,30 @@ var QDR = (function(QDR) {
return QDR;
}(QDR || {}));
+
+// see https://stackoverflow.com/questions/11503151/in-d3-how-to-get-the-interpolated-line-data-from-a-svg-line/39442651#
+var findYatXbyBisection = function(x, path, error){
+ var length_end = path.getTotalLength()
+ , length_start = 0
+ , point = path.getPointAtLength((length_end + length_start) / 2) // get the middle point
+ , bisection_iterations_max = 50
+ , bisection_iterations = 0
+
+ error = error || 0.01
+
+ while (x < point.x - error || x > point.x + error) {
+ // get the middle point
+ point = path.getPointAtLength((length_end + length_start) / 2)
+
+ if (x < point.x) {
+ length_end = (length_start + length_end)/2
+ } else {
+ length_start = (length_start + length_end)/2
+ }
+
+ // Increase iteration
+ if(bisection_iterations_max < ++ bisection_iterations)
+ break;
+ }
+ return point.y
+}
\ No newline at end of file
