Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to set number of xAxis ticks #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions gantt-chart-d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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;
Expand Down