Last active
August 30, 2022 10:48
-
-
Save usausa/f53995add1a2ec77630454cfc798a587 to your computer and use it in GitHub Desktop.
AxisCalculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TimeAxisCalculator | |
{ | |
private static readonly TimeSpan[] CandidateValues = | |
{ | |
TimeSpan.FromMinutes(1), | |
TimeSpan.FromMinutes(2), | |
TimeSpan.FromMinutes(5), | |
TimeSpan.FromMinutes(10), | |
TimeSpan.FromMinutes(15), | |
TimeSpan.FromMinutes(30), | |
TimeSpan.FromHours(1), | |
TimeSpan.FromHours(2), | |
TimeSpan.FromHours(3), | |
TimeSpan.FromHours(4), | |
TimeSpan.FromHours(6), | |
TimeSpan.FromHours(12), | |
TimeSpan.FromDays(1) | |
}; | |
public static TimeSpan Calc(TimeSpan range) | |
{ | |
var value = range / 5; | |
foreach (var candidateValue in CandidateValues) | |
{ | |
if (value <= candidateValue) | |
{ | |
return candidateValue; | |
} | |
} | |
return CandidateValues[^1]; | |
} | |
} | |
// 00:00:01 -> 00:00:01 | |
// 00:00:05 -> 00:00:01 | |
// 00:00:06 -> 00:00:02 | |
// 00:00:09 -> 00:00:02 | |
// 00:00:10 -> 00:00:02 | |
// 00:00:11 -> 00:00:05 | |
// 00:00:25 -> 00:00:05 | |
// 00:00:26 -> 00:00:10 | |
// 00:00:50 -> 00:00:10 | |
// 00:00:51 -> 00:00:15 | |
// 00:01:15 -> 00:00:15 | |
// 00:01:16 -> 00:00:30 | |
// 00:02:30 -> 00:00:30 | |
// 00:02:31 -> 00:01:00 | |
// 00:05:00 -> 00:01:00 | |
// 00:05:01 -> 00:02:00 | |
// 00:10:00 -> 00:02:00 | |
// 00:10:01 -> 00:03:00 | |
// 00:15:00 -> 00:03:00 | |
// 00:15:01 -> 00:04:00 | |
// 00:20:00 -> 00:04:00 | |
// 00:20:01 -> 00:06:00 | |
// 01:06:00 -> 00:06:00 | |
// 01:06:01 -> 00:12:00 | |
// 02:12:00 -> 00:12:00 | |
// 02:12:01 -> 01:00:00 | |
// 05:00:00 -> 01:00:00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ValueAxisCalculator | |
{ | |
public static double Calc(double value) | |
{ | |
var baseValue = 30; | |
var log = 0; | |
while (value >= baseValue) | |
{ | |
baseValue *= 10; | |
log++; | |
} | |
var pow = (int)Math.Pow(10, log); | |
if (value < 6 * pow) | |
{ | |
return pow; | |
} | |
if (value < 12 * pow) | |
{ | |
return 2 * pow; | |
} | |
if (value < 15 * pow) | |
{ | |
return 2.5 * pow; | |
} | |
return 5 * pow; | |
} | |
} | |
// 0.00 -> 1.00 | |
// 1.00 -> 1.00 | |
// 3.00 -> 1.00 | |
// 5.90 -> 1.00 | |
// 6.00 -> 2.00 | |
// 11.90 -> 2.00 | |
// 12.00 -> 2.50 | |
// 14.90 -> 2.50 | |
// 15.00 -> 5.00 | |
// 29.90 -> 5.00 | |
// 30.00 -> 10.00 | |
// 59.90 -> 10.00 | |
// 60.00 -> 20.00 | |
// 119.90 -> 20.00 | |
// 120.00 -> 25.00 | |
// 149.90 -> 25.00 | |
// 150.00 -> 50.00 | |
// 299.90 -> 50.00 | |
// 300.00 -> 100.00 | |
// 599.90 -> 100.00 | |
// 600.00 -> 200.00 | |
// 1199.90 -> 200.00 | |
// 1200.00 -> 250.00 | |
// 1499.90 -> 250.00 | |
// 1500.00 -> 500.00 | |
// 2999.90 -> 500.00 | |
// 3000.00 -> 1000.00 | |
// 5999.90 -> 1000.00 | |
// 6000.00 -> 2000.00 | |
// 11999.90 -> 2000.00 | |
// 12000.00 -> 2500.00 | |
// 29999.90 -> 5000.00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment