Hi,
I’m trying to format x-axis for duration/elapsed time. Depending on the data chosen by the user the data displayed can vary a lot with respect to duration so I need to be able to cover from less than a minute to days (measured in hours, hence if duration is 1 day and 7 hours, the axis should show in hh:mm).
I have tried using NumeralTickFormatter with format="00:00:00". It works to some extent in the sence it show days in hours, but it is always on the format of hh:mm:ss. I had hoped it would automatically change between hh:mm or mm:ss depending on the data being displayed.
I have tried formatting the axis as datetime, but here the problem is that duration extending for more than a day, I’m not able to control have days in hours; when duration is 0 or 24 it is shown as a day/date.
Any help/hints with respect to formatting duration appreciated.
Cheers,
Jonas
Take a look at how DatetimeTicker is implemented. It’s built on top of CompositeTicker and just specifies a bunch of other tickers for different scales.
It seems like you should be able to create your own version of CompositeTicker that does what you want.
@p-himik thanks for a quick reply! I do struggle to understand how to get something like hh:mm or mm:ss for the labels… I’m not able to get DateTimeTicker to show days in hours, hence 1 day and 7 hours should be 31:00
There is no ticker that is denominated in only in perpetually accumulating hours. You can probably use a SingleIntervalTicker with an interval of 1hr (in milliseconds) and then a FuncTickFormatter to format those values as “total hours” (assuming here that your range starts at 0 for 0 hours)
@p-himik So I have managed to make two FuncTickFormatter's, one for hh:mm and one for mm:ss. However I struggle to combine those into CompositeTicker since I made formatters and not ticker (or maybe I misunderstood)?
Hmm, yeah, you might need to write a custom formatter that has access to the full set of ticks so it could at least guess what range it should use - hours or minutes.
Sorry, I can’t really add anything else without spending significant amount of time on this.
@Jonas_Grave_Kristens are you can’t just change the default formats on the built-in DatetimeTickFormatter? It has properties for minutes, hourmin, and hours scales. If you don’t like the default format strings for those scales you can provide your own.
@Bryan the issue with DatetimeTickFormatter is that I have not been able to figure out to have the duration in hours as a running total, eg 24 hours should be 24:00. If I have plot.axis[0].formatter.days = ['%H:%M'] then I get 0:00 @ 24:00. I would like the ticker to continue from 23:00, 24:00, 25:00 etc.
Oh right, I forgot that was also a requirement. This is a fairly specialized ask, I am afraid I don’t think there are any simple solutions available. Offhand, my best suggestion is to configure a CompositeTicker with two AdaptiveTickers similar to what the existing DatetimeTicker does:
You’d want to configure the mantissas for whatever “nice” multiples you want to be avaialble for selection as tick locations. You may also need to set the max_interval higher on the “hours” ticker. Then you will need to combine your two FuncTickFormatters above into a single one, that checks to see if the tick value is an even hour or not, and applies different formats appropriately.