Exemplo n.º 1
0
        /// <summary>
        /// Called when initialized.
        /// </summary>
        protected override void OnInitialized()
        {
            if (Grid != null)
            {
                Grid.AddColumn(this);

                if (!string.IsNullOrEmpty(FilterProperty) || Type == null)
                {
                    var property = GetFilterProperty();

                    if (!string.IsNullOrEmpty(property))
                    {
                        _filterPropertyType = PropertyAccess.GetPropertyType(typeof(TItem), property);
                    }
                }

                if (_filterPropertyType == null)
                {
                    _filterPropertyType = Type;
                }
                else
                {
                    propertyValueGetter = PropertyAccess.Getter <TItem, object>(Property);
                }

                if (_filterPropertyType == typeof(string))
                {
                    FilterOperator = FilterOperator.Contains;
                }
            }
        }
Exemplo n.º 2
0
        Func <object, T> Getter <T>(object data, string property)
        {
            if (string.IsNullOrEmpty(property))
            {
                return((value) => (T)value);
            }

            return(PropertyAccess.Getter <T>(data, property));
        }
        /// <inheritdoc />
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var needsReload = false;

            if (parameters.DidParameterChange(nameof(Date), Date))
            {
                CurrentDate = parameters.GetValueOrDefault <DateTime>(nameof(Date));
                needsReload = true;
            }

            if (parameters.DidParameterChange(nameof(SelectedIndex), SelectedIndex))
            {
                selectedIndex = parameters.GetValueOrDefault <int>(nameof(SelectedIndex));
                needsReload   = true;
            }

            if (parameters.DidParameterChange(nameof(Data), Data))
            {
                appointments = null;
            }

            if (parameters.DidParameterChange(nameof(StartProperty), StartProperty))
            {
                startGetter = PropertyAccess.Getter <TItem, DateTime>(parameters.GetValueOrDefault <string>(nameof(StartProperty)));
            }

            if (parameters.DidParameterChange(nameof(EndProperty), EndProperty))
            {
                endGetter = PropertyAccess.Getter <TItem, DateTime>(parameters.GetValueOrDefault <string>(nameof(EndProperty)));
            }

            if (parameters.DidParameterChange(nameof(TextProperty), TextProperty))
            {
                textGetter = PropertyAccess.Getter <TItem, string>(parameters.GetValueOrDefault <string>(nameof(TextProperty)));
            }

            await base.SetParametersAsync(parameters);

            if (needsReload)
            {
                await InvokeLoadData();
            }
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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,
            });
        }