From 12e5f25da8fdc7c702fce135110725dbf3a4b0b4 Mon Sep 17 00:00:00 2001 From: Dominic Bordelon Date: Fri, 26 Aug 2016 14:42:13 +0200 Subject: [PATCH] add ability to set number of xAxis ticks --- gantt-chart-d3.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gantt-chart-d3.js b/gantt-chart-d3.js index c79dad3..1413853 100644 --- a/gantt-chart-d3.js +++ b/gantt-chart-d3.js @@ -23,6 +23,9 @@ d3.gantt = function() { var width = document.body.clientWidth - margin.right - margin.left-5; var tickFormat = "%H:%M"; + var ticksCount = 10; + var ticksInterval = null; + var ticksIntervalCount = null; var keyFunction = function(d) { return d.startDate + d.taskName + d.endDate; @@ -64,6 +67,11 @@ d3.gantt = function() { y = d3.scale.ordinal().domain(taskTypes).rangeRoundBands([ 0, height - margin.top - margin.bottom ], .1); xAxis = d3.svg.axis().scale(x).orient("bottom").tickFormat(d3.time.format(tickFormat)).tickSubdivide(true) .tickSize(8).tickPadding(8); + if (ticksInterval !== null && ticksIntervalCount !== null) { + xAxis.ticks(ticksInterval, ticksIntervalCount); + } else { + xAxis.ticks(ticksCount); + } yAxis = d3.svg.axis().scale(y).orient("left").tickSize(0); }; @@ -216,6 +224,20 @@ d3.gantt = function() { return gantt; }; + gantt.ticks = function(...args) { + if (!arguments.length) + return ticksCount; + if (arguments.length == 1) { + ticksInterval = null; + ticksIntervalCount = null; + ticksCount = arguments[0]; + } else { + ticksInterval = arguments[0]; + ticksIntervalCount = arguments[1]; + } + return gantt; + }; + gantt.selector = function(value) { if (!arguments.length) return selector;