private void DrawValueGrid() { float pixels = RenderArea.height; // number of available pixels to render value grid double deltaValue = MaxValue - MinValue; if (_LabelStyle != null) { _PixelRequiredForLabel = _LabelStyle.CalcSize(_SampleText).y; // number of pixel required to draw a value label } else { _PixelRequiredForLabel = 10; } int num = Mathf.FloorToInt(pixels / (_PixelRequiredForLabel * 3));// number of labels can we draw _BigStep = deltaValue / num; bool extraDecimal = TimeBar.NormalizeStep(ref _BigStep);// normalize step to first upper round value if (_BigStep >= 0.1) { _Format = extraDecimal ? "{0:F2}" : "{0:F1}"; _Factor = 10; } else if (_BigStep >= 0.01) { _Format = extraDecimal ? "{0:F3}" : "{0:F2}"; _Factor = 100; } else if (_BigStep >= 0.001) { _Format = extraDecimal ? "{0:F4}" : "{0:F3}"; _Factor = 1000; } else { _Format = extraDecimal ? "{0:F5}" : "{0:F4}"; _Factor = 10000; } bool fiveSplit = (long)(_BigStep * _Factor) % 10 == 5; _SmallStep = _BigStep * (fiveSplit ? 0.2 : 0.5); _Factor = 1000000; // scale doubles and convert to longs because of better divide precision _LongStep = (long)(_BigStep * _Factor); _LongMiniStep = (long)(_SmallStep * _Factor); _LongMinValue = (long)(MinValue * _Factor); _LongMaxValue = (long)(MaxValue * _Factor); _LongFirstStep = (_LongMinValue / _LongMiniStep + 1) * _LongMiniStep; _DPy = pixels / deltaValue; // number of pixel required for each unit of time long fs = _LongFirstStep; // start by first time while (fs < _LongMaxValue) { float y = (float)((double)(fs - _LongMinValue) / _Factor * _DPy); if (fs % _LongStep == 0) { DrawHorizontalLine(y, true); string text = GetFormattedTime(fs); DrawText(y, text); } else { DrawHorizontalLine(y, false); } fs += _LongMiniStep; } }