Beispiel #1
0
        /// <summary>
        /// Determines whether the specified scale is equal to the current one.
        /// </summary>
        /// <param name="scale">The scale.</param>
        /// <returns><c>true</c> if the scales are equal; otherwise, <c>false</c>.</returns>
        public bool IsEqualTo(ScaleBase scale)
        {
            if (GetType() != scale.GetType())
            {
                return(false);
            }

            return(Input.IsEqualTo(scale.Input) && Output.IsEqualTo(scale.Output));
        }
Beispiel #2
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,
            });
        }
Beispiel #3
0
 internal string Format(ScaleBase scale, object value)
 {
     if (Formatter != null)
     {
         return(Formatter(value));
     }
     else
     {
         return(scale.FormatTick(FormatString, value));
     }
 }
Beispiel #4
0
        public virtual ScaleBase TransformValueScale(ScaleBase scale)
        {
            if (Items != null)
            {
                if (Items.Any())
                {
                    scale.Input.MergeWidth(ScaleRange.From(Items, Value));
                }
            }

            return(scale);
        }
Beispiel #5
0
        protected Func <TItem, double> Category(ScaleBase scale)
        {
            if (IsNumeric(CategoryProperty))
            {
                return(PropertyAccess.Getter <TItem, double>(CategoryProperty));
            }

            if (IsDate(CategoryProperty))
            {
                var category = PropertyAccess.Getter <TItem, DateTime>(CategoryProperty);

                return((item) => category(item).Ticks);
            }

            if (scale is OrdinalScale ordinal)
            {
                Func <TItem, object> category = String.IsNullOrEmpty(CategoryProperty) ? (item) => string.Empty : PropertyAccess.Getter <TItem, object>(CategoryProperty);

                return((item) => ordinal.Data.IndexOf(category(item)));
            }

            return((item) => Items.IndexOf(item));
        }
Beispiel #6
0
 protected Func <TItem, double> ComposeValue(ScaleBase scale)
 {
     return(scale.Compose(Value));
 }
Beispiel #7
0
 protected Func <TItem, double> ComposeCategory(ScaleBase scale)
 {
     return(scale.Compose(Category(scale)));
 }
Beispiel #8
0
 public abstract RenderFragment Render(ScaleBase categoryScale, ScaleBase valueScale);
Beispiel #9
0
        internal string Format(ScaleBase scale, double idx)
        {
            var value = scale.Value(idx);

            return(Format(scale, value));
        }
Beispiel #10
0
 /// <inheritdoc />
 public override ScaleBase TransformValueScale(ScaleBase scale)
 {
     return(base.TransformCategoryScale(scale));
 }