renderchart = (svg, {xscale, yscale, ytickformatter, margin, ybandwidth}) => {
console.log('this is render chart')
return function({domain}){
console.log('this is render chart call')
yscale.domain(d3.extent(domain));
let imousebehavior = mousebehavior({xscale, yscale})
, yaxis = d3.axisLeft(yscale)
.tickSize(0)
.tickValues(domain.filter((d, i) => d % 60 === 0))
.tickFormat(ytickformatter)
;
svg.selectAll('g.yaxis')
.data([0])
.join('g').attr('class', 'yaxis')
.attr('transform', `translate(${[margin.left, margin.top]})`)
.call(yaxis)
let plot = svg.selectAll('g.plot')
.data([0])
.join('g').attr('class', 'plot')
.attr('transform', `translate(${[margin.left, margin.top]})`)
plot.selectAll('g.day-band')
.data(xscale.domain())
.join('g').attr('class', 'day-band')
.each(function(d){
let dayband = d3.select(this);
dayband.selectAll('g.time-cell')
.data(domain)
.join('g').attr('class', 'time-cell')
.attr('fill', '#000')
.each(function(cd){
d3.select(this)
.selectAll('rect')
.data([0])
.join('rect')
.attr('x', xscale(d))
.attr('width', xscale.bandwidth())
.attr('height', ybandwidth)
.attr('y', yscale(cd))
})
.call(imousebehavior);
});
let ydomain = yscale.domain();
plot.selectAll('g.events')
.data([0])
.join('g').attr('class', 'events')
.selectAll('g.event')
.data(events.filter(e => e['start_time'] >= ydomain[0] && e['end_time'] <= ydomain[1]))
.join('g').attr('class', 'event')
.each(function(d){
let ed = new Date(`${d['event_date']} 00:00:00`);
d3.select(this)
.selectAll('rect')
.data([0])
.join('rect')
.attr('x', xscale(ed))
.attr('y', yscale(d['start_time']))
.attr('height', yscale(d['end_time']) - yscale(d['start_time']))
.attr('width', xscale.bandwidth() * 0.8)
.attr('fill', '#666');
})
}
}