예제 #1
0
        public virtual ScaleBase TransformCategoryScale(ScaleBase scale)
        {
            if (Items == null)
            {
                return(scale);
            }

            if (Items.Any())
            {
                scale.Input.MergeWidth(ScaleRange.From(Items, Category(scale)));
            }

            if (IsNumeric(CategoryProperty))
            {
                return(scale);
            }

            if (IsDate(CategoryProperty))
            {
                return(new DateScale
                {
                    Input = scale.Input,
                    Output = scale.Output
                });
            }

            Func <TItem, object> category = String.IsNullOrEmpty(CategoryProperty) ? (item) => string.Empty : PropertyAccess.Getter <TItem, object>(CategoryProperty);

            var data = Items.Select(category).ToList();

            if (scale is OrdinalScale ordinal)
            {
                foreach (var item in ordinal.Data)
                {
                    if (!data.Contains(item))
                    {
                        var index = ordinal.Data.IndexOf(item);
                        if (index <= data.Count)
                        {
                            data.Insert(index, item);
                        }
                        else
                        {
                            data.Add(item);
                        }
                    }
                }
            }

            return(new OrdinalScale
            {
                Data = data,
                Input = scale.Input,
                Output = scale.Output,
            });
        }
예제 #2
0
        public virtual ScaleBase TransformValueScale(ScaleBase scale)
        {
            if (Items != null)
            {
                if (Items.Any())
                {
                    scale.Input.MergeWidth(ScaleRange.From(Items, Value));
                }
            }

            return(scale);
        }
예제 #3
0
 public bool IsEqualTo(ScaleRange range)
 {
     return(Start == range.Start && End == range.End);
 }
예제 #4
0
 public void MergeWidth(ScaleRange range)
 {
     Start = Math.Min(Start, range.Start);
     End   = Math.Max(End, range.End);
 }