score:2

Accepted answer

Since you have a time scale, you cannot simply multiply the domain values by a given number, as the answer linked in the comments correctly does (which is the most common solution for a linear scale).

In a time scale, you can add or subtract time using interval.offset.

For instance, in your case, I'll subtract 10 seconds from the first date and add 10 seconds in the last date:

var x = d3.scaleTime()
    .domain([d3.timeSecond.offset(d3.min(data[0], function(d) {
            return d.inspected_at;
        }), -10),
        d3.timeSecond.offset(d3.max(data[0], function(d) {
            return d.inspected_at;
        }), +10)
    ])
    .range([0, width - 100]);

That should be enough, but you can change that magic number the way you want.

Also, it's worth mentioning that interval.offset is way easier and handier than the JS alternatives, since you can use d3.timeSecond for seconds, d3.timeMinute for minutes, d3.timeDay for days and so on, adding or subtracting the necessary amount of seconds, minutes, days, weeks etc you want.

Here is the updated CodePen: https://codepen.io/anon/pen/NBEyrN?editors=0010


Related Query