Skip to content

Instantly share code, notes, and snippets.

View connerxyz's full-sized avatar

Conner Cowling connerxyz

View GitHub Profile
@connerxyz
connerxyz / d3-scaling-tick-number-with-window-inner-width.js
Created August 8, 2019 21:20
d3.js: v5: scaling number of ticks with window's inner width
var xScale = d3.scaleTime()
.domain(d3.extent(data, function(d) { return d.key; })) // Input
.range([0, width]); // output
// Quantize 400px - 1600px window range
var tickScale = d3.scaleQuantize()
.domain([400, 1600])
.range([3, 7, 10]);
// Set number of ticks based on window height