uPlot icon indicating copy to clipboard operation
uPlot copied to clipboard

Highlight intervals (weekends, etc..)

Open CrashLaker opened this issue 6 years ago • 2 comments

Hi all,

Is there a way to highlight intervals along the X axis? e.g. weekends, holidays, etc. Like in: http://dygraphs.com/gallery/#g/highlighted-weekends

CrashLaker avatar Feb 05 '20 18:02 CrashLaker

nothing out of the box, but it should be easy enough to author a plugin that does this. you have full access to all timestamps obviously, and you can use uPlot.tzDate() to get a timezone-adjusted date objects which you can use to isolate weekend ranges, then simply paint on u.ctx in the drawAxes hook if want it atop the grid (but below the series), or drawClear hook if you need it under the grid.

take a look at how https://github.com/leeoniya/uPlot/blob/master/demos/draw-hooks.html does everything.

would be a good plugin to author for the demos here ;)

leeoniya avatar Feb 05 '20 18:02 leeoniya

copying from https://github.com/leeoniya/uPlot/pull/126#issuecomment-594074971:

yes, you have to use uPlot.tzDate. the real trick is not to iterate every datapoint in the scale range in search of weekends, because that would mean creating 60,000 Date instances when you have 30,000 datapoints. you have to find these weekends efficiently, like the axis ticks find breaks in months, days, hours without walking the data.

leeoniya avatar Mar 21 '20 18:03 leeoniya