score:2

Accepted answer

I got this working: livecoding.io example

And here the relevant code, not particularly clean but working:

var w = h = 600;
var padding = 20;
var svg = d3.select("svg").attr("width", w).attr("height", h);

var xScale = d3.scale.linear()
             .domain([0, 100])
             .range([padding, w - padding * 2]);

var sharedAxis = function() {
  return d3.svg.axis()
            .scale(xScale)
            .tickValues([19,69])
            .tickSize(50);
}

var downAxis = sharedAxis()
            .orient("bottom");

var upAxis = sharedAxis()
            .orient("top");

var addPlayer = function(playerAxis) {
  svg.append("g")
   .attr("class", "axis")
   .attr("transform", "translate(0," + (100) + ")")
   .call(playerAxis);
}


addPlayer(downAxis);
addPlayer(upAxis);

var drag = d3.behavior.drag()
    .on("drag", dragmove);

function dragmove(d) {
  // move it
  var curX = d3.select(this).attr("transform").match(/\(([^,]+),/)[1];
  var newX = Math.max(xScale.range()[0], d3.event.x);
  newX = Math.min(xScale.range()[1], newX);
  var newTransform = d3.select(this).attr("transform").replace(/\([^,]+,/, "(" + newX + ",");
  d3.select(this).attr("transform", newTransform);
  // update text
  d3.select(this).select("text").text(parseInt(xScale.invert(newX)));
}

var allTicks = d3.selectAll(".axis g").call(drag);

Related Query