in atlas-chart/src/main/scala/com/netflix/atlas/chart/graphics/Ticks.scala [532:570]
private def durationTicks(
v1: Double,
v2: Double,
t: (Double, Double, Int),
prevPrefix: UnitPrefix = null
): List[ValueTick] = {
val (major, minor, minorPerMajor) = t
val ticks = List.newBuilder[ValueTick]
val prefix = if (prevPrefix == null) getDurationPrefix(math.abs(v2), major) else prevPrefix
val labelFmt = durationLabelFormat(prefix, v2)
val base = round(v1, major)
val end = ((v2 - base) / minor).toInt + 1
var pos = 0
while (pos <= end) {
val v = base + pos * minor
if (v >= v1 && v <= v2) {
val label = prefix.format(v, labelFmt)
ticks += ValueTick(v, 0.0, pos % minorPerMajor == 0, Some(label))
}
pos += 1
}
val ts = ticks.result()
val useOffset = majorLabelDuplication(ts)
if (useOffset) {
if (prevPrefix == null && v2 < (year.factor * 2) && v2 > 1e-3) {
val previousPrefix = prevDurationPrefix(prefix)
return durationTicks(v1, v2, t, previousPrefix)
}
val range = v2 - v1
val offsetPrefix = getDurationPrefix(range, major)
val newFormat = durationLabelFormat(prefix, major)
ts.map(t =>
t.copy(offset = base, labelOpt = Some(offsetPrefix.format(t.v - base, newFormat)))
)
} else ts
}