1.7.7 Resolution recommendation
How the system decides the best time resolution
Measure the total time range
- The system first calculates how much time you are looking at.
- It converts the chosen start and end dates into milliseconds.
- This gives a precise number that represents the full span of time.
Pick a base unit
- Based on the time span, the system chooses an initial time unit (seconds, minutes, hours, days, weeks, or months).
- This is done using simple rules:
- Years -> months
- Months -> weeks
- Weeks -> days
- Days -> hours
- Hours -> minutes
- Minutes -> seconds
- This ensures the starting unit makes sense for the total time range.
Determine how many points can fit on the chart
- The system assumes each data point needs at least 3 pixels to remain readable.
- For example, a 400-pixel-wide chart can display roughly 133 points (400 / 3).
- This is the maximum number of data points that can fit without making the chart look crowded.
Check different step sizes
- For the chosen unit, the system tests several step sizes (like 1 hour, 3 hours, 6 hours, etc.).
- For each step size, it calculates how many points the chart would need by dividing the total time in milliseconds by the step size in milliseconds.
- If the number of points is less than or equal to the maximum allowed, that step size is chosen.
Fallback if needed
- If none of the step sizes fit neatly, the system automatically moves to the next larger unit (e.g., hours -> days) and uses a default step of 1.
- This ensures the chart is never too crowded, no matter the time range.
Example
- Time range: 2 days
- Chart width: 400 pixels → max 133 points
- Step options for hours: 1 hour, 3 hours, 6 hours, 12 hours
- The system calculates:
- Total milliseconds / step in milliseconds = number of points
- 2 days ÷ 1 hour → 48 points - fits
- 2 days ÷ 3 hours → 16 points - also fits
- The first step size that fits (48 points) is selected.
Result: Time unit = hours, Step = 1
In short
It converts your chosen date range into milliseconds, calculates how many points can fit on the chart based on a simple 3-pixel-per-point rule, and then selects the most readable time unit and step size automatically.