hashg
hashg

Reputation: 806

D3js : data update is not updating right objects

I am trying to build a horizontal calendar timeline using d3.js. Main goal is to highlight holidays and vacations of user.

http://jsbin.com/ceperavu/2/edit?css,js,output

Is this wrong d3.selectAll('rect.day').data(vacations).attr('class', 'holiday'); ?

Edit: format and additional details.

Upvotes: 0

Views: 159

Answers (2)

FernOfTheAndes
FernOfTheAndes

Reputation: 5015

I have changed the input data a bit so that you can compare apples to apples and also used a helper function from jquery. This fiddle is the result. Hope this helps.

days.selectAll('rect.day')
    .attr('class', function (d) {
        return  ($.inArray(d.getTime(), vacations))  > -1 ? 'holiday' : 'day';
    });

Upvotes: 3

Unknown User
Unknown User

Reputation: 3658

Here's the Fiddle.

Problem was with this code near the days variable.

var days = chart.selectAll(".day")
    .data(function(d) { return d3.time.days(new Date(date.start), new Date(date.end)); })
        .enter()
        .append('svg:g')
    .attr('class', 'day');

Earlier it was like this.

var days = chart
.selectAll(".day")
    .data(function(d) { return d3.time.days(new Date(date.start), new Date(date.end)); })
        .enter()
        .append('svg:g')
    .attr('class', 'day');

Please check if it helps.

Upvotes: -1

Related Questions