scaleTimeNoWeekends = function(timeScale) {
const scale = (d) => {
const t = d.getTime();
const monday = d3.timeMonday.floor(d);
const saturday = d3.timeSaturday.ceil(monday);
const nextMonday = d3.timeMonday.ceil(saturday);
const f = Math.min(1, (t - monday.getTime()) / (saturday.getTime() - monday.getTime()));
const d1 = new Date(monday.getTime() + f * (nextMonday.getTime() - monday.getTime()));
return timeScale(d1);
};
function steal(methods) {
methods.forEach(f => {
scale[f] = function(_) {
if (arguments.length) {
timeScale[f].apply(timeScale, arguments);
return scale;
}
return timeScale[f]();
}
});
}
steal(['domain', 'range', 'round', 'nice', 'tickFormat', 'clamp']);
scale.invert = (_) => {
return timeScale.invert(_);
}
scale.ticks = (_) => {
return timeScale.ticks(_);
}
scale.copy = () => {
timeScale = timeScale.copy();
return scale;
}
return scale;
}