I have created two if conditions inside the function but it is taking only one if condition and returns that. I need to execute both if conditions at same time or how can we write condition before .attr('x2', d => self.x(0)) using d3 js
function updateLines(select) {
if(data.filter(d => d.esp != null) || (d => d.esp == 0)){
return select
.attr('y1', d => self.y(d.esp))
.attr('y2', d => self.y(d.esp))
.attr('x1', d => self.x(d.hour)-3)
.attr('x2', d => self.x(d.hour)+3 + self.x.bandwidth())
}
if(data.filter(d => esp == null)){
return select
.attr('y1', d => self.y(d.esp))
.attr('y2', d => self.y(d.esp))
.attr('x1', d => self.x(0))
.attr('x2', d => self.x(0))
}
}
The checking should happen at the
.attrlevel because it will be executed for each element in the selection. You can prepare upfront the data filters and check them in the.attrcallbacks:assuming that the selection was created with
.data(data)wheredatais the same array of objects that is used in theupdateLinesfunction.