title: D3.js Mouseover and Focus + Context issue
body: <p>I am new to D3.js
  I've gone through some tutorials and have straight up jumped into my first project. I was hoping to combine the following with slight tweaks according to my needs. Currently I am having two issues</p>
  
  <p><a href="http://bl.ocks.org/mbostock/1667367" rel="nofollow">Focus+Context via Brushing</a></p>
  
  <p>and</p>
  
  <p><a href="http://bl.ocks.org/mbostock/3902569" rel="nofollow"> X-Value Mouseover</a></p>
  
  <ol>
  <li>The Mouseover is wrongly displayed. It renders to the left of the chart. Could be a very small issue but I cant seem to find it.</li>
  <li>I cant seem to figure out a way to display the "Safe Value" text outside the chart right next to the line. EDIT 2 - I've figured this out</li>
  </ol>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Here is the CSS</p>
  
  <pre><code>body {
      font: 10px sans-serif;
  }
  
  svg {
      font: 10px sans-serif;
  }
  
  .line {
      fill: none;
      stroke: steelBlue;
      stroke-width: 1.5px;
      /*clip-path: url(#clip);*/
  }
  
  .axis path,
  .axis line {
      fill: none;
      stroke: #000;
      shape-rendering: crispEdges;
  }
  
  .brush .extent {
      stroke: #fff;
      fill-opacity: .125;
      shape-rendering: crispEdges;
  }
  
  .overlay {
      fill: none;
      pointer-events: all;
  }
  
  .xy circle {
      fill: steelblue;
      stroke: black;
  
  }
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>var margin = {top: 10, right: 15, bottom: 100, left: 60},
      margin2 = {top: 430, right: 15, bottom: 20, left: 60},
      width = 960 - margin.left - margin.right,
      height = 500 - margin.top - margin.bottom,
      height2 = 500 - margin2.top - margin2.bottom;
  
  var parseDate = d3.time.format("%Y-%m-%dT%H:%M:%SZ").parse,
      bisectDate = d3.bisector(function(d) { return d.date; }).left,
      formatValue = d3.format(",.2f"),
      formatData = function(d) { return formatValue(d) + " %"; };
  
  var x = d3.time.scale().range([0, width]),
      x2 = d3.time.scale().range([0, width]),
      y = d3.scale.linear().range([height, 0]),
      y2 = d3.scale.linear().range([height2, 0]);
  
  var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(d3.time.months, 1).tickFormat(d3.time.format("%m/%y")),
      xAxis2 = d3.svg.axis().scale(x2).orient("bottom").ticks(d3.time.months, 1).tickFormat(d3.time.format("%m/%y")),
      yAxis = d3.svg.axis().scale(y).orient("left");
  
  
  var brush = d3.svg.brush()
          .x(x2)
          .on("brush", brushed);
  
  var line = d3.svg.line()
          .interpolate("monotone")
          .x(function(d) { return x(d.date); })
          .y(function(d) { return y(d.value); });
  
  var line2 = d3.svg.line()
          .interpolate("monotone")
          .x(function(d) { return x2(d.date); })
          .y(function(d) { return y2(d.value); });
  
  var svg = d3.select("body").append("svg")
          .attr("width", width + margin.left + margin.right)
          .attr("height", height + margin.top + margin.bottom)
  
  
  svg.append("defs").append("clipPath")
          .attr("id", "clip")
          .append("rect")
          .attr("width", width)
          .attr("height", height);
  
  var focus = svg.append("g")
          .attr("class", "focus")
          .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  
  var context = svg.append("g")
          .attr("class", "context")
          .attr("transform", "translate(" + margin2.left + "," + margin2.top + ")");
  
  d3.csv("data.csv", function(error, data) {
  
      if (error) throw error;
  
      data.forEach(function(d) {
          d.date = parseDate(d.date);
          d.value = +d.value;
      });
  
      data.sort(function(a, b) {
          return a.date - b.date;
      });
  
  
      x.domain(d3.extent(data.map(function(d) { return d.date; })));
      y.domain([0, d3.max(data.map(function(d) { return d.value; }))]);
      x2.domain(x.domain());
      y2.domain(y.domain());
  
      focus.append("path")
              .datum(data)
              .attr("class", "line")
              .attr("d", line);
  
      focus.append("line")
              .attr("x1",x(data[0].date))
              .attr("y1",y(83))
              .attr("x2",x(data[data.length - 1].date))
              .attr("y2",y(83))
              .attr("stroke","orangered");
  
      svg.append("text")
              .attr("transform", "translate(" + (width+3) + "," + y(83) + ")")
              .attr("dy", ".35em")
              .attr("text-anchor", "start")
              .style("fill", "orangered")
              .text(function(d) { return "Safe Value = 83" });
  
      focus.append("g")
              .attr("class", "x axis")
              .attr("transform", "translate(0," + height + ")")
              .call(xAxis);
  
      focus.append("g")
              .attr("class", "y axis")
              .call(yAxis)
              .append("text")
              .attr("x", 0)
              .attr("y", 0)
              .style("text-anchor", "middle")
              .attr("transform", "translate(-50,"+ height/2 + ") rotate(-90)")
              .text("Dissolved Oxygen (%)");
  
      context.append("path")
              .datum(data)
              .attr("class", "line")
              .attr("d", line2);
  
      context.append("g")
              .attr("class", "x axis")
              .attr("transform", "translate(0," + height2 + ")")
              .call(xAxis2);
  
      context.append("g")
              .attr("class", "x brush")
              .call(brush)
              .selectAll("rect")
              .attr("y", -6)
              .attr("height", height2 + 7);
  
      var xy = svg.append("g")
              .attr("class", "xy")
              .style("display", "none");
  
      xy.append("circle")
              .attr("r", 4.5);
  
      xy.append("text")
              .attr("x", 9)
              .attr("dy", ".35em");
  
      svg.append("rect")
              .attr("class", "overlay")
              .attr("width", width)
              .attr("height", height)
              .style("fill", "none")
              .on("mouseover", function() { xy.style("display", null); })
              .on("mouseout", function() { xy.style("display", "none"); })
              .on("mousemove", mousemove);
  
      function mousemove() {
          var x0 = x.invert(d3.mouse(this)[0]),
                  i = bisectDate(data, x0, 1),
                  d0 = data[i - 1],
                  d1 = data[i],
                  d = x0 - d0.date &gt; d1.date - x0 ? d1 : d0;
  
          console.log(x0);
          xy.attr("transform", "translate(" + x(d.date) + "," + y(d.value) + ")");
          xy.select("text").text(formatData(d.value));
  
      }
  
  });
  
  function brushed() {
      x.domain(brush.empty() ? x2.domain() : brush.extent());
      focus.select(".line").attr("d", line);
      focus.select(".x.axis").call(xAxis);
  }
  </code></pre>
  
  <p><a href="http://plnkr.co/k4MY6qKe6E1VmvCtgVM7" rel="nofollow">Plunker Code</a>
  (Please refer to the code at Plunker, since I have updated a few things over there.) Thanks</p>
  
  <p><a href="http://i.stack.imgur.com/dsiYa.png" rel="nofollow">Image1</a>
  <a href="http://i.stack.imgur.com/rxwDT.png" rel="nofollow">Image2</a></p>