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

adds option to only tick at block start #107

Open
wants to merge 2 commits 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
37 changes: 36 additions & 1 deletion src/d3-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,39 @@

setWidth();

var generateTicksFromBlocks = function(overlap) {
var ticks = []
g.each(function(d) {
for (var datum of d) {
for (var time of datum.times) {
var current = new Date(time.starting_time)

if (!ticks.length) {
ticks.push(current)
continue
}

// check for overlap
if (overlap) {
var tickOverlaps = false
for (var tick of ticks) {
if ((current >= tick && current - tick <= overlap)
|| (current < tick && tick - current <= overlap)) {
tickOverlaps = true
}
}

if (!tickOverlaps) ticks.push(current)
} else {
ticks.push(current)
}
}
}
})

return ticks
}

// check if the user wants relative time
// if so, substract the first timestamp from each subsequent timestamps
if(timeIsRelative){
Expand Down Expand Up @@ -233,7 +266,9 @@
.tickFormat(tickFormat.format)
.tickSize(tickFormat.tickSize);

if (tickFormat.tickValues != null) {
if (tickFormat.atBlockStart) {
xAxis.tickValues(generateTicksFromBlocks(tickFormat.hideOverlapTicks))
} else if (tickFormat.tickValues != null) {
xAxis.tickValues(tickFormat.tickValues);
} else {
xAxis.ticks(tickFormat.numTicks || tickFormat.tickTime, tickFormat.tickInterval);
Expand Down