Using Brush Slider to select date

30 views
Skip to first unread message

Jared Vacanti

unread,
Aug 24, 2016, 3:48:51 PM8/24/16
to d3-js
I have a jsfiddle set up here that I'm trying to update a line based on what day is selected on the slider. Right now it works sporadically - trying to replicate this behavior: https://bl.ocks.org/mbostock/6452972 but for a date range. It appears to me that this should work, but it doesn't work all time (hangs, skips about 15% of the time). 


Is it possible to user a slider as a date selector? Do I need to use a different scale or something? 

Thanks, Jared

Curran

unread,
Aug 25, 2016, 3:49:06 AM8/25/16
to d3-js
Hi Jared,

I tried your fiddle and it the date slider seems to work perfectly. I'm not able to reproduce any odd behavior (hanging/skipping).

One thing that does come to mind though is that maybe there is excessive computation for the line chart blocking the UI. It looks like your code triggers a re-rendering of the line chart (with transitions also) on every single drag event from the slider. One thing you could try is to throttle the brush handler. As you are already using Underscore, you could try _.throttle, replacing

.on("brush", brushed);

with

.on("brush", _.throttle(brushed, 100));

This will cause the line to be re-rendered at most 10 times per second, which might get rid of the lagging behavior you describe.

Best regards,
Curran
Reply all
Reply to author
Forward
0 new messages