Javascript – d3.js how to get minimum value of scale’s domain when using nice()

d3.jsjavascript

I have a scatter plot where I am trying to plot a reference point that should appear directly on the x-axis, but I am creating the y-axis like so:

   // give ourselves some space
    yMin = yMin * 0.9;
    yMax = yMax * 1.1;

    // set up y
    var yValue = function (d) {
            return d.price;
        },
        yScale = d3.scale.linear()
            .domain([yMin, yMax])
            .range([height, 0])
            .nice(),
        yAxis = d3.svg.axis()
            .scale(yScale)
            .orient("left");

The issue is that I want to plot a reference point directly on the x-axis. If I don't use .nice(), I can easily plot the reference point like so:

        var reference = svg.append('g').attr("class", "grid-reference");
        reference.append("circle").attr("id", "some-reference-value")
            .attr("class", "dot")
            .attr("r", 9)
            .attr("cx", xScale(someReferenceValue))
            .attr("cy", yScale(yMin))
            .style("fill", "grey")
            .style("opacity", 1);

but I can't seem to figure out how to do this when using .nice(). Is there another way I could go about this such as somehow getting the y-coordinate of the x-axis line?

I started digging through the d3 code to see how I could calculate the nice value and I understand the code, but it seems wasteful to calculate the value again not to mention the unnecessary maintenance of duplicate code – especially considering I also have reference points I will need to plot along the y-axis and I am using a logarithmic scale for my x-axis (the logarithmic nice() function is different from the linear nice() function so this would mean additional duplicate code and unnecessary maintenance).

Ideas?

Best Solution

You can simply query the scale for its domain after .nice() and then get the minimum value of that:

var yMin = yScale.domain()[0];