# need an intelligent scale

This topic is 3941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 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 on other sites
Quote:
 Original post by tstrimpAre 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 weeksIt time range > 2 days: use daysIf time range > 2 hours: use hoursetc...

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 on other sites
Why not measure the string that is being displayed? When it is to big scale up.

##### Share on other sites
Quote:
 Original post by tstrimpIf time range > 2 weeks: use weeksIt time range > 2 days: use daysIf time range > 2 hours: use hoursetc...

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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 16
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632928
• Total Posts
3009265
• ### Who's Online (See full list)

There are no registered users currently online

×