Skip to content

Instantly share code, notes, and snippets.

@ryanand26
Created May 19, 2015 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanand26/b391972140857561fb81 to your computer and use it in GitHub Desktop.
Save ryanand26/b391972140857561fb81 to your computer and use it in GitHub Desktop.
D3.js: Generate the ticks for an axis without having to render them to the svg. Allows us to adapt the tickSize and tickPadding to these values before drawing rather than afterwards.
/**
* Generate the tick values for a given axis
* Reference: https://github.com/mbostock/d3/blob/master/src/svg/axis.js
*/
function getAxisTicks(axis) {
var scale1 = axis.scale(),
tickArguments_ = axis.ticks(),
tickValues = axis.tickValues(),
ticks;
ticks = tickValues == null ? (scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain()) : tickValues,
return ticks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment