Sign in to follow this  
hydroo

need an intelligent scale

Recommended Posts

Two pictures to show what I am sitting in front of: - 0.372 and 0.373 have multiple lines - The numbers are a bit too close to each other - one doesn't need hours, minutes and seconds when viewing weeks Since making a halfway intelligent scale is a generic problem I hope that someone can point me to material covering this topic. thanks in advance.

Share this post


Link to post
Share on other sites
Sorry, I'm not sure if I understand your problem.

If they are too close, then why not just show the week number (20w, 40w, 60w...)? If you have multiple of the same number, then just go down another order of magnitude (0.3721, 0.3722, 0.3723...)

Share this post


Link to post
Share on other sites
Yes you are totally right. It's just two examples of how not doing it.

The problem is that I have to invent something, which I think might be already invented because this is a common problem.

Share this post


Link to post
Share on other sites
Are the time ranges arbitrary? Why would you have to create the scale dynamically instead of just choosing a scale based on the amount of time in the range?

If time range > 2 weeks: use weeks
It time range > 2 days: use days
If time range > 2 hours: use hours
etc...

Share this post


Link to post
Share on other sites
I think here you could write a specific hard coded solution in a fraction of the time spent just thinking of a generic solution. (i.e. use tstrimp's solution)

If ever you will meet a second problem with similar inputs/outputs you could think of refactoring your specifics to a more generic solution.


If you want a custom solution that is not hard coded, you can use an array of value ranges and the proper resolution for each range.

Share this post


Link to post
Share on other sites
Quote:
Original post by tstrimp
Are the time ranges arbitrary? Why would you have to create the scale dynamically instead of just choosing a scale based on the amount of time in the range?

If time range > 2 weeks: use weeks
It time range > 2 days: use days
If time range > 2 hours: use hours
etc...


They are in fact arbitrarily. (Because the user can zoom in and out as he wishes)

Ranging from nanoseconds to weeks.
And it needs to handle ticks too, not only time.

The more interesting part is of course sub hours.

Share this post


Link to post
Share on other sites
Quote:
Original post by tstrimp
If time range > 2 weeks: use weeks
It time range > 2 days: use days
If time range > 2 hours: use hours
etc...

Is a good idea. You could save yourself some if-statements by taking a base-10 logarithm when things get into the decimal range (below 1s).

A slightly easier-to-maintain, if less efficient, alternative would be to determine the weeks, days, hours etc. as separate numerical values, then combine the first one or two non-zero sub-units into the string. Depending on your ideal output, this may also require separate treatment in the sub-second range, so it may not be worth the effort.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this