Exemplo n.º 1
0
        internal void UpdateAxisTickValueList(Axis axis)
        {
            if (axis.IsTime())
            {
                var lastCount = axis.context.labelValueList.Count;
                DateTimeUtil.UpdateTimeAxisDateTimeList(axis.context.labelValueList, (int)axis.context.minValue,
                                                        (int)axis.context.maxValue, axis.splitNumber);

                if (axis.context.labelValueList.Count != lastCount)
                {
                    axis.SetAllDirty();
                }
            }
            else if (axis.IsValue())
            {
                var list      = axis.context.labelValueList;
                var lastCount = list.Count;
                list.Clear();

                var range = axis.context.maxValue - axis.context.minValue;
                if (range <= 0)
                {
                    return;
                }

                double tick = axis.interval;

                if (axis.interval == 0)
                {
                    if (axis.splitNumber > 0)
                    {
                        tick = range / axis.splitNumber;
                    }
                    else
                    {
                        var each = GetTick(range);
                        tick = each;
                        if (range / tick > 8)
                        {
                            tick = 2 * each;
                        }
                        else if (range / tick < 4)
                        {
                            tick = each / 2;
                        }
                    }
                }
                var value = 0d;
                if (Mathf.Approximately((float)(axis.context.minValue % tick), 0))
                {
                    value = axis.context.minValue;
                }
                else
                {
                    list.Add(axis.context.minValue);
                    value = Math.Ceiling(axis.context.minValue / tick) * tick;
                }
                var maxSplitNumber = chart.settings.axisMaxSplitNumber;
                while (value <= axis.context.maxValue)
                {
                    list.Add(value);
                    value += tick;

                    if (maxSplitNumber > 0 && list.Count > maxSplitNumber)
                    {
                        break;
                    }
                }
                if (!ChartHelper.IsEquals(axis.context.maxValue, list[list.Count - 1]))
                {
                    list.Add(axis.context.maxValue);
                }
                if (lastCount != list.Count)
                {
                    axis.SetAllDirty();
                }
            }
        }