grid.js 731 B

123456789101112131415161718192021222324252627
  1. import * as d3 from 'd3';
  2. // d3js module: add grid
  3. export default (selection, scales, options) => {
  4. const addGridlinesX = () => d3.axisBottom(scales.xScale).ticks(5);
  5. const addGridlinesY = () => d3.axisLeft(scales.yScale).ticks(15);
  6. // add the X gridlines
  7. selection.append('g')
  8. .attr('class', 'grid grid--x')
  9. .attr('transform', `translate(0, ${options.heightWithoutMargin})`)
  10. .call(
  11. addGridlinesX()
  12. .tickSize(-options.heightWithoutMargin)
  13. .tickFormat('')
  14. );
  15. // add the Y gridlines
  16. selection.append('g')
  17. .attr('class', `grid grid--y mod${options.module}__grid--y`)
  18. .call(
  19. addGridlinesY()
  20. .tickSize(-options.widthWithoutMargin)
  21. .tickFormat('')
  22. );
  23. };